forked from ShibuyaKosuke/laravel-yasumi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from inquid/Phpunit
Phpunit
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"> | ||
<coverage/> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShibuyaKosuke\LaravelYasumi\Tests; | ||
|
||
use Illuminate\Config\Repository; | ||
use Illuminate\Support\Carbon; | ||
use ReflectionException; | ||
use ShibuyaKosuke\LaravelYasumi\Holiday; | ||
use Yasumi\Exception\MissingTranslationException; | ||
|
||
class HolidayTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider holidayDataProvider | ||
* @return array[] | ||
*/ | ||
public static function holidayDataProvider() | ||
{ | ||
return [ | ||
[ 'Japan', 'ja_JP', '2020-01-01', '元日' ], | ||
[ 'Japan', 'ja_JP', '2020-01-13', '成人の日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-11', '建国記念の日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-23', '天皇誕生日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-24', '振替休日 (天皇誕生日)' ], | ||
[ 'Japan', 'ja_JP', '2020-03-20', '春分の日' ], | ||
[ 'Japan', 'ja_JP', '2020-04-29', '昭和の日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-03', '憲法記念日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-04', 'みどりの日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-05', 'こどもの日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-06', '振替休日 (憲法記念日)' ], | ||
[ 'Japan', 'ja_JP', '2020-07-23', '海の日' ], | ||
[ 'Japan', 'ja_JP', '2020-07-24', 'スポーツの日' ], | ||
[ 'Japan', 'ja_JP', '2020-08-10', '山の日' ], | ||
[ 'Japan', 'ja_JP', '2020-09-21', '敬老の日' ], | ||
[ 'Japan', 'ja_JP', '2020-09-22', '秋分の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-03', '文化の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-23', '勤労感謝の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-23', '勤労感謝の日' ], | ||
[ 'Spain', 'es', '2021-01-01', 'Año Nuevo' ], | ||
[ 'USA', 'en_US', '2020-01-01', 'New Year’s Day' ], | ||
[ 'USA', 'en_US', '2020-01-20', 'Dr. Martin Luther King Jr’s Birthday' ], | ||
[ 'USA', 'en_US', '2020-02-17', 'Washington’s Birthday' ], | ||
[ 'USA', 'en_US', '2020-05-25', 'Memorial Day' ], | ||
[ 'USA', 'en_US', '2020-07-03', 'Independence Day observed' ], | ||
[ 'USA', 'en_US', '2020-09-07', 'Labor Day' ], | ||
[ 'USA', 'en_US', '2020-10-12', 'Columbus Day' ], | ||
[ 'USA', 'en_US', '2020-11-11', 'Veterans Day' ], | ||
[ 'USA', 'en_US', '2020-11-26', 'Thanksgiving Day' ], | ||
[ 'USA', 'en_US', '2020-12-25', 'Christmas' ], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $country | ||
* @param string $locale | ||
* @param string $date | ||
* @param string $expectedHoliday | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testCanGetHolidays($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date); | ||
$holidayResult = $holiday->get($newYear); | ||
$this->assertEquals($expectedHoliday, $holidayResult); | ||
} | ||
|
||
/** | ||
* Test isHoliday method. | ||
* | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testIsHoliday($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date); | ||
$this->assertTrue($holiday->isHoliday($newYear)); | ||
} | ||
|
||
/** | ||
* Test isBeforeHoliday method. | ||
* | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testIsDayBeforeHoliday($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date)->subDay(); | ||
$this->assertTrue($holiday->isDayBeforeHoliday($newYear)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShibuyaKosuke\LaravelYasumi\Tests; | ||
|
||
abstract class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
} |