Skip to content

Commit

Permalink
Merge pull request #1 from inquid/Phpunit
Browse files Browse the repository at this point in the history
Phpunit
  • Loading branch information
gogl92 authored Dec 7, 2023
2 parents 51421bd + c6bf359 commit fd2a7fa
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
php: [7.4,8.0,8.1]
php: [8.1, 8.2]
dependency-version: [prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
Expand All @@ -25,3 +25,6 @@ jobs:

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Run tests
run: composer test
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"ShibuyaKosuke\\LaravelYasumi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ShibuyaKosuke\\LaravelYasumi\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
Expand All @@ -27,5 +32,11 @@
"Holiday": "ShibuyaKosuke\\LaravelYasumi\\Facades\\Holiday"
}
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"require-dev": {
"phpunit/phpunit": "^10.5"
}
}
17 changes: 17 additions & 0 deletions phpunit.xml
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>
117 changes: 117 additions & 0 deletions tests/HolidayTest.php
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));
}
}
10 changes: 10 additions & 0 deletions tests/TestCase.php
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
{

}

0 comments on commit fd2a7fa

Please sign in to comment.