diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f701bc8..1e457a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} @@ -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 diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..0a88aac --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,39 @@ +name: PHP Composer + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" + # Docs: https://getcomposer.org/doc/articles/scripts.md + + - name: Run test suite + run: composer test diff --git a/composer.json b/composer.json index c005884..7745b30 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,11 @@ "ShibuyaKosuke\\LaravelYasumi\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "ShibuyaKosuke\\LaravelYasumi\\Tests\\": "tests/" + } + }, "extra": { "laravel": { "providers": [ @@ -27,5 +32,11 @@ "Holiday": "ShibuyaKosuke\\LaravelYasumi\\Facades\\Holiday" } } + }, + "scripts": { + "test": "vendor/bin/phpunit" + }, + "require-dev": { + "phpunit/phpunit": "^10.5" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c95503b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,17 @@ + + + + + + ./tests + + + + + + + + ./src + + + diff --git a/tests/HolidayTest.php b/tests/HolidayTest.php new file mode 100644 index 0000000..909a1a1 --- /dev/null +++ b/tests/HolidayTest.php @@ -0,0 +1,117 @@ + [ + '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)); + } +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..f3261b7 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,10 @@ +