diff --git a/.cliffignore b/.cliffignore new file mode 100644 index 000000000..882753204 --- /dev/null +++ b/.cliffignore @@ -0,0 +1,5 @@ +# skip commits by their SHA1 + +# 2.8.0 release +074fe08b5e48cea705943f5d77d0fc8956aa3be8 +4049db27e2dc197865aa857531d6baaa4e76be04 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..cf96b88c1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.json] +indent_size = 2 + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..0fd4e90d0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.php_cs export-ignore +/CHANGELOG.md export-ignore +/CODE_OF_CONDUCT.md export-ignore +/CONTRIBUTING.md export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..2eff6b978 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml new file mode 100644 index 000000000..cdc6bc00b --- /dev/null +++ b/.github/workflows/coding-standard.yml @@ -0,0 +1,53 @@ +name: "Coding Standard" + +on: + - push + - pull_request + +jobs: + run: + name: "CI" + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.2", "8.3", "8.4", "8.5"] + + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout + uses: actions/checkout@v6 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: intl + + - name: Get Composer Cache Directory + id: composer-cache + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v5 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Check Composer configuration + run: composer validate --strict + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Check Code Style + run: vendor/bin/php-cs-fixer --diff --dry-run -v fix + env: + PHP_CS_FIXER_IGNORE_ENV: 1 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 000000000..bae5a657b --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,30 @@ +name: "Stale issues and pull requests" + +on: + schedule: + - cron: "0 0 * * *" + +env: + DAYS_BEFORE_CLOSE: 10 + DAYS_BEFORE_STALE: 90 + +jobs: + stale: + + runs-on: "ubuntu-latest" + + steps: + - name: "Prune stale issues and pull requests" + uses: "actions/stale@v10.2.0" + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + days-before-close: "${{ env.DAYS_BEFORE_CLOSE }}" + days-before-stale: "${{ env.DAYS_BEFORE_STALE }}" + stale-issue-label: "no-issue-activity" + stale-issue-message: | + Since this issue has not had any activity within the last ${{ env.DAYS_BEFORE_STALE }} days, I have marked it as stale. + I will close it if no further activity occurs within the next ${{ env.DAYS_BEFORE_CLOSE }} days. + stale-pr-label: "no-pr-activity" + stale-pr-message: | + Since this pull request has not had any activity within the last ${{ env.DAYS_BEFORE_STALE }} days, I have marked it as stale. + I will close it if no further activity occurs within the next ${{ env.DAYS_BEFORE_CLOSE }} days. diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..8e5d5c40c --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,51 @@ +name: "Static analysis" + +on: + - push + - pull_request + +jobs: + run: + name: "CI" + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.2", "8.3", "8.4", "8.5"] + + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout + uses: actions/checkout@v6 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: intl + + - name: Get Composer Cache Directory + id: composer-cache + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v5 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Check Composer configuration + run: composer validate --strict + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Run static analysis - PHPStan + run: composer phpstan diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 000000000..3ad1ead67 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,51 @@ +name: "Testing" + +on: + - push + - pull_request + +jobs: + run: + name: "CI" + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.2", "8.3", "8.4", "8.5"] + + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout + uses: actions/checkout@v6 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: intl, calendar + + - name: Get Composer Cache Directory + id: composer-cache + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v5 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Check Composer configuration + run: composer validate --strict + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Run unit tests + run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 84c417656..3244eed84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ .DS_Store .idea/ -vendor -composer.lock +.php-cs-fixer.cache .php_cs.cache -bin/_* +.phpactor.json +.phpunit.cache .phpunit.result.cache +bin/_* +composer.lock +var +vendor diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 000000000..067aa0e2d --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,27 @@ + + */ + +$config = new AzuyaLabs\PhpCsFixerConfig\Config('2015', null, 'Yasumi'); +$config->getFinder()->in(__DIR__)->notPath('var'); + +$defaults = $config->getRules(); + +$config->setRules(array_merge($defaults, [ + 'php_unit_method_casing' => ['case' => 'camel_case'], +])); + +return $config; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 231c3b0a2..000000000 --- a/.php_cs +++ /dev/null @@ -1,24 +0,0 @@ - - */ - -$finder = PhpCsFixer\Finder::create()->in(__DIR__); - -return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([ - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'native_function_invocation' => true, - 'ordered_imports' => ['sortAlgorithm' => 'alpha'], - 'no_unused_imports' => true, - 'single_quote' => true, - 'space_after_semicolon' => true, - 'trailing_comma_in_multiline_array' => true - ])->setLineEnding("\n")->setFinder($finder); \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 330bafe04..000000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,23 +0,0 @@ -checks: - php: - code_rating: true - duplication: false - no_short_open_tag: true - no_debug_code: true - -tools: - external_code_coverage: false - php_code_sniffer: true - php_mess_detector: true - php_cs_fixer: - config: { level: psr2 } - -filter: - paths: [src/*] - -build: - nodes: - analysis: - tests: - override: - - php-scrutinizer-run \ No newline at end of file diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index b508228b0..000000000 --- a/.styleci.yml +++ /dev/null @@ -1,12 +0,0 @@ -preset: psr2 - -risky: true - -enabled: - - short_array_syntax - - native_function_invocation - - alpha_ordered_imports - - no_unused_imports - - single_quote - - space_after_semicolon - - trailing_comma_in_multiline_array \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 288d5033c..000000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4snapshot - - nightly - -dist: trusty -sudo: required - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - if [[ $HHVM == true ]]; then sudo apt-get update; fi - - if [[ $HHVM == true ]]; then sudo apt-get install hhvm=3.\*; fi - -before_script: - - composer self-update - - composer install --no-interaction - -script: - - if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.11 && vendor/bin/phpstan analyse -l 5 src; fi - - ./vendor/bin/phpunit - - phpenv config-rm xdebug.ini || return 0 - - ./vendor/bin/php-cs-fixer --diff --dry-run -v fix - -matrix: - allow_failures: - - php: 7.1 - - php: 7.4snapshot - - php: hhvm - - php: nightly - - include: - - php: 7.1 - env: PHPSTAN=1 - - php: 7.2 - env: PHPSTAN=1 - - php: 7.3 - env: PHPSTAN=1 - - php: 7.4snapshot - env: PHPSTAN=1 - - php: hhvm - env: HHVM=true diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..2fdf270d9 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,76 @@ +# Yasumi — Agent Instructions + +Yasumi is a PHP library for calculating public holidays across countries and regions. +It is calculation-driven (no database), provider-based (one class per country/region), +and PSR-12/PSR-4 compliant. + +## Project Structure + +``` +src/Yasumi/ + Yasumi.php # Main entry point / factory + Holiday.php # Represents a single holiday + SubstituteHoliday.php # Substituted holiday + ProviderInterface.php # Contract all providers must implement + Translations.php # Holiday name translations + Provider/ # One file (or directory) per country/region + AbstractProvider.php # Base class for all providers + CommonHolidays.php # Reusable holiday calculations (New Year's, etc.) + ChristianHolidays.php # Easter and related calculations + *.php / */ # Country and sub-region providers + Filters/ # Holiday type filters (Official, Bank, etc.) + data/ # Translation data files +tests/ # PHPUnit tests, mirroring src structure +examples/ # Usage examples +``` + +## Requirements + +- PHP 8.2+ +- `ext-json` (required), `ext-intl` (dev), `ext-calendar` (optional, for Easter) + +## Key Commands + +```shell +composer test # Run the full PHPUnit test suite +composer cs # Check coding standard (dry-run) +composer cs-fix # Auto-fix coding standard violations (alias: composer format) +composer phpstan # Run static analysis (level 8) +``` + +## Coding Conventions + +- **PSR-12** coding standard enforced via `php-cs-fixer`. Always run `composer cs-fix` after changes. +- **PSR-4** autoloading: `Yasumi\` → `src/Yasumi/`, `Yasumi\tests\` → `tests/`. +- Strict types (`declare(strict_types=1)`) are required in all PHP files. +- Holiday providers extend `AbstractProvider` and implement `initialize()`. + +## Adding a New Holiday Provider + +1. Create `src/Yasumi/Provider/{CountryName}.php` extending `AbstractProvider`. +2. Implement `initialize()`: call `addHoliday()` for each holiday. +3. Implement `getSources()`: list of external resources. +4. Add translations to `src/Yasumi/data/`. +5. Create `tests/{CountryName}/{CountryName}BaseTestCase.php` (shared assertions). +6. Create `tests/{CountryName}/{CountryName}Test.php` (country-level tests asserting all expected holidays). +7. Add a `` entry in `phpunit.xml.dist`. +8. Each test must cover multiple years; respect establishment/abolition years of holidays. + +## Testing + +- All new providers and holidays **must** have unit tests — PRs without tests are not accepted. +- Tests use PHPUnit 11 and iterate over a range of years automatically. +- Run a specific suite: `vendor/bin/phpunit --testsuite Netherlands` + +## Static Analysis + +- PHPStan at level 8. Run `composer phpstan` and fix all errors before committing. +- Ignored errors are listed in `phpstan.neon.dist`; do not add new ignores without good reason. + +## Pull Request Guidelines + +- One PR per feature or country provider. +- Run `composer test`, `composer cs`, and `composer phpstan` before submitting. +- Adhere to conventional commits for commit conventions. +- Squash intermediate commits; keep history meaningful. +- Branch off `develop`; target `develop` for PRs. diff --git a/CHANGELOG-ARCHIVE.md b/CHANGELOG-ARCHIVE.md new file mode 100644 index 000000000..79e22c986 --- /dev/null +++ b/CHANGELOG-ARCHIVE.md @@ -0,0 +1,816 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +Changes related to the business logic of the holidays or their providers are listed first, followed by any technical or architectural +changes. + +## [2.7.0] - 2024-01-02 + +### Added + +- Mexico Provider [\#329](https://github.com/azuyalabs/yasumi/pull/329) ([Luis Gonzalez](https://github.com/gogl92)). +- From 2024, Romania will officially include the holidays of St. Johns ('Sfântul Ioan Botezătorul') and Epiphany ('Bobotează'). + [#310](https://github.com/azuyalabs/yasumi/pull/310) ([AngelinCalu](https://github.com/AngelinCalu) ) +- For the German state of Mecklenburg-Western Pomerania, International Women's Day is considered to be officially + observed. [#311](https://github.com/azuyalabs/yasumi/pull/311) ([ihmels](https://github.com/ihmels)) +- Recently, the South Korean government announced a bill to apply alternative public holidays to Buddha's Day + and Christmas Day. + [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- Extra checks in case date subtraction fails for some holiday providers. +- PHP 8.3 support for the unit test CI pipeline. [#328](https://github.com/azuyalabs/yasumi/pull/328) ([fezfez](https://github.com/fezfez)) +- Add code styling rules to have a space after the `NOT` operator and mark parameters with a default null value as nullable. + +### Changed + +- Refactor the rules for calculating holidays in South Korea based on the history of holiday changes. + ([#314](https://github.com/azuyalabs/yasumi/issues/314)) [barami](https://github.com/barams@gmail.com) +- Update links to related documentation in the South Korea provider's note and added links to conversion utilities. + [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- Optimize the method for the Emperor's birthday calculation in Japan. +- For Croatia, extract Day of Antifascist Struggle calculation to a private method and simplify Statehood Day calculation + to make it more concise. +- Simplify the conditions for the Coming of Age day (Japan) calculation. +- Simplify the calculation of Carnival in Argentina, Brazil and the Netherlands to reduce duplication. +- Avoid silent exceptions by throwing a new one from the previous exception. + +### Fixed + +- For South Korea, some of the past dates for Buddha's Day, Chuseok, Armed Forces Day + and United Nations Day were incorrectly calculated during for certain periods. [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- The holiday `twoDaysLaterNewYearsDay` of South Korea has been removed from 1990, however the unit test for the name + and holiday type allowed the possible testing range to include the year 1990. +- New Years Day tests for South Korea were failing due to incorrect date checks. +- The Easter Date calculation resulted in wrong values for the year 2025, due to an incorrect rounding for the lunar + correction when the calendar extension is not used. [#326](https://github.com/azuyalabs/yasumi/pull/326) ([rChassat](https://github.com/rChassat)) + +### Removed + +- Denmark will abolish Great Prayer Day ('store bededag') from 2024. [#308](https://github.com/azuyalabs/yasumi/pull/308) ([c960657](https://github.com/c960657)) +- Summertime and Wintertime in the Netherlands and Denmark as these can't be reliably established for historical dates and + aren't true holidays in the context of Yasumi. Refer to this [discussion](https://github.com/azuyalabs/yasumi/discussions/321) + for further details and rationale. [#322](https://github.com/azuyalabs/yasumi/pull/322) +- PHP 7.4 support. +- The PHP [Infection](https://infection.github.io/) test package as it was hardly used. +- Unit tests from a Git export to reduce the export size. [#323](https://github.com/azuyalabs/yasumi/pull/323) ([fezfez](https://github.com/fezfez)) +- Checks for superfluous naming as we follow PER which supports such convention. +- MacOS from testing matrix as it returns errors (requires further investigation). + +## [2.6.0] - 2023-04-27 + +### Added + +- Bank holiday for King Charles III’s Coronation in the United Kingdom. [\#305](https://github.com/azuyalabs/yasumi/pull/305) ([Freshleaf Media](https://www.github.com/freshleafmedia)) +- Bank holiday for Queen Elizabeth II’s State Funeral on September 19, 2022, for the United Kingdom. [\#287](https://github.com/azuyalabs/yasumi/pull/287) ([Freshleaf Media](https://www.github.com/freshleafmedia)) +- National Day of Mourning for Australia. [\#288](https://github.com/azuyalabs/yasumi/pull/288) ([FuzzyWuzzyFraggle](https://www.github.com/FuzzyWuzzyFraggle)). +- In Japan, Marine Day was rescheduled to July 23 as the 2020 Tokyo Olympics took place. The rescheduled Marine Day for + 2021 was included, but not the original rescheduled day for 2020. +- Slovak translations for a couple of popular holidays. [\#298](https://github.com/azuyalabs/yasumi/pull/298) ([Jozef Grencik](https://www.github.com/jozefgrencik)) +- All examples as shown on the documentation site as a convenience to developers who like to have all information in a + single place. +- Included an `.editorconfig` file to maintain a consistent style for developers using different text editors. +- The `ext-intl` extension as a required extension. [\#306](https://github.com/azuyalabs/yasumi/pull/306) ([Freshleaf Media](https://www.github.com/freshleafmedia)) +- An exception is thrown in case the time stamp of the start and end date in the `dateTimeBetween` method can't be established. +- Checks in case getting transition details or a date interval subtraction fails. + +### Changed + +- Adjusted the visibility of the `calculateSummerWinterTime` method to `private` as it is an internal method and + shouldn't be accessible directly. +- Made the calculation for summer/winter time more defensive by adding a check that the timestamps are successfully created. +- Changed to use the `strtotime` function as `mktime` does not generate timestamps before 1970-01-01 (negative values), + which is needed to determine winter/summertime before that. +- Refactored summer and winter time tests for Denmark and The Netherlands by introducing a base class holding the domain + logic. +- Switched from `getShortName()` to `getName()` for the `ReflectionClass` created by the method `anotherTime()` in the + `AbstractProvider` class. Using `getShortName` could result in a `ProviderNotFoundException` for some custom holiday + providers, since the namespace is not fully qualified. This can happen, if you create a custom holiday provider. + [\#292](https://github.com/azuyalabs/yasumi/pull/292) ([SupraSmooth](https://github.com/SupraSmooth)). +- Replaced the use of the `DateTime` class with `DateTimeInterface` (always use interface where possible). +- Use the preferred/idiomatic way of getting an immutable date from a mutable one. Added extra checks if modifying date + methods are not successful. +- Split functions that generate random dates/years into a new trait to slim down the overgrown base trait. +- Code styling fixes and improvements. +- Upgraded dependencies to latest working versions. +- Improved and cleaned up numerous unit tests. + +### Fixed + +- Liberation Day for The Netherlands is only an official holiday every 5 years [\#280](https://github.com/azuyalabs/yasumi/pull/280) ([Daan Roet](https://github.com/droet)). +- Pentecost Monday in France was only recognized as an official holiday until 2004. Since 2004, it is considered a + special holiday, a so called 'working holiday'. Hence, it is therefore classified as an observed holiday in Yasumi + from 2004 and forward. [\#281](https://github.com/azuyalabs/yasumi/issues/281). +- The holiday of Epiphany (6th of January) was incorrectly categorized as `other` and changed to an official holiday in + Baden-Württemberg, Bavaria and SaxonyAnhalt. [\#296](https://github.com/azuyalabs/yasumi/issues/296) ([Anna Damm](https://github.com/AnnaDamm)). +- The year 1988 was incorrectly omitted from observing the Emperor's birthday in Japan. +- The tests for Remembrance Day, Malvina's Day and National Sovereignty Day in Argentina were considered for all years; + however, these have only been celebrated since their establishment. +- Tests for New Year's Day, Spring Bank Holiday, and May Day Holiday in the United Kingdom (England, Wales, Northern + Ireland, and Scotland), as well as Battle of the Boyne in Northern Ireland, were considered for any calendar year; + however, these are celebrated only since a particular calendar year. +- In version 2022f of the `tz` db, a correction for 1947 was made for the summertime transition in Denmark to April + the 6th. Various corrections have been made to accommodate for change. +- The `ProviderInterface::getHolidays` has been re-added after it was erroneously removed. [\#277](https://github.com/azuyalabs/yasumi/pull/277) ([Jakub Wojtyra](https://github.com/jwojtyra-aterian)). +- Created the interface methods of the `ProviderInterface` that the abstract provider class implements. Since the return + type of the Yasumi factory methods is now `ProviderInterface`, those missing methods generated errors, especially by + static analysers. +- Changed the visibility of various class methods back to `protected`. The visibility was accidentally reduced during a clean-up + of code. This caused these methods not being accessible any more when extending a provider class. + +### Removed + +- The `count` method from the `ProviderInterface` as the `AbstractProvider` class already implements the Countable interface. +- Unused `InvalidDateException` class and other unused imported classes. +- `tests` folder from analysis by PHPStan (the large number of files makes the analysis needlessly long). +- Redundant checks for empty arrays and types. +- Mutation testing from GitHub Actions, as currently the outcome is not actively used. Running mutation tests locally + should be sufficient. + +## [2.5.0] - 2022-01-30 + +### Added + +- Argentina Provider [\#264](https://github.com/azuyalabs/yasumi/pull/264) ([Nader Safadi](https://github.com/nedSaf)). +- Turkey Provider [\#250](https://github.com/azuyalabs/yasumi/pull/250). +- World Children's Day for Thuringia (Germany) [\#260](https://github.com/azuyalabs/yasumi/issues/260). +- New National Day for Truth and Reconciliation to + Canada [\#257](https://github.com/azuyalabs/yasumi/pull/257) ([Owen V. Gray](https://github.com/adrx)). +- New Juneteenth National Independence Day to + USA [\#253](https://github.com/azuyalabs/yasumi/pull/253) ([Mark Heintz](https://github.com/mheintz)). +- The Korea Tourism Organization's holiday guide link was added to the source of South Korea + Provider. [\#255](https://github.com/azuyalabs/yasumi/pull/255) ([barami](https://github.com/barami)). +- Mothering Day for the United Kingdom [\#266](https://github.com/azuyalabs/yasumi/issues/266). + +- All holiday providers now include a method that returns a list of external sources (i.e. references to websites, + books, scientific papers, etc.) that are used for determining the calculation logic of the providers' holidays. + +### Changed + +- Revised rules to calculate substitution holidays of South Korea to apply the newly enacted law on June 2021. [\#255](https://github.com/azuyalabs/yasumi/pull/255) ([barami](https://github.com/barami)). +- Separate `calculateSubstituteHolidays` method of South Korea Provider to `calculateSubstituteHolidays` + and `calculateOldSubstituteHolidays` + . [\#255](https://github.com/azuyalabs/yasumi/pull/255) ([barami](https://github.com/barami)) +- Refactored the tests of South Korea provider to testing substitution + holidays. [\#255](https://github.com/azuyalabs/yasumi/pull/255) ([barami](https://github.com/barami)). +- Moved the United Kingdom Spring Bank Holiday to June 2nd and added Platinum Jubilee bank holiday on June 3rd + for [\#270](https://github.com/azuyalabs/yasumi/issues/270) ([Dan](https://github.com/dch-dev)). + +- Provider tests must implement the `ProviderTestCase` interface to ensure all required test methods are defined. +- `YasumiTestCaseInterface` was renamed to `HolidayTestCase` to better match the newly added `ProviderTestCase` + interface. +- Updated codebase using PHP7.4 syntax features. +- Upgraded PHP CS Fixer to v3. + +### Fixed + +- All Saints Day (German: 'AllerHeiligen') was classified as `Other` for states celebrating this day. This was + incorrect (or officially changed) and has been altered to `Official` + . [\#263](https://github.com/azuyalabs/yasumi/issues/263) +- Corpus Christi (German: 'Fronleichnam') was classified as `Other` for states celebrating this day. This was + incorrect (or officially changed) + and has been altered to `Official`. [\#252](https://github.com/azuyalabs/yasumi/issues/252). +- The test for the USA in that juneteenthDay was considered for all years: it is only celebrated since 2021. +- Definition of Canada Day in Canada [\#257](https://github.com/azuyalabs/yasumi/pull/257) in that, Canada Day is July 1 + if that day is not Sunday, and July 2 if July 1 is a Sunday.([Owen V. Gray](https://github.com/adrx)). + +- Reverted the visibility of the `AbstractProvider->getHolidaDates()` method as it incorrectly was set to `protectecd`. + +### Removed + +- PHP7.3 Support as it is End of Life. + +## [2.4.0] - 2021-05-09 + +### Added + +- Georgia + Provider [\#245](https://github.com/azuyalabs/yasumi/pull/245) ([Zurab Sardarov](https://github.com/zsardarov)) +- Pentecost (Sunday) to + Germany [\#225](https://github.com/azuyalabs/yasumi/pull/225) ([Patrick-Root](https://github.com/Patrick-Root)) + +- PHP8 Support [\#238](https://github.com/azuyalabs/yasumi/pull/238) ([Stéphane](https://github.com/fezfez)) +- Infection PHP to perform mutation testing. +- PHPStan to the dependencies allowing for local analysis. +- `.gitattributes` file to reduce the size of a release + package [\#237](https://github.com/azuyalabs/yasumi/pull/237) ([Stéphane](https://github.com/fezfez)) + +### Changed + +- Rescheduled exceptional Japanese holidays for Olympic Games 2020 after + COVID-19 [\#240](https://github.com/azuyalabs/yasumi/pull/240) ([tanakahisateru](https://github.com/tanakahisateru)) +- Some improvements/refactoring of the Swiss holiday providers (including source + references) [\#233](https://github.com/azuyalabs/yasumi/pull/233) ([Quentin Ligier](https://github.com/qligier)) + +- Allow the `WEEKEND_DATA` constant in provider classes to be + overridden. [\#235](https://github.com/azuyalabs/yasumi/pull/235) ([Mahmood Dhia](https://github.com/mdhia)) +- Upgraded PHPUnit's XML configuration. +- Refactored removing the magic numbers for the lower and upper limits of the calendar year. +- Reformatted code using new/updated Code Styling rules. +- Hardened error handling of json functions. +- Updated Copyright year. + +### Fixed + +- The test for North West Territories (Canada) in that the National Indigenous Peoples Day was considered for all years: + it is only celebrated since 1996. +- The test for NovaScotia (Canada) in that novaScotiaHeritageDay was considered for all years: it is only celebrated + since 2015. +- The test for Ontario (Canada) in that IslanderDay was considered for all years: it is only celebrated since 2009. +- The test for Marine Day (Japan) as the rescheduled day was moved to 2021 (due to the COVID-19 pandemic). +- Typo for Estonian Day of Restoration of + Independence [\#228](https://github.com/azuyalabs/yasumi/pull/228) ([Reijo Vosu](https://github.com/reijovosu)) + +- The substitute holiday unit test as the use of the `at()` method will be deprecated in PHPUnit 10. +- Incorrect invocation of `Fribourg::calculateBerchtoldsTag()` and `Fribourg::calculateDecember26th` (Switzerland) +- Use proper parameter and return type hinting +- Replaced the `mt_rand` function with the `random_int` function as it is cryptographically insecure. +- Some static functions were used as if they are object functions. + +### Removed + +- Travis/StyleCI/Scrutinizer services replaced by GitHub Actions. +- PHP 7.2 Support (PHP 7.2 is EOL) +- Faker library as it has been + sunset [\#238](https://github.com/azuyalabs/yasumi/pull/238) ([Stéphane](https://github.com/fezfez)) +- Native function invocations. +- Various undefined class references, unused imports, etc. +- Unnecessary curly braces in strings, `continue` keyword in while loops, typecasting. + +## [2.3.0] - 2020-06-22 + +### Added + +- Added Canada Provider [\#215](https://github.com/azuyalabs/yasumi/pull/215) ([lux](https://github.com/lux)) +- Added Luxembourg + Provider [\#205](https://github.com/azuyalabs/yasumi/pull/205) ([Arkounay](https://github.com/Arkounay)) +- Holiday providers for states of + Austria. [\#182](https://github.com/azuyalabs/yasumi/pull/182) ([aprog](https://github.com/aprog)) +- Added All Souls Day to + Lithuania [\#227](https://github.com/azuyalabs/yasumi/pull/227) ([norkunas](https://github.com/norkunas)) +- Catholic Christmas Day is a new official holiday since 2017 in the + Ukraine. [\#202](https://github.com/azuyalabs/yasumi/pull/202) +- Additional Dates for Australia/Victoria:AFL Grand Final + Friday [\#190](https://github.com/azuyalabs/yasumi/pull/190) ([brucealdridge](https://github.com/brucealdridge)) +- Substituted holidays (holidays that fall in the weekend) for + Australia. [\#201](https://github.com/azuyalabs/yasumi/pull/201) ([c960657](https://github.com/c960657)) +- Added New Years Eve to + Germany [\#226](https://github.com/azuyalabs/yasumi/pull/226) ([Patrick-Root](https://github.com/Patrick-Root)) +- Day of Liberation (Tag der Befreiung) is a one-time official holiday in 2020 in Berlin (Germany). +- Catalan translations for holidays in Catalonia, Valencian Community, Balearic Islands and + Aragon [\#189](https://github.com/azuyalabs/yasumi/pull/189) ([c960657](https://github.com/c960657)) +- Added American English spelling for Labour Day [\#216](https://github.com/azuyalabs/yasumi/issues/216) +- Added French translation for Second Christmas + Day [\#188](https://github.com/azuyalabs/yasumi/pull/188) ([Arkounay](https://github.com/Arkounay)) + +- Added accessor methods Holiday::getKey() and SubstituteHoliday:: + getSubstitutedHoliday() [\#220](https://github.com/azuyalabs/yasumi/pull/220)+[\#221](https://github.com/azuyalabs/yasumi/pull/221) ([c960657](https://github.com/c960657)) +- Added missing return (correct) and parameter types in various methods. + +### Changed + +- Renamed the Australian states to be full names instead of abbreviations to be in line with other Holiday + Providers [\#214](https://github.com/azuyalabs/yasumi/pull/214) +- Statehood Day is celebrated at a new date since 2020 in + Croatia. [\#203](https://github.com/azuyalabs/yasumi/pull/203) ([krukru](https://github.com/krukru)) +- Independence Day is no longer an official holiday since 2020 in + Croatia. [\#203](https://github.com/azuyalabs/yasumi/pull/203) ([krukru](https://github.com/krukru)) +- Homeland Thanksgiving Day has been renamed to "Victory and Homeland Thanksgiving Day and the Day of Croatian + Defenders" since 2020 in + Croatia. [\#203](https://github.com/azuyalabs/yasumi/pull/203) ([krukru](https://github.com/krukru)) +- Remembrance Day for Homeland War Victims and Remembrance Day for the Victims of Vukovar and Skabrnja is a new official + holiday since 2020 in + Croatia. [\#203](https://github.com/azuyalabs/yasumi/pull/203) ([krukru](https://github.com/krukru)) +- Second International Workers' Day in Ukraine was an official holiday only until 2018. [\#202](https://github.com/azuyalabs/yasumi/pull/202) +- Holiday names in Danish, Dutch, and Norwegian are no longer + capitalized. [\#185](https://github.com/azuyalabs/yasumi/pull/185) ([c960657](https://github.com/c960657)) + +- Changed the fallback from DEFAULT_LANGUAGE to ' + en'. [\#183](https://github.com/azuyalabs/yasumi/pull/183) ([c960657](https://github.com/c960657)) +- Introduced a DateTimeZoneFactory class to improve performance. This will keep a static reference to the instantiated + DateTimezone, thus saving + resources. [\#213](https://github.com/azuyalabs/yasumi/pull/213) ([pvgnd](https://github.com/pvgn)) +- Changed DateTime to DateTimeImmutable as dates should be that: immutable (by default) +- Explicitly set nullable parameters as such. +- Refactored various conditional structures. +- Changed signature of some methods as parameters with defaults should come after required parameters. +- Updated third party dependencies. + +### Fixed + +- Fixed Ukraine holidays on weekends. These days need to be + substituted. [\#202](https://github.com/azuyalabs/yasumi/pull/202) +- Fixed issue if the next working day happens to be in the next year (i.e. not in the year of the Yasumi + instance) [\#192](https://github.com/azuyalabs/yasumi/issues/192) ([tniemann](https://github.com/tniemann)) +- Fix locale fallback for substitute + holidays [\#180](https://github.com/azuyalabs/yasumi/pull/180) ([c960657](https://github.com/c960657)) +- Fixed issue if the previous working day happens to be in the previous year (i.e. not in the year of the Yasumi + instance) + +- Fixed compound conditions that are always true by simplifying the condition steps. + +### Deprecated + +- Deprecated direct access to public properties Holiday::$shortName and SubstituteHoliday::$substitutedHoliday in favor + of accessor methods [\#220](https://github.com/azuyalabs/yasumi/pull/220) ([c960657](https://github.com/c960657)) + +### Removed + +- PHP 7.1 Support, as it has reached its end of life. +- Removed the assertion of the instance type in some functions as it is already defined by the return type. +- Removed unused variables, namespaces, brackets, empty tests, etc. + +## [2.2.0] - 2019-10-06 + +### Added + +- Holiday providers for England, Wales, Scotland and Northern + Ireland [\#166](https://github.com/azuyalabs/yasumi/pull/166) ([c960657](https://github.com/c960657)) +- Holiday Provider for South + Korea. [\#156](https://github.com/azuyalabs/yasumi/pull/156) ([blood72](https://github.com/blood72)) +- Translation for the Easter holiday for the `fr_FR` + locale [\#146](https://github.com/azuyalabs/yasumi/pull/146) ([pioc92](https://github.com/pioc92)) +- Translation for the Pentecost holiday for the `fr_FR` + locale [\#145](https://github.com/azuyalabs/yasumi/pull/145) ([pioc92](https://github.com/pioc92)) +- Late Summer Bank Holiday in the United Kingdom prior to + 1965 [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657)) +- Observance holidays for + Sweden [\#172](https://github.com/azuyalabs/yasumi/pull/172) ([c960657](https://github.com/c960657)) +- Created a special subclass of Holiday for substitute + holidays [\#162](https://github.com/azuyalabs/yasumi/pull/162) ([c960657](https://github.com/c960657)) +- Added additional code style fixers and aligning StyleCI settings with PHP-CS. +- Included extra requirement for some PHP Extensions in the composer file. + +### Changed + +- Updated the translation for the All Saints holiday for the `fr_FR` + locale [\#152](https://github.com/azuyalabs/yasumi/pull/152) ([pioc92](https://github.com/pioc92)) +- Updated the translation for the Armistice holiday for the `fr_FR` + locale [\#154](https://github.com/azuyalabs/yasumi/pull/154) ([pioc92](https://github.com/pioc92)) +- Updated the translation for the Victory in Europe holiday for the `fr_FR` + locale [\#153](https://github.com/azuyalabs/yasumi/pull/153) ([pioc92](https://github.com/pioc92)) +- Updated the translation for the Assumption of Mary holiday for the `fr_FR` + locale [\#155](https://github.com/azuyalabs/yasumi/pull/155) ([pioc92](https://github.com/pioc92)) +- Updated the translation for Christmas Day for the `nl_NL` + locale [\#160](https://github.com/azuyalabs/yasumi/pull/160) ([pioc92](https://github.com/pioc92)) +- Reordered arguments to Yoda style. +- Replaced null checks by appropriate instance / type checks. +- Moved default method values to method body as parameters should be nullable. +- Applying the use of strict types. Strict typing allows for improved readability, maintainability, and less prone to + bugs and security vulnerabilities. +- PHP 7.1 is allowed to fail for Travis-CI due to the fact PHPUnit 8 requires PHP >= 7.2. PHP 7.1 support will be + dropped in Yasumi once 7.1 has reached its end of life (December 2019). +- Code using class imports rather than Fully Qualified Class names. +- Upgraded to PHPUnit 8. +- Replaced the standard 'InvalidArgumentException' when an invalid year or holiday provider is given by a new exception + for each of these two situations separately ('InvalidYearException' and 'ProviderNotFoundException'). This allows you + to better distinguish which exception may occur when instantiating the Yasumi + class. [\#95](https://github.com/azuyalabs/yasumi/pull/95) ([qneyrat](https://github.com/qneyrat)) +- Refactored the AbstractProvider::count method to use the newly added SubstituteHoliday class. +- Fallback support added to getName() to allow e.g. fallback from `de_AT` to `de` + . [\#176](https://github.com/azuyalabs/yasumi/pull/176) ([c960657](https://github.com/c960657)) + +### Fixed + +- Late Summer Bank Holiday in 1968 and 1969 in United + Kingdom [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657)) +- Fixed one-off exceptions for May Day Bank Holiday in 1995 and 2020 and Spring Bank Holiday in 2002 and 2012 (United + Kingdom) [\#160](https://github.com/azuyalabs/yasumi/pull/160) ([c960657](https://github.com/c960657)) +- Fixed revoked holidays in Portugal in + 2013-2015 [\#163](https://github.com/azuyalabs/yasumi/pull/163) ([c960657](https://github.com/c960657)) +- Fixed spelling issues in the Danish translation for Second Christmas + Day. [\#167](https://github.com/azuyalabs/yasumi/pull/167) ([c960657](https://github.com/c960657)) +- Corpus Christi is official in + Poland [\#168](https://github.com/azuyalabs/yasumi/pull/168) ([c960657](https://github.com/c960657)) +- Liberation Day is official in the + Netherlands [\#169](https://github.com/azuyalabs/yasumi/pull/169) ([c960657](https://github.com/c960657)) +- Typos in Easter Monday and Republic Day for the 'it_IT' + locale [\#171](https://github.com/azuyalabs/yasumi/pull/171) ([c960657](https://github.com/c960657)) +- Corrected the name of the Emperors Birthday function and variable. +- Good Friday is not official in + Brazil [\#174](https://github.com/azuyalabs/yasumi/pull/174) ([c960657](https://github.com/c960657)) + +### Removed + +- Unused constants. + +## [2.1.0] - 2019-03-29 + +### Added + +- As the Japanese Emperor will abdicate the throne on May 1st 2019, the holiday of the Emperors Birthday will change to + February 23rd from 2020 (No holiday in 2019). In addition, Coronation Day and the Enthronement Proclamation Ceremony + will be extra holidays in 2019. [\#130](https://github.com/azuyalabs/yasumi/pull/130) ([cookie-maker](https://github.com/cookie-maker)) +- International Women's Day is an official holiday since 2019 in Berlin (Germany) + . [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) + +### Changed + +- Japanese Health And Sports Day will be renamed to Sports Day from 2020. [\#129](https://github.com/azuyalabs/yasumi/pull/129) ([cookie-maker](https://github.com/cookie-maker)) +- Dutch spelling for Easter/Pentecost/Christmas to use lower + case. [\#128](https://github.com/azuyalabs/yasumi/pull/128) ([c960657](https://github.com/c960657)) +- Refactored the Netherlands Holiday provider by moving the calculation of individual holidays to private methods. This + will reduce the complexity of the initialize method. +- Visibility of internal class functions to 'private'. These are to be used within the class only and should not be + public. + +### Fixed + +- "Bridge Day" for Japan takes two days in 2019. Currently, the code only allows for 1 bridge day at a + maximum. [\#141](https://github.com/azuyalabs/yasumi/pull/141) ([cookie-maker](https://github.com/cookie-maker)) +- Tests for Bremen, Lower Saxony and Schleswig-Holstein (Germany) also celebrated Reformation Day in 2017. The unit + tests were failing as it didn't account for that. +- Changed the USA Provider to check all holidays for potential substitute holidays, not just New Year's Day, + Independence Day, and Christmas + Day. [\#140](https://github.com/azuyalabs/yasumi/pull/140) ([jagers](https://github.com/jagers)) +- Adjusted tests for the 'next' and 'previous' methods to avoid actually exceeding the year boundaries. +- Deprecation warning for the package mikey179/vfStream. Composer 2.0 requires package names to not contain any upper + case characters. [\#135](https://github.com/azuyalabs/yasumi/pull/135) ([IceShack](https://github.com/IceShack)) +- Incorrect comment about weekends in + India [\#126](https://github.com/azuyalabs/yasumi/pull/126) ([c960657](https://github.com/c960657)) +- Correction to the test of New Year's Day in the United Kingdom. It has been identified as a Bank Holiday only since + 1975 (not from 1974). + +### Removed + +- Duplicate definition of + newYearsDay [\#125](https://github.com/azuyalabs/yasumi/pull/125) ([c960657](https://github.com/c960657)) + +## [2.0.0] - 2019-01-11 + +### Added + +- New filter to select holidays that happen on a given + date [\#119](https://github.com/azuyalabs/yasumi/pull/119) ([cruxicheiros](https://github.com/cruxicheiros)) +- Holiday Providers for all Australian states and + territories. [\#112](https://github.com/azuyalabs/yasumi/pull/112) ([Milamber33](https://github.com/Milamber33)) +- Holiday Provider for + Bosnia. [\#94](https://github.com/azuyalabs/yasumi/pull/94) ([TheAdnan](https://github.com/TheAdnan)) +- Added Reformation Day as official holiday since 2018 in Lower Saxony (Germany) + . [#115](https://github.com/azuyalabs/yasumi/issues/115) ([Taxcamp](https://github.com/Taxcamp)) +- Added Reformation Day as official holiday since 2018 in Schleswig-Holstein (Germany) + . [#106](https://github.com/azuyalabs/yasumi/pull/106) ([HenningCash](https://github.com/HenningCash)) +- Added Reformation Day as official holiday since 2018 in Hamburg (Germany) + . [#108](https://github.com/azuyalabs/yasumi/pull/108) ([HenningCash](https://github.com/HenningCash)) +- Added Reformation Day as official holiday since 2018 in Bremen (Germany) + . [#116](https://github.com/azuyalabs/yasumi/issues/116) ([TalonTR](https://github.com/TalonTR)) +- The (observed) holidays Lukkeloven, Constitution Day, New Year's Eve and Labour Day, as well as summertime and + wintertime are included for + Denmark [\#104](https://github.com/azuyalabs/yasumi/pull/104) ([c960657](https://github.com/c960657)) + +### Changed + +- Upgraded entirely to PHP version 7 with PHP 7.1 being the minimum required version. Base code and all unit tests have + been reworked to compatibility with PHP 7. +- Upgraded to PHPUnit to version 7.5. +- Changed Japanese holiday for the 2020 Olympic Games. Marine Day, Mountain Day and Health And Sports + Day. [\#113](https://github.com/azuyalabs/yasumi/pull/113) ([cookie-maker](https://github.com/cookie-maker)) +- Summer/winter time is now fetched from PHP's tz + database. [\#103](https://github.com/azuyalabs/yasumi/pull/103) ([c960657](https://github.com/c960657)) +- Changed translation for Norway's national + day. [\#98](https://github.com/azuyalabs/yasumi/pull/98) ([c960657](https://github.com/c960657)) +- Applied proper null checks in the summer time and wintertime calculations for Denmark and The Netherlands. +- Corrected some namespaces for Australia and Germany. +- Updated copyright year. +- Upgraded various dependency packages. +- Internal locale list updated based on CLDR v34. +- Refactored the Japan and USA Holiday Provider by moving the holiday calculations to private methods. This reduced the + complexity of the initialize method. +- Changed individual added International Women's Day for Ukraine and Russia to common + holiday. [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) + +### Fixed + +- Translation for Russia showed in English (except New Year's Day) as the proper locale was not in place. +- Fixed issue for summertime in Denmark in 1980. By default, summertime in Denmark is set for the last day of March + since 1980, however in 1980 itself, it started on April, 6th. +- Fixed spelling issue in the Swedish + translation. [\#97](https://github.com/azuyalabs/yasumi/pull/97) ([c960657](https://github.com/c960657)) +- Fixed spelling issues in the Danish + translation. [\#96](https://github.com/azuyalabs/yasumi/pull/96) ([c960657](https://github.com/c960657)) +- Fixed German Easter Sunday and Pentecost Sunday holidays (not nationwide, only in Brandenburg) + . [\#100](https://github.com/azuyalabs/yasumi/pull/100) ([TalonTR](https://github.com/TalonTR)) +- Fixed BetweenFilter to ignore time part and + timezone. [\#101](https://github.com/azuyalabs/yasumi/pull/101) ([c960657](https://github.com/c960657)) +- Fixed bug in provider list generation related to variable order of files returned by the + filesystem [\#107](https://github.com/azuyalabs/yasumi/pull/107) ([leafnode](https://github.com/leafnode)) + +### Removed + +## [1.8.0] - 2018-02-21 + +### Added + +- Added a function that can remove a holiday from the holidays providers (i.e. country/state) list of holidays. This + function can be helpful in cases where an existing holiday provider class can be extended, but some holidays are not + part of the original (extended) provider. +- Changed various functions that have a date parameter to support now objects implementing the DateTimeInterface and + objects of the DateTimeImmutable type. +- Added support for countries where the weekend definition (start and end day) differs from the global definition ( + Saturday and Sunday). +- Holiday Provider for + Russia. [\#72](https://github.com/azuyalabs/yasumi/pull/72) ([lukosius](https://github.com/lukosius)) +- Holiday Provider for + Estonia. [\#71](https://github.com/azuyalabs/yasumi/pull/71) ([lukosius](https://github.com/lukosius)) +- Added Scrutinizer integration. + +### Changed + +- Locale List updated based on CLDR version 32. +- Added PHPStan static analysis tool to Travis + CI [\#88](https://github.com/azuyalabs/yasumi/pull/88) ([lukosius](https://github.com/lukosius)) +- Various inline documentation + enhancements. [\#87](https://github.com/azuyalabs/yasumi/pull/87) ([lukosius](https://github.com/lukosius)) +- Removed unnecessary typecasts and + if-construct. [\#87](https://github.com/azuyalabs/yasumi/pull/87) ([lukosius](https://github.com/lukosius)) +- Updated inline documentation to include correction Exception throws. +- Removed unnecessary NULL checks. + +### Fixed + +- Fixed Brazilian Carnival Day and added Ash Wednesday to Brazilian + Holidays. [\#92](https://github.com/azuyalabs/yasumi/pull/92) ([glauberm](https://github.com/glauberm)) +- Yasumi listed 01.04.2018 (Easter Sunday) for Spain as an official holiday, however it is not recognized as such. Fix + made that recognizes Easter Sunday as being observed (in all regions) + . [\#86](https://github.com/azuyalabs/yasumi/pull/86) ([Bastian Konetzny](https://github.com/bkonetzny)) +- Corrected reference to the Holiday Provider's ID to be static. +- Changed weekend data property into constant as it is not dynamic (runtime). +- Corrected the name translation test for the Restoration of Independence Day (Portugal). The test didn't account for + the fact that this holiday was abolished and reinstated at some time. +- Corrected unit test for Geneva (Switzerland) as the jeune Genevois day was incorrectly asserted as a regional holiday. +- Corrected the count logic so that in case a holiday is substituted (or observed), it is only counted once. +- Dropped unnecessary arguments of some methods in various Holiday Providers. +- Corrected Japanese "Green Day" and "Children's Day" to use "Hiragana" instead of + Kanji. [\#80](https://github.com/azuyalabs/yasumi/pull/80) ([cookie-maker](https://github.com/cookie-maker)) + +## [1.7.0] - 2017-12-11 + +### Added + +- All filters implement the [Countable](https://php.net/manual/en/class.countable.php) interface allowing you to use the + ->count() method. [\#77](https://github.com/azuyalabs/yasumi/issues/77) +- Holiday Provider for + Latvia. [\#70](https://github.com/azuyalabs/yasumi/pull/70) ([lukosius](https://github.com/lukosius)) +- Holiday Provider for + Lithuania. [\#67](https://github.com/azuyalabs/yasumi/pull/67) ([lukosius](https://github.com/lukosius)) +- Sometimes it is more convenient to be able to create a Yasumi instance by ISO3166 code rather than Yasumi's Holiday + Provider name. A new function `createByISO3166_2` has been added to allow for + that. [\#62](https://github.com/azuyalabs/yasumi/pull/62) ([huehnerhose](https://github.com/huehnerhose)) +- Missing translations (de_DE) for Easter Sunday and + Whitsunday. [\#60](https://github.com/azuyalabs/yasumi/pull/60) ([IceShack](https://github.com/IceShack)) +- Holiday Provider for + Hungary. [\#57](https://github.com/azuyalabs/yasumi/pull/57) ([AronNovak](https://github.com/AronNovak)) +- Holiday Provider for + Switzerland. [\#56](https://github.com/azuyalabs/yasumi/pull/56) ([qligier](https://github.com/qligier)) + +### Changed + +- Made `calculate` method public and use of proper camel + casing. [\#73](https://github.com/azuyalabs/yasumi/pull/73) ([patrickreck](https://github.com/patrickreck)) +- Upgraded Faker Library to version 1.7 +- Renamed the holiday type NATIONAL to OFFICIAL. Sub-regions may have official holidays, and the name NATIONAL doesn't + suit these situations. [\#65](https://github.com/azuyalabs/yasumi/pull/65) +- Upgraded PHP-CS-Fixer to version 2.6 + +### Fixed + +- Corrected Geneva (Switzerland) unit test to ensure some holidays that are established at a particular year are handled + as such. +- Repentance Day is an official holiday in Saxony (Germany) [\#63](https://github.com/azuyalabs/yasumi/issues/63) +- Corrected the Easter Sunday translation for Austria (de_AT) [\#66](https://github.com/azuyalabs/yasumi/issues/66) +- Corrected Hungary unit test to ensure holidays that are established at a particular year are handled as such. +- Added missing Summer Bank Holiday for the United Kingdom. [\#64](https://github.com/azuyalabs/yasumi/issues/64) + +## [1.6.1] - 2017-02-07 + +### Added + +- Added missing unit tests for Reformation Day as in 2017 it is celebrated in all German states for its 500th + anniversary. +- Added missing unit tests for the German Unit Day for each German state. +- Created fallback calculation of the easter_days function in case the PHP extension 'calendar' is not + loaded. [\#55](https://github.com/azuyalabs/yasumi/pull/55) ([stelgenhof](https://github.com/stelgenhof)) + +### Changed + +- Moved Reformation Day to Christian Holidays as it is not only celebrated in Germany. +- Changed Travis configuration to use Composer-installed phpunit to avoid if any issues arise with globally installed + phpunit. + +### Fixed + +- Fixed Christmas Day and Boxing Day for the United Kingdom. A substitute bank holiday is now created for both Christmas + and Boxing Day when either of those days fall on a + weekend. [\#48](https://github.com/azuyalabs/yasumi/issues/48) ([joshuabaker](https://github.com/joshuabaker)) +- Renamed 'en_US' translation for the Second Christmas Day (from ‘Boxing Day’ to ‘Second Christmas Day’: Boxing Day + concept does not exist in the US) + . [\#53](https://github.com/azuyalabs/yasumi/pull/53) ([AngelinCalu](https://github.com/AngelinCalu)) + +## [1.6.0] - 2017-01-06 + +### Added + +- Added Holiday Provider for + Romania. [\#52](https://github.com/azuyalabs/yasumi/pull/52) ([AngelinCalu](https://github.com/AngelinCalu)) +- Added Holiday Provider for Ireland. [stelgenhof](https://github.com/stelgenhof) +- Added Holiday Provider for South Africa. [stelgenhof](https://github.com/stelgenhof) +- Added Holiday Provider for Austria. [stelgenhof](https://github.com/stelgenhof) +- Added 'en_US' translations for the Polish Independence Day and Constitution + Day. [\#45](https://github.com/azuyalabs/yasumi/pull/45) ([AngelinCalu](https://github.com/AngelinCalu)) + +### Changed + +- Refactored the calculation of Orthodox Easter using the function from + ChristianHolidays.php. [\#47](https://github.com/azuyalabs/yasumi/pull/47) ([AngelinCalu](https://github.com/AngelinCalu)) + +### Fixed + +- The parameters of the `isHoliday` and `isWorkingDay` methods now allow for classes that derive from DateTime (like the + very popular Carbon class) + . [\#49](https://github.com/azuyalabs/yasumi/issues/49) ([stelgenhof](https://github.com/stelgenhof)) + +## [1.5.0] - 2016-11-25 + +### Added + +- Added Holiday Provider for Australia (and the sub-region of Victoria) + . [\#38](https://github.com/azuyalabs/yasumi/pull/38) ([brucealdridge](https://github.com/brucealdridge)) +- You can now also use your own holiday providers in addition to the included holiday providers. A very helpful + improvement if Yasumi does not include your provider (yet), but you want to use + yours! [\#29](https://github.com/azuyalabs/yasumi/pull/29) ([navarr](https://github.com/navarr)) +- Added Holiday Provider for + Portugal. [\#44](https://github.com/azuyalabs/yasumi/pull/44) ([rvelhote](https://github.com/rvelhote)) +- Added Holiday Provider for + Ukraine. [\#41](https://github.com/azuyalabs/yasumi/pull/41) ([madmis](https://github.com/madmis)) +- Possibility to retrieve the next or previous working day within a defined number of days from + today [\#39](https://github.com/azuyalabs/yasumi/pull/39) ([brucealdridge](https://github.com/brucealdridge)) +- Added Holiday Providers for all 16 German + States. [\#34](https://github.com/azuyalabs/yasumi/pull/34) ([stelgenhof](https://github.com/stelgenhof)) +- Added Holiday Provider for + Croatia. [\#32](https://github.com/azuyalabs/yasumi/pull/32) ([karlomikus](https://github.com/karlomikus)) + +### Fixed + +- Carnival Day in Brazil was incorrectly set to be 47 days after Easter. Carnival Day begins Friday before Ash + Wednesday (51 days to Easter) + . [\#36](https://github.com/azuyalabs/yasumi/pull/36) ([icaroce](https://github.com/icaroce)) +- All Saints Day for Finland was incorrectly set for November 1st. The correct date is Saturday between 31 Oct and 6 + Nov, similar to + Sweden. [\#43](https://github.com/azuyalabs/yasumi/issues/43) ([stelgenhof](https://github.com/stelgenhof)) + +## [1.4.0] - 2016-06-04 + +### Added + +- Added Holiday Provider for + Brazil. [\#21](https://github.com/azuyalabs/yasumi/pull/21) ([dorianneto](https://github.com/dorianneto)) +- Added Holiday Provider for the Czech + Republic. [\#26](https://github.com/azuyalabs/yasumi/pull/26) ([dfridrich](https://github.com/dfridrich)) +- Added Holiday Provider for the United + Kingdom. [\#23](https://github.com/azuyalabs/yasumi/pull/23) ([stelgenhof](https://github.com/stelgenhof)) +- Add Welsh language (spoken in Wales, UK) translations for the holidays in the United + Kingdom [\#25](https://github.com/azuyalabs/yasumi/pull/25) ([meigwilym](https://github.com/meigwilym)) +- To determine a set of holidays between two dates you can now use the aptly named 'between()' method. + +### Changed + +- All Holiday Provider must now implement a code that will identify it. Typically, this is the ISO3166 code + corresponding to the respective country or sub-region. This can help for purposes such as translations or interfacing + with other API's for example. + +### Fixed + +- Fixed an issue with the unit test for the 'getProviders' method failing on Windows. Hardcoded unix-style directory + separators have been replaced by + DIRECTORY_SEPARATOR. [\#30](https://github.com/azuyalabs/yasumi/pull/30) ([navarr](https://github.com/navarr)) +- Corrected a typo in the English translation for 敬老の日 ( + Japan) [\#22](https://github.com/azuyalabs/yasumi/pull/22) ([navarr](https://github.com/navarr)) +- Fixed issue that the unit tests in 'YasumiTest' (methods 'next' and 'previous') did not cover the situations that the + limits are exceeded. [\#28](https://github.com/azuyalabs/yasumi/issues/28) + +## [1.3.0] - 2016-05-02 + +### Added + +- Added Holiday Provider for + Poland. [\#18](https://github.com/azuyalabs/yasumi/pull/18) ([mpdx](https://github.com/mpdx)) +- Added Holiday Provider for New + Zealand. [\#13](https://github.com/azuyalabs/yasumi/pull/13) ([badams](https://github.com/badams)) +- Added Holiday Provider for + Greece. [\#10](https://github.com/azuyalabs/yasumi/pull/10) ([sebdesign](https://github.com/sebdesign)) +- Added Holiday Provider for + Germany. [\#9](https://github.com/azuyalabs/yasumi/pull/9) ([eaglefsd](https://github.com/eaglefsd)) +- Added translations (`fr_FR`, `fr_BE`) for Belgium National + day [\#864d250](https://github.com/azuyalabs/yasumi/commit/864d25097abbeedbee15bcc37702a34c36a5b696) ([R2c](https://github.com/R2c)) +- Added missing English (`en_US`) translations for the Christian holidays 'Immaculate Conception', 'Maundy Thursday', + 'St. Georges Day', 'St. John's Day', 'St. Josephs Day' and 'St. Stephens Day'. +- Added Test Interface class to ensure the unit tests contain a some minimal assertions. + +### Changed + +- Sorted all translations in the translation files alphabetically (descending). +- Refactoring and cleanup of all unit tests. + +### Fixed + +- Fixed issue for Sweden as All Saints Day was always calculated to be on November 1st. However, the holiday has always + been celebrated on a Saturday (between October 31 and November 6th). +- Fixed the getProviders as it was not able to load Holiday Providers defined in (sub) + regions [\#5879133](https://github.com/azuyalabs/yasumi/commit/58791330ccf5c13b1626885921534c32866b7faf) ([R2c](https://github.com/R2c)) +- Fixed issue that it was possible for the AbstractProvider class to be loaded as a Holiday + Provider [\#9678bc4](https://github.com/azuyalabs/yasumi/commit/9678bc490e34980404ad5dc5b3d45a3c76a3ca0f) ([R2c](https://github.com/R2c)) +- Corrected incorrect pathname reference \*BaseTestCase.php files ("Test" -> "test). +- Fixed issue for France as Good Friday and St. Stephens Day were defined as official holidays. These aren't national + holidays and are only observed in the French departments Moselle, Bas-Rhin and Haut-Rhin. With this fix, these + holidays have been removed from the France Holiday providers and new providers for the departments Moselle, Bas-Rhin + and Haut-Rhin are added. [\#17](https://github.com/azuyalabs/yasumi/issues/17) ([R2c](https://github.com/R2c)) +- Updated locales list based on CLDR version 29. Removed locales of which the region identifier is not specified. +- Fixed issue for Sweden as Midsummer's Day (st. Johns Day) was always calculated to be on June 24th. However, the + holiday has always been celebrated on a Saturday (between June 20 and June 26). +- Fixed base test for some Spain/LaRioja as some holidays have been established only in a particular year, causing false + failures in the unit tests. +- Running php-cs-fixer fix . --level=psr2 generated a massive list of changes, and broke unit tests. Added a custom + .php_cs config file to adhere to the PSR-2 Coding Standards and resolve this issue. In addition, the php-cs-fixer + command has been added to composer to run the fixers and on the CI server (Travis), meaning PR’s will need to be PSR2 + compliant before they can be merged. If any files do not pass, the build + fails. [\#15](https://github.com/azuyalabs/yasumi/issues/15) [\#16](https://github.com/azuyalabs/yasumi/pull/16) ([badams](https://github.com/badams)) +- Accidentally the timezone for Norway was set to "Europe/Copenhagen". This has been corrected to "Europe/Oslo" + . [\#11](https://github.com/azuyalabs/yasumi/issues/11) [\#12](https://github.com/azuyalabs/yasumi/pull/12) ([badams](https://github.com/badams)) +- Fixed issue for Finland as Midsummer's Day (st. Johns Day) was always calculated to be on June 24th. However, since + 1955, the holiday has always been celebrated on a Saturday (between June 20 and June 26). + +## [1.2.0] - 2016-04-04 + +### Added + +- Added Holiday Provider for Denmark +- Added Holiday Provider for Norway +- Added Holiday Provider for Sweden +- Added Holiday Provider for Finland +- New function 'isWorkingDay' added that determines whether a date represents a working day or not. A working day is a + date that is neither a holiday nor falls into the weekend. + +### Changed + +- Refactoring and cleanup of unit tests + +### Fixed + +- The Vernal Equinox Day and Autumnal Equinox Day in Japan were excluded from having it substituted for another day in + case these days would fall on the weekend. +- Fixed tests for some holiday providers as some holidays have been established only in a particular year, causing false + failures in the unit tests. + +## [1.1.0] - 2016-03-10 + +### Added + +- Added Spain Holiday Provider (including the autonomous communities Andalusia, Aragon, Asturias, Balearic Islands, + Basque Country, Canary Islands, Cantabria, Castile and León, Castilla-La Mancha, Ceuta, Community of Madrid, + Extremadura, Galicia, La Rioja, Melilla, Navarre, Region of Murcia, Valencian Community) +- Added Corpus Christi, St. Joseph's Day, Maundy Thursday, St. George's Day, St. John's Day to the common Christian + Holidays. +- Created separate tests for holidays that are substituted on different days. +- Allow for namespaced holiday providers. +- Added test for translation of Ash Wednesday and Valentine's Day in the Netherlands. +- Added test to check whether all holidays for a Holiday Provider are defined by the respective provider class. + +### Changed + +- Updated some English, Italian, French and Dutch translations. +- Moved all other holiday calculations in the Netherlands and France to individual methods. + +### Fixed + +- For Japan substituted holidays had the same date as the original holidays. + +### Removed + +- Removed support for PHP 5.4. The minimum version is now 5.5. PHP 7.0 is known to work however in Travis CI still + allowed to fail. + +## [1.0.0] - 2015-04-21 + +- Initial Release + +[Unreleased]: https://github.com/azuyalabs/yasumi/compare/2.7.0...HEAD +[2.7.0]: https://github.com/azuyalabs/yasumi/compare/2.6.0...2.7.0 +[2.6.0]: https://github.com/azuyalabs/yasumi/compare/2.5.0...2.6.0 +[2.5.0]: https://github.com/azuyalabs/yasumi/compare/2.4.0...2.5.0 +[2.4.0]: https://github.com/azuyalabs/yasumi/compare/2.3.0...2.4.0 +[2.3.0]: https://github.com/azuyalabs/yasumi/compare/2.2.0...2.3.0 +[2.2.0]: https://github.com/azuyalabs/yasumi/compare/2.1.0...2.2.0 +[2.1.0]: https://github.com/azuyalabs/yasumi/compare/2.0.0...2.1.0 +[2.0.0]: https://github.com/azuyalabs/yasumi/compare/1.8.0...2.0.0 +[1.8.0]: https://github.com/azuyalabs/yasumi/compare/1.7.0...1.8.0 +[1.7.0]: https://github.com/azuyalabs/yasumi/compare/1.6.1...1.7.0 +[1.6.1]: https://github.com/azuyalabs/yasumi/compare/1.6.1...1.6.0 +[1.6.0]: https://github.com/azuyalabs/yasumi/compare/1.5.0...1.6.0 +[1.5.0]: https://github.com/azuyalabs/yasumi/compare/1.4.0...1.5.0 +[1.4.0]: https://github.com/azuyalabs/yasumi/compare/1.3.0...1.4.0 +[1.3.0]: https://github.com/azuyalabs/yasumi/compare/1.2.0...1.3.0 +[1.2.0]: https://github.com/azuyalabs/yasumi/compare/1.1.0...1.2.0 +[1.1.0]: https://github.com/azuyalabs/yasumi/compare/1.0.0...1.1.0 +[1.0.0]: https://github.com/azuyalabs/yasumi/releases/tag/1.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 201ddcfc8..c8aaf688a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,327 +1,214 @@ -# Change Log +# Changelog + All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org). - -## [Unreleased] - -### Added - -### Changed - -### Fixed - -### Removed - - -## [2.2.0] - 2019-10-06 - -### Added -- Holiday providers for England, Wales, Scotland and Northern Ireland [\#166](https://github.com/azuyalabs/yasumi/pull/166) ([c960657](https://github.com/c960657)) -- Holiday Provider for South Korea. [\#156](https://github.com/azuyalabs/yasumi/pull/156) ([blood72](https://github.com/blood72)) -- Translation for the Easter holiday for the 'fr_FR' locale [\#146](https://github.com/azuyalabs/yasumi/pull/146) ([pioc92](https://github.com/pioc92)) -- Translation for the Pentecost holiday for the 'fr_FR' locale [\#145](https://github.com/azuyalabs/yasumi/pull/145) ([pioc92](https://github.com/pioc92)) -- Late Summer Bank Holiday in United Kingdom prior to 1965 [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657)) -- Observance holidays for Sweden [\#172](https://github.com/azuyalabs/yasumi/pull/172) ([c960657](https://github.com/c960657)) -- Special subclass of Holiday for substitute holidays [\#162](https://github.com/azuyalabs/yasumi/pull/162) ([c960657](https://github.com/c960657)) -- Added additional code style fixers and aligning StyleCI settings with PHP-CS. -- Included extra requirement for some PHP Extensions in the composer file. - -### Changed -- Updated the translation for the All Saints holiday for the 'fr_FR' locale [\#152](https://github.com/azuyalabs/yasumi/pull/152) ([pioc92](https://github.com/pioc92)) -- Updated the translation for the Armistice holiday for the 'fr_FR' locale [\#154](https://github.com/azuyalabs/yasumi/pull/154) ([pioc92](https://github.com/pioc92)) -- Updated the translation for the Victory in Europe holiday for the 'fr_FR' locale [\#153](https://github.com/azuyalabs/yasumi/pull/153) ([pioc92](https://github.com/pioc92)) -- Updated the translation for the Assumption of Mary holiday for the 'fr_FR' locale [\#155](https://github.com/azuyalabs/yasumi/pull/155) ([pioc92](https://github.com/pioc92)) -- Updated the translation for Christmas Day for the 'nl_NL' locale [\#160](https://github.com/azuyalabs/yasumi/pull/160) ([pioc92](https://github.com/pioc92)) -- Reordered arguments to Yoda style. -- Replaced null checks by appropriate instance / type checks. -- Moved default method values to method body as parameters should be nullable. -- Applying the use of strict types. Strict typing allows for improved readability, maintainability, and less prone to bugs and security vulnerabilities. -- PHP 7.1 is allowed to fail for Travis-CI due to the fact PHPUnit 8 requires PHP >= 7.2. PHP 7.1 support will be dropped in Yasumi once 7.1 has reached its end of life (December 2019). -- Code using class imports rather than Fully Qualified Class names. -- Upgraded to PHPUnit 8. -- Replaced the standard 'InvalidArgumentException' when an invalid year or holiday provider are given by a new exception for each of these two situations separately ('InvalidYearException' and 'ProviderNotFoundException'). This allows you to better distinguish which exception may occur when instantiating the Yasumi class. [\#95](https://github.com/azuyalabs/yasumi/pull/95) ([qneyrat](https://github.com/qneyrat)) -- Refactored the AbstractProvider::count method to use the newly added SubstituteHoliday class. -- Fallback support added to getName() to allow e.g. fallback from 'de_AT' to 'de'. [\#176](https://github.com/azuyalabs/yasumi/pull/176) ([c960657](https://github.com/c960657)) - -### Fixed -- Late Summer Bank Holiday in 1968 and 1969 in United Kingdom [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657)) -- Fixed one-off exceptions for May Day Bank Holiday in 1995 and 2020 and Spring Bank Holiday in 2002 and 2012 (United Kingdom) [\#160](https://github.com/azuyalabs/yasumi/pull/160) ([c960657](https://github.com/c960657)) -- Fixed revoked holidays in Portugal in 2013-2015 [\#163](https://github.com/azuyalabs/yasumi/pull/163) ([c960657](https://github.com/c960657)) -- Fixed spelling issues in the Danish translation for Second Christmas Day. [\#167](https://github.com/azuyalabs/yasumi/pull/167) ([c960657](https://github.com/c960657)) -- Corpus Christi is official in Poland [\#168](https://github.com/azuyalabs/yasumi/pull/168) ([c960657](https://github.com/c960657)) -- Liberation Day is official in the Netherlands [\#169](https://github.com/azuyalabs/yasumi/pull/169) ([c960657](https://github.com/c960657)) -- Typos in Easter Monday and Republic Day for the 'it_IT' locale [\#171](https://github.com/azuyalabs/yasumi/pull/171) ([c960657](https://github.com/c960657)) -- Corrected the name of the Emperors Birthday function and variable. -- Good Friday is not official in Brazil [\#174](https://github.com/azuyalabs/yasumi/pull/174) ([c960657](https://github.com/c960657)) - -### Removed -- Unused constants. - - -## [2.1.0] - 2019-03-29 - -### Added -- As the Japanese Emperor will abdicate the throne on May 1st 2019, the holiday of the Emporers Birthday will change to February 23rd from 2020 (No holiday in 2019). In addition, Coronation Day and the Enthronement Proclamation Ceremony will be extra holidays in 2019. [\#130](https://github.com/azuyalabs/yasumi/pull/130) ([cookie-maker](https://github.com/cookie-maker)) -- International Women's Day is an official holiday since 2019 in Berlin (Germany). [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) - -### Changed -- Japanese Health And Sports Day will be renamed to Sports Day from 2020. [\#129](https://github.com/azuyalabs/yasumi/pull/129) ([cookie-maker](https://github.com/cookie-maker)) -- Dutch spelling for Easter/Pentecost/Christmas to use lower case. [\#128](https://github.com/azuyalabs/yasumi/pull/128) ([c960657](https://github.com/c960657)) -- Refactored the Netherlands Holiday provider by moving the calculation of individual holidays to private methods. This will reduce the complexity of the initialize method. -- Visibility of internal class functions to 'private'. These are to be used within the class only and should not be public. - -### Fixed -- "Bridge Day" for Japan takes two days in 2019. Currently the code only allows for 1 bridge day at a maximum. [\#141](https://github.com/azuyalabs/yasumi/pull/141) ([cookie-maker](https://github.com/cookie-maker)) -- Tests for Bremen, Lower Saxony and Schleswig Holstein (Germany) also celebrated Reformation Day in 2017. The unit tests were failing as it didn't account for that. -- Changed the USA Provider to check all holidays for potential substitute holidays, not just New Year's Day, Independence Day, and Christmas Day. [\#140](https://github.com/azuyalabs/yasumi/pull/140) ([jagers](https://github.com/jagers)) -- Adjusted tests for the 'next' and 'previous' methods to avoid actually exceeding the year boundaries. -- Deprecation warning for the package mikey179/vfStream. Composer 2.0 requires package names to not contain any upper case characters. [\#135](https://github.com/azuyalabs/yasumi/pull/135) ([IceShack](https://github.com/IceShack)) -- Incorrect comment about weekends in India [\#126](https://github.com/azuyalabs/yasumi/pull/126) ([c960657](https://github.com/c960657)) -- Correction to the test of New Year's day in the United Kingdom. It has been identified as a Bank Holiday only since 1975 (not from 1974). - -### Removed -- Duplicate definition of newYearsDay [\#125](https://github.com/azuyalabs/yasumi/pull/125) ([c960657](https://github.com/c960657)) - - -## [2.0.0] - 2019-01-11 - -### Added -- New filter to select holidays that happen on a given date [\#119](https://github.com/azuyalabs/yasumi/pull/119) ([cruxicheiros](https://github.com/cruxicheiros)) -- Holiday Providers for all Australian states and territories. [\#112](https://github.com/azuyalabs/yasumi/pull/112) ([Milamber33](https://github.com/Milamber33)) -- Holiday Provider for Bosnia. [\#94](https://github.com/azuyalabs/yasumi/pull/94) ([TheAdnan](https://github.com/TheAdnan)) -- Added Reformation Day as official holiday since 2018 in Lower Saxony (Germany). [#115](https://github.com/azuyalabs/yasumi/issues/115) ([Taxcamp](https://github.com/Taxcamp)) -- Added Reformation Day as official holiday since 2018 in Schleswig-Holstein (Germany). [#106](https://github.com/azuyalabs/yasumi/pull/106) ([HenningCash](https://github.com/HenningCash)) -- Added Reformation Day as official holiday since 2018 in Hamburg (Germany). [#108](https://github.com/azuyalabs/yasumi/pull/108) ([HenningCash](https://github.com/HenningCash)) -- Added Reformation Day as official holiday since 2018 in Bremen (Germany). [#116](https://github.com/azuyalabs/yasumi/issues/116) ([TalonTR](https://github.com/TalonTR)) -- The (observed) holidays Lukkeloven, Constitution Day, New Year's Eve and Labour Day, as well as summertime and wintertime are included for Denmark [\#104](https://github.com/azuyalabs/yasumi/pull/104) ([c960657](https://github.com/c960657)) - -### Changed -- Upgraded entirely to PHP version 7 with PHP 7.1 being the minimum required version. Base code and all unit tests have been reworked to compatibility with PHP 7. -- Upgraded to PHPUnit to version 7.5. -- Changed Japanese holiday for the 2020 Olympic Games. Marine Day, Mountain Day and Health And Sports Day. [\#113](https://github.com/azuyalabs/yasumi/pull/113) ([cookie-maker](https://github.com/cookie-maker)) -- Summer/winter time is now fetched from PHP's tz database. [\#103](https://github.com/azuyalabs/yasumi/pull/103) ([c960657](https://github.com/c960657)) -- Changed translation for Norway's national day. [\#98](https://github.com/azuyalabs/yasumi/pull/98) ([c960657](https://github.com/c960657)) -- Applied proper null checks in the summertime and wintertime calculations for Denmark and The Netherlands. -- Corrected some namespaces for Australia and Germany. -- Updated copyright year. -- Upgraded various dependency packages. -- Internal locale list updated based on CLDR v34. -- Refactored the Japan and USA Holiday Provider by moving the holiday calculations to private methods. This reduced the complexity of the initialize method. -- Changed individual added International Women's Day for Ukraine and Russia to common holiday. [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) - -### Fixed -- Translation for Russia showed in English (except New Year's Day) as the proper locale was not in place. -- Fixed issue for summertime in Denmark in 1980. By default summertime in Denmark is set for the last day of March since 1980, however in 1980 itself, it started on April, 6th. -- Fixed spelling issue in the Swedish translation. [\#97](https://github.com/azuyalabs/yasumi/pull/97) ([c960657](https://github.com/c960657)) -- Fixed spelling issues in the Danish translation. [\#96](https://github.com/azuyalabs/yasumi/pull/96) ([c960657](https://github.com/c960657)) -- Fixed German Easter Sunday and Pentecost Sunday holidays (not nationwide, only in Brandenburg). [\#100](https://github.com/azuyalabs/yasumi/pull/100) ([TalonTR](https://github.com/TalonTR)) -- Fixed BetweenFilter to ignore time part and timezone. [\#101](https://github.com/azuyalabs/yasumi/pull/101) ([c960657](https://github.com/c960657)) -- Fixed bug in provider list generation related to variable order of files returned by the filesystem [\#107](https://github.com/azuyalabs/yasumi/pull/107) ([leafnode](https://github.com/leafnode)) - -### Removed - - -## [1.8.0] - 2018-02-21 - -### Added -- Added a function that can remove a holiday from the holidays providers (i.e. country/state) list of holidays. This function can be helpful in cases where an existing holiday provider class can be extended but some holidays are not part of the original (extended) provider. -- Changed various functions that have a date parameter to support now objects implementing the DateTimeInterface and objects of the DateTimeImmutable type. -- Added support for countries where the weekend definition (start and end day) differs from the global definition (Saturday and Sunday). -- Holiday Provider for Russia. [\#72](https://github.com/azuyalabs/yasumi/pull/72) ([lukosius](https://github.com/lukosius)) -- Holiday Provider for Estonia. [\#71](https://github.com/azuyalabs/yasumi/pull/71) ([lukosius](https://github.com/lukosius)) -- Added Scrutinizer integration. - -### Changed -- Locale List updated based on CLDR version 32. -- Added PHPStan static analysis tool to Travis CI [\#88](https://github.com/azuyalabs/yasumi/pull/88) ([lukosius](https://github.com/lukosius)) -- Various inline documentation enhancements. [\#87](https://github.com/azuyalabs/yasumi/pull/87) ([lukosius](https://github.com/lukosius)) -- Removed unnecessary typecasts and if-construct. [\#87](https://github.com/azuyalabs/yasumi/pull/87) ([lukosius](https://github.com/lukosius)) -- Updated inline documentation to include correction Exception throws. -- Removed unnecessary NULL checks. - -### Fixed -- Fixed Brazilian Carnaval Day and added Ash Wednesday to Brazilian Holidays. [\#92](https://github.com/azuyalabs/yasumi/pull/92) ([glauberm](https://github.com/glauberm)) -- Yasumi listed 01.04.2018 (Easter Sunday) for Spain as an official holiday, however it is not recognized as such. Fix made that recognizes Easter Sunday as being observed (in all regions). [\#86](https://github.com/azuyalabs/yasumi/pull/86) ([Bastian Konetzny](https://github.com/bkonetzny)) -- Corrected reference to the Holiday Provider's ID to be static. -- Changed weekend data property into constant as it is not dynamic (runtime). -- Corrected the name translation test for the Restoration of Independence Day (Portugal). The test didn't account for the fact that this holiday was abolished and reinstated at some time. -- Corrected unit test for Geneva (Switzerland) as the jeune Genevois day was incorrectly asserted as a regional holiday. -- Corrected the count logic so that in case a holiday is substituted (or observed), it is only counted once. -- Dropped unnecessary arguments of some methods in various Holiday Providers. -- Corrected Japanese "Green Day" and "Children's Day" to use "Hiragana" instead of Kanji. [\#80](https://github.com/azuyalabs/yasumi/pull/80) ([cookie-maker](https://github.com/cookie-maker)) - - -## [1.7.0] - 2017-12-11 -### Added -- All filters implement the [Countable](https://php.net/manual/en/class.countable.php) interface allowing you to use the ->count() method. [\#77](https://github.com/azuyalabs/yasumi/issues/77) -- Holiday Provider for Latvia. [\#70](https://github.com/azuyalabs/yasumi/pull/70) ([lukosius](https://github.com/lukosius)) -- Holiday Provider for Lithuania. [\#67](https://github.com/azuyalabs/yasumi/pull/67) ([lukosius](https://github.com/lukosius)) -- Sometimes it is more convenient to be able to create a Yasumi instance by ISO3166 code rather than Yasumi's Holiday Provider name. A new function `createByISO3166_2` has been added to allow for that. [\#62](https://github.com/azuyalabs/yasumi/pull/62) ([huehnerhose](https://github.com/huehnerhose)) -- Missing translations (de_DE) for Easter Sunday and Whitsunday. [\#60](https://github.com/azuyalabs/yasumi/pull/60) ([IceShack](https://github.com/IceShack)) -- Holiday Provider for Hungary. [\#57](https://github.com/azuyalabs/yasumi/pull/57) ([AronNovak](https://github.com/AronNovak)) -- Holiday Provider for Switzerland. [\#56](https://github.com/azuyalabs/yasumi/pull/56) ([qligier](https://github.com/qligier)) - -### Changed -- Made `calculate` method public and use of proper camel casing. [\#73](https://github.com/azuyalabs/yasumi/pull/73) ([patrickreck](https://github.com/patrickreck)) -- Upgraded Faker Library to version 1.7 -- Renamed the holiday type NATIONAL to OFFICIAL. Subregions may have official holidays and the name NATIONAL doesn't suit these situations. [\#65](https://github.com/azuyalabs/yasumi/pull/65) -- Upgraded PHP-CS-Fixer to version 2.6 - -### Fixed -- Corrected Geneva (Switzerland) unit test to ensure some holidays that are established at a particular year are handled as such. -- Repentance Day is an official holiday in Saxony (Germany) [\#63](https://github.com/azuyalabs/yasumi/issues/63) -- Corrected the Easter Sunday translation for Austria (de_AT) [\#66](https://github.com/azuyalabs/yasumi/issues/66) -- Corrected Hungary unit test to ensure holidays that are established at a particular year are handled as such. -- Added missing Summer Bank Holiday for the United Kingdom. [\#64](https://github.com/azuyalabs/yasumi/issues/64) - - -## [1.6.1] - 2017-02-07 -### Added -- Added missing unit tests for Reformation Day as in 2017 it is celebrated in all German states for its 500th anniversary. -- Added missing unit tests for the German Unit Day for each German state. -- Created fallback calculation of the easter_days function in case the PHP extension 'calendar' is not loaded. [\#55](https://github.com/azuyalabs/yasumi/pull/55) ([stelgenhof](https://github.com/stelgenhof)) - -### Changed -- Moved Reformation Day to Christian Holidays as it is not only celebrated in Germany. -- Changed Travis configuration to use Composer-installed phpunit to avoid if any issues arise with globally installed phpunit. - -### Fixed -- Fixed Christmas Day and Boxing Day for the United Kingdom. A substitute bank holiday is now created for both Christmas and Boxing Day when either of those days fall on a weekend. [\#48](https://github.com/azuyalabs/yasumi/issues/48) ([joshuabaker](https://github.com/joshuabaker)) -- Renamed 'en_US' translation for the Second Christmas Day (from ‘Boxing Day’ to ‘Second Christmas Day’: Boxing Day concept does not exist in the US). [\#53](https://github.com/azuyalabs/yasumi/pull/53) ([AngelinCalu](https://github.com/AngelinCalu)) - - -## [1.6.0] - 2017-01-06 -### Added -- Added Holiday Provider for Romania. [\#52](https://github.com/azuyalabs/yasumi/pull/52) ([AngelinCalu](https://github.com/AngelinCalu)) -- Added Holiday Provider for Ireland. [stelgenhof](https://github.com/stelgenhof) -- Added Holiday Provider for South Africa. [stelgenhof](https://github.com/stelgenhof) -- Added Holiday Provider for Austria. [stelgenhof](https://github.com/stelgenhof) -- Added 'en_US' translations for the Polish Independence Day and Constitution Day. [\#45](https://github.com/azuyalabs/yasumi/pull/45) ([AngelinCalu](https://github.com/AngelinCalu)) - -### Changed -- Refactored the calculation of Orthodox Easter using the function from ChristianHolidays.php. [\#47](https://github.com/azuyalabs/yasumi/pull/47) ([AngelinCalu](https://github.com/AngelinCalu)) - -### Fixed -- The parameters of the `isHoliday` and `isWorkingDay` methods now allow for classes that derive from DateTime (like the very popular Carbon class). [\#49](https://github.com/azuyalabs/yasumi/issues/49) ([stelgenhof](https://github.com/stelgenhof)) - - -## [1.5.0] - 2016-11-25 -### Added -- Added Holiday Provider for Australia (and the sub-region of Victoria). [\#38](https://github.com/azuyalabs/yasumi/pull/38) ([brucealdridge](https://github.com/brucealdridge)) -- You can now also use your own holiday providers in addition to the included holiday providers. - A very helpful improvement if Yasumi does not include your provider (yet), but you want to use yours! [\#29](https://github.com/azuyalabs/yasumi/pull/29) ([navarr](https://github.com/navarr)) -- Added Holiday Provider for Portugal. [\#44](https://github.com/azuyalabs/yasumi/pull/44) ([rvelhote](https://github.com/rvelhote)) -- Added Holiday Provider for Ukraine. [\#41](https://github.com/azuyalabs/yasumi/pull/41) ([madmis](https://github.com/madmis)) -- Possibility to retrieve the next or previous working day within a defined number of days from today [\#39](https://github.com/azuyalabs/yasumi/pull/39) ([brucealdridge](https://github.com/brucealdridge)) -- Added Holiday Providers for all 16 German States. [\#34](https://github.com/azuyalabs/yasumi/pull/34) ([stelgenhof](https://github.com/stelgenhof)) -- Added Holiday Provider for Croatia. [\#32](https://github.com/azuyalabs/yasumi/pull/32) ([karlomikus](https://github.com/karlomikus)) - -### Fixed -- Carnival Day in Brazil was incorrectly set to be 47 days after Easter. Carnival Day begins Friday before Ash Wednesday (51 days to Easter). [\#36](https://github.com/azuyalabs/yasumi/pull/36) ([icaroce](https://github.com/icaroce)) -- All Saints Day for Finland was incorrectly set for November 1st. The correct date is Saturday between 31 Oct and 6 Nov, similar to Sweden. [\#43](https://github.com/azuyalabs/yasumi/issues/43) ([stelgenhof](https://github.com/stelgenhof)) - - -## [1.4.0] - 2016-06-04 -### Added -- Added Holiday Provider for Brazil. [\#21](https://github.com/azuyalabs/yasumi/pull/21) ([dorianneto](https://github.com/dorianneto)) -- Added Holiday Provider for the Czech Republic. [\#26](https://github.com/azuyalabs/yasumi/pull/26) ([dfridrich](https://github.com/dfridrich)) -- Added Holiday Provider for the United Kingdom. [\#23](https://github.com/azuyalabs/yasumi/pull/23) ([stelgenhof](https://github.com/stelgenhof)) -- Add Welsh language (spoken in Wales, UK) translations for the holidays in the United Kingdom [\#25](https://github.com/azuyalabs/yasumi/pull/25) ([meigwilym](https://github.com/meigwilym)) -- To determine a set of holidays between two dates you can now use the aptly named 'between()' method. - -### Changed -- All Holiday Provider must now implement a code that will identify it. Typically this is the ISO3166 code - corresponding to the respective country or sub-region. This can help for purposes such as translations or interfacing - with other API's for example. - -### Fixed -- Fixed an issue with the unit test for the 'getProviders' method failing on Windows. Hardcoded unix-style directory separators have been replaced by DIRECTORY_SEPARATOR. [\#30](https://github.com/azuyalabs/yasumi/pull/30) ([navarr](https://github.com/navarr)) -- Corrected a typo in the English translation for 敬老の日 (Japan) [\#22](https://github.com/azuyalabs/yasumi/pull/22) ([navarr](https://github.com/navarr)) -- Fixed issue that the unit tests in 'YasumiTest' (methods 'next' and 'previous') did not cover the situations that the limits are exceeded. [\#28](https://github.com/azuyalabs/yasumi/issues/28) - - -## [1.3.0] - 2016-05-02 -### Added -- Added Holiday Provider for Poland. [\#18](https://github.com/azuyalabs/yasumi/pull/18) ([mpdx](https://github.com/mpdx)) -- Added Holiday Provider for New Zealand. [\#13](https://github.com/azuyalabs/yasumi/pull/13) ([badams](https://github.com/badams)) -- Added Holiday Provider for Greece. [\#10](https://github.com/azuyalabs/yasumi/pull/10) ([sebdesign](https://github.com/sebdesign)) -- Added Holiday Provider for Germany. [\#9](https://github.com/azuyalabs/yasumi/pull/9) ([eaglefsd](https://github.com/eaglefsd)) -- Added translations ('fr_FR', 'fr_BE') for Belgium National day [\#864d250](https://github.com/azuyalabs/yasumi/commit/864d25097abbeedbee15bcc37702a34c36a5b696) ([R2c](https://github.com/R2c)) -- Added missing English ('en_US') translations for the Christian holidays 'Immaculate Conception', 'Maundy Thursday', - 'St. Georges Day', 'St. John's Day', 'St. Josephs Day' and 'St. Stephens Day'. -- Added Test Interface class to ensure the unit tests contain a some minimal assertions. - -### Changed -- Sorted all translations in the translation files alphabetically (descending). -- Refactoring and cleanup of all unit tests. - -### Fixed -- Fixed issue for Sweden as All Saints Day was always calculated to be on November 1st. However the holiday has always - been celebrated on a Saturday (between October 31 and November 6th). -- Fixed the getProviders as it was not able to load Holiday Providers defined in (sub) regions [\#5879133](https://github.com/azuyalabs/yasumi/commit/58791330ccf5c13b1626885921534c32866b7faf) ([R2c](https://github.com/R2c)) -- Fixed issue that it was possible for the AbstractProvider class to be loaded as a Holiday Provider [\#9678bc4](https://github.com/azuyalabs/yasumi/commit/9678bc490e34980404ad5dc5b3d45a3c76a3ca0f) ([R2c](https://github.com/R2c)) -- Corrected incorrect pathname reference \*BaseTestCase.php files ("Test" -> "test). -- Fixed issue for France as Good Friday and St. Stephens Day were defined as official holidays. These aren't national - holidays and are only observed in the French departments Moselle, Bas-Rhin and Haut-Rhin. With this fix, these - holidays have been removed from the France Holiday providers and new providers for the departments Moselle, Bas-Rhin - and Haut-Rhin are added. [\#17](https://github.com/azuyalabs/yasumi/issues/17) ([R2c](https://github.com/R2c)) -- Updated locales list based on CLDR version 29. Removed locales of which the region identifier is not specified. -- Fixed issue for Sweden as Midsummer's Day (st. Johns Day) was always calculated to be on June 24th. However the - holiday has always been celebrated on a Saturday (between June 20 and June 26). -- Fixed base test for some Spain/LaRioja as some holidays have been established only in a particular year, causing - false failures in the unit tests. -- Running php-cs-fixer fix . --level=psr2 generated a massive list of changes, and broke unit tests. Added a custom - .php_cs config file to adhere to the PSR-2 Coding Standards and resolve this issue. In addition the php-cs-fixer - command to has been added to composer to run the fixers and on the CI server (Travis), meaning PR’s will need to be - PSR2 compliant before they can be merged. If any files do not pass, the build fails. [\#15](https://github.com/azuyalabs/yasumi/issues/15) [\#16](https://github.com/azuyalabs/yasumi/pull/16) ([badams](https://github.com/badams)) -- Accidentally the timezone for Norway was set to "Europe/Copenhagen". This has been corrected to "Europe/Oslo". [\#11](https://github.com/azuyalabs/yasumi/issues/11) [\#12](https://github.com/azuyalabs/yasumi/pull/12) ([badams](https://github.com/badams)) -- Fixed issue for Finland as Midsummer's Day (st. Johns Day) was always calculated to be on June 24th. However since - 1955, the holiday has always been celebrated on a Saturday (between June 20 and June 26). - - -## [1.2.0] - 2016-04-04 -### Added -- Added Holiday Provider for Denmark -- Added Holiday Provider for Norway -- Added Holiday Provider for Sweden -- Added Holiday Provider for Finland -- New function 'isWorkingDay' added that determines whether a date represents a working day or not. A working day is - considered a date that is neither a holiday nor falls into the weekend. - -### Changed -- Refactoring and cleanup of unit tests - -### Fixed -- The Vernal Equinox Day and Autumnal Equinox Day in Japan were excluded from having it substituted for another day in - case these days would fall on the weekend. -- Fixed tests for some holiday providers as some holidays have been established only in a particular year, causing - false failures in the unit tests. - - -## [1.1.0] - 2016-03-10 -### Added -- Added Spain Holiday Provider (including the autonomous communities Andalusia, Aragon, Asturias, Balearic Islands, - Basque Country, Canary Islands, Cantabria, Castile and León, Castilla-La Mancha, Ceuta, Community of Madrid, - Extremadura, Galicia, La Rioja, Melilla, Navarre, Region of Murcia, Valencian Community) -- Added Corpus Christi, St. Joseph's Day, Maundy Thursday, St. George's Day, St. John's Day to the common Christian - Holidays. -- Created separate tests for holidays that are substituted on different days. -- Allow for name spaced holiday providers. -- Added test for translation of Ash Wednesday and Valentinesday in the Netherlands. -- Added test to check whether all holidays for a Holiday Provider are defined by the respective provider class. - -### Changed -- Updated some English, Italian, French and Dutch translations. -- Moved all other holiday calculations in Netherlands and France to individual methods. - -### Fixed -- For Japan substituted holidays had same date as the original holidays. - -### Removed -- Removed support for PHP 5.4. Minimum version is now 5.5. PHP 7.0 is known to work however in Travis CI still allowed - to fail - - -## [1.0.0] - 2015-04-21 -- Initial Release +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and +[Conventional Commits](https://conventionalcommits.org) for commit conventions. + +Changes related to the logic of the holidays or their providers are listed first, +followed by any architectural or technical changes. + +## [2.11.0] - 2026-03-30 + +### Features + +- Add Venezuela holiday provider +- Add San Marino holiday provider +- Add Andorra holiday provider +- Add "Czechia" provider as a short form of "Czech Republic" ([#397](https://github.com/azuyalabs/yasumi/issues/397)) + +### Refactor + +- Add sorting to getHolidayNames +- Add key validation to removeHoliday +- Remove unnecessary sorting on getHoliday +- Remove deprecated isHolidayNameNotEmpty method +- Remove redundant initialize interface method +- *(Test)* Add context to base assertion failure messages +- *(Test)* Tighten default range for random year generator + +### Documentation + +- Improve contribution guidelines + +### Code Style + +- Fix code styling issue +- *(Netherlands)* Use strict comparison operators + +### Testing + +- *(Spain)* Fix murciaDay minimum year in RegionOfMurcia test +- *(South Korea)* Fix holiday type test of HangulDay +- *(United Kingdom)* Fix year boundary and test conditions +- *(Slovakia)* Fix excluded years in data providers +- *(South Korea)* Fix twoDaysLaterNewYearsDay test +- *(Spain)* Fix Extremadura test +- *(Nyse)* Fix tests for NYSE provider + +### Other + +- *(Test)* Add missing provider test suites +- *(Test)* Upgrade to PHPUnit 11 +- Increase PHPStan analysis level to 8 +- Add AGENTS.md file +- *(Deps)* Bump actions/stale from 10.1.1 to 10.2.0 ([#398](https://github.com/azuyalabs/yasumi/issues/398)) + +## New Contributors ❤️ + +* @ppaulis made their first contribution + +## [2.10.0] - 2026-01-22 + +### Documentation + +- Update list of supported versions + +### Other + +- Drop PHP 8.1 support + + +## [2.9.0] - 2025-12-29 + +### Features + +- *(Netherlands)* Add new holiday-equivalent days 2026 till 2028 ([#393](https://github.com/azuyalabs/yasumi/issues/393)) +- *(Slovakia)* Slovak State Consolidation Package for 2025 ([#389](https://github.com/azuyalabs/yasumi/issues/389)) +- Add Slovenia holiday provider ([#387](https://github.com/azuyalabs/yasumi/issues/387)) +- Add New York Stock Exchange (NYSE) provider ([#384](https://github.com/azuyalabs/yasumi/issues/384)) +- *(New Zealand)* Add Matariki public holiday ([#378](https://github.com/azuyalabs/yasumi/issues/378)) + +### Fixes + +- *(New Zealand)* Add missing namespace in the MatarikiTest +- Various typos + +### Refactor + +- Use strict comparison with equal types + +### Performance + +- Optimize filter count() +- Fix needless sorting on every holiday insert + +### Documentation + +- Add requirements and installation/quick start sections +- Update list of supported versions + +### Testing + +- *(Poland)* Fix Christmas Eve test +- *(Slovakia)* Fix failing tests for the years 2025 and 2026 + +### Other + +- *(Deps)* Bump actions/stale from 10.1.0 to 10.1.1 ([#391](https://github.com/azuyalabs/yasumi/issues/391)) +- Add support for PHP 8.5 +- Remove Psalm static analysis tool +- Fix deprecated 'set-output' command +- *(Deps)* Bump actions/stale from 10.0.0 to 10.1.0 ([#386](https://github.com/azuyalabs/yasumi/issues/386)) +- *(Deps)* Bump actions/stale from 9.1.0 to 10.0.0 ([#385](https://github.com/azuyalabs/yasumi/issues/385)) + +## New Contributors ❤️ + +* @Stollie made their first contribution +* @mgwebgroup made their first contribution +* @soukicz made their first contribution +* @timeshifting made their first contribution + +## [2.8.0] - 2025-07-13 + +### Features + +- *(Canada)* Nunavut Day for the Nunavut province +- Add Bulgaria provider +- *(Latvia)* Add Pentecost and Mother's Day ([#368](https://github.com/azuyalabs/yasumi/issues/368)) +- *(Argentina)* Movable holidays ([#367](https://github.com/azuyalabs/yasumi/issues/367)) +- *(Poland)* Christmas Eve is a public holiday from 2025 ([#371](https://github.com/azuyalabs/yasumi/issues/371)) +- *(Ireland)* Saint Brigid's Day ([#374](https://github.com/azuyalabs/yasumi/issues/374)) +- *(Lithuania)* Mother's Day and Father's Day ([#370](https://github.com/azuyalabs/yasumi/issues/370)) +- *(Mexico)* Add Transmission of Federal Executive Power Holiday ([#361](https://github.com/azuyalabs/yasumi/issues/361)) +- *(Brazil)* Black Consciousness Day ([#365](https://github.com/azuyalabs/yasumi/issues/365)) +- *(Germany)* Day of Liberation is celebrated in Berlin in 2025 too. +- *(Germany)* Add Assumption of Mary holiday to Bavaria +- Add Iran provider ([#341](https://github.com/azuyalabs/yasumi/issues/341)) + +### Fixes + +- *(Brazil)* Add passing $this->locale for calculateProclamationOfRepublicDay() ([#376](https://github.com/azuyalabs/yasumi/issues/376)) +- *(Scotland)* Easter Monday is not a bank holiday ([#372](https://github.com/azuyalabs/yasumi/issues/372)) +- *(Ireland)* New Year's Day on a Saturday also gives a substitute holiday ([#375](https://github.com/azuyalabs/yasumi/issues/375)) +- *(Ukraine)* Ukraine 2021-2023 changes ([#369](https://github.com/azuyalabs/yasumi/issues/369)) +- *(Ireland)* Easter Sunday is not an official holiday ([#373](https://github.com/azuyalabs/yasumi/issues/373)) +- *(Mexico)* Mark several holidays as observance ([#362](https://github.com/azuyalabs/yasumi/issues/362)) +- *(Mexico)* Mark three holidays as official ([#359](https://github.com/azuyalabs/yasumi/issues/359)) +- *(Portugal)* Corpus Christi is official ([#363](https://github.com/azuyalabs/yasumi/issues/363)) +- *(Czech-republic)* Christmas Eve is official ([#366](https://github.com/azuyalabs/yasumi/issues/366)) +- *(Germany)* Pentecost is not an official holiday - except in Brandenburg ([#337](https://github.com/azuyalabs/yasumi/issues/337)) +- *(Slovakia)* Update rules for Anniversary of the Declaration of the Slovak Nation ([#340](https://github.com/azuyalabs/yasumi/issues/340)) + +### Refactor + +- *(South Korea)* Simplify code by using early returns +- Fix use of concatenation with mixed types +- Make the Holiday class implement the Stringable interface +- Remove astray var_dump use +- Update methods visibility in multiple Providers ([#332](https://github.com/azuyalabs/yasumi/issues/332)) + +### Documentation + +- Include supported PHP versions with security updates +- Move DCO fulltext to its own file +- Clean up examples and correct spelling mistakes +- Fix parameter types that do not match signature +- Add announcement of new documentation site +- Remove duplicate commit messages from the changelog +- Sort the first time contributors alphabetically (a-z) +- Add initial git-cliff configuration + +### Code Style + +- Fix code styling issues +- Fix code styling and formatting issues ([#338](https://github.com/azuyalabs/yasumi/issues/338)) + +### Testing + +- *(Portugal)* Fix official holidays tests +- Fix test for the previous function +- Increase memory_limit, to be able to run all tests on MacOS +- *(Portugal)* Fix issue with Republic Day failing for the restored years between 2013 and 2016 + +### Other + +- Bump composer package versions to latest installed versions +- Remove phpinsights config +- Remove Phan static analysis tool +- Update maintainer information in composer.json +- Disable enforcing the Override attribute by Psalm +- Report unused classes, etc by Psalm as informational +- Drop PHP 8.0 support and add support for PHP 8.4 +- Bump package versions to latest working versions +- Upgrade PHPStan to v2.0 +- Replace deprecated PHPstan configuration option +- Add dependabot configuration file +- Exclude phpactor configuration file from Git +- Use shared PHP CS Fixer config +- Pin version of PHP CS Fixer to 3.46 as latest (3.47) release produces undesired changes + +## New Contributors ❤️ + +* @attepulkkinen made their first contribution +* @dependabot[bot] made their first contribution +* @fbett made their first contribution +* @hamrak made their first contribution +* @mtbossa made their first contribution +* @thrashzone13 made their first contribution + +[2.11.0]: https://github.com/azuyalabs/yasumi/compare/2.10.0..2.11.0 +[2.10.0]: https://github.com/azuyalabs/yasumi/compare/2.9.0..2.10.0 +[2.9.0]: https://github.com/azuyalabs/yasumi/compare/2.8.0..2.9.0 +[2.8.0]: https://github.com/azuyalabs/yasumi/compare/2.7.0..2.8.0 + diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index cb48dfbfe..01bcc3951 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,45 +2,131 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall + community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +- The use of sexualized language or imagery, and sexual attention or advances of + any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, + without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at me@sachatelgenhof.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[me@sachatelgenhof.com](mailto:me@sachatelgenhof.com). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. -[homepage]: https://contributor-covenant.org -[version]: https://contributor-covenant.org/version/1/4/ +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 882e2db80..c4ed0569c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,46 +1,77 @@ # Contributing -Contributions are encouraged and welcome; we are always happy to get feedback or pull requests on [Github](https://github.com/azuyalabs/yasumi). +Contributions are encouraged and welcome; we are always happy to get feedback or pull requests +on [GitHub](https://github.com/azuyalabs/yasumi). When contributing there are a few guidelines we'd like you to keep in mind: - + ## Pull Requests -- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** +- **[PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12/)** Please use the following command after you have completed your work: - - ``` bash - $ composer format - ``` - This will check/correct all the code for the PSR-2 Coding Standard using the wonderful [php-cs-fixer](https://cs.symfony.com). - -- **Add unit tests!** - Your Pull Request won't be accepted if it doesn't have tests: + ```shell + composer format + ``` + + This will check/correct all the code for the PSR-12 Coding Standard using the + wonderful [php-cs-fixer](https://cs.symfony.com). +- **Add unit tests!** - Your Pull Request won't be accepted if it does not have tests: 1. Ensure your new Holiday Provider contains all the necessary unit tests. - 2. Next to the file 'BaseTestCase.php', a file called 'Test.php' needs to be present. This file - needs to include region/country level tests and requires assertion of all expected holidays. - 3. All the unit tests and the implementation Holiday Provider require to have the correct locale, timezone and - region/country name. - 4. As almost all of the tests use automatic iterations, make sure the year for which the test is executed is a valid - year. Some holidays are only established from a certain year and having the test year number smaller than the minimum - establishment year (amongst all holidays) can result in false errors. + 2. Next to the file `{REGIONNAME}BaseTestCase.php`, a file called `{REGIONNAME}Test.php` needs to be present. This + file needs to include region/country level tests and requires assertion of all expected holidays. + 3. All the unit tests and the implementation Holiday Provider require to have the correct locale, time zone and + region/country name. + 4. As almost all tests use automatic iterations, make sure the year for which the test is executed is a valid year. + Some holidays are only established from a certain year and having the test year number smaller than the minimum + establishment year (amongst all holidays) can result in false errors. -- **Document any change** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. +- **Document any change** - Make sure the `CHANGELOG.md` and any other relevant documentation are kept up-to-date. - **One pull request per feature** - If you want to contribute more than one thing, send multiple pull requests. -- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_changing_multiple) before submitting. +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make + multiple intermediate commits while developing, + please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_changing_multiple) before + submitting. + +- **Use [Conventional Commits](https://www.conventionalcommits.org)** - Commit messages must follow the Conventional + Commits specification (e.g. `feat(Netherlands): add holiday X`, `fix(Germany): correct date for Y`). +- **Sign your commits (DCO)** - Each commit must include a `Signed-off-by` trailer to certify you agree to the + [Developer Certificate of Origin](DCO): + + ```shell + git commit -s -m "feat: your change" + ``` + +- **Branch and PR target** - Always branch off `develop` and open your pull request against `develop`. ## Running Tests -``` bash -$ composer test +```shell +composer test +``` + +Or, alternatively run with: + +```shell +vendor/bin/phpunit +``` + +Run a specific suite by name: + +```shell +vendor/bin/phpunit --testsuite Netherlands ``` -or alternatively run with: +## Before Submitting + +Always run all three checks before opening a pull request: -``` bash -$ vendor/bin/phpunit +```shell +composer cs # Check coding standard +composer phpstan # Static analysis (level 8) +composer test # Full test suite ``` diff --git a/DCO b/DCO new file mode 100644 index 000000000..49b8cb054 --- /dev/null +++ b/DCO @@ -0,0 +1,34 @@ +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. diff --git a/LICENSE b/LICENSE index 9ffbc6f6b..5fd61e244 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 - 2019 AzuyaLabs +Copyright (c) 2015 - 2026 AzuyaLabs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,29 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. \ No newline at end of file diff --git a/README.md b/README.md index b6c365558..291a51254 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,105 @@ -![Logo](https://github.com/azuyalabs/yasumi/blob/gh-pages/images/yasumi_logo_wb.png) - [![GitHub Release](https://img.shields.io/github/release/azuyalabs/yasumi.svg?style=flat-square)](https://github.com/azuyalabs/yasumi/releases) [![Total Downloads](https://img.shields.io/packagist/dt/azuyalabs/yasumi.svg?style=flat-square)](https://packagist.org/packages/azuyalabs/yasumi) +![Coding Standard](https://img.shields.io/github/actions/workflow/status/azuyalabs/yasumi/coding-standard.yml?label=Coding%20Standard&style=flat-square) +![Static analysis](https://img.shields.io/github/actions/workflow/status/azuyalabs/yasumi/static-analysis.yml?label=Static%20analysis&style=flat-square) +![Testing](https://img.shields.io/github/actions/workflow/status/azuyalabs/yasumi/testing.yml?label=Testing&style=flat-square) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![Build Status](https://img.shields.io/travis/azuyalabs/yasumi.svg?style=flat-square)](https://travis-ci.org/azuyalabs/yasumi) -[![StyleCI](https://styleci.io/repos/32797151/shield?branch=master)](https://styleci.io/repos/32797151) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/azuyalabs/yasumi/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/azuyalabs/yasumi/?branch=master) -Introduction ------------- -Yasumi (Japanese for 'Holiday'「休み」) is an easy PHP library to help you calculate the dates and names of holidays and other -special celebrations from various countries/states. Many services exist on the internet that provide holidays, however -are either not free or offer only limited information. In addition, no complete PHP library seems to exist today -that covers a wide range of holidays and countries, except maybe [PEAR's Date_Holidays](https://pear.php.net/package/Date_Holidays) which unfortunately hasn't been updated for a long time. +![Logo](https://www.yasumi.dev/assets/img/yasumi_logo.svg) + +## Introduction + +Yasumi (Japanese for 'Holiday'「休み」) is the easy PHP library that helps you retrieve the dates and names of holidays and +other special celebrations from various countries/states. It is calculation and rule driven avoiding the need of a +comprehensive database. + +Many services exist that can provide holiday information, however are either not entirely free or only offer limited +information. In addition, no exhaustive PHP library exists today covering a wide range of holidays and +countries. [PEAR's Date_Holidays](https://pear.php.net/package/Date_Holidays) library was a similar attempt, however it +hasn't been updated for a long time. + +## Requirements + +Yasumi requires **PHP 8.2** or higher. The library supports PHP 8.2, 8.3, 8.4, and 8.5. + +For detailed information about supported PHP versions and security updates, please refer to +the [SECURITY.md](SECURITY.md) file. + +## Installation + +Install Yasumi using [Composer](https://getcomposer.org): + +```shell +composer require azuyalabs/yasumi +``` + +## Quick Start + +Here's a simple example to get you started: + +```php +getName() . ': ' . $holiday->format('Y-m-d') . PHP_EOL; +} + +// Get a specific holiday +$independenceDay = $holidays->getHoliday('independenceDay'); +echo $independenceDay->getName() . ' is on ' . $independenceDay->format('F j, Y') . PHP_EOL; + +// Check if a date is a holiday +$newYearsDay = $holidays->getHoliday('newYearsDay'); +if ($newYearsDay !== null) { + echo 'New Year\'s Day is a holiday!' . PHP_EOL; +} +``` + +For more examples, check the [examples](examples/) directory in the repository. + +## Highlights The goal of Yasumi is to be powerful while remaining lightweight, by utilizing PHP native classes wherever possible. -Yasumi's calculation is provider-based (i.e. by country/state) so it's easy to add new holiday providers that calculate -holidays. The methods of Yasumi can be used to get a holiday's date and name in various languages. +Yasumi's calculation is provider-based (i.e. by country/state), making it easy to add new holiday providers that +calculate holidays. -Documentation -------------- +- Pure PHP with a straightforward API +- Framework-agnostic +- Use of Providers to easily extend and expand new Holidays +- Common Holiday Providers (e.g. Christian Holidays) +- Accounts for the date/time when holidays have been officially established and/or abolished +- Filters enabling to easily select certain holiday types (Official, Observed, Bank, Seasonal or Other) +- Global Translations +- Time zone aware +- Implements [ArrayIterator](https://www.php.net/manual/en/class.arrayiterator.php) to easily process a provider's + holidays +- Fully [documented](https://www.yasumi.dev) +- Fully unit tested +- [Composer](https://getcomposer.org) ready, [PSR-12](https://www.php-fig.org/psr/psr-12/) + and [PSR-4](https://www.php-fig.org/psr/psr-4/) compliant -Yasumi’s documentation is available on [https://azuyalabs.github.io/yasumi/](https://azuyalabs.github.io/yasumi/). You will find all the necessary information how to install Yasumi and also recipes how you can use Yasumi in your project. +## Documentation -Blog ----- -Checkout the [blog](https://azuyalabs.github.io/yasumi/blog/) section on documentation site regularly for latest updates. Keeping you informed about any news, releases, etc. in a handy blog post format! +Yasumi’s documentation is available on [https://www.yasumi.dev](https://www.yasumi.dev). You will find all the necessary +information how to install Yasumi and also recipes how you can use Yasumi in your project. ## Contributing -Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :) Create [Github Issues](https://github.com/azuyalabs/yasumi/issues) for bugs and new features and comment on the ones you are interested in. +Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on GitHub :) +Create [GitHub Issues](https://github.com/azuyalabs/yasumi/issues) for bugs and new features and comment on the ones you +are interested in. -If you enjoy what I am making, an extra cup of coffee is very much appreciated :). Your support helps me to put more time into Open-Source Software projects like this. +If you enjoy what I am making, an extra cup of coffee is very much appreciated :). Your support helps me to put more +time into Open-Source Software projects like this. Buy Me A Coffee -License -------- +## License -Yasumi is open-sourced software licensed under the MIT License (MIT). Please see [LICENSE](LICENSE) for more information. +This project is open-sourced software licensed under the MIT License (MIT). Please see [LICENSE](LICENSE) for more information. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..001008f0f --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,35 @@ +# Security Policy + +## Supported Versions + +The following versions are supported with security updates: + +| Version | Supported | +| ------- | ------------------ | +| 2.10.0 | :white_check_mark: | +| 2.9.0 | :white_check_mark: | +| 2.8.0 | :x: | +| 2.7.0 | :x: | +| <2.7 | :x: | + +As for supported PHP versions, this project only supports the actively supported versions of PHP and versions of PHP +that only receive critical security updates. Currently, that is PHP 8.2, 8.3, 8.4 and 8.5. +Please refer to the [supported versions](https://www.php.net/supported-versions.php) page, to find more details. +When a version of PHP becomes EOL, generally a new release of this project will be issued that sunsets the +support of that retired PHP version. + +## Reporting a Vulnerability + +If you would like to report a vulnerability or have any security concerns with this project, +please use [GitHub's private vulnerability reporting](https://github.com/azuyalabs/yasumi/security/advisories/new) +to disclose it privately before a fix is available. + +To investigate your request as good as possible, please include any of the following when reporting: + +- Proof of concept / Code example +- Any tools, including versions used +- Any relevant output + +I will take all disclosures very seriously and will do my best to rapidly respond and verify the vulnerability before +taking the necessary steps to fix it. After my initial reply to your disclosure, which should be directly after +receiving it, I will periodically update you with the status of the fix. diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..414e5eebd --- /dev/null +++ b/cliff.toml @@ -0,0 +1,175 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[remote.github] +owner = "azuyalabs" +repo = "yasumi" + +[changelog] + +# limit the number of commits processed to keep changelog manageable +limit_commits = 200 + +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and +[Conventional Commits](https://conventionalcommits.org) for commit conventions. + +Changes related to the logic of the holidays or their providers are listed first, +followed by any architectural or technical changes.\n +""" + +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% macro print_commit(commit) -%} + - {% if commit.scope %}*({{ commit.scope | upper_first }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | split(pat="\n") | first | split(pat=":") | last | trim | upper_first }}\ +{% endmacro -%} + +{% if version -%} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else -%} + ## [unreleased] +{% endif -%} + +{% for group, commits in commits | unique(attribute="message") | filter(attribute="merge_commit", value=false) | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + {{ self::print_commit(commit=commit) }} + {%- endfor %} +{% endfor %}\n + +{%- if github -%} +{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} + ## New Contributors ❤️ +{% endif %}\ +{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) | sort(attribute="username") %} + * @{{ contributor.username }} made their first contribution +{%- endfor -%} +{%- endif %}\n\n +""" + +footer = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% for release in releases -%} + {% if release.version -%} + {% if release.previous.version -%} + [{{ release.version | trim_start_matches(pat="v") }}]: \ + {{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }} + {% endif -%} + {% else -%} + [unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD + {% endif -%} +{% endfor %} +""" + +# Remove leading and trailing whitespaces from the changelog's body. +trim = true + +# An array of regex based postprocessors to modify the changelog. +postprocessors = [ + # Replace the placeholder `` with a URL. + { pattern = '', replace = "https://github.com/azuyalabs/yasumi" }, # replace repository URL +] + +[git] + +# Parse commits according to the conventional commits specification. +# See https://www.conventionalcommits.org +conventional_commits = true + +# Exclude commits that do not match the conventional commits specification. +filter_unconventional = true + +# Split commits on newlines, treating each line as an individual commit. +split_commits = false + +# An array of regex based parsers to modify commit messages prior to further processing. +commit_preprocessors = [ + # Replace issue numbers with link templates to be updated in `changelog.postprocessors`. + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))" }, + + # Strip HTML tags and content from commit messages + { pattern = "<[^>]*>.*?]*>", replace = "" }, + + # Fix proper nouns in commit scopes before upper_first is applied + { pattern = "\\(czech republic\\)", replace = "(Czech Republic)" }, + { pattern = "\\(new zealand\\)", replace = "(New Zealand)" }, + { pattern = "\\(south africa\\)", replace = "(South Africa)" }, + { pattern = "\\(south korea\\)", replace = "(South Korea)" }, + { pattern = "\\(united kingdom\\)", replace = "(United Kingdom)" }, + { pattern = "\\(united states\\)", replace = "(United States)" }, + + { pattern = "typo", replace = "Various typos" }, + + # Check spelling of the commit message using https://github.com/crate-ci/typos. + # If the spelling is incorrect, it will be fixed automatically. + { pattern = '.*', replace_command = 'typos --write-changes -' }, +] + +# An array of regex based parsers for extracting data from the commit message. +# Assigns commits to groups. +# Optionally sets the commit's scope and can decide to exclude commits from further processing. +commit_parsers = [ + # skip commits related to composer (e.g. package updates) + { message = "^chore\\(composer\\)", skip = true }, + { message = ".*dependencies", skip = true }, + + # skip commits related to fixes of code style issues + { message = "^chore\\(style\\)", skip = true }, + + { message = "^docs:.*copyright", skip = true }, + + { message = "^chore\\(changelog\\)", skip = true }, + { message = "^chore\\(readme\\)", skip = true }, + { message = "^chore\\(release\\): prepare for", skip = true }, + + # skip merge commits + { message = "^[Mm]erge", skip = true }, + + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Fixes" }, + { message = "^refactor", group = "Refactor" }, + { message = "^perf", group = "Performance" }, + { message = "^doc", group = "Documentation" }, + { message = "^style", group = "Code Style" }, + { message = "^test", group = "Testing" }, + { message = "^chore|^ci|^build", group = "Other" }, +] + +# Prevent commits that are breaking from being excluded by commit parsers. +protect_breaking_commits = false + +# Exclude commits that are not matched by any commit parser. +filter_commits = true + +# Regex to select git tags that represent releases. +tag_pattern = "[0-9].*" + +# Regex to select git tags that do not represent proper releases. +# Takes precedence over `tag_pattern`. +# Changes belonging to these releases will be included in the next release. +skip_tags = "beta|alpha" + +# Regex to exclude git tags after applying the tag_pattern. +ignore_tags = "" + +# Order releases topologically instead of chronologically. +topo_order = false + +# Order of commits in each group/release within the changelog. +# Allowed values: newest, oldest +sort_commits = "newest" diff --git a/composer.json b/composer.json old mode 100755 new mode 100644 index 1b256086a..3d4f13d7d --- a/composer.json +++ b/composer.json @@ -1,6 +1,8 @@ { "name": "azuyalabs/yasumi", - "description": "Yasumi is an easy PHP Library for calculating national holidays.", + "description": "The easy PHP Library for calculating holidays", + "license": "MIT", + "type": "library", "keywords": [ "holiday", "holidays", @@ -12,23 +14,43 @@ "bank", "national" ], - "license": "MIT", + "readme": "README.md", "authors": [ { "name": "Sacha Telgenhof", - "email": "me@sachatelgenhof.com" + "email": "me@sachatelgenhof.com", + "homepage": "https://www.sachatelgenhof.com", + "role": "Maintainer" + } + ], + "homepage": "https://www.yasumi.dev", + "support": { + "issues": "https://github.com/azuyalabs/yasumi/issues", + "source": "https://github.com/azuyalabs/yasumi", + "docs": "https://www.yasumi.dev" + }, + "funding": [ + { + "type": "other", + "url": "https://www.buymeacoffee.com/sachatelgenhof" } ], "require": { - "php": ">=7.1", + "php": ">=8.2", "ext-json": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "fzaninotto/faker": "~1.8", - "mikey179/vfsstream": "~1.6", - "phpunit/phpunit": "~8.4" + "ext-intl": "*", + "azuyalabs/php-cs-fixer-config": "^0.3", + "mikey179/vfsstream": "^1.6", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpunit/phpunit": "^11.5" + }, + "suggest": { + "ext-calendar": "For calculating the date of Easter" }, + "prefer-stable": true, "autoload": { "psr-4": { "Yasumi\\": "src/Yasumi/" @@ -39,14 +61,16 @@ "Yasumi\\tests\\": "tests/" } }, - "scripts": { - "format": "./vendor/bin/php-cs-fixer fix .", - "test": "vendor/bin/phpunit" - }, "config": { + "allow-plugins": { + "composer/package-versions-deprecated": true + }, "sort-packages": true }, - "suggest": { - "ext-calendar": "For calculating the date of Easter" + "scripts": { + "cs": "vendor/bin/php-cs-fixer fix -v --diff --dry-run", + "cs-fix": "vendor/bin/php-cs-fixer fix -v", + "phpstan": "vendor/bin/phpstan analyse", + "test": "vendor/bin/phpunit" } } diff --git a/examples/basic.php b/examples/basic.php new file mode 100644 index 000000000..35a5a1214 --- /dev/null +++ b/examples/basic.php @@ -0,0 +1,62 @@ + + */ + +// This file demonstrates the general use of Yasumi and its basic methods. + +require 'vendor/autoload.php'; + +// Use the factory to create a new holiday provider instance +$holidays = Yasumi\Yasumi::create('USA', (int) date('Y')); + +// Show the number of defined holidays +echo "Number of defined holidays: {$holidays->count()}" . PHP_EOL; +echo PHP_EOL; + +// Display a list all of the holiday names (short names) +echo 'List of all the holiday names: ' . PHP_EOL; +foreach ($holidays->getHolidayNames() as $name) { + echo $name . PHP_EOL; +} +echo PHP_EOL; + +// Display a list all of the holiday dates +echo 'List of all the holiday dates:' . PHP_EOL; +foreach ($holidays->getHolidayDates() as $date) { + echo $date . PHP_EOL; +} +echo PHP_EOL; + +// Get a holiday instance for Independence Day +$independenceDay = $holidays->getHoliday('independenceDay'); + +if (null !== $independenceDay) { + // Show the localized name + echo 'Name of the holiday : ' . $independenceDay->getName() . PHP_EOL; + + // Show the date + echo "Date of the holiday : {$independenceDay}" . PHP_EOL; + + // Show the type of holiday + echo 'Type of holiday : ' . $independenceDay->getType() . PHP_EOL; +} +echo PHP_EOL; + +// Dump the holiday as a JSON object +echo 'Holiday as a JSON object:' . PHP_EOL; +echo json_encode($independenceDay ?? [], JSON_PRETTY_PRINT); + +echo PHP_EOL; diff --git a/examples/between_filter.php b/examples/between_filter.php new file mode 100644 index 000000000..4a2954c42 --- /dev/null +++ b/examples/between_filter.php @@ -0,0 +1,40 @@ + + */ + +// This file demonstrates the use of the `between` filter, selecting only a number of holidays +// that fall in the given date range. + +require 'vendor/autoload.php'; + +$year = (int) date('Y'); + +// Use the factory to create a new holiday provider instance +$holidays = Yasumi\Yasumi::create('Italy', $year); +$holidaysInDecember = $holidays->between( + new DateTime("12/01/{$year}"), + new DateTime("12/31/{$year}") +); + +// Show all holidays in Italy for December +echo 'List of all the holidays in December: ' . PHP_EOL; +foreach ($holidaysInDecember as $holiday) { + echo $holiday . ' - ' . $holiday->getName() . PHP_EOL; +} +echo PHP_EOL; + +// Show the number of filtered holidays +echo "Number of filtered holidays: {$holidaysInDecember->count()}" . PHP_EOL; diff --git a/examples/custom_provider.php b/examples/custom_provider.php new file mode 100644 index 000000000..57eb4cea1 --- /dev/null +++ b/examples/custom_provider.php @@ -0,0 +1,56 @@ + + */ + +// This file demonstrates the use of a custom Holiday provider. A custom holiday provider can be used for +// those scenarios where you would need only a subset of holidays of an existing provider. Or, if you like to +// extend an existing provider with additional, non-standard holidays. + +require 'vendor/autoload.php'; + +/** Provider for all observed holidays by the NYSE (New York Stock Exchange) */ +class NYSE extends Yasumi\Provider\USA +{ + /** + * Initialize holidays for the NYSE. + * + * @throws Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add Good Friday + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + + // Remove Columbus Day and Veterans Day + $this->removeHoliday('columbusDay'); + $this->removeHoliday('veteransDay'); + } +} + +// Use the factory method to create a new holiday provider instance +$NYSEHolidays = Yasumi\Yasumi::create(NYSE::class, (int) date('Y')); + +// We then can retrieve the NYSE observed holidays in the usual manner: +echo 'List of all the holiday names: ' . PHP_EOL; +foreach ($NYSEHolidays->getHolidayNames() as $day) { + echo $day . PHP_EOL; +} +echo PHP_EOL; + +// Use the count() method to show how many holidays are returned +echo "Number of defined holidays: {$NYSEHolidays->count()}" . PHP_EOL; diff --git a/examples/filters.php b/examples/filters.php new file mode 100644 index 000000000..5e9e97c5b --- /dev/null +++ b/examples/filters.php @@ -0,0 +1,33 @@ + + */ + +// This file demonstrates the use of filters; selecting only a number of holidays +// based on certain conditions. In this example we show only the holidays that are +// marked as 'official'. + +require 'vendor/autoload.php'; + +// Use the factory to create a new holiday provider instance +$holidays = Yasumi\Yasumi::create('Netherlands', (int) date('Y')); + +// Create a filter instance for the official holidays +$official = new Yasumi\Filters\OfficialHolidaysFilter($holidays->getIterator()); + +echo 'List of all official holidays: ' . PHP_EOL; +foreach ($official as $day) { + echo $day->getName() . PHP_EOL; +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 000000000..3690021d8 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,12 @@ +parameters: + level: 8 + paths: + - src + - examples + ignoreErrors: + - + message: '#Comparison operation "<=" between [0-9]+ and int<[0-9]+, max> is always true.#' + path: src/Yasumi/Provider/Turkey.php + reportUnmatchedIgnoredErrors: true # Do not allow outdated errors in the baseline + treatPhpDocTypesAsCertain: false + tipsOfTheDay: false diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 7cbade3eb..000000000 --- a/phpunit.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - ./tests - - - - - ./tests/Base - - - - - ./tests/Australia - - - - - ./tests/Austria - - - - - ./tests/Belgium - - - - - ./tests/Bosnia - - - - - ./tests/Brazil - - - - - ./tests/Croatia - - - - - ./tests/CzechRepublic - - - - - ./tests/Denmark - - - - - ./tests/Estonia - - - - - ./tests/Finland - - - - - ./tests/France - - - - - ./tests/Germany - - - - - ./tests/Greece - - - - - ./tests/Hungary - - - - - ./tests/Ireland - - - - - ./tests/Italy - - - - - ./tests/Japan - - - - - ./tests/Latvia - - - - - ./tests/Lithuania - - - - - ./tests/Netherlands - - - - - ./tests/NewZealand - - - - - ./tests/Norway - - - - - ./tests/Poland - - - - - ./tests/Portugal - - - - - ./tests/Romania - - - - - ./tests/Russia - - - - - ./tests/Slovakia - - - - - ./tests/SouthAfrica - - - - - ./tests/SouthKorea - - - - - ./tests/Spain - - - - - ./tests/Sweden - - - - - ./tests/Switzerland - - - - - ./tests/USA - - - - - ./tests/Ukraine - - - - - ./tests/UnitedKingdom - - - - - - ./src/Yasumi - - ./src/Yasumi/data - - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..4d689dfe1 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,223 @@ + + + + + + + + + + ./tests/Base + + + + ./tests/Andorra + + + + ./tests/Argentina + + + + ./tests/Australia + + + + ./tests/Austria + + + + ./tests/Belgium + + + + ./tests/Bosnia + + + + ./tests/Brazil + + + + ./tests/Bulgaria + + + + ./tests/Canada + + + + ./tests/Croatia + + + + ./tests/CzechRepublic + + + + ./tests/Denmark + + + + ./tests/Estonia + + + + ./tests/Finland + + + + ./tests/France + + + + ./tests/Georgia + + + + ./tests/Germany + + + + ./tests/Greece + + + + ./tests/Hungary + + + + ./tests/Iran + + + + ./tests/Ireland + + + + ./tests/Italy + + + + ./tests/Japan + + + + ./tests/Latvia + + + + ./tests/Lithuania + + + + ./tests/Luxembourg + + + + ./tests/Mexico + + + + ./tests/Netherlands + + + + ./tests/NewZealand + + + + ./tests/Norway + + + + ./tests/Poland + + + + ./tests/Portugal + + + + ./tests/Romania + + + + ./tests/Russia + + + + ./tests/SanMarino + + + + ./tests/Slovakia + + + + ./tests/Slovenia + + + + ./tests/SouthAfrica + + + + ./tests/SouthKorea + + + + ./tests/Spain + + + + ./tests/Sweden + + + + ./tests/Switzerland + + + + ./tests/Turkey + + + + ./tests/Ukraine + + + + ./tests/Venezuela + + + + ./tests/UnitedKingdom + + + + ./tests/USA + ./tests/USA/NYSE + + + + ./tests/USA/NYSE + + + + + ./src/Yasumi + + + ./src/Yasumi/data + + + diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..26124c57f --- /dev/null +++ b/rector.php @@ -0,0 +1,41 @@ + + */ + +use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; +use Rector\Config\RectorConfig; +use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Set\ValueObject\SetList; + +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // single rules + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // sets of rules + $rectorConfig->sets([ + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + SetList::EARLY_RETURN, + SetList::PHP_82, + SetList::TYPE_DECLARATION, + PHPUnitSetList::PHPUNIT_110, + ]); +}; diff --git a/src/Yasumi/Exception/Exception.php b/src/Yasumi/Exception/Exception.php index 14b038858..dbcb57c3b 100644 --- a/src/Yasumi/Exception/Exception.php +++ b/src/Yasumi/Exception/Exception.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Exception; diff --git a/src/Yasumi/Exception/InvalidDateException.php b/src/Yasumi/Exception/InvalidDateException.php deleted file mode 100644 index 78ae46e26..000000000 --- a/src/Yasumi/Exception/InvalidDateException.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ - -namespace Yasumi\Exception; - -use InvalidArgumentException; - -/** - * Class InvalidDateException. - */ -class InvalidDateException extends InvalidArgumentException implements Exception -{ - - /** - * Initializes the Exception instance - * - * @param mixed $argumentValue The value of the invalid argument - */ - public function __construct($argumentValue) - { - $type = \gettype($argumentValue); - switch ($type) { - case 'boolean': - $displayName = $argumentValue ? 'true' : 'false'; - break; - case 'integer': - case 'double': - $displayName = (string)$argumentValue; - break; - case 'string': - $displayName = $argumentValue; - break; - case 'object': - $displayName = \get_class($argumentValue); - break; - default: - $displayName = $type; - break; - } - - parent::__construct(\sprintf(\sprintf('\'%s\' is not a valid DateTime(Immutable) instance', $displayName))); - } -} diff --git a/src/Yasumi/Exception/InvalidYearException.php b/src/Yasumi/Exception/InvalidYearException.php index db37c6759..e559ae9f3 100644 --- a/src/Yasumi/Exception/InvalidYearException.php +++ b/src/Yasumi/Exception/InvalidYearException.php @@ -1,24 +1,27 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Exception; -use InvalidArgumentException; - /** * Class InvalidYearException. * * @author Quentin Neyrat */ -class InvalidYearException extends InvalidArgumentException implements Exception +class InvalidYearException extends \InvalidArgumentException implements Exception { } diff --git a/src/Yasumi/Exception/MissingTranslationException.php b/src/Yasumi/Exception/MissingTranslationException.php new file mode 100644 index 000000000..08cd7874d --- /dev/null +++ b/src/Yasumi/Exception/MissingTranslationException.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\Exception; + +use Exception as BaseException; + +/** + * Class MissingTranslationException. + */ +class MissingTranslationException extends BaseException implements Exception +{ + /** + * Initializes the Exception instance. + * + * @param string $key The holiday key + * @param array $locales The locales that was searched + */ + public function __construct(string $key, array $locales) + { + parent::__construct(\sprintf("Translation for '%s' not found for any locale: '%s'", $key, \implode("', '", $locales))); + } +} diff --git a/src/Yasumi/Exception/ProviderNotFoundException.php b/src/Yasumi/Exception/ProviderNotFoundException.php index 31b26140e..d55e71748 100644 --- a/src/Yasumi/Exception/ProviderNotFoundException.php +++ b/src/Yasumi/Exception/ProviderNotFoundException.php @@ -1,24 +1,27 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Exception; -use InvalidArgumentException; - /** * Class ProviderNotFoundException. * * @author Quentin Neyrat */ -class ProviderNotFoundException extends InvalidArgumentException implements Exception +class ProviderNotFoundException extends \InvalidArgumentException implements Exception { } diff --git a/src/Yasumi/Exception/UnknownLocaleException.php b/src/Yasumi/Exception/UnknownLocaleException.php index b7b434454..af8464fdb 100644 --- a/src/Yasumi/Exception/UnknownLocaleException.php +++ b/src/Yasumi/Exception/UnknownLocaleException.php @@ -1,22 +1,25 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Exception; -use InvalidArgumentException; - /** * Class UnknownLocaleException. */ -class UnknownLocaleException extends InvalidArgumentException implements Exception +class UnknownLocaleException extends \InvalidArgumentException implements Exception { } diff --git a/src/Yasumi/Filters/AbstractFilter.php b/src/Yasumi/Filters/AbstractFilter.php index a82353db5..1ed6493ed 100644 --- a/src/Yasumi/Filters/AbstractFilter.php +++ b/src/Yasumi/Filters/AbstractFilter.php @@ -1,46 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; -use Countable; -use FilterIterator; +use Yasumi\Holiday; use Yasumi\SubstituteHoliday; -/** - * AbstractFilter. - * - * @package Yasumi\Filters - */ -abstract class AbstractFilter extends FilterIterator implements Countable +/** @extends \FilterIterator> */ +abstract class AbstractFilter extends \FilterIterator implements \Countable { /** * Returns the number of holidays returned by this iterator. * * In case a holiday is substituted (e.g. observed), the holiday is only counted once. * - * @return int Number of unique holidays. + * @return int number of unique holidays */ public function count(): int { - $names = \array_map(static function (&$holiday) { - if ($holiday instanceof SubstituteHoliday) { - return $holiday->substitutedHoliday->shortName; - } + $names = []; + + foreach ($this as $holiday) { + $key = $holiday instanceof SubstituteHoliday + ? $holiday->getSubstitutedHoliday()->getKey() + : $holiday->getKey(); - return $holiday->shortName; - }, \iterator_to_array($this)); + $names[$key] = true; + } - return \count(\array_unique($names)); + return count($names); } } diff --git a/src/Yasumi/Filters/BankHolidaysFilter.php b/src/Yasumi/Filters/BankHolidaysFilter.php index abcee3e70..56e594997 100644 --- a/src/Yasumi/Filters/BankHolidaysFilter.php +++ b/src/Yasumi/Filters/BankHolidaysFilter.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; @@ -26,13 +31,8 @@ */ class BankHolidaysFilter extends AbstractFilter { - /** - * Checks whether the current element of the iterator is an observed holiday. - * - * @return bool - */ public function accept(): bool { - return $this->getInnerIterator()->current()->getType() === Holiday::TYPE_BANK; + return Holiday::TYPE_BANK === $this->getInnerIterator()->current()->getType(); } } diff --git a/src/Yasumi/Filters/BetweenFilter.php b/src/Yasumi/Filters/BetweenFilter.php index 73d556d64..880bc3e6f 100644 --- a/src/Yasumi/Filters/BetweenFilter.php +++ b/src/Yasumi/Filters/BetweenFilter.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; -use Iterator; - /** * BetweenFilter is a class used for filtering holidays based on given date range. * @@ -22,58 +24,43 @@ * start and end date need to be included in the comparison. * * Note: this class can be used separately, however is implemented by the AbstractProvider::between method. - * - * @package Yasumi\Filters */ class BetweenFilter extends AbstractFilter { - /** - * @var string start date of the time frame to check against - */ - private $start_date; + private const DATE_FORMAT = 'Y-m-d'; - /** - * @var string end date of the time frame to check against - */ - private $end_date; + /** start date of the time frame to check against. */ + private readonly string $startDate; - /** - * @var bool indicates whether the start and end dates should be included in the comparison - */ - private $equal; + /** end date of the time frame to check against */ + private readonly string $endDate; /** - * Construct the Between FilterIterator Object + * Construct the Between FilterIterator Object. * - * @param Iterator $iterator Iterator object of the Holidays Provider - * @param \DateTimeInterface $start_date Start date of the time frame to check against - * @param \DateTimeInterface $end_date End date of the time frame to check against - * @param bool $equal Indicate whether the start and end dates should be included in the - * comparison + * @param \Iterator $iterator Iterator object of the Holidays Provider + * @param \DateTimeInterface $startDate Start date of the time frame to check against + * @param \DateTimeInterface $endDate End date of the time frame to check against + * @param bool $equal Indicate whether the start and end dates should be included in the + * comparison */ public function __construct( - Iterator $iterator, - \DateTimeInterface $start_date, - \DateTimeInterface $end_date, - $equal = true + \Iterator $iterator, + \DateTimeInterface $startDate, + \DateTimeInterface $endDate, + private readonly bool $equal = true, ) { parent::__construct($iterator); - $this->equal = $equal; - $this->start_date = $start_date->format('Y-m-d'); - $this->end_date = $end_date->format('Y-m-d'); + $this->startDate = $startDate->format(self::DATE_FORMAT); + $this->endDate = $endDate->format(self::DATE_FORMAT); } - /** - * @return bool Check whether the current element of the iterator is acceptable - */ public function accept(): bool { - $holiday = $this->getInnerIterator()->current()->format('Y-m-d'); - - if ($this->equal && $holiday >= $this->start_date && $holiday <= $this->end_date) { - return true; - } + $holiday = $this->getInnerIterator()->current()->format(self::DATE_FORMAT); - return $holiday > $this->start_date && $holiday < $this->end_date; + return $this->equal + ? $holiday >= $this->startDate && $holiday <= $this->endDate + : $holiday > $this->startDate && $holiday < $this->endDate; } } diff --git a/src/Yasumi/Filters/ObservedHolidaysFilter.php b/src/Yasumi/Filters/ObservedHolidaysFilter.php index 4d5bbd23c..0769b2116 100644 --- a/src/Yasumi/Filters/ObservedHolidaysFilter.php +++ b/src/Yasumi/Filters/ObservedHolidaysFilter.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; @@ -26,13 +31,8 @@ */ class ObservedHolidaysFilter extends AbstractFilter { - /** - * Checks whether the current element of the iterator is an observed holiday. - * - * @return bool - */ public function accept(): bool { - return $this->getInnerIterator()->current()->getType() === Holiday::TYPE_OBSERVANCE; + return Holiday::TYPE_OBSERVANCE === $this->getInnerIterator()->current()->getType(); } } diff --git a/src/Yasumi/Filters/OfficialHolidaysFilter.php b/src/Yasumi/Filters/OfficialHolidaysFilter.php index 7fe421018..941229e6c 100644 --- a/src/Yasumi/Filters/OfficialHolidaysFilter.php +++ b/src/Yasumi/Filters/OfficialHolidaysFilter.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; @@ -26,13 +31,8 @@ */ class OfficialHolidaysFilter extends AbstractFilter { - /** - * Checks whether the current element of the iterator is an official holiday. - * - * @return bool - */ public function accept(): bool { - return $this->getInnerIterator()->current()->getType() === Holiday::TYPE_OFFICIAL; + return Holiday::TYPE_OFFICIAL === $this->getInnerIterator()->current()->getType(); } } diff --git a/src/Yasumi/Filters/OnFilter.php b/src/Yasumi/Filters/OnFilter.php index f32b10554..a1c6d947a 100644 --- a/src/Yasumi/Filters/OnFilter.php +++ b/src/Yasumi/Filters/OnFilter.php @@ -1,58 +1,52 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; -use Iterator; - /** * OnFilter is a class used for filtering holidays based on a given date. * * Filters for all holidays that happen on the given date. * * Note: this class can be used separately, however is implemented by the AbstractProvider::on method. - * - * @package Yasumi\Filters */ class OnFilter extends AbstractFilter { - /** - * @var string date to check for holidays - */ - private $date; + private const DATE_FORMAT = 'Y-m-d'; + /** date to check for holidays */ + private readonly string $date; /** - * Construct the On FilterIterator Object + * Construct the On FilterIterator Object. * - * @param Iterator $iterator Iterator object of the Holidays Provider - * @param \DateTimeInterface $date Start date of the time frame to check against + * @param \Iterator $iterator Iterator object of the Holidays Provider + * @param \DateTimeInterface $date Start date of the time frame to check against */ - public function __construct( - Iterator $iterator, - \DateTimeInterface $date + \Iterator $iterator, + \DateTimeInterface $date, ) { parent::__construct($iterator); - $this->date = $date->format('Y-m-d'); + $this->date = $date->format(self::DATE_FORMAT); } - /** - * @return bool Check whether the current element of the iterator is acceptable - */ public function accept(): bool { - $holiday = $this->getInnerIterator()->current()->format('Y-m-d'); - return $holiday === $this->date; + return $this->getInnerIterator()->current()->format(self::DATE_FORMAT) === $this->date; } } diff --git a/src/Yasumi/Filters/OtherHolidaysFilter.php b/src/Yasumi/Filters/OtherHolidaysFilter.php index bd141ec12..fd9de4f2d 100644 --- a/src/Yasumi/Filters/OtherHolidaysFilter.php +++ b/src/Yasumi/Filters/OtherHolidaysFilter.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; @@ -17,7 +22,7 @@ /** * OtherHolidaysFilter is a class for filtering all other type of holidays. * - * OtherHolidaysFilter is a class that returns all holidays that are considered an other type of holiday of any given + * OtherHolidaysFilter is a class that returns all holidays that are considered another type of holiday of any given * holiday provider. * * Example usage: @@ -26,13 +31,8 @@ */ class OtherHolidaysFilter extends AbstractFilter { - /** - * Checks whether the current element of the iterator is an other type of holiday. - * - * @return bool - */ public function accept(): bool { - return $this->getInnerIterator()->current()->getType() === Holiday::TYPE_OTHER; + return Holiday::TYPE_OTHER === $this->getInnerIterator()->current()->getType(); } } diff --git a/src/Yasumi/Filters/SeasonalHolidaysFilter.php b/src/Yasumi/Filters/SeasonalHolidaysFilter.php index a98566de3..2af24e109 100644 --- a/src/Yasumi/Filters/SeasonalHolidaysFilter.php +++ b/src/Yasumi/Filters/SeasonalHolidaysFilter.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Filters; @@ -26,13 +31,8 @@ */ class SeasonalHolidaysFilter extends AbstractFilter { - /** - * Checks whether the current element of the iterator is a seasonal holiday. - * - * @return bool - */ public function accept(): bool { - return $this->getInnerIterator()->current()->getType() === Holiday::TYPE_SEASON; + return Holiday::TYPE_SEASON === $this->getInnerIterator()->current()->getType(); } } diff --git a/src/Yasumi/Holiday.php b/src/Yasumi/Holiday.php old mode 100755 new mode 100644 index f611cc9e6..11e78841a --- a/src/Yasumi/Holiday.php +++ b/src/Yasumi/Holiday.php @@ -1,27 +1,29 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; -use DateTime; -use InvalidArgumentException; -use JsonSerializable; -use Yasumi\Exception\InvalidDateException; +use Yasumi\Exception\MissingTranslationException; use Yasumi\Exception\UnknownLocaleException; /** * Class Holiday. */ -class Holiday extends DateTime implements JsonSerializable +class Holiday extends \DateTime implements \JsonSerializable, \Stringable { /** * Type definition for Official (i.e. National/Federal) holidays. @@ -54,87 +56,98 @@ class Holiday extends DateTime implements JsonSerializable public const DEFAULT_LOCALE = 'en_US'; /** - * @var array list of all defined locales + * Pseudo-locale representing the holiday key. */ - private static $locales = []; + public const LOCALE_KEY = '_key'; /** - * @var string short name (internal name) of this holiday + * @deprecated Public access to this property is deprecated in favor of getKey() + * @see getKey() */ - public $shortName; + public string $shortName; - /** - * @var array list of translations of this holiday - */ - public $translations; + /** locale (i.e. language) in which the holiday information needs to be displayed in. (Default 'en_US') */ + protected string $displayLocale; /** - * @var string identifies the type of holiday + * @var array list of all defined locales */ - protected $type; - - /** - * @var string Locale (i.e. language) in which the holiday information needs to be displayed in. (Default 'en_US') - */ - protected $displayLocale; + private static array $locales = []; /** * Creates a new Holiday. * * If a holiday date needs to be defined for a specific timezone, make sure that the date instance - * (DateTimeInterface) has the correct timezone set. Otherwise the default system timezone is used. - * - * @param string $shortName The short name (internal name) of this holiday - * @param array $names An array containing the name/description of this holiday in various - * languages. Overrides global translations - * @param \DateTimeInterface $date A DateTimeInterface instance representing the date of the holiday - * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to be - * displayed in. (Default 'en_US') - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, - * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an - * official holiday is considered. - * - * @throws InvalidDateException + * (DateTimeInterface) has the correct timezone set. Otherwise, the default system timezone is used. + * + * @param string $key Holiday key + * @param array $translations An array containing the name/description of this holiday in various + * languages. Overrides global translations + * @param \DateTimeInterface $date A DateTimeInterface instance representing the date of the holiday + * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to be + * displayed in. (Default 'en_US') + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, + * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default, an + * official holiday is considered. + * * @throws UnknownLocaleException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \Exception */ public function __construct( - string $shortName, - array $names, + string $key, + public array $translations, \DateTimeInterface $date, string $displayLocale = self::DEFAULT_LOCALE, - string $type = self::TYPE_OFFICIAL + protected string $type = self::TYPE_OFFICIAL, ) { - // Validate if short name is not empty - if (empty($shortName)) { - throw new InvalidArgumentException('Holiday name can not be blank.'); + // Validate if key is not empty + if ('' === $key) { + throw new \InvalidArgumentException('Holiday name can not be blank.'); } // Load internal locales variable - if (empty(self::$locales)) { + if ([] === self::$locales) { self::$locales = Yasumi::getAvailableLocales(); } // Assert display locale input - if (!\in_array($displayLocale, self::$locales, true)) { - throw new UnknownLocaleException(\sprintf('Locale "%s" is not a valid locale.', $displayLocale)); + if (! \in_array($displayLocale, self::$locales, true)) { + throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $displayLocale)); } // Set additional attributes - $this->shortName = $shortName; - $this->translations = $names; + $this->shortName = $key; $this->displayLocale = $displayLocale; - $this->type = $type; // Construct instance parent::__construct($date->format('Y-m-d'), $date->getTimezone()); } + /** + * Format the instance as a string using the set format. + * + * @return string this instance as a string using the set format + */ + public function __toString(): string + { + return $this->format('Y-m-d'); + } + + /** + * Returns the key for this holiday. + * + * @return string the key, e.g. "newYearsDay". + */ + public function getKey(): string + { + return $this->shortName; + } + /** * Returns what type this holiday is. * - * @return string the type of holiday (official, observance, season, bank or other). + * @return string the type of holiday (official, observance, season, bank or other) */ public function getType(): string { @@ -143,8 +156,6 @@ public function getType(): string /** * Serializes the object to a value that can be serialized natively by json_encode(). - * - * @return $this */ public function jsonSerialize(): self { @@ -152,28 +163,33 @@ public function jsonSerialize(): self } /** - * Returns the name of this holiday. + * Returns the localized name of this holiday. + * + * The provided locales are searched for a translation. The first locale containing a translation will be used. + * + * If no locale is provided, proceed as if an array containing the display locale, Holiday::DEFAULT_LOCALE ('en_US'), and + * Holiday::LOCALE_KEY (the holiday key) was provided. * - * The name of this holiday is returned translated in the given locale. If for the given locale no translation is - * defined, the name in the default locale ('en_US') is returned. In case there is no translation at all, the short - * internal name is returned. + * @param array $locales The locales to search for translations + * + * @throws MissingTranslationException + * + * @see Holiday::DEFAULT_LOCALE + * @see Holiday::LOCALE_KEY */ - public function getName(): string + public function getName(?array $locales = null): string { - $locales = [$this->displayLocale]; - $parts = \explode('_', $this->displayLocale); - while (\array_pop($parts) && $parts) { - $locales[] = \implode('_', $parts); - } - $locales[] = self::DEFAULT_LOCALE; - + $locales = $this->getLocales($locales); foreach ($locales as $locale) { + if (self::LOCALE_KEY === $locale) { + return $this->shortName; + } if (isset($this->translations[$locale])) { return $this->translations[$locale]; } } - return $this->shortName; + throw new MissingTranslationException($this->shortName, $locales); } /** @@ -181,19 +197,54 @@ public function getName(): string * * @param TranslationsInterface $globalTranslations global translations */ - public function mergeGlobalTranslations(TranslationsInterface $globalTranslations) + public function mergeGlobalTranslations(TranslationsInterface $globalTranslations): void { $holidayGlobalTranslations = $globalTranslations->getTranslations($this->shortName); - $this->translations = \array_merge($holidayGlobalTranslations, $this->translations); + $this->translations = array_merge($holidayGlobalTranslations, $this->translations); } /** - * Format the instance as a string using the set format. + * Expands the provided locale into an array of locales to check for translations. + * + * For each provided locale, return all locales including their parent locales. E.g. + * ['ca_ES_VALENCIA', 'es_ES'] is expanded into ['ca_ES_VALENCIA', 'ca_ES', 'ca', 'es_ES', 'es']. + * + * If a string is provided, return as if this string, Holiday::DEFAULT_LOCALE, and Holiday::LOCALE_SHORT_NAME + * was provided. E.g. 'de_DE' is expanded into ['de_DE', 'de', 'en_US', 'en', Holiday::LOCALE_KEY]. * - * @return string this instance as a string using the set format. + * If null is provided, return as if the display locale was provided as a string. + * + * @param array|null $locales Array of locales, or null if the display locale should be used + * + * @return array an array of locales to check for translations + * + * @see Holiday::DEFAULT_LOCALE + * @see Holiday::LOCALE_KEY */ - public function __toString(): string + protected function getLocales(?array $locales): array { - return $this->format('Y-m-d'); + if (null !== $locales && [] !== $locales) { + $expanded = []; + } else { + $locales = [$this->displayLocale]; + // DEFAULT_LOCALE is 'en_US', and its parent is 'en'. + $expanded = [self::LOCALE_KEY, 'en', 'en_US']; + } + + // Expand e.g. ['de_DE', 'en_GB'] into ['de_DE', 'de', 'en_GB', 'en']. + foreach (array_reverse($locales) as $locale) { + $parent = strtok($locale, '_'); + if (! $parent) { + continue; + } + + while ($child = strtok('_')) { + $expanded[] = $parent; + $parent .= '_' . $child; + } + $expanded[] = $locale; + } + + return array_reverse($expanded); } } diff --git a/src/Yasumi/Provider/AbstractProvider.php b/src/Yasumi/Provider/AbstractProvider.php old mode 100755 new mode 100644 index 427b975a3..d43c9c67f --- a/src/Yasumi/Provider/AbstractProvider.php +++ b/src/Yasumi/Provider/AbstractProvider.php @@ -1,22 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use ArrayIterator; -use Countable; -use InvalidArgumentException; -use IteratorAggregate; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Filters\BetweenFilter; use Yasumi\Filters\OnFilter; @@ -28,22 +28,23 @@ /** * Class AbstractProvider. + * + * @implements \IteratorAggregate */ -abstract class AbstractProvider implements ProviderInterface, Countable, IteratorAggregate +abstract class AbstractProvider implements \Countable, ProviderInterface, \IteratorAggregate { /** - * Code to identify the Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify the Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'US'; /** - * @var array list of the days of the week (the index of the weekdays) that are considered weekend days. - * This list only concerns those countries that deviate from the global common definition, - * where the weekend starts on Saturday and ends on Sunday (0 = Sunday, 1 = Monday, etc.). + * @var array> list of the days of the week (the index of the weekdays) that are considered weekend days. + * This list only concerns those countries that deviate from the global common definition, + * where the weekend starts on Saturday and ends on Sunday (0 = Sunday, 1 = Monday, etc.). */ public const WEEKEND_DATA = [ - // Thursday and Friday 'AF' => [4, 5], // Afghanistan @@ -73,226 +74,103 @@ abstract class AbstractProvider implements ProviderInterface, Countable, Iterato 'IN' => [0], // India ]; - /** - * @var int the object's current year - */ - protected $year; + /** the object's current year */ + protected int $year; - /** - * @var string the object's current timezone - */ - protected $timezone; + /** the object's current timezone */ + protected string $timezone; - /** - * @var string the object's current locale - */ - protected $locale; + /** the object's current locale */ + protected string $locale; /** * @var Holiday[] list of dates of the available holidays */ - private $holidays = []; + private array $holidays = []; /** - * @var TranslationsInterface|null global translations + * flag to track if holidays need to be sorted */ - private $globalTranslations; + private bool $needSorting = false; /** * Creates a new holiday provider (i.e. country/state). * - * @param int $year the year for which to provide holidays - * @param string $locale |null the locale/language in which holidays need to be + * @param int $year the year for which to provide holidays + * @param string|null $locale |null the locale/language in which holidays need to be * represented * @param TranslationsInterface|null $globalTranslations global translations */ - public function __construct($year, $locale = null, TranslationsInterface $globalTranslations = null) - { + public function __construct( + int $year, + ?string $locale = null, + private readonly ?TranslationsInterface $globalTranslations = null, + ) { $this->clearHolidays(); - $this->year = $year ?: \getdate()['year']; + $this->year = $year ?: (int) date('Y'); $this->locale = $locale ?? 'en_US'; - $this->globalTranslations = $globalTranslations; $this->initialize(); } - /** - * Clear all holidays. - */ - protected function clearHolidays() - { - $this->holidays = []; - } - - /** - * Internal function to compare dates in order to sort them chronologically. - * - * @param \DateTimeInterface $dateA First date - * @param \DateTimeInterface $dateB Second date - * - * @return int result where 0 means dates are equal, -1 the first date is before the second date, and 1 if the - * second date is after the first. - */ - private static function compareDates(\DateTimeInterface $dateA, \DateTimeInterface $dateB): int - { - if ($dateA === $dateB) { - return 0; - } - - return ($dateA < $dateB) ? -1 : 1; - } + /** Initialize country holidays */ + abstract public function initialize(): void; - /** - * Adds a holiday to the holidays providers (i.e. country/state) list of holidays. - * - * @param Holiday $holiday Holiday instance (representing a holiday) to be added to the internal list - * of holidays of this country. - */ - public function addHoliday(Holiday $holiday) + public function addHoliday(Holiday $holiday): void { if ($this->globalTranslations instanceof TranslationsInterface) { $holiday->mergeGlobalTranslations($this->globalTranslations); } - $this->holidays[$holiday->shortName] = $holiday; - \uasort($this->holidays, [__CLASS__, 'compareDates']); + $this->holidays[$holiday->getKey()] = $holiday; + $this->needSorting = true; } - - /** - * Removes a holiday from the holidays providers (i.e. country/state) list of holidays. - * - * This function can be helpful in cases where an existing holiday provider class can be extended but some holidays - * are not part of the original (extended) provider. - * - * @param string $shortName short name of the holiday - * - * @return void - */ - public function removeHoliday($shortName): void + public function removeHoliday(string $key): void { - unset($this->holidays[$shortName]); + $this->isHolidayKeyNotEmpty($key); + + unset($this->holidays[$key]); } - /** - * Determines whether a date represents a working day or not. - * - * A working day is defined as a day that is not a holiday nor falls in the weekend. The index of the weekdays of - * the defined date is used for establishing this (0 = Sunday, 1 = Monday, etc.) - * - * @param \DateTimeInterface $date any date object that implements the DateTimeInterface (e.g. Yasumi\Holiday, - * \DateTime) - * - * @return bool true if date represents a working day, otherwise false - * @throws InvalidDateException - * - */ public function isWorkingDay(\DateTimeInterface $date): bool { - $isWorkingDay = true; - - // First check if the given date is a holiday if ($this->isHoliday($date)) { - $isWorkingDay = false; - } - - // Check if given date is a falls in the weekend or not - // If no data is defined for this Holiday Provider, the function falls back to the global weekend definition. - // @TODO Ideally avoid late static binding here (static::ID) - $weekend_data = self::WEEKEND_DATA; - $weekend_days = $weekend_data[$this::ID] ?? [0, 6]; - - if (\in_array((int)$date->format('w'), $weekend_days, true)) { - $isWorkingDay = false; + return false; } - return $isWorkingDay; + return ! $this->isWeekendDay($date); } - /** - * Determines whether a date represents a holiday or not. - * - * @param \DateTimeInterface $date any date object that implements the DateTimeInterface (e.g. Yasumi\Holiday, - * \DateTime) - * - * @return bool true if date represents a holiday, otherwise false - * @throws InvalidDateException - * - */ public function isHoliday(\DateTimeInterface $date): bool { // Check if given date is a holiday or not - if (\in_array($date->format('Y-m-d'), \array_values($this->getHolidayDates()), true)) { - return true; - } - - return false; + return \in_array($date->format('Y-m-d'), $this->getHolidayDates(), true); } - /** - * Gets all of the holiday dates defined by this holiday provider (for the given year). - * - * @return array list of all holiday dates defined for the given year - */ - public function getHolidayDates(): array + public function isWeekendDay(\DateTimeInterface $date): bool { - return \array_map(static function ($holiday) { - return (string)$holiday; - }, $this->holidays); + // If no data is defined for this Holiday Provider, the function falls back to the global weekend definition. + return \in_array( + (int) $date->format('w'), + static::WEEKEND_DATA[$this::ID] ?? [0, 6], + true + ); } - /** - * On what date is the given holiday? - * - * @param string $shortName short name of the holiday - * - * @return string the date of the requested holiday - * @throws InvalidArgumentException when the given name is blank or empty. - * - */ - public function whenIs($shortName): string + public function whenIs(string $key): string { - $this->isHolidayNameNotEmpty($shortName); // Validate if short name is not empty + $this->isHolidayKeyNotEmpty($key); // Validate if key is not empty - return (string)$this->holidays[$shortName]; + return (string) $this->holidays[$key]; } - /** - * Checks whether the given holiday (short name) is not empty. - * - * @param string $shortName the name of the holiday to be checked. - * - * @return true upon success, otherwise an InvalidArgumentException is thrown - * @throws InvalidArgumentException An InvalidArgumentException is thrown if the given holiday parameter is empty. - * - */ - protected function isHolidayNameNotEmpty($shortName): bool + public function whatWeekDayIs(string $key): int { - if (empty($shortName)) { - throw new InvalidArgumentException('Holiday name can not be blank.'); - } + $this->isHolidayKeyNotEmpty($key); // Validate if key is not empty - return true; - } - - /** - * On what day of the week is the given holiday? - * - * This function returns the index number for the day of the week on which the given holiday falls. - * The index number is an integer starting with 0 being Sunday, 1 = Monday, etc. - * - * @param string $shortName short name of the holiday - * - * @return int the index of the weekdays of the requested holiday (0 = Sunday, 1 = Monday, etc.) - * @throws InvalidArgumentException when the given name is blank or empty. - * - */ - public function whatWeekDayIs($shortName): int - { - $this->isHolidayNameNotEmpty($shortName); // Validate if short name is not empty - - return (int)$this->holidays[$shortName]->format('w'); + return (int) $this->holidays[$key]->format('w'); } /** @@ -303,182 +181,151 @@ public function whatWeekDayIs($shortName): int */ public function count(): int { - $names = \array_map(static function (&$holiday) { + $names = array_map(static function (Holiday $holiday): string { if ($holiday instanceof SubstituteHoliday) { - return $holiday->substitutedHoliday->shortName; + return $holiday->getSubstitutedHoliday()->getKey(); } - return $holiday->shortName; + return $holiday->getKey(); }, $this->getHolidays()); - return \count(\array_unique($names)); + return \count(array_unique($names)); } - /** - * Gets all of the holidays defined by this holiday provider (for the given year). - * - * @return Holiday[] list of all holidays defined for the given year - */ public function getHolidays(): array { + $this->ensureSorted(); + return $this->holidays; } - /** - * Gets all of the holiday names defined by this holiday provider (for the given year). - * - * @return array list of all holiday names defined for the given year - */ public function getHolidayNames(): array { - return \array_keys($this->holidays); + $this->ensureSorted(); + + return array_keys($this->holidays); } - /** - * Returns the current year set for this Holiday calendar. - * - * @return int the year set for this Holiday calendar - */ public function getYear(): int { return $this->year; } - /** - * Retrieves the next date (year) the given holiday is going to take place. - * - * @param string $shortName the name of the holiday for which the next occurrence need to be retrieved. - * - * @return Holiday|null a Holiday instance for the given holiday - * - * @throws \ReflectionException - * @throws UnknownLocaleException - * @throws \RuntimeException - * @throws InvalidArgumentException - * - * @covers AbstractProvider::anotherTime - */ - public function next($shortName): ?Holiday + public function next(string $key): ?Holiday { - return $this->anotherTime($this->year + 1, $shortName); + return $this->anotherTime($this->year + 1, $key); } - /** - * Determines the date of the given holiday for another year. - * - * @param int $year the year to get the holiday date for - * @param string $shortName the name of the holiday for which the date needs to be fetched - * - * @return Holiday|null a Holiday instance for the given holiday and year - * - * @throws \ReflectionException - * @throws InvalidArgumentException when the given name is blank or empty. - * @throws UnknownLocaleException - * @throws \RuntimeException - */ - private function anotherTime($year, $shortName): ?Holiday + public function getHoliday(string $key): ?Holiday { - $this->isHolidayNameNotEmpty($shortName); // Validate if short name is not empty + return $this->holidays[$key] ?? null; + } - // Get calling class name - $hReflectionClass = new \ReflectionClass(\get_class($this)); + public function previous(string $key): ?Holiday + { + return $this->anotherTime($this->year - 1, $key); + } + + public function between( + \DateTimeInterface $startDate, + \DateTimeInterface $endDate, + ?bool $equals = null, + ): BetweenFilter { + if ($startDate > $endDate) { + throw new \InvalidArgumentException('Start date must be a date before the end date.'); + } - return Yasumi::create($hReflectionClass->getShortName(), $year, $this->locale)->getHoliday($shortName); + return new BetweenFilter($this->getIterator(), $startDate, $endDate, $equals ?? true); } - /** - * Retrieves the holiday object for the given holiday. - * - * @param string $shortName the name of the holiday. - * - * @return Holiday|null a Holiday instance for the given holiday - * @throws InvalidArgumentException when the given name is blank or empty. - * - */ - public function getHoliday($shortName): ?Holiday + /** @return \ArrayIterator */ + public function getIterator(): \ArrayIterator { - $this->isHolidayNameNotEmpty($shortName); // Validate if short name is not empty + $this->ensureSorted(); - $holidays = $this->getHolidays(); + return new \ArrayIterator($this->holidays); + } - return $holidays[$shortName] ?? null; + public function on(\DateTimeInterface $date): OnFilter + { + return new OnFilter($this->getIterator(), $date); + } + + public function getHolidayDates(): array + { + $this->ensureSorted(); + + return array_map(static fn (Holiday $holiday): string => (string) $holiday, $this->holidays); } /** - * Retrieves the previous date (year) the given holiday took place. - * - * @param string $shortName the name of the holiday for which the previous occurrence need to be retrieved. - * - * @return Holiday|null a Holiday instance for the given holiday - * - * @throws \ReflectionException - * @throws UnknownLocaleException - * @throws \RuntimeException - * @throws InvalidArgumentException - * - * @covers AbstractProvider::anotherTime + * Clear all holidays. */ - public function previous($shortName): ?Holiday + private function clearHolidays(): void { - return $this->anotherTime($this->year - 1, $shortName); + $this->holidays = []; + $this->needSorting = false; } /** - * Retrieves a list of all holidays between the given start and end date. - * - * Yasumi only calculates holidays for a single year, so a start date or end date beyond the given year will only - * return holidays for the given year. For example, holidays calculated for the year 2016, will only return 2016 - * holidays if the provided period is for example 01/01/2012 - 31/12/2017. - * - * Please take care to use the appropriate timezone for the start and end date parameters. In case you use - * different - * timezone for these parameters versus the instantiated Holiday Provider, the outcome might be unexpected (but - * correct). + * Ensures holidays are sorted chronologically if needed. + */ + private function ensureSorted(): void + { + if ($this->needSorting) { + uasort($this->holidays, static fn (\DateTimeInterface $dateA, \DateTimeInterface $dateB): int => self::compareDates($dateA, $dateB)); + $this->needSorting = false; + } + } + + /** + * Checks whether the given holiday is not empty. * - * @param \DateTimeInterface $start_date Start date of the time frame to check against - * @param \DateTimeInterface $end_date End date of the time frame to check against - * @param bool $equals indicate whether the start and end dates should be included in the - * comparison + * @param string $key key of the holiday to be checked * - * @return BetweenFilter - * @throws InvalidArgumentException An InvalidArgumentException is thrown if the start date is set after the end - * date. + * @return true upon success, otherwise an InvalidArgumentException is thrown * + * @throws \InvalidArgumentException an InvalidArgumentException is thrown if the given holiday parameter is empty */ - public function between(\DateTimeInterface $start_date, \DateTimeInterface $end_date, $equals = null): BetweenFilter + private function isHolidayKeyNotEmpty(string $key): bool { - if ($start_date > $end_date) { - throw new InvalidArgumentException('Start date must be a date before the end date.'); + if ('' === $key) { + throw new \InvalidArgumentException('Holiday key can not be blank.'); } - return new BetweenFilter($this->getIterator(), $start_date, $end_date, $equals ?? true); + return true; } /** - * Get an iterator for the holidays. + * Internal function to compare dates in order to sort them chronologically. + * + * @param \DateTimeInterface $dateA First date + * @param \DateTimeInterface $dateB Second date * - * @return ArrayIterator iterator for the holidays of this calendar + * @return int result where 0 means dates are equal, -1 the first date is before the second date, and 1 if the + * second date is after the first */ - public function getIterator(): ArrayIterator + private static function compareDates(\DateTimeInterface $dateA, \DateTimeInterface $dateB): int { - return new ArrayIterator($this->getHolidays()); + return $dateA <=> $dateB; } /** - * Retrieves a list of all holidays that happen on the given date. - * - * Yasumi only calculates holidays for a single year, so a date outside of the given year will not appear to - * contain any holidays. + * Determines the date of the given holiday for another year. * - * Please take care to use the appropriate timezone for the date parameters. If there is a different timezone used - * for these parameters versus the instantiated Holiday Provider, the outcome might be unexpected (but correct). + * @param int $year the year to get the holiday date for + * @param string $key key of the holiday for which the date needs to be fetched * - * @param \DateTimeInterface $date Date to check for holidays on. + * @return Holiday|null a Holiday instance for the given holiday and year * - * @return OnFilter + * @throws \InvalidArgumentException when the given name is blank or empty + * @throws UnknownLocaleException + * @throws \RuntimeException */ - public function on(\DateTimeInterface $date): OnFilter + private function anotherTime(int $year, string $key): ?Holiday { - return new OnFilter($this->getIterator(), $date); + $this->isHolidayKeyNotEmpty($key); + + return Yasumi::create(static::class, $year, $this->locale)->getHoliday($key); } } diff --git a/src/Yasumi/Provider/Andorra.php b/src/Yasumi/Provider/Andorra.php new file mode 100644 index 000000000..c927682ae --- /dev/null +++ b/src/Yasumi/Provider/Andorra.php @@ -0,0 +1,176 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Andorra. + * + * Andorra observes 14 national public holidays. The official language is Catalan (ca_AD). + * The Principality of Andorra is a co-principality, with the President of France and + * the Bishop of Urgell serving as co-princes. + * + * @see https://en.wikipedia.org/wiki/Public_holidays_in_Andorra + */ +class Andorra extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + /** + * The year the Constitution of Andorra was signed and came into force. + */ + public const CONSTITUTION_YEAR = 1993; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AD'; + + /** + * Initialize holidays for Andorra. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Europe/Andorra'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->stStephensDay($this->year, $this->timezone, $this->locale)); + + // Add Andorra-specific holidays + $this->calculateCarnival(); + $this->calculateConstitutionDay(); + $this->calculateMeritxellDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Andorra', + 'https://wit.ad/en/calendar-public-holidays-in-andorra/', + ]; + } + + /** + * Carnival (Dimarts Gras / Mardi Gras). + * + * Carnival in Andorra is celebrated on Shrove Tuesday (Mardi Gras), the day before Ash Wednesday. + * It falls 47 days before Easter Sunday and is one of the 14 official national public holidays. + * + * @see https://en.wikipedia.org/wiki/Carnival + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCarnival(): void + { + $easter = $this->calculateEaster($this->year, $this->timezone); + $date = (clone $easter)->sub(new \DateInterval('P47D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:carnival', self::class)); + } + + $this->addHoliday(new Holiday( + 'carnival', + [ + 'ca' => 'Dimarts Gras', + 'en' => 'Carnival', + 'es' => 'Martes de Carnaval', + ], + $date, + $this->locale + )); + } + + /** + * Constitution Day. + * + * Constitution Day (Catalan: Dia de la Constitució) commemorates the signing of the Constitution of Andorra + * on 14 March 1993. The constitution established Andorra as a parliamentary co-principality. It is celebrated + * annually on 14 March. + * + * @see https://en.wikipedia.org/wiki/Constitution_of_Andorra + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateConstitutionDay(): void + { + if ($this->year >= self::CONSTITUTION_YEAR) { + $this->addHoliday(new Holiday( + 'constitutionDay', + [ + 'ca' => 'Dia de la Constitució', + 'en' => 'Constitution Day', + 'es' => 'Día de la Constitución', + ], + new \DateTime("{$this->year}-3-14", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Our Lady of Meritxell Day (National Day of Andorra). + * + * Our Lady of Meritxell Day (Catalan: Dia de la Mare de Déu de Meritxell) is the National Day of Andorra. + * It is celebrated on 8 September each year in honour of the Virgin of Meritxell, the patron saint of Andorra. + * The sanctuary of Our Lady of Meritxell is located in the parish of Canillo. + * + * @see https://en.wikipedia.org/wiki/Our_Lady_of_Meritxell + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateMeritxellDay(): void + { + $this->addHoliday(new Holiday( + 'meritxellDay', + [ + 'ca' => 'Dia de la Mare de Déu de Meritxell', + 'en' => 'Our Lady of Meritxell Day', + 'es' => 'Día de Nuestra Señora de Meritxell', + ], + new \DateTime("{$this->year}-9-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Argentina.php b/src/Yasumi/Provider/Argentina.php new file mode 100644 index 000000000..d471e0430 --- /dev/null +++ b/src/Yasumi/Provider/Argentina.php @@ -0,0 +1,410 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Argentina. + */ +class Argentina extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + public const PROCLAMATION_OF_INDEPENDENCE_YEAR = 1816; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 + * code corresponding to the respective country or sub-region. + */ + public const ID = 'AR'; + + /** + * Initialize holidays for Argentina. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'America/Argentina/Buenos_Aires'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + + // Add official Christian holidays + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + + $this->addCarnavalHolidays(); + $this->addRemembranceDay(); + $this->addMalvinasDay(); + $this->addMayRevolution(); + $this->addFlagDay(); + $this->addIndependenceDay(); + $this->addImmaculateConceptionDay(); + + // Add movable holidays (these must be added after all immovable official holidays and + // before non-official holidays). + $this->addGeneralMartinMigueldeGuemesDay(); + $this->addGeneralJoseSanMartinDay(); + $this->addRaceDay(); + $this->addNationalSovereigntyDay(); + + // Non-official holidays + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + } + + /** + * The source of the holidays. + * + * @return string[] The source URL + */ + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Argentina', + 'https://www.argentina.gob.ar/interior/feriados-nacionales-2025', + 'https://www.argentina.gob.ar/normativa/nacional/ley-27399-281835/texto', + 'https://www.argentina.gob.ar/normativa/nacional/decreto-789-2021-356678/texto', + ]; + } + + /** + * Carnaval. + * + * Carnaval is the biggest popular festival of country. The festival + * happens on Day 48 and 47 before Easter. + * + * @see https://en.wikipedia.org/wiki/Brazilian_Carnival + */ + protected function addCarnavalHolidays(): void + { + if ($this->year >= 1700) { + $easter = $this->calculateEaster($this->year, $this->timezone); + + $days = [ + 'carnavalMonday' => [ + 'interval' => 'P48D', + 'name' => 'Lunes de Carnaval', + 'name_en' => 'Carnival Monday', + ], + 'carnavalTuesday' => [ + 'interval' => 'P47D', + 'name' => 'Martes de Carnaval', + 'name_en' => 'Carnival Tuesday', + ], + ]; + + foreach ($days as $name => $day) { + $date = (clone $easter)->sub(new \DateInterval($day['interval'])); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $name)); + } + + $this->addHoliday(new Holiday( + $name, + [ + 'es' => $day['name'], + 'en' => $day['name_en'], + ], + $date, + $this->locale + )); + } + } + } + + /* + * Day of Remembrance for Truth and Justice. + * + * The Day of Remembrance for Truth and Justice (Spanish: Día de la + * Memoria por la Verdad y la Justicia) is a public holiday in + * Argentina, commemorating the victims of the Dirty War. It is held on + * 24 March, the anniversary of the coup d'état of 1976 that brought the + * National Reorganization Process to power. + * + * @link https://en.wikipedia.org/wiki/Day_of_Remembrance_for_Truth_and_Justice + */ + protected function addRemembranceDay(): void + { + if ($this->year >= 2006) { + $this->addHoliday(new Holiday( + 'remembranceDay', + [ + 'en' => 'Day of Remembrance for Truth and Justice', + 'es' => 'Día Nacional de la Memoria por la Verdad y la Justicia', + ], + new \DateTime("{$this->year}-03-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * Malvinas Day. + * + * Malvinas Day (Spanish: Día de las Malvinas), officially Day of the + * Veterans and Fallen of the Malvinas War (Día del Veterano y de los + * Caídos en la Guerra de las Malvinas), is a public holiday in + * Argentina, observed each year on 2 April.[1] The name refers to the + * Malvinas Islands, known in Spanish as the Islas Malvinas. + * + * @link https://en.wikipedia.org/wiki/Malvinas_Day + */ + protected function addMalvinasDay(): void + { + if ($this->year >= 1982) { + $this->addHoliday(new Holiday( + 'malvinasDay', + [ + 'en' => 'Malvinas Day', + 'es' => 'Día del Veterano y de los Caídos en la Guerra de Malvinas', + ], + new \DateTime("{$this->year}-04-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * First National Government. + * + * The Anniversary of the First National Government + * (Spanish: Primer gobierno patrio) is a public holiday of Argentina, + * commemorating the May Revolution and the creation of the Primera + * Junta on May 25, 1810, which is considered the first patriotic + * government of Argentina. Along with the 9 July, which commemorates + * the Declaration of Independence, it is considered a National Day of + * Argentina. + * + * @link https://en.wikipedia.org/wiki/First_National_Government + */ + protected function addMayRevolution(): void + { + if ($this->year >= 1810) { + $this->addHoliday(new Holiday( + 'mayRevolution', + [ + 'en' => 'May Revolution', + 'es' => 'Día de la Revolución de Mayo', + ], + new \DateTime("{$this->year}-05-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * Anniversary of the Passing of General Martín Miguel de Güemes. + * + * Anniversary of the death of Martín Miguel de Güemes, general of the + * Argentine War of Independence. + */ + protected function addGeneralMartinMigueldeGuemesDay(): void + { + if ($this->year >= 1821) { + $this->addHoliday(new Holiday( + 'generalMartinMigueldeGuemesDay', + [ + 'en' => 'Anniversary of the Passing of General Martín Miguel de Güemes', + 'es' => 'Paso a la Inmortalidad del General Martín Miguel de Güemes', + ], + $this->adjustMovableHoliday(new \DateTime("{$this->year}-06-17", DateTimeZoneFactory::getDateTimeZone($this->timezone))), + $this->locale + )); + } + } + + /* + * General Manuel Belgrano Memorial Day. + * + * Anniversary of the death of Manuel Belgrano, creator of the Flag of + * Argentina. + * + * @link https://en.wikipedia.org/wiki/Flag_Day_(Argentina) + */ + protected function addFlagDay(): void + { + if ($this->year >= 1938) { + $this->addHoliday(new Holiday( + 'flagDay', + [ + 'en' => 'General Manuel Belgrano Memorial Day', + 'es' => 'Paso a la Inmortalidad del General Manuel Belgrano', + ], + new \DateTime("{$this->year}-06-20", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * Independence Day. + * + * Anniversary of the Declaration of Independence in 1816. + * + * @link https://en.wikipedia.org/wiki/Argentine_Declaration_of_Independence + */ + protected function addIndependenceDay(): void + { + if ($this->year >= self::PROCLAMATION_OF_INDEPENDENCE_YEAR) { + $this->addHoliday(new Holiday( + 'independenceDay', + [ + 'en' => 'Independence Day', + 'es' => 'Día de la Independencia', + ], + new \DateTime("{$this->year}-07-09", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * General José de San Martín Memorial Day. + * + * Anniversary of the death of José de San Martín, liberator of + * Argentina, Chile and Peru. + */ + protected function addGeneralJoseSanMartinDay(): void + { + if ($this->year >= 1850) { + $this->addHoliday(new Holiday( + 'generalJoseSanMartinDay', + [ + 'en' => 'General José de San Martín Memorial Day', + 'es' => 'Paso a la Inmortalidad del General José de San Martín', + ], + $this->adjustMovableHoliday(new \DateTime("{$this->year}-08-17", DateTimeZoneFactory::getDateTimeZone($this->timezone))), + $this->locale + )); + } + } + + /* + * Day of Respect for Cultural Diversity. + * + * Former "Día de la raza" (English: Race day), anniversary of the + * arrival of Columbus to the Americas. + * + * @link https://en.wikipedia.org/wiki/Columbus_Day + */ + protected function addRaceDay(): void + { + if ($this->year >= 1492) { + $this->addHoliday(new Holiday( + 'raceDay', + [ + 'en' => 'Day of Respect for Cultural Diversity', + 'es' => 'Día del Respeto a la Diversidad Cultural', + ], + $this->adjustMovableHoliday(new \DateTime("{$this->year}-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone))), + $this->locale + )); + } + } + + /* + * National Sovereignty Day. + * + * Anniversary of the 1845 Battle of Vuelta de Obligado against the + * Anglo-French blockade of the Río de la Plata. + * + * @link https://en.wikipedia.org/wiki/National_Sovereignty_Day + */ + protected function addNationalSovereigntyDay(): void + { + if ($this->year >= 2010) { + $this->addHoliday(new Holiday( + 'nationalSovereigntyDay', + [ + 'en' => 'National Sovereignty Day', + 'es' => 'Día de la Soberanía Nacional', + ], + $this->adjustMovableHoliday(new \DateTime("{$this->year}-11-20", DateTimeZoneFactory::getDateTimeZone($this->timezone))), + $this->locale + )); + } + } + + /* + * Immaculate Conception Day. + * + * Christian holiday, conception of the Virgin Mary free from original + * sin. + * + * @link https://en.wikipedia.org/wiki/Immaculate_Conception + */ + protected function addImmaculateConceptionDay(): void + { + if ($this->year >= 1900) { + $this->addHoliday(new Holiday( + 'immaculateConceptionDay', + [ + 'en' => 'Immaculate Conception Day', + 'es' => 'Día de la Inmaculada Concepción de María', + ], + new \DateTime("{$this->year}-12-08", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Adjusts a movable holiday. + * + * If certain holidays fall on a weekday, they are moved to a Monday in order to provide "long weekends". + * If the holiday falls on a Tuesday or Wednesday, it is moved to the previous Monday; if it falls on + * a Thursday or Friday, it is moved to the following Monday. + * + * These rules were introduced in 2017. Previously the were different rules which are currently not supported + * by Yasumi. + */ + protected function adjustMovableHoliday(\DateTime $dateTime): \DateTime + { + if ($this->year >= 2017) { + $adjustedDateTime = clone $dateTime; + switch ($adjustedDateTime->format('w')) { + case 2: + $adjustedDateTime->sub(new \DateInterval('P1D')); + break; + case 3: + $adjustedDateTime->sub(new \DateInterval('P2D')); + break; + case 4: + $adjustedDateTime->add(new \DateInterval('P4D')); + break; + case 5: + $adjustedDateTime->add(new \DateInterval('P3D')); + break; + } + + if (! $this->isHoliday($adjustedDateTime)) { + $dateTime = $adjustedDateTime; + } + } + + return $dateTime; + } +} diff --git a/src/Yasumi/Provider/Australia.php b/src/Yasumi/Provider/Australia.php old mode 100755 new mode 100644 index 2f87b0e78..2f2cdbc03 --- a/src/Yasumi/Provider/Australia.php +++ b/src/Yasumi/Provider/Australia.php @@ -1,38 +1,41 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; +use Yasumi\SubstituteHoliday; /** * Provider for all holidays in Australia. */ class Australia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU'; - public $timezone = 'Australia/Melbourne'; + public string $timezone = 'Australia/Melbourne'; /** * Initialize holidays for Australia. @@ -47,6 +50,7 @@ public function initialize(): void $this->calculateNewYearHolidays(); $this->calculateAustraliaDay(); $this->calculateAnzacDay(); + $this->calculateNationalDayOfMourning(); // Add Christian holidays $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); @@ -54,6 +58,13 @@ public function initialize(): void $this->calculateChristmasDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Australia', + ]; + } + /** * Holidays associated with the start of the modern Gregorian calendar. * @@ -62,59 +73,46 @@ public function initialize(): void * to the International Date Line, Australia is one of the first countries in the world to welcome the New Year. * If it falls on a weekend an additional public holiday is held on the next available weekday. * - * @link https://www.timeanddate.com/holidays/australia/new-year-day + * @see https://www.timeanddate.com/holidays/australia/new-year-day * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNewYearHolidays(): void + protected function calculateNewYearHolidays(): void { - $newyearsday = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)); - $this->calculateHoliday('newYearsDay', [], $newyearsday, false, false); - switch ($newyearsday->format('w')) { + $newYearsDay = new \DateTime("{$this->year}-01-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $this->addHoliday(new Holiday( + 'newYearsDay', + [], + $newYearsDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + switch ($newYearsDay->format('w')) { case 0: // sunday - $newyearsday->add(new DateInterval('P1D')); - $this->calculateHoliday('newYearsHoliday', ['en' => 'New Year\'s Holiday'], $newyearsday, false, false); + $newYearsDay->add(new \DateInterval('P1D')); + $this->addHoliday(new Holiday( + 'newYearsHoliday', + ['en' => 'New Year’s Holiday'], + $newYearsDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); break; case 6: // saturday - $newyearsday->add(new DateInterval('P2D')); - $this->calculateHoliday('newYearsHoliday', ['en' => 'New Year\'s Holiday'], $newyearsday, false, false); + $newYearsDay->add(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'newYearsHoliday', + ['en' => 'New Year’s Holiday'], + $newYearsDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); break; } } - /** - * Function to simplify moving holidays to mondays if required - * - * @param string $shortName - * @param array $names - * @param DateTime $date - * @param bool $moveFromSaturday - * @param bool $moveFromSunday - * @param string $type - * - * @throws InvalidDateException - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - public function calculateHoliday( - string $shortName, - array $names = [], - $date, - $moveFromSaturday = null, - $moveFromSunday = null, - $type = null - ): void { - $day = (int)$date->format('w'); - if ((0 === $day && ($moveFromSunday ?? true)) || (6 === $day && ($moveFromSaturday ?? true))) { - $date = $date->add(0 === $day ? new DateInterval('P1D') : new DateInterval('P2D')); - } - - $this->addHoliday(new Holiday($shortName, $names, $date, $this->locale, $type ?? Holiday::TYPE_OFFICIAL)); - } - /** * Australia Day. * @@ -126,18 +124,38 @@ public function calculateHoliday( * reflections on Australian history, official community awards, and citizenship ceremonies * welcoming new immigrants into the Australian community. * - * @link https://en.wikipedia.org/wiki/Waitangi_Day - * @link https://www.timeanddate.com/holidays/australia/australia-day + * @see https://en.wikipedia.org/wiki/Waitangi_Day + * @see https://www.timeanddate.com/holidays/australia/australia-day * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAustraliaDay(): void + protected function calculateAustraliaDay(): void { - $date = new DateTime("$this->year-01-26", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-01-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)); - $this->calculateHoliday('australiaDay', ['en' => 'Australia Day'], $date); + $holiday = new Holiday( + 'australiaDay', + ['en' => 'Australia Day'], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + ); + $this->addHoliday($holiday); + + $day = (int) $date->format('w'); + if (0 === $day || 6 === $day) { + $date = $date->add(0 === $day ? new \DateInterval('P1D') : new \DateInterval('P2D')); + + $this->addHoliday(new SubstituteHoliday( + $holiday, + [], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } } /** @@ -149,32 +167,71 @@ private function calculateAustraliaDay(): void * to the next available weekday, nor is there an additional public holiday held. However, if it clashes with Easter, * an additional public holiday is held for Easter. * - * @link https://en.wikipedia.org/wiki/Anzac_Day - * @link https://www.timeanddate.com/holidays/australia/anzac-day + * @see https://en.wikipedia.org/wiki/Anzac_Day + * @see https://www.timeanddate.com/holidays/australia/anzac-day * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAnzacDay(): void + protected function calculateAnzacDay(): void { if ($this->year < 1921) { return; } - $date = new DateTime("$this->year-04-25", new DateTimeZone($this->timezone)); - $this->calculateHoliday('anzacDay', [], $date, false, false); + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $this->addHoliday(new Holiday( + 'anzacDay', + [], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); $easter = $this->calculateEaster($this->year, $this->timezone); $easterMonday = $this->calculateEaster($this->year, $this->timezone); - $easterMonday->add(new DateInterval('P1D')); + $easterMonday->add(new \DateInterval('P1D')); $fDate = $date->format('Y-m-d'); if ($fDate === $easter->format('Y-m-d') || $fDate === $easterMonday->format('Y-m-d')) { - $easterMonday->add(new DateInterval('P1D')); - $this->calculateHoliday('easterTuesday', ['en' => 'Easter Tuesday'], $easterMonday, false, false); + $easterMonday->add(new \DateInterval('P1D')); + $this->addHoliday(new Holiday( + 'easterTuesday', + ['en' => 'Easter Tuesday'], + $easterMonday, + $this->locale, + Holiday::TYPE_OFFICIAL + )); } - unset($fDate); + } + + /** + * National Day of Mourning. + * + * An additional, once off, national public holiday was proclaimed on the 10th of September 2022, to be observed on the 22nd of September 2022, as a + * National day of mourning for the passing of Queen Elizabeth II + * + * @see https://www.pm.gov.au/media/commemorating-her-majesty-queen-elizabeth-ii + * @see https://www.timeanddate.com/holidays/australia/national-day-of-mourning + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalDayOfMourning(): void + { + if (2022 !== $this->year) { + return; + } + + $this->addHoliday(new Holiday( + 'nationalDayOfMourning', + ['en' => 'National Day of Mourning'], + new \DateTime("{$this->year}-9-22", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** @@ -183,33 +240,69 @@ private function calculateAnzacDay(): void * Christmas day, and Boxing day are public holidays in Australia, * if they fall on the weekend an additional public holiday is held on the next available weekday. * - * @link https://www.timeanddate.com/holidays/australia/christmas-day-holiday + * @see https://www.timeanddate.com/holidays/australia/christmas-day-holiday * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateChristmasDay(): void + protected function calculateChristmasDay(): void { - $christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone)); - $boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone)); - $this->calculateHoliday('christmasDay', [], $christmasDay, false, false); - $this->calculateHoliday('secondChristmasDay', [], $boxingDay, false, false); + $christmasDay = new \DateTime("{$this->year}-12-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $boxingDay = new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $this->addHoliday(new Holiday( + 'christmasDay', + [], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + $this->addHoliday(new Holiday( + 'secondChristmasDay', + [], + $boxingDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); switch ($christmasDay->format('w')) { case 0: // sunday - $christmasDay->add(new DateInterval('P2D')); - $this->calculateHoliday('christmasHoliday', ['en' => 'Christmas Holiday'], $christmasDay, false, false); + $christmasDay->add(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'christmasHoliday', + ['en' => 'Christmas Holiday'], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); break; case 5: // friday - $boxingDay->add(new DateInterval('P2D')); - $this->calculateHoliday('secondChristmasHoliday', ['en' => 'Boxing Day Holiday'], $boxingDay, false, false); + $boxingDay->add(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'secondChristmasHoliday', + ['en' => 'Boxing Day Holiday'], + $boxingDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); break; case 6: // saturday - $christmasDay->add(new DateInterval('P2D')); - $boxingDay->add(new DateInterval('P2D')); - $this->calculateHoliday('christmasHoliday', ['en' => 'Christmas Holiday'], $christmasDay, false, false); - $this->calculateHoliday('secondChristmasHoliday', ['en' => 'Boxing Day Holiday'], $boxingDay, false, false); + $christmasDay->add(new \DateInterval('P2D')); + $boxingDay->add(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'christmasHoliday', + ['en' => 'Christmas Holiday'], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + $this->addHoliday(new Holiday( + 'secondChristmasHoliday', + ['en' => 'Boxing Day Holiday'], + $boxingDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); break; } } diff --git a/src/Yasumi/Provider/Australia/ACT.php b/src/Yasumi/Provider/Australia/ACT.php deleted file mode 100644 index 4fc035f2e..000000000 --- a/src/Yasumi/Provider/Australia/ACT.php +++ /dev/null @@ -1,190 +0,0 @@ - - */ - -namespace Yasumi\Provider\Australia; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\UnknownLocaleException; -use Yasumi\Holiday; -use Yasumi\Provider\Australia; - -/** - * Provider for all holidays in Australian Capital Territory (Australia). - * - */ -class ACT extends Australia -{ - /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective - * country or sub-region. - */ - public const ID = 'AU-ACT'; - - public $timezone = 'Australia/ACT'; - - /** - * Initialize holidays for Australian Capital Territory (Australia). - * - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - public function initialize(): void - { - parent::initialize(); - - $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); - $this->calculateLabourDay(); - $this->calculateCanberraDay(); - $this->calculateReconciliationDay(); - } - - /** - * Easter Sunday. - * - * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated - * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council - * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. - * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function easterSunday($year, $timezone, $locale, $type = null): Holiday - { - return new Holiday( - 'easter', - ['en' => 'Easter Sunday'], - $this->calculateEaster($year, $timezone), - $locale, - $type ?? Holiday::TYPE_OFFICIAL - ); - } - - /** - * Easter Saturday. - * - * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated - * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council - * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. - * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function easterSaturday($year, $timezone, $locale, $type = null): Holiday - { - return new Holiday( - 'easterSaturday', - ['en' => 'Easter Saturday'], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P1D')), - $locale, - $type ?? Holiday::TYPE_OFFICIAL - ); - } - - /** - * Queens Birthday. - * - * The Queen's Birthday is an Australian public holiday but the date varies across - * states and territories. Australia celebrates this holiday because it is a constitutional - * monarchy, with the English monarch as head of state. - * - * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. - * (Except QLD & WA) - * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday - * - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function calculateQueensBirthday(): void - { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } - - /** - * Labour Day - * - * @throws \Exception - */ - private function calculateLabourDay(): void - { - $date = new DateTime("first monday of october $this->year", new DateTimeZone($this->timezone)); - - $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); - } - - /** - * Canberra Day - * - * @throws \Exception - */ - private function calculateCanberraDay(): void - { - if ($this->year < 2007) { - $date = new DateTime("third monday of march $this->year", new DateTimeZone($this->timezone)); - } else { - $date = new DateTime("second monday of march $this->year", new DateTimeZone($this->timezone)); - } - $this->addHoliday(new Holiday('canberraDay', ['en' => 'Canberra Day'], $date, $this->locale)); - } - - /** - * Reconciliation Day - * - * @throws \Exception - */ - private function calculateReconciliationDay(): void - { - if ($this->year < 2018) { - return; - } - - $date = new DateTime($this->year . '-05-27', new DateTimeZone($this->timezone)); - $day = (int)$date->format('w'); - if (1 !== $day) { - $date = $date->add(0 === $day ? new DateInterval('P1D') : new DateInterval('P' . (8 - $day) . 'D')); - } - $this->addHoliday(new Holiday('reconciliationDay', ['en' => 'Reconciliation Day'], $date, $this->locale)); - } -} diff --git a/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php new file mode 100644 index 000000000..2156e8cf3 --- /dev/null +++ b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php @@ -0,0 +1,202 @@ + + */ + +namespace Yasumi\Provider\Australia; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Australian Capital Territory (Australia). + */ +class AustralianCapitalTerritory extends Australia +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AU-ACT'; + + public string $timezone = 'Australia/ACT'; + + /** + * Initialize holidays for Australian Capital Territory (Australia). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); + $this->calculateQueensBirthday(); + $this->calculateLabourDay(); + $this->calculateCanberraDay(); + $this->calculateReconciliationDay(); + } + + /** + * Easter Sunday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + return new Holiday( + 'easter', + ['en' => 'Easter Sunday'], + $this->calculateEaster($year, $timezone), + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Easter Saturday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + + return new Holiday( + 'easterSaturday', + ['en' => 'Easter Saturday'], + $date, + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Queens Birthday. + * + * The Queen's Birthday is an Australian public holiday but the date varies across + * states and territories. Australia celebrates this holiday because it is a constitutional + * monarchy, with the English monarch as head of state. + * + * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. + * (Except QLD & WA) + * + * @see https://www.timeanddate.com/holidays/australia/queens-birthday + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function calculateQueensBirthday(): void + { + $this->addHoliday(new Holiday( + 'queensBirthday', + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Labour Day. + * + * @throws \Exception + */ + protected function calculateLabourDay(): void + { + $date = new \DateTime("first monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); + } + + /** + * Canberra Day. + * + * @throws \Exception + */ + protected function calculateCanberraDay(): void + { + $datePattern = $this->year < 2007 ? "third monday of march {$this->year}" : "second monday of march {$this->year}"; + + $this->addHoliday( + new Holiday( + 'canberraDay', + ['en' => 'Canberra Day'], + new \DateTime($datePattern, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + ) + ); + } + + /** + * Reconciliation Day. + * + * @throws \Exception + */ + protected function calculateReconciliationDay(): void + { + if ($this->year < 2018) { + return; + } + + $date = new \DateTime("{$this->year}-05-27", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $day = (int) $date->format('w'); + if (1 !== $day) { + $date = $date->add(0 === $day ? new \DateInterval('P1D') : new \DateInterval(sprintf('P%dD', 8 - $day))); + } + $this->addHoliday(new Holiday('reconciliationDay', ['en' => 'Reconciliation Day'], $date, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Australia/NSW.php b/src/Yasumi/Provider/Australia/NewSouthWales.php similarity index 52% rename from src/Yasumi/Provider/Australia/NSW.php rename to src/Yasumi/Provider/Australia/NewSouthWales.php index df5c7567e..b2c8c6a56 100644 --- a/src/Yasumi/Provider/Australia/NSW.php +++ b/src/Yasumi/Provider/Australia/NewSouthWales.php @@ -1,37 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in New South Wales (Australia). - * */ -class NSW extends Australia +class NewSouthWales extends Australia { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU-NSW'; - public $timezone = 'Australia/NSW'; + public string $timezone = 'Australia/NSW'; /** * Initialize holidays for New South Wales (Australia). @@ -58,26 +60,32 @@ public function initialize(): void * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @see https://en.wikipedia.org/wiki/Easter * - * @return Holiday + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - private function easterSaturday($year, $timezone, $locale, $type = null): Holiday - { + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + return new Holiday( 'easterSaturday', ['en' => 'Easter Saturday'], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P1D')), + $date, $locale, $type ?? Holiday::TYPE_OFFICIAL ); @@ -93,30 +101,30 @@ private function easterSaturday($year, $timezone, $locale, $type = null): Holida * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. * (Except QLD & WA) * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday + * @see https://www.timeanddate.com/holidays/australia/queens-birthday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** - * Labour Day + * Labour Day. * * @throws \Exception */ - private function calculateLabourDay(): void + protected function calculateLabourDay(): void { - $date = new DateTime("first monday of october $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("first monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); } @@ -127,15 +135,14 @@ private function calculateLabourDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateBankHoliday(): void + protected function calculateBankHoliday(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'bankHoliday', ['en' => 'Bank Holiday'], - new DateTime('first monday of august ' . $this->year, new DateTimeZone($this->timezone)), - false, - false, + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, Holiday::TYPE_BANK - ); + )); } } diff --git a/src/Yasumi/Provider/Australia/NT.php b/src/Yasumi/Provider/Australia/NorthernTerritory.php similarity index 50% rename from src/Yasumi/Provider/Australia/NT.php rename to src/Yasumi/Provider/Australia/NorthernTerritory.php index 53444460c..1b3b1291c 100644 --- a/src/Yasumi/Provider/Australia/NT.php +++ b/src/Yasumi/Provider/Australia/NorthernTerritory.php @@ -1,37 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Northern Territory (Australia). - * */ -class NT extends Australia +class NorthernTerritory extends Australia { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU-NT'; - public $timezone = 'Australia/North'; + public string $timezone = 'Australia/North'; /** * Initialize holidays for Northern Territory (Australia). @@ -57,26 +59,32 @@ public function initialize(): void * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @see https://en.wikipedia.org/wiki/Easter * - * @return Holiday + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - private function easterSaturday($year, $timezone, $locale, $type = null): Holiday - { + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + return new Holiday( 'easterSaturday', ['en' => 'Easter Saturday'], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P1D')), + $date, $locale, $type ?? Holiday::TYPE_OFFICIAL ); @@ -92,50 +100,50 @@ private function easterSaturday($year, $timezone, $locale, $type = null): Holida * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. * (Except QLD & WA) * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday + * @see https://www.timeanddate.com/holidays/australia/queens-birthday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** - * May Day + * May Day. * * @throws \Exception */ - private function calculateMayDay(): void + protected function calculateMayDay(): void { - $date = new DateTime("first monday of may $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("first monday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('mayDay', ['en' => 'May Day'], $date, $this->locale)); } /** - * Picnic Day + * Picnic Day. * - * @link https://en.wikipedia.org/wiki/Picnic_Day_(Australian_holiday) + * @see https://en.wikipedia.org/wiki/Picnic_Day_(Australian_holiday) * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculatePicnicDay(): void + protected function calculatePicnicDay(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'picnicDay', ['en' => 'Picnic Day'], - new DateTime('first monday of august ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } } diff --git a/src/Yasumi/Provider/Australia/Queensland.php b/src/Yasumi/Provider/Australia/Queensland.php index 0e954878b..f77c57949 100644 --- a/src/Yasumi/Provider/Australia/Queensland.php +++ b/src/Yasumi/Provider/Australia/Queensland.php @@ -1,36 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Queensland (Australia). - * */ class Queensland extends Australia { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU-QLD'; - public $timezone = 'Australia/Queensland'; + public string $timezone = 'Australia/Queensland'; /** * Initialize holidays for Queensland (Australia). @@ -57,43 +60,38 @@ public function initialize(): void * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. * (Except QLD & WA) * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday + * @see https://www.timeanddate.com/holidays/australia/queens-birthday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { + $birthDay = "first monday of october {$this->year}"; + if ($this->year < 2012 || 2013 === $this->year || 2014 === $this->year || 2015 === $this->year) { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } else { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('first monday of october ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + $birthDay = "second monday of june {$this->year}"; } + + $this->addHoliday(new Holiday( + 'queensBirthday', + [], + new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** - * Labour Day + * Labour Day. * * @throws \Exception */ - private function calculateLabourDay(): void + protected function calculateLabourDay(): void { + $date = new \DateTime("first monday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if (2013 === $this->year || 2014 === $this->year || 2015 === $this->year) { - $date = new DateTime("first monday of october $this->year", new DateTimeZone($this->timezone)); - } else { - $date = new DateTime("first monday of may $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("first monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); diff --git a/src/Yasumi/Provider/Australia/Queensland/Brisbane.php b/src/Yasumi/Provider/Australia/Queensland/Brisbane.php index 84accf1a6..6fcc85daf 100644 --- a/src/Yasumi/Provider/Australia/Queensland/Brisbane.php +++ b/src/Yasumi/Provider/Australia/Queensland/Brisbane.php @@ -1,38 +1,40 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Queensland; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Queensland; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Brisbane (Australia). - * */ class Brisbane extends Queensland { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there isn't one specifically for Brisbane, * and I believe this is a logical extension. */ public const ID = 'AU-QLD-BRI'; - public $timezone = 'Australia/Brisbane'; + public string $timezone = 'Australia/Brisbane'; /** * Initialize holidays for Brisbane (Australia). @@ -59,19 +61,19 @@ public function initialize(): void * "People's Day". The Ekka starts on the first Friday in August, except if the first Friday is before 5 August, in * which case it starts on the second Friday of August. People's Day is then the Wednesday after the Ekka commences. * - * @link https://en.wikipedia.org/wiki/Ekka + * @see https://en.wikipedia.org/wiki/Ekka * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePeoplesDay(): void + protected function calculatePeoplesDay(): void { - $date = new DateTime('first friday of august ' . $this->year, new DateTimeZone($this->timezone)); + $date = new \DateTime("first friday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if ($date->format('d') < 5) { - $date = $date->add(new DateInterval('P7D')); + $date = $date->add(new \DateInterval('P7D')); } - $date = $date->add(new DateInterval('P5D')); - $this->addHoliday(new Holiday('peoplesDay', ['en' => 'Ekka People\'s Day'], $date, $this->locale)); + $date = $date->add(new \DateInterval('P5D')); + $this->addHoliday(new Holiday('peoplesDay', ['en' => 'Ekka People’s Day'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/SA.php b/src/Yasumi/Provider/Australia/SA.php deleted file mode 100644 index 1f337c229..000000000 --- a/src/Yasumi/Provider/Australia/SA.php +++ /dev/null @@ -1,194 +0,0 @@ - - */ - -namespace Yasumi\Provider\Australia; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\UnknownLocaleException; -use Yasumi\Holiday; -use Yasumi\Provider\Australia; - -/** - * Provider for all holidays in South Australia (Australia). - * - */ -class SA extends Australia -{ - /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective - * country or sub-region. - */ - public const ID = 'AU-SA'; - - public $timezone = 'Australia/South'; - - /** - * Initialize holidays for South Australia (Australia). - * - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - public function initialize(): void - { - parent::initialize(); - - $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); - $this->calculateLabourDay(); - $this->calculateAdelaideCupDay(); - - // South Australia have Proclamation Day instead of Boxing Day, but the date definition is slightly different, - // so we have to rework everything here... - $this->removeHoliday('christmasDay'); - $this->removeHoliday('secondChristmasDay'); - $this->removeHoliday('christmasHoliday'); - $this->removeHoliday('secondChristmasHoliday'); - $this->calculateProclamationDay(); - } - - /** - * Easter Saturday. - * - * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated - * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council - * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. - * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function easterSaturday($year, $timezone, $locale, $type = null): Holiday - { - return new Holiday( - 'easterSaturday', - ['en' => 'Easter Saturday'], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P1D')), - $locale, - $type ?? Holiday::TYPE_OFFICIAL - ); - } - - /** - * Queens Birthday. - * - * The Queen's Birthday is an Australian public holiday but the date varies across - * states and territories. Australia celebrates this holiday because it is a constitutional - * monarchy, with the English monarch as head of state. - * - * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. - * (Except QLD & WA) - * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday - * - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function calculateQueensBirthday(): void - { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } - - /** - * Labour Day - * - * @throws \Exception - */ - private function calculateLabourDay(): void - { - $date = new DateTime("first monday of october $this->year", new DateTimeZone($this->timezone)); - - $this->addHoliday(new Holiday('labourDay', ['en' => 'Labour Day'], $date, $this->locale)); - } - - /** - * Adelaide Cup Day - * - * @link https://en.wikipedia.org/wiki/Adelaide_Cup - * - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function calculateAdelaideCupDay(): void - { - if ($this->year >= 1973) { - if ($this->year < 2006) { - $this->calculateHoliday( - 'adelaideCup', - ['en' => 'Adelaide Cup'], - new DateTime('third monday of may ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } else { - $this->calculateHoliday( - 'adelaideCup', - ['en' => 'Adelaide Cup'], - new DateTime('second monday of march ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } - } - } - - /** - * Proclamation Day - * - * @throws \Exception - */ - private function calculateProclamationDay(): void - { - $christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone)); - $this->calculateHoliday('christmasDay', [], $christmasDay, false, false); - switch ($christmasDay->format('w')) { - case 0: // sunday - $christmasDay->add(new DateInterval('P1D')); - $this->calculateHoliday('christmasHoliday', ['en' => 'Christmas Holiday'], $christmasDay, false, false); - $proclamationDay = $christmasDay->add(new DateInterval('P1D')); - $this->calculateHoliday('proclamationDay', ['en' => 'Proclamation Day'], $proclamationDay, false, false); - break; - case 5: // friday - $proclamationDay = $christmasDay->add(new DateInterval('P3D')); - $this->calculateHoliday('proclamationDay', ['en' => 'Proclamation Day'], $proclamationDay, false, false); - break; - case 6: // saturday - $christmasDay->add(new DateInterval('P2D')); - $this->calculateHoliday('christmasHoliday', ['en' => 'Christmas Holiday'], $christmasDay, false, false); - $proclamationDay = $christmasDay->add(new DateInterval('P1D')); - $this->calculateHoliday('proclamationDay', ['en' => 'Proclamation Day'], $proclamationDay, false, false); - break; - default: // monday-thursday - $proclamationDay = $christmasDay->add(new DateInterval('P1D')); - $this->calculateHoliday('proclamationDay', ['en' => 'Proclamation Day'], $proclamationDay, false, false); - break; - } - } -} diff --git a/src/Yasumi/Provider/Australia/SouthAustralia.php b/src/Yasumi/Provider/Australia/SouthAustralia.php new file mode 100644 index 000000000..7c4854639 --- /dev/null +++ b/src/Yasumi/Provider/Australia/SouthAustralia.php @@ -0,0 +1,222 @@ + + */ + +namespace Yasumi\Provider\Australia; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in South Australia (Australia). + */ +class SouthAustralia extends Australia +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AU-SA'; + + public string $timezone = 'Australia/South'; + + /** + * Initialize holidays for South Australia (Australia). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); + $this->calculateQueensBirthday(); + $this->calculateLabourDay(); + $this->calculateAdelaideCupDay(); + + // South Australia have Proclamation Day instead of Boxing Day, but the date definition is slightly different, + // so we have to rework everything here... + $this->removeHoliday('christmasDay'); + $this->removeHoliday('secondChristmasDay'); + $this->removeHoliday('christmasHoliday'); + $this->removeHoliday('secondChristmasHoliday'); + $this->calculateProclamationDay(); + } + + /** + * Easter Saturday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + + return new Holiday( + 'easterSaturday', + ['en' => 'Easter Saturday'], + $date, + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Queens Birthday. + * + * The Queen's Birthday is an Australian public holiday but the date varies across + * states and territories. Australia celebrates this holiday because it is a constitutional + * monarchy, with the English monarch as head of state. + * + * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. + * (Except QLD & WA) + * + * @see https://www.timeanddate.com/holidays/australia/queens-birthday + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function calculateQueensBirthday(): void + { + $this->addHoliday(new Holiday( + 'queensBirthday', + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Labour Day. + * + * @throws \Exception + */ + protected function calculateLabourDay(): void + { + $date = new \DateTime("first monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('labourDay', ['en' => 'Labour Day'], $date, $this->locale)); + } + + /** + * Adelaide Cup Day. + * + * @see https://en.wikipedia.org/wiki/Adelaide_Cup + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function calculateAdelaideCupDay(): void + { + if ($this->year >= 1973) { + $cupDay = "second monday of march {$this->year}"; + + if ($this->year < 2006) { + $cupDay = "third monday of may {$this->year}"; + } + + $this->addHoliday(new Holiday( + 'adelaideCup', + ['en' => 'Adelaide Cup'], + new \DateTime($cupDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + } + + /** + * Proclamation Day. + * + * @throws \Exception + */ + protected function calculateProclamationDay(): void + { + $christmasDay = new \DateTime("{$this->year}-12-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday( + 'christmasDay', + [], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + + switch ($christmasDay->format('w')) { + case 0: // sunday + $christmasDay->add(new \DateInterval('P1D')); + $this->addHoliday(new Holiday( + 'christmasHoliday', + ['en' => 'Christmas Holiday'], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + $christmasDay->add(new \DateInterval('P1D')); + break; + case 5: // friday + $christmasDay->add(new \DateInterval('P3D')); + break; + case 6: // saturday + $christmasDay->add(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'christmasHoliday', + ['en' => 'Christmas Holiday'], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + $christmasDay->add(new \DateInterval('P1D')); + break; + default: // monday-thursday + $christmasDay->add(new \DateInterval('P1D')); + break; + } + + $this->addHoliday(new Holiday( + 'proclamationDay', + ['en' => 'Proclamation Day'], + $christmasDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } +} diff --git a/src/Yasumi/Provider/Australia/Tasmania.php b/src/Yasumi/Provider/Australia/Tasmania.php index bf53bbe03..e23a3994d 100644 --- a/src/Yasumi/Provider/Australia/Tasmania.php +++ b/src/Yasumi/Provider/Australia/Tasmania.php @@ -1,36 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Tasmania (Australia). - * */ class Tasmania extends Australia { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU-TAS'; - public $timezone = 'Australia/Tasmania'; + public string $timezone = 'Australia/Tasmania'; /** * Initialize holidays for Tasmania (Australia). @@ -49,13 +52,13 @@ public function initialize(): void } /** - * Eight Hours Day + * Eight Hours Day. * * @throws \Exception */ - private function calculateEightHoursDay(): void + protected function calculateEightHoursDay(): void { - $date = new DateTime("second monday of march $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("second monday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('eightHourDay', ['en' => 'Eight Hour Day'], $date, $this->locale)); } @@ -70,38 +73,38 @@ private function calculateEightHoursDay(): void * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. * (Except QLD & WA) * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday + * @see https://www.timeanddate.com/holidays/australia/queens-birthday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'queensBirthday', - ['en' => 'Queen\'s Birthday'], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** - * Recreation Day + * Recreation Day. * - * @link https://en.wikipedia.org/wiki/Recreation_Day_holiday + * @see https://en.wikipedia.org/wiki/Recreation_Day_holiday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateRecreationDay(): void + protected function calculateRecreationDay(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'recreationDay', ['en' => 'Recreation Day'], - new DateTime('first monday of november ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + new \DateTime("first monday of november {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/CentralNorth.php b/src/Yasumi/Provider/Australia/Tasmania/CentralNorth.php index 65761d3fb..016a827f6 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/CentralNorth.php +++ b/src/Yasumi/Provider/Australia/Tasmania/CentralNorth.php @@ -1,31 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in central north Tasmania (Australia). - * */ class CentralNorth extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -46,14 +49,19 @@ public function initialize(): void } /** - * Devonport Show + * Devonport Show. * * @throws \Exception */ - private function calculateDevonportShow(): void + protected function calculateDevonportShow(): void { - $date = new DateTime($this->year . '-12-02', new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-12-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $date = $date->modify('previous friday'); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'devonportShow')); + } + $this->addHoliday(new Holiday('devonportShow', ['en' => 'Devonport Show'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/FlindersIsland.php b/src/Yasumi/Provider/Australia/Tasmania/FlindersIsland.php index 2dedb98d8..dac5990f9 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/FlindersIsland.php +++ b/src/Yasumi/Provider/Australia/Tasmania/FlindersIsland.php @@ -1,32 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Flinders Island (Australia). - * */ class FlindersIsland extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -47,14 +49,14 @@ public function initialize(): void } /** - * Flinders Island Show + * Flinders Island Show. * * @throws \Exception */ - private function calculateFlindersIslandShow(): void + protected function calculateFlindersIslandShow(): void { - $date = new DateTime('third saturday of october ' . $this->year, new DateTimeZone($this->timezone)); - $date = $date->sub(new DateInterval('P1D')); + $date = new \DateTime("third saturday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $date = $date->sub(new \DateInterval('P1D')); $this->addHoliday(new Holiday('flindersIslandShow', ['en' => 'Flinders Island Show'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/KingIsland.php b/src/Yasumi/Provider/Australia/Tasmania/KingIsland.php index f26bdd06d..e7540f281 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/KingIsland.php +++ b/src/Yasumi/Provider/Australia/Tasmania/KingIsland.php @@ -1,30 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in King Island (Australia). - * */ class KingIsland extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -45,18 +49,18 @@ public function initialize(): void } /** - * King Island Show + * King Island Show. * * @throws \Exception */ - private function calculateKingIslandShow(): void + protected function calculateKingIslandShow(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'kingIslandShow', ['en' => 'King Island Show'], - new DateTime('first tuesday of march ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + new \DateTime("first tuesday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/Northeast.php b/src/Yasumi/Provider/Australia/Tasmania/Northeast.php index dcd67f1c1..da40d8dda 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/Northeast.php +++ b/src/Yasumi/Provider/Australia/Tasmania/Northeast.php @@ -1,32 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in northeastern Tasmania (Australia). - * */ class Northeast extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -47,14 +49,14 @@ public function initialize(): void } /** - * Royal Launceston Show + * Royal Launceston Show. * * @throws \Exception */ - private function calculateLauncestonShow(): void + protected function calculateLauncestonShow(): void { - $date = new DateTime('second saturday of october ' . $this->year, new DateTimeZone($this->timezone)); - $date = $date->sub(new DateInterval('P2D')); + $date = new \DateTime("second saturday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $date = $date->sub(new \DateInterval('P2D')); $this->addHoliday(new Holiday('launcestonShow', ['en' => 'Royal Launceston Show'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/Northwest.php b/src/Yasumi/Provider/Australia/Tasmania/Northwest.php index 049d56c0f..3b4b51ff1 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/Northwest.php +++ b/src/Yasumi/Provider/Australia/Tasmania/Northwest.php @@ -1,32 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in northwestern Tasmania (Australia). - * */ class Northwest extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -47,14 +49,14 @@ public function initialize(): void } /** - * Burnie Show + * Burnie Show. * * @throws \Exception */ - private function calculateBurnieShow(): void + protected function calculateBurnieShow(): void { - $date = new DateTime('first saturday of october ' . $this->year, new DateTimeZone($this->timezone)); - $date = $date->sub(new DateInterval('P1D')); + $date = new \DateTime("first saturday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $date = $date->sub(new \DateInterval('P1D')); $this->addHoliday(new Holiday('burnieShow', ['en' => 'Burnie Show'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/Northwest/CircularHead.php b/src/Yasumi/Provider/Australia/Tasmania/Northwest/CircularHead.php index 4c7108281..fabb82d31 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/Northwest/CircularHead.php +++ b/src/Yasumi/Provider/Australia/Tasmania/Northwest/CircularHead.php @@ -1,32 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania\Northwest; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania\Northwest; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Circular Head (Australia). - * */ class CircularHead extends Northwest { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -47,14 +49,14 @@ public function initialize(): void } /** - * AGFEST + * AGFEST. * * @throws \Exception */ - private function calculateAGFEST(): void + protected function calculateAGFEST(): void { - $date = new DateTime('first thursday of may ' . $this->year, new DateTimeZone($this->timezone)); - $date = $date->add(new DateInterval('P1D')); + $date = new \DateTime("first thursday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $date = $date->add(new \DateInterval('P1D')); $this->addHoliday(new Holiday('agfest', ['en' => 'AGFEST'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/South.php b/src/Yasumi/Provider/Australia/Tasmania/South.php index 562b59de0..53951dbcb 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/South.php +++ b/src/Yasumi/Provider/Australia/Tasmania/South.php @@ -1,32 +1,34 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in southern Tasmania (Australia). - * */ class South extends Tasmania { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ @@ -47,14 +49,14 @@ public function initialize(): void } /** - * Royal Hobart Show + * Royal Hobart Show. * * @throws \Exception */ - private function calculateHobartShow(): void + protected function calculateHobartShow(): void { - $date = new DateTime('fourth saturday of october ' . $this->year, new DateTimeZone($this->timezone)); - $date = $date->sub(new DateInterval('P2D')); + $date = new \DateTime("fourth saturday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $date = $date->sub(new \DateInterval('P2D')); $this->addHoliday(new Holiday('hobartShow', ['en' => 'Royal Hobart Show'], $date, $this->locale)); } } diff --git a/src/Yasumi/Provider/Australia/Tasmania/South/Southeast.php b/src/Yasumi/Provider/Australia/Tasmania/South/Southeast.php index c1ae91d3c..12497bb72 100644 --- a/src/Yasumi/Provider/Australia/Tasmania/South/Southeast.php +++ b/src/Yasumi/Provider/Australia/Tasmania/South/Southeast.php @@ -1,36 +1,40 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia\Tasmania\South; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; use Yasumi\Provider\Australia\Tasmania\South; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in southeastern Tasmania (Australia). - * */ class Southeast extends South { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. This one is not a proper ISO3166 code, but there aren't any for areas within Tasmania, * and I believe it to be a logical extension. */ public const ID = 'AU-TAS-SOU-SE'; - public $timezone = 'Australia/Hobart'; + public string $timezone = 'Australia/Hobart'; /** * Initialize holidays for southeastern Tasmania (Australia). @@ -48,18 +52,18 @@ public function initialize(): void } /** - * Royal Hobart Regatta + * Royal Hobart Regatta. * * @throws \Exception */ - private function calculateHobartRegatta(): void + protected function calculateHobartRegatta(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'hobartRegatta', ['en' => 'Royal Hobart Regatta'], - new DateTime('second monday of february ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + new \DateTime("second monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } } diff --git a/src/Yasumi/Provider/Australia/Victoria.php b/src/Yasumi/Provider/Australia/Victoria.php index 88a9a2ccf..4b66dd0f2 100644 --- a/src/Yasumi/Provider/Australia/Victoria.php +++ b/src/Yasumi/Provider/Australia/Victoria.php @@ -1,37 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Australia; -use DateInterval; -use DateTime; -use DateTimeZone; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; /** * Provider for all holidays in Victoria (Australia). - * */ class Victoria extends Australia { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AU-VIC'; - public $timezone = 'Australia/Victoria'; + public string $timezone = 'Australia/Victoria'; /** * Initialize holidays for Victoria (Australia). @@ -59,22 +61,22 @@ public function initialize(): void * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @link https://en.wikipedia.org/wiki/Easter - * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @see https://en.wikipedia.org/wiki/Easter * - * @return Holiday + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - private function easterSunday($year, $timezone, $locale, $type = null): Holiday - { + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { return new Holiday( 'easter', ['en' => 'Easter Sunday'], @@ -91,39 +93,45 @@ private function easterSunday($year, $timezone, $locale, $type = null): Holiday * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @link https://en.wikipedia.org/wiki/Easter + * @see https://en.wikipedia.org/wiki/Easter * - * @param int $year the year for which Easter Saturday need to be created - * @param string $timezone the timezone in which Easter Saturday is celebrated - * @param string $locale the locale for which Easter Saturday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - private function easterSaturday($year, $timezone, $locale, $type = null): Holiday - { + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + return new Holiday( 'easterSaturday', ['en' => 'Easter Saturday'], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P1D')), + $date, $locale, $type ?? Holiday::TYPE_OFFICIAL ); } /** - * Labour Day + * Labour Day. * * @throws \Exception */ - private function calculateLabourDay(): void + protected function calculateLabourDay(): void { - $date = new DateTime("second monday of march $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("second monday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); } @@ -138,40 +146,40 @@ private function calculateLabourDay(): void * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. * (Except QLD & WA) * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday + * @see https://www.timeanddate.com/holidays/australia/queens-birthday * * @throws \InvalidArgumentException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { - $this->calculateHoliday( + $this->addHoliday(new Holiday( 'queensBirthday', - ['en' => 'Queen\'s Birthday'], - new DateTime('second monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); + [], + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** - * Melbourne Cup Day + * Melbourne Cup Day. * * @throws \Exception */ - private function calculateMelbourneCupDay(): void + protected function calculateMelbourneCupDay(): void { - $date = new DateTime('first Tuesday of November' . " $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("first Tuesday of November {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('melbourneCup', ['en' => 'Melbourne Cup'], $date, $this->locale)); } /** - * AFL Grand Final Day + * AFL Grand Final Day. * * @throws \Exception */ - private function calculateAFLGrandFinalDay(): void + protected function calculateAFLGrandFinalDay(): void { switch ($this->year) { case 2015: @@ -186,11 +194,17 @@ private function calculateAFLGrandFinalDay(): void case 2018: $aflGrandFinalFriday = '2018-09-28'; break; + case 2019: + $aflGrandFinalFriday = '2019-09-27'; + break; + case 2020: + $aflGrandFinalFriday = '2020-09-25'; + break; default: return; } - $date = new DateTime($aflGrandFinalFriday, new DateTimeZone($this->timezone)); + $date = new \DateTime($aflGrandFinalFriday, DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday( 'aflGrandFinalFriday', diff --git a/src/Yasumi/Provider/Australia/WA.php b/src/Yasumi/Provider/Australia/WA.php deleted file mode 100644 index 74649e098..000000000 --- a/src/Yasumi/Provider/Australia/WA.php +++ /dev/null @@ -1,125 +0,0 @@ - - */ - -namespace Yasumi\Provider\Australia; - -use DateTime; -use DateTimeZone; -use Yasumi\Exception\UnknownLocaleException; -use Yasumi\Holiday; -use Yasumi\Provider\Australia; - -/** - * Provider for all holidays in Western Australia (Australia). - * - */ -class WA extends Australia -{ - /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective - * country or sub-region. - */ - public const ID = 'AU-WA'; - - public $timezone = 'Australia/West'; - - /** - * Initialize holidays for Western Australia (Australia). - * - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - public function initialize(): void - { - parent::initialize(); - - $this->calculateQueensBirthday(); - $this->calculateLabourDay(); - $this->calculateWesternAustraliaDay(); - } - - /** - * Queens Birthday. - * - * The Queen's Birthday is an Australian public holiday but the date varies across - * states and territories. Australia celebrates this holiday because it is a constitutional - * monarchy, with the English monarch as head of state. - * - * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. - * (Except QLD & WA) - * - * @link https://www.timeanddate.com/holidays/australia/queens-birthday - * - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function calculateQueensBirthday(): void - { - if (2011 === $this->year) { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('2011-10-28', new DateTimeZone($this->timezone)), - false, - false - ); - } elseif (2012 === $this->year) { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('2012-10-01', new DateTimeZone($this->timezone)), - false, - false - ); - } else { - $this->calculateHoliday( - 'queensBirthday', - ['en' => "Queen's Birthday"], - new DateTime('last monday of september ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } - } - - /** - * Labour Day - * - * @throws \Exception - */ - private function calculateLabourDay(): void - { - $date = new DateTime("first monday of march $this->year", new DateTimeZone($this->timezone)); - - $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); - } - - /** - * Western Australia Day - * - * @link https://en.wikipedia.org/wiki/Western_Australia_Day - * - * @throws \InvalidArgumentException - * @throws \Exception - */ - private function calculateWesternAustraliaDay(): void - { - $this->calculateHoliday( - 'westernAustraliaDay', - ['en' => 'Western Australia Day'], - new DateTime('first monday of june ' . $this->year, new DateTimeZone($this->timezone)), - false, - false - ); - } -} diff --git a/src/Yasumi/Provider/Australia/WesternAustralia.php b/src/Yasumi/Provider/Australia/WesternAustralia.php new file mode 100644 index 000000000..b0cd462ea --- /dev/null +++ b/src/Yasumi/Provider/Australia/WesternAustralia.php @@ -0,0 +1,119 @@ + + */ + +namespace Yasumi\Provider\Australia; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Australia; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Western Australia (Australia). + */ +class WesternAustralia extends Australia +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AU-WA'; + + public string $timezone = 'Australia/West'; + + /** + * Initialize holidays for Western Australia (Australia). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->calculateQueensBirthday(); + $this->calculateLabourDay(); + $this->calculateWesternAustraliaDay(); + } + + /** + * Queens Birthday. + * + * The Queen's Birthday is an Australian public holiday but the date varies across + * states and territories. Australia celebrates this holiday because it is a constitutional + * monarchy, with the English monarch as head of state. + * + * Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June. + * (Except QLD & WA) + * + * @see https://www.timeanddate.com/holidays/australia/queens-birthday + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function calculateQueensBirthday(): void + { + $birthDay = "last monday of september {$this->year}"; + if (2011 === $this->year) { + $birthDay = '2011-10-28'; + } + + if (2012 === $this->year) { + $birthDay = '2012-10-01'; + } + + $this->addHoliday(new Holiday( + 'queensBirthday', + [], + new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Labour Day. + * + * @throws \Exception + */ + protected function calculateLabourDay(): void + { + $date = new \DateTime("first monday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); + } + + /** + * Western Australia Day. + * + * @see https://en.wikipedia.org/wiki/Western_Australia_Day + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function calculateWesternAustraliaDay(): void + { + $this->addHoliday(new Holiday( + 'westernAustraliaDay', + ['en' => 'Western Australia Day'], + new \DateTime("first monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } +} diff --git a/src/Yasumi/Provider/Austria.php b/src/Yasumi/Provider/Austria.php index 0d31900db..b5f621f4f 100644 --- a/src/Yasumi/Provider/Austria.php +++ b/src/Yasumi/Provider/Austria.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Austria extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'AT'; @@ -34,7 +37,6 @@ class Austria extends AbstractProvider /** * Initialize holidays for Austria. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -65,6 +67,43 @@ public function initialize(): void $this->calculateNationalDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Austria', + 'https://de.wikipedia.org/wiki/Feiertage_in_%C3%96sterreich', + ]; + } + + /** + * Saint Leopold's Day. + * + * Saint Leopold III, known as Leopold the Good, was the Margrave of Austria + * from 1095 to his death in 1136. He was a member of the House of + * Babenberg. He was canonized on 6 January 1485 and became the patron saint + * of Austria, Lower Austria, Upper Austria, and Vienna. His feast day is 15 + * November. + * + * @see https://en.wikipedia.org/wiki/Leopold_III,_Margrave_of_Austria + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateStLeopoldsDay(): void + { + if ($this->year < 1136) { + return; + } + + $this->addHoliday(new Holiday( + 'stLeopoldsDay', + [], + new \DateTime("{$this->year}-11-15", new \DateTimeZone($this->timezone)), + $this->locale + )); + } + /** * National Day. * @@ -73,14 +112,13 @@ public function initialize(): void * become a deeply ingrained element of Austrian identity. Austria's national holiday on 26 October commemorates * the declaration. * - * @link https://en.wikipedia.org/wiki/Declaration_of_Neutrality + * @see https://en.wikipedia.org/wiki/Declaration_of_Neutrality * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalDay(): void + protected function calculateNationalDay(): void { if ($this->year < 1955) { return; @@ -89,7 +127,7 @@ private function calculateNationalDay(): void $this->addHoliday(new Holiday( 'nationalDay', ['de' => 'Nationalfeiertag'], - new DateTime($this->year . '-10-26', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-26", new \DateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Austria/Burgenland.php b/src/Yasumi/Provider/Austria/Burgenland.php new file mode 100644 index 000000000..9ae42737a --- /dev/null +++ b/src/Yasumi/Provider/Austria/Burgenland.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Burgenland (Austria). + * + * @see https://en.wikipedia.org/wiki/Burgenland + */ +class Burgenland extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-1'; + + /** + * Initialize holidays for Burgenland (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom Common holidays. + $this->addHoliday($this->stMartinsDay($this->year, $this->timezone, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Austria/Carinthia.php b/src/Yasumi/Provider/Austria/Carinthia.php new file mode 100644 index 000000000..5c10fbb68 --- /dev/null +++ b/src/Yasumi/Provider/Austria/Carinthia.php @@ -0,0 +1,80 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Carinthia (Austria). + * + * @see https://en.wikipedia.org/wiki/Carinthia + */ +class Carinthia extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-2'; + + /** + * Initialize holidays for Carinthia (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom Common holidays. + $this->addHoliday($this->stJosephsDay($this->year, $this->timezone, $this->locale)); + $this->calculatePlebisciteDay(); + } + + /** + * Plebiscite Day. + * + * The Carinthian plebiscite was held on 10 October 1920 in the area + * predominantly settled by Carinthian Slovenes. It determined the final + * southern border between the Republic of Austria and the newly formed + * Kingdom of Serbs, Croats and Slovenes (Yugoslavia) after World War I. + * + * @see https://en.wikipedia.org/wiki/1920_Carinthian_plebiscite + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculatePlebisciteDay(): void + { + if ($this->year < 1920) { + return; + } + + $this->addHoliday(new Holiday( + 'plebisciteDay', + [], + new \DateTime("{$this->year}-10-10", new \DateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Austria/LowerAustria.php b/src/Yasumi/Provider/Austria/LowerAustria.php new file mode 100644 index 000000000..314a5e7ff --- /dev/null +++ b/src/Yasumi/Provider/Austria/LowerAustria.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Lower Austria (Austria). + * + * @see https://en.wikipedia.org/wiki/Lower_Austria + */ +class LowerAustria extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-3'; + + /** + * Initialize holidays for Lower Austria (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom holidays. + $this->calculateStLeopoldsDay(); + } +} diff --git a/src/Yasumi/Provider/Austria/Salzburg.php b/src/Yasumi/Provider/Austria/Salzburg.php new file mode 100644 index 000000000..9285762de --- /dev/null +++ b/src/Yasumi/Provider/Austria/Salzburg.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Salzburg (Austria). + * + * @see https://en.wikipedia.org/wiki/Salzburg_(state) + */ +class Salzburg extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-5'; + + /** + * Initialize holidays for Salzburg (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom holidays. + $this->calculateStRupertsDay(); + } + + /** + * Saint Rupert's Day. + * + * Rupert of Salzburg was Bishop of Worms as well as the first Bishop of + * Salzburg and abbot of St. Peter's in Salzburg. He was a contemporary of + * the Frankish king Childebert III and is venerated as a saint in the + * Roman Catholic and Eastern Orthodox Churches. Rupert is also patron + * saint of the Austrian state of Salzburg. His feast day in Austria is + * September 24 (since 710). + * + * @see https://en.wikipedia.org/wiki/Rupert_of_Salzburg + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateStRupertsDay(): void + { + if ($this->year < 710) { + return; + } + + $this->addHoliday(new Holiday( + 'stRupertsDay', + [], + new \DateTime("{$this->year}-9-24", new \DateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Austria/Styria.php b/src/Yasumi/Provider/Austria/Styria.php new file mode 100644 index 000000000..b20416564 --- /dev/null +++ b/src/Yasumi/Provider/Austria/Styria.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Styria (Austria). + * + * @see https://en.wikipedia.org/wiki/Styria + */ +class Styria extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-6'; + + /** + * Initialize holidays for Styria (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom Common holidays. + $this->addHoliday($this->stJosephsDay($this->year, $this->timezone, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Austria/Tyrol.php b/src/Yasumi/Provider/Austria/Tyrol.php new file mode 100644 index 000000000..eb1f23aa6 --- /dev/null +++ b/src/Yasumi/Provider/Austria/Tyrol.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Tyrol (Austria). + * + * @see https://en.wikipedia.org/wiki/Tyrol_(state) + */ +class Tyrol extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-7'; + + /** + * Initialize holidays for Tyrol (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom Common holidays. + $this->addHoliday($this->stJosephsDay($this->year, $this->timezone, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Austria/UpperAustria.php b/src/Yasumi/Provider/Austria/UpperAustria.php new file mode 100644 index 000000000..7e3b8540e --- /dev/null +++ b/src/Yasumi/Provider/Austria/UpperAustria.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Upper Austria (Austria). + * + * @see https://en.wikipedia.org/wiki/Upper_Austria + */ +class UpperAustria extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-4'; + + /** + * Initialize holidays for Upper Austria (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom holidays. + $this->calculateStFloriansDay(); + } + + /** + * Saint Florian's Day. + * + * St. Florian was born around 250 AD in the ancient Roman city of Aelium + * Cetium, present-day Sankt Pölten, Austria. He joined the Roman Army and + * advanced in the ranks, rising to commander of the imperial army in the + * Roman province of Noricum. In addition to his military duties, he was + * also responsible for organizing and leading firefighting brigades. + * Florian organized and trained an elite group of soldiers whose sole duty + * was to fight fires. His feast day is May 4 (since 304). + * + * @see https://en.wikipedia.org/wiki/Saint_Florian + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateStFloriansDay(): void + { + if ($this->year < 304) { + return; + } + + $this->addHoliday(new Holiday( + 'stFloriansDay', + [], + new \DateTime("{$this->year}-5-4", new \DateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Austria/Vienna.php b/src/Yasumi/Provider/Austria/Vienna.php new file mode 100644 index 000000000..09424f167 --- /dev/null +++ b/src/Yasumi/Provider/Austria/Vienna.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Vienna (Austria). + * + * @see https://en.wikipedia.org/wiki/Vienna + */ +class Vienna extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-9'; + + /** + * Initialize holidays for Vienna (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom holidays. + $this->calculateStLeopoldsDay(); + } +} diff --git a/src/Yasumi/Provider/Austria/Vorarlberg.php b/src/Yasumi/Provider/Austria/Vorarlberg.php new file mode 100644 index 000000000..b51d9f261 --- /dev/null +++ b/src/Yasumi/Provider/Austria/Vorarlberg.php @@ -0,0 +1,50 @@ + + */ + +namespace Yasumi\Provider\Austria; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Austria; + +/** + * Provider for all holidays in Vorarlberg (Austria). + * + * @see https://en.wikipedia.org/wiki/Vorarlberg + */ +class Vorarlberg extends Austria +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'AT-8'; + + /** + * Initialize holidays for Vorarlberg (Austria). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + // Add custom Common holidays. + $this->addHoliday($this->stJosephsDay($this->year, $this->timezone, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Belgium.php b/src/Yasumi/Provider/Belgium.php old mode 100755 new mode 100644 index 720a68c56..97bb09224 --- a/src/Yasumi/Provider/Belgium.php +++ b/src/Yasumi/Provider/Belgium.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Belgium extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'BE'; @@ -34,7 +37,6 @@ class Belgium extends AbstractProvider /** * Initialize holidays for Belgium. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -58,7 +60,7 @@ public function initialize(): void $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->armisticeDay($this->year, $this->timezone, $this->locale)); - /** + /* * Belgian National Day. * * Belgian National Day is the National Day of Belgium celebrated on 21 July each year. @@ -66,7 +68,14 @@ public function initialize(): void $this->addHoliday(new Holiday('nationalDay', [ 'fr' => 'Fête nationale', 'en' => 'Belgian National Day', - 'nl' => 'Nationale feestdag', - ], new DateTime("$this->year-7-21", new DateTimeZone($this->timezone)), $this->locale)); + 'nl' => 'nationale feestdag', + ], new \DateTime("{$this->year}-7-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Belgium', + ]; } } diff --git a/src/Yasumi/Provider/Bosnia.php b/src/Yasumi/Provider/Bosnia.php index 5ec2b109a..fb3bbe9e0 100644 --- a/src/Yasumi/Provider/Bosnia.php +++ b/src/Yasumi/Provider/Bosnia.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -25,10 +27,11 @@ */ class Bosnia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'BA'; @@ -36,7 +39,6 @@ class Bosnia extends AbstractProvider /** * Initialize holidays for Bosnia. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -59,42 +61,50 @@ public function initialize(): void $this->addHoliday(new Holiday('orthodoxChristmasDay', [ 'en' => 'Orthodox Christmas Day', 'bs_Latn' => 'Pravoslavni Božić', - ], new DateTime("{$this->year}-01-07", new DateTimeZone($this->timezone)))); + ], new \DateTime("{$this->year}-01-07", DateTimeZoneFactory::getDateTimeZone($this->timezone)))); - /** + /* * Independence Day */ if ($this->year >= 1992) { $this->addHoliday(new Holiday('independenceDay', [ 'en' => 'Independence Day', 'bs_Latn' => 'Dan Nezavisnosti', - ], new DateTime("$this->year-3-1", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-3-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } - /** + /* * Bosnian Statehood Day */ if ($this->year >= 1943) { $this->addHoliday(new Holiday('statehoodDay', [ 'en' => 'Statehood Day', 'bs_Latn' => 'Dan državnosti', - ], new DateTime("$this->year-11-25", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-11-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } - /** + /* * Day after New Years Day */ $this->addHoliday(new Holiday('dayAfterNewYearsDay', [ - 'en' => 'Day after New Year\'s Day', + 'en' => 'Day after New Year’s Day', 'bs_Latn' => 'Nova godina - drugi dan', - ], new DateTime("$this->year-01-02", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); - /** + /* * Second Labour day */ $this->addHoliday(new Holiday('secondLabourDay', [ 'en' => 'Second Labour Day', 'bs_Latn' => 'Praznik rada - drugi dan', - ], new DateTime("$this->year-05-02", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-05-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Bosnia_and_Herzegovina', + 'https://bs.wikipedia.org/wiki/Praznici_i_blagdani_u_Bosni_i_Hercegovini', + ]; } } diff --git a/src/Yasumi/Provider/Brazil.php b/src/Yasumi/Provider/Brazil.php index fa27e96a8..df0f177d2 100644 --- a/src/Yasumi/Provider/Brazil.php +++ b/src/Yasumi/Provider/Brazil.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Brazil extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'BR'; @@ -35,7 +37,6 @@ class Brazil extends AbstractProvider /** * Initialize holidays for Brazil. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -45,132 +46,198 @@ public function initialize(): void $this->timezone = 'America/Fortaleza'; // Add common holidays - $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); // Add Christian holidays + $this->addHoliday($this->ashWednesday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); - $this->addHoliday($this->ashWednesday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); - /** - * Carnaval - * - * Carnaval is the biggest popular festival of country. The festival it happens during 4 days and the last day above - * the wednesday of ashes (initiation of lent). - * - * @link https://en.wikipedia.org/wiki/Brazilian_Carnival - */ - if ($this->year >= 1700) { - $easter = $this->calculateEaster($this->year, $this->timezone); + // Calculate other holidays + $this->calculateAllSoulsDay(); + $this->calculateCarnival(); + $this->calculateIndependenceDay(); + $this->calculateOurLadyOfAparecidaDay(); + $this->calculateProclamationOfRepublicDay(); + $this->calculateTiradentesDay(); + $this->calculateBlackConsciousnessDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Brazil', + ]; + } - $carnavalMonday = clone $easter; + /* + * Proclamation of Republic Day + * + * The Brazilian Proclamation of Republic was an act relevant military politic it happened on 15 November 1889 + * that initiated the build federative presidential of govern in Brazil, downed the monarchy constitutional + * parliamentary of Brazil's Empire. + * + * @link https://en.wikipedia.org/wiki/Proclamation_of_the_Republic_(Brazil) + */ + protected function calculateProclamationOfRepublicDay(): void + { + if ($this->year >= 1889) { $this->addHoliday(new Holiday( - 'carnavalMonday', - ['pt' => 'Segunda-feira de Carnaval'], - $carnavalMonday->sub(new DateInterval('P48D')), - $this->locale, - Holiday::TYPE_OBSERVANCE + 'proclamationOfRepublicDay', + ['pt' => 'Dia da Proclamação da República'], + new \DateTime("{$this->year}-11-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale )); + } + } - $carnavalTuesday = clone $easter; + /* + * All Souls Day + * + * The All Souls day (known like Deads Day in Mexico), is celebrated for Catholic Church on 2 November. + * + * @link http://www.johninbrazil.org/all-souls-day-o-dia-dos-finados/ + */ + protected function calculateAllSoulsDay(): void + { + if ($this->year >= 1300) { $this->addHoliday(new Holiday( - 'carnavalTuesday', - ['pt' => 'Terça-feira de Carnaval'], - $carnavalTuesday->sub(new DateInterval('P47D')), - $this->locale, - Holiday::TYPE_OBSERVANCE + 'allSoulsDay', + [], + new \DateTime("{$this->year}-11-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale )); } + } - /** - * Tiradentes Day - * - * Tiradentes Day is a the Brazilian national holidays. Is the a tribute to national Brazilian hero Joaquim José - * da Silva Xavier, martyr of Inconfidência Mineira. Is celebrated on 21 Abril, because the execution of - * Tiradentes got in the day, in 1792. - * - * @link https://en.wikipedia.org/wiki/Tiradentes - */ - if ($this->year >= 1792) { + /* + * Our Lady of Aparecida Day + * + * Our Lady of Conceição Aparecida, popularly called Our Lady Aparecida, Brazil's patroness. She is + * venerated in Catholic Church. Our Lady Aparecida is represented like a little image of Virgen Maria, + * currently in Basílica of Our Lady Aparecida, localized in São Paulo. + * + * The event is celebrated on 12 October, a national holiday in Brazil since 1980. + * + * @link https://en.wikipedia.org/wiki/Our_Lady_of_Aparecida + */ + protected function calculateOurLadyOfAparecidaDay(): void + { + if ($this->year >= 1980) { $this->addHoliday(new Holiday( - 'tiradentesDay', - ['pt' => 'Dia de Tiradentes'], - new DateTime("$this->year-04-21", new DateTimeZone($this->timezone)), + 'ourLadyOfAparecidaDay', + ['pt' => 'Dia de Nossa Senhora Aparecida'], + new \DateTime("{$this->year}-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } + } - /** - * Independence Day - * - * The Homeland Day is a national holiday of Brazilian homeland celebrated on 7 September. The date is - * celebrated the independence declaration of Brazil to Portuguese empire on 7 September 1822. - * - * @link https://en.wikipedia.org/wiki/Independence_of_Brazil - */ + /* + * Independence Day + * + * The Homeland Day is a national holiday of Brazilian homeland celebrated on 7 September. The date is + * celebrated the independence declaration of Brazil to Portuguese empire on 7 September 1822. + * + * @link https://en.wikipedia.org/wiki/Independence_of_Brazil + */ + protected function calculateIndependenceDay(): void + { if ($this->year >= 1822) { $this->addHoliday(new Holiday( 'independenceDay', ['pt' => 'Dia da Independência do Brasil'], - new DateTime("$this->year-09-07", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-09-07", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } + } - /** - * Our Lady of Aparecida Day - * - * Our Lady of Conceição Aparecida, popularly called Our Lady Aparecida, Brazil's patroness. She is - * venerated in Catholic Church. Our Lady Aparecida is represented like a little image of Virgen Maria, - * currently in Basílica of Our Lady Aparecida, localized in São Paulo. - * - * The event is celebrated on 12 October, a national holiday in Brazil since 1980. - * - * @link https://en.wikipedia.org/wiki/Our_Lady_of_Aparecida - */ - if ($this->year >= 1980) { + /* + * Tiradentes Day + * + * Tiradentes Day is a Brazilian national holiday. Is is a tribute to national Brazilian hero Joaquim José + * da Silva Xavier, martyr of Inconfidência Mineira. Is celebrated on 21 Abril, because the execution of + * Tiradentes got in the day, in 1792. + * + * @link https://en.wikipedia.org/wiki/Tiradentes + */ + protected function calculateTiradentesDay(): void + { + if ($this->year >= 1792) { $this->addHoliday(new Holiday( - 'ourLadyOfAparecidaDay', - ['pt' => 'Dia de Nossa Senhora Aparecida'], - new DateTime("$this->year-10-12", new DateTimeZone($this->timezone)), + 'tiradentesDay', + ['pt' => 'Dia de Tiradentes'], + new \DateTime("{$this->year}-04-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } + } - /** - * All Souls Day - * - * The All Souls day (known like Deads Day in Mexico), is celebrated for Catholic Church on 2 November. - * - * @link http://www.johninbrazil.org/all-souls-day-o-dia-dos-finados/ - */ - if ($this->year >= 1300) { - $this->addHoliday(new Holiday( - 'allSoulsDay', - ['pt' => 'Dia de Finados'], - new DateTime("$this->year-11-02", new DateTimeZone($this->timezone)), - $this->locale - )); + /* + * Carnaval + * + * Carnaval is the biggest popular festival of country. The festival it happens during 4 days and the last day above + * the wednesday of ashes (initiation of lent). + * + * @link https://en.wikipedia.org/wiki/Brazilian_Carnival + */ + protected function calculateCarnival(): void + { + if ($this->year >= 1700) { + $easter = $this->calculateEaster($this->year, $this->timezone); + + $days = [ + 'carnavalMonday' => [ + 'interval' => 'P48D', + 'name' => 'Segunda-feira de Carnaval', + ], + 'carnavalTuesday' => [ + 'interval' => 'P47D', + 'name' => 'Terça-feira de Carnaval', + ], + ]; + + foreach ($days as $name => $day) { + $date = (clone $easter)->sub(new \DateInterval($day['interval'])); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $name)); + } + + $this->addHoliday(new Holiday( + $name, + ['pt' => $day['name']], + $date, + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } } + } - /** - * Proclamation of Republic Day - * - * The Brazilian Proclamation of Republic was an act relevant military politic it happened on 15 November 1889 - * that initiated the build federative presidential of govern in Brazil, downed the monarchy constitutional - * parlamentary of Brazil's Empire. - * - * @link https://en.wikipedia.org/wiki/Proclamation_of_the_Republic_(Brazil) - */ - if ($this->year >= 1889) { + /* + * Black Consciousness Day + * + * Black Consciousness Day is a Brazilian national holiday commemorating Afro-Brazilians and their struggle + * to achieve racial equality. It is celebrated on 20 November, the anniversary of the death of resistance + * leader Zumbi dos Palmares, and is also known as Zumbi Day. + * + * @link https://en.wikipedia.org/wiki/Black_Awareness_Day + */ + protected function calculateBlackConsciousnessDay(): void + { + if ($this->year >= 2011) { + $type = $this->year <= 2023 ? Holiday::TYPE_OBSERVANCE : Holiday::TYPE_OFFICIAL; $this->addHoliday(new Holiday( - 'proclamationOfRepublicDay', - ['pt' => 'Dia da Proclamação da República'], - new DateTime("$this->year-11-15", new DateTimeZone($this->timezone)), - $this->locale + 'blackConsciousnessDay', + ['pt' => 'Dia Nacional de Zumbi e da Consciência Negra'], + new \DateTime("{$this->year}-11-20", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + $type )); } } diff --git a/src/Yasumi/Provider/Bulgaria.php b/src/Yasumi/Provider/Bulgaria.php new file mode 100644 index 000000000..95cfd787d --- /dev/null +++ b/src/Yasumi/Provider/Bulgaria.php @@ -0,0 +1,194 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Holiday; + +class Bulgaria extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + public const ID = 'BG'; + + public function initialize(): void + { + $this->timezone = 'Europe/Sofia'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->stGeorgesDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); + + // Add other holidays + $this->calculateEducationCultureSlavonicLiteratureDay(); + $this->calculateIndependenceDay(); + $this->calculateLiberationDay(); + $this->calculateOrthodoxEasterHolidays(); + $this->calculateStGeorgesDay(); + $this->calculateUnificationDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Bulgaria', + 'https://bg.wikipedia.org/wiki/%D0%9E%D1%84%D0%B8%D1%86%D0%B8%D0%B0%D0%BB%D0%BD%D0%B8_%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8_%D0%B2_%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F', + ]; + } + + private function calculateOrthodoxEasterHolidays(): void + { + $orthodoxEaster = $this->calculateOrthodoxEaster($this->year, $this->timezone); + + $this->addHoliday(new Holiday( + 'orthodoxEaster', + ['en' => 'Orthodox Easter', 'bg' => 'Великден'], + $orthodoxEaster, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + + $goodFriday = clone $orthodoxEaster; + $goodFriday->sub(new \DateInterval('P2D')); + $this->addHoliday(new Holiday( + 'orthodoxGoodFriday', + ['en' => 'Orthodox Good Friday', 'bg' => 'Разпети петък'], + $goodFriday, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + + $easterMonday = clone $orthodoxEaster; + $easterMonday->add(new \DateInterval('P1D')); + $this->addHoliday(new Holiday( + 'orthodoxEasterMonday', + ['en' => 'Orthodox Easter Monday', 'bg' => 'Велики понеделник'], + $easterMonday, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Liberation Day + * + * Liberation Day on March 3 marks the Liberation of Bulgaria from Ottoman rule in 1878. + * However, it became an official holiday by decree 236 of the Chairman of the State + * Council on 27 February 1990, coming into effect on 5 March. + * + * @throws \Exception + */ + private function calculateLiberationDay(): void + { + if ($this->year >= 1990) { + $this->addHoliday(new Holiday( + 'liberationDay', + ['en' => 'Liberation Day', 'bg' => 'Ден на Освобождението на България от османско иго'], + new \DateTime("{$this->year}-03-03", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Bulgarian Education and Culture and Slavonic Literature Day + * + * May 24 celebrates the Bulgarian education, culture, and creation of the Cyrillic alphabet. + * + * @see https://en.wikipedia.org/wiki/Bulgarian_Education_and_Culture_and_Slavonic_Literature_Day + * + * @throws \Exception + */ + private function calculateEducationCultureSlavonicLiteratureDay(): void + { + if ($this->year >= 1990) { + $this->addHoliday(new Holiday( + 'educationCultureSlavonicLiteratureDay', + ['en' => 'Bulgarian Education and Culture and Slavonic Literature Day', 'bg' => 'Ден на българската просвета и култура и на славянската писменост'], + new \DateTime("{$this->year}-05-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Saint George's Day + * + * @see https://en.wikipedia.org/wiki/Bulgarian_Armed_Forces_Day + * + * @throws \Exception + */ + private function calculateStGeorgesDay(): void + { + $this->addHoliday(new Holiday( + 'stGeorgesDay', + ['bg' => 'Гергьовден, ден на храбростта и Българската армия'], + new \DateTime("{$this->year}-05-06", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Unification Day + * + * September 6 marks the unification of the Principality of Bulgaria and Eastern Rumelia in 1885. + * + * @see https://en.wikipedia.org/wiki/Unification_Day_(Bulgaria) + * @see https://en.wikipedia.org/wiki/Bulgarian_unification + * + * @throws \Exception + */ + private function calculateUnificationDay(): void + { + if ($this->year >= 1885) { + $this->addHoliday(new Holiday( + 'unificationDay', + ['en' => 'Unification Day', 'bg' => 'Ден на Съединението'], + new \DateTime("{$this->year}-09-06", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Independence Day + * + * September 22 marks Bulgaria's declaration of independence from the Ottoman Empire in 1908. + * + * @see https://en.wikipedia.org/wiki/Bulgarian_Declaration_of_Independence + * + * @throws \Exception + */ + private function calculateIndependenceDay(): void + { + if ($this->year >= 1908) { + $this->addHoliday(new Holiday( + 'independenceDay', + ['en' => 'Independence Day', 'bg' => 'Ден на Независимостта на България'], + new \DateTime("{$this->year}-09-22", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } +} diff --git a/src/Yasumi/Provider/Canada.php b/src/Yasumi/Provider/Canada.php new file mode 100644 index 000000000..d0444bbd1 --- /dev/null +++ b/src/Yasumi/Provider/Canada.php @@ -0,0 +1,284 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Canada. + */ +class Canada extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA'; + + /** + * Initialize holidays for Canada. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'America/Toronto'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + + // Calculate other holidays + $this->calculateCanadaDay(); + $this->calculateLabourDay(); + $this->calculateThanksgivingDay(); + $this->calculateRemembranceDay(); + $this->calculateNationalDayForTruthAndReconciliation(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Canada', + ]; + } + + /** + * Family Day. + * + * @see https://en.wikipedia.org/wiki/Family_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateFamilyDay(): void + { + if ($this->year < 2009) { + return; + } + + $this->addHoliday(new Holiday( + 'familyDay', + [], + new \DateTime("third monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Victoria Day. + * + * @see https://en.wikipedia.org/wiki/Victoria_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateVictoriaDay(): void + { + if ($this->year < 1845) { + return; + } + + $this->addHoliday(new Holiday( + 'victoriaDay', + [], + new \DateTime("last monday front of {$this->year}-05-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * National Indigenous Peoples Day. + * + * @see https://www.rcaanc-cirnac.gc.ca/eng/1100100013248/1534872397533 + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalIndigenousPeoplesDay(): void + { + if ($this->year < 1996) { + return; + } + + $this->addHoliday(new Holiday( + 'nationalIndigenousPeoplesDay', + [], + new \DateTime("{$this->year}-06-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Civic Holiday. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCivicHoliday(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'civicHoliday', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Canada Day. + * + * @see https://en.wikipedia.org/wiki/Canada_Day. + * @see Holidays Act, R.S.C., 1985, c. H-5, https://laws-lois.justice.gc.ca/eng/acts/h-5/page-1.html + * + * by statute, Canada Day is July 1 if that day is not Sunday, and July 2 if July 1 is a Sunday. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCanadaDay(): void + { + if ($this->year < 1983) { + return; + } + $date = new \DateTime("{$this->year}-07-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + if (7 === (int) $date->format('N')) { + $date = new \DateTime("{$this->year}-07-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + } + $this->addHoliday(new Holiday( + 'canadaDay', + [], + $date, + $this->locale + )); + } + + /** + * Thanksgiving. + * + * @see https://en.wikipedia.org/wiki/Thanksgiving_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateThanksgivingDay(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'thanksgivingDay', + [], + new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Remembrance Day. + * + * @see https://en.wikipedia.org/wiki/Remembrance_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateRemembranceDay(): void + { + if ($this->year < 1919) { + return; + } + + $this->addHoliday(new Holiday( + 'remembranceDay', + [], + new \DateTime("{$this->year}-11-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Labour Day. + * + * @see https://en.wikipedia.org/wiki/Labour_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateLabourDay(): void + { + if ($this->year < 1894) { + return; + } + + $this->addHoliday(new Holiday( + 'labourDay', + [], + new \DateTime("first monday of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * National Day For Truth And Reconciliation. + * + * @see https://parl.ca/Content/Bills/432/Government/C-5/C-5_4/C-5_4.PDF, S. C. 2021, C.11. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalDayForTruthAndReconciliation(): void + { + if ($this->year < 2021) { + return; + } + + $this->addHoliday(new Holiday( + 'truthAndReconciliationDay', + [], + new \DateTime("last day of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Alberta.php b/src/Yasumi/Provider/Canada/Alberta.php new file mode 100644 index 000000000..4825652c9 --- /dev/null +++ b/src/Yasumi/Provider/Canada/Alberta.php @@ -0,0 +1,80 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Alberta (Canada). + * + * Alberta is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Alberta + */ +class Alberta extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-AB'; + + /** + * Initialize holidays for Alberta (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Edmonton'; + + $this->calculateHeritageDay(); + $this->calculateFamilyDay(); + $this->calculateVictoriaDay(); + } + + /** + * Heritage Day. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateHeritageDay(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'heritageDay', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/BritishColumbia.php b/src/Yasumi/Provider/Canada/BritishColumbia.php new file mode 100644 index 000000000..1ea55026b --- /dev/null +++ b/src/Yasumi/Provider/Canada/BritishColumbia.php @@ -0,0 +1,55 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Canada; + +/** + * Provider for all holidays in British Columbia (Canada). + * + * British Columbia is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/British_Columbia + */ +class BritishColumbia extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-BC'; + + /** + * Initialize holidays for British Columbia (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Vancouver'; + + $this->calculateCivicHoliday(); + $this->calculateFamilyDay(); + $this->calculateVictoriaDay(); + } +} diff --git a/src/Yasumi/Provider/Canada/Manitoba.php b/src/Yasumi/Provider/Canada/Manitoba.php new file mode 100644 index 000000000..cf47db952 --- /dev/null +++ b/src/Yasumi/Provider/Canada/Manitoba.php @@ -0,0 +1,103 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Manitoba (Canada). + * + * Manitoba is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Manitoba + */ +class Manitoba extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-MB'; + + /** + * Initialize holidays for Manitoba (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Winnipeg'; + + $this->calculateCivicHoliday(); + $this->calculateLouisRielDay(); + $this->calculateVictoriaDay(); + } + + /** + * Civic Holiday. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCivicHoliday(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'terryFoxDay', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Louis Riel Day. + * + * @see https://en.wikipedia.org/wiki/Family_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateLouisRielDay(): void + { + if ($this->year < 2008) { + return; + } + + $this->addHoliday(new Holiday( + 'louisRielDay', + [], + new \DateTime("third monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/NewBrunswick.php b/src/Yasumi/Provider/Canada/NewBrunswick.php new file mode 100644 index 000000000..cfd3197d4 --- /dev/null +++ b/src/Yasumi/Provider/Canada/NewBrunswick.php @@ -0,0 +1,55 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Canada; + +/** + * Provider for all holidays in New Brunswick (Canada). + * + * New Brunswick is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/New_Brunswick + */ +class NewBrunswick extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-NB'; + + /** + * Initialize holidays for New Brunswick (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Halifax'; + + $this->calculateCivicHoliday(); + $this->calculateFamilyDay(); + $this->calculateVictoriaDay(); + } +} diff --git a/src/Yasumi/Provider/Canada/NewfoundlandAndLabrador.php b/src/Yasumi/Provider/Canada/NewfoundlandAndLabrador.php new file mode 100644 index 000000000..8aee6d325 --- /dev/null +++ b/src/Yasumi/Provider/Canada/NewfoundlandAndLabrador.php @@ -0,0 +1,148 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; +use Yasumi\SubstituteHoliday; + +/** + * Provider for all holidays in Newfoundland and Labrador (Canada). + * + * Newfoundland and Labrador is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Newfoundland_and_Labrador + */ +class NewfoundlandAndLabrador extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-NL'; + + /** + * Initialize holidays for Newfoundland and Labrador (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/St_Johns'; + + $this->calculateStPatricksDay(); + $this->calculateOrangemensDay(); + $this->addHoliday($this->stGeorgesDay($this->year, $this->timezone, $this->locale)); + } + + /** + * St. Patrick's Day. + * + * Saint Patrick's Day, or the Feast of Saint Patrick (Irish: Lá Fhéile Pádraig, "the Day of the Festival of + * Patrick"), is a cultural and religious celebration held on 17 March, the traditional death date of Saint Patrick + * (c. AD 385–461), the foremost patron saint of Ireland. Saint Patrick's Day is a public holiday in the Republic + * of Ireland, Northern Ireland, the Canadian province of Newfoundland and Labrador, and the British Overseas + * Territory of Montserrat. + * + * @see https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateStPatricksDay(): void + { + if ($this->year < 1971) { + return; + } + + $holiday = new Holiday( + 'stPatricksDay', + ['en' => 'St. Patrick’s Day'], + new \DateTime("{$this->year}-3-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + ); + + $this->addHoliday($holiday); + + // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { + $date = clone $holiday; + $date->modify('next monday'); + + $this->addHoliday(new SubstituteHoliday( + $holiday, + [], + $date, + $this->locale, + Holiday::TYPE_BANK + )); + } + } + + /** + * Orangemen's Day. + * + * Orangemen's Day, also called The Twelfth or Glorious Twelfth) celebrates the Glorious Revolution (1688) + * and victory of Protestant King William of Orange over Catholic king James II at the Battle of the + * Boyne (1690), which began the Protestant Ascendancy in Ireland. + * + * @see https://en.wikipedia.org/wiki/The_Twelfth + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateOrangemensDay(): void + { + if ($this->year < 1926) { + return; + } + + $holiday = new Holiday( + 'orangemensDay', + [], + new \DateTime("{$this->year}-7-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + ); + + $this->addHoliday($holiday); + + // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { + $date = clone $holiday; + $date->modify('next monday'); + + $this->addHoliday(new SubstituteHoliday( + $holiday, + [], + $date, + $this->locale, + Holiday::TYPE_BANK + )); + } + } +} diff --git a/src/Yasumi/Provider/Canada/NorthwestTerritories.php b/src/Yasumi/Provider/Canada/NorthwestTerritories.php new file mode 100644 index 000000000..7c31030b0 --- /dev/null +++ b/src/Yasumi/Provider/Canada/NorthwestTerritories.php @@ -0,0 +1,55 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Canada; + +/** + * Provider for all holidays in Northwest Territories (Canada). + * + * Northwest Territories is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Northwest_Territories + */ +class NorthwestTerritories extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-NT'; + + /** + * Initialize holidays for Northwest Territories (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Yellowknife'; + + $this->calculateCivicHoliday(); + $this->calculateNationalIndigenousPeoplesDay(); + $this->calculateVictoriaDay(); + } +} diff --git a/src/Yasumi/Provider/Canada/NovaScotia.php b/src/Yasumi/Provider/Canada/NovaScotia.php new file mode 100644 index 000000000..4afbddd2d --- /dev/null +++ b/src/Yasumi/Provider/Canada/NovaScotia.php @@ -0,0 +1,103 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Nova Scotia (Canada). + * + * Nova Scotia is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Nova_Scotia + */ +class NovaScotia extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-NS'; + + /** + * Initialize holidays for Nova Scotia (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Halifax'; + + $this->calculateCivicHoliday(); + $this->calculateHeritageDay(); + $this->calculateVictoriaDay(); + } + + /** + * Civic Holiday. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCivicHoliday(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'natalHoliday', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Nova Scotia Heritage Day. + * + * @see https://en.wikipedia.org/wiki/Family_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateHeritageDay(): void + { + if ($this->year < 2015) { + return; + } + + $this->addHoliday(new Holiday( + 'novaScotiaHeritageDay', + [], + new \DateTime("third monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Nunavut.php b/src/Yasumi/Provider/Canada/Nunavut.php new file mode 100644 index 000000000..6151e26ca --- /dev/null +++ b/src/Yasumi/Provider/Canada/Nunavut.php @@ -0,0 +1,83 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Nunavut (Canada). + * + * Nunavut is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Nunavut + */ +class Nunavut extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-NU'; + + /** + * Initialize holidays for Nunavut (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Iqaluit'; + + $this->calculateCivicHoliday(); + $this->calculateVictoriaDay(); + $this->calculateNunavutDay(); + } + + /** + * Nunavut Day – July 9, originated as a paid holiday for Nunavut Tunngavik Incorporated + * and regional Inuit associations. It became a half-day holiday for government employees + * in 1999 and a full day in 2001. + * + * @see https://en.wikipedia.org/wiki/Nunavut_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNunavutDay(): void + { + if ($this->year < 1999) { + return; + } + + $this->addHoliday(new Holiday( + 'nunavutDay', + ['en' => 'Nunavut Day'], + new \DateTime("{$this->year}-07-09", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Ontario.php b/src/Yasumi/Provider/Canada/Ontario.php new file mode 100644 index 000000000..4ea36c7b8 --- /dev/null +++ b/src/Yasumi/Provider/Canada/Ontario.php @@ -0,0 +1,55 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Provider\Canada; + +/** + * Provider for all holidays in Ontario (Canada). + * + * Ontario is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Ontario + */ +class Ontario extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-ON'; + + /** + * Initialize holidays for Ontario (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Toronto'; + + $this->calculateCivicHoliday(); + $this->calculateFamilyDay(); + $this->calculateVictoriaDay(); + } +} diff --git a/src/Yasumi/Provider/Canada/PrinceEdwardIsland.php b/src/Yasumi/Provider/Canada/PrinceEdwardIsland.php new file mode 100644 index 000000000..0f06b78f9 --- /dev/null +++ b/src/Yasumi/Provider/Canada/PrinceEdwardIsland.php @@ -0,0 +1,103 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Prince Edward Island (Canada). + * + * Prince Edward Island is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Prince_Edward_Island + */ +class PrinceEdwardIsland extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-PE'; + + /** + * Initialize holidays for Prince Edward Island (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Halifax'; + + $this->calculateIslanderDay(); + $this->calculateGoldCupParadeDay(); + $this->calculateVictoriaDay(); + } + + /** + * Islander Day. + * + * @see https://en.wikipedia.org/wiki/Family_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateIslanderDay(): void + { + if ($this->year < 2009) { + return; + } + + $this->addHoliday(new Holiday( + 'islanderDay', + [], + new \DateTime("third monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Gold Cup Parade Day. + * + * @see https://en.wikipedia.org/wiki/Public_holidays_in_Canada#Statutory_holidays + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateGoldCupParadeDay(): void + { + if ($this->year < 1962) { + return; + } + + $this->addHoliday(new Holiday( + 'goldCupParadeDay', + [], + new \DateTime("third friday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Quebec.php b/src/Yasumi/Provider/Canada/Quebec.php new file mode 100644 index 000000000..b836a0b1b --- /dev/null +++ b/src/Yasumi/Provider/Canada/Quebec.php @@ -0,0 +1,115 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Quebec (Canada). + * + * Quebec is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Quebec + */ +class Quebec extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-QC'; + + /** + * Initialize holidays for Quebec (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Toronto'; + + $this->addHoliday($this->saintJeanBaptisteDay($this->year, $this->timezone, $this->locale)); + $this->calculateNationalPatriotsDay(); + } + + /** + * Saint-Jean-Baptiste Day. + * + * The Nativity of John the Baptist (or Birth of John the Baptist, or Nativity of the Forerunner) is a Christian + * feast day celebrating the birth of John the Baptist, a prophet who foretold the coming of the Messiah in the + * person of Jesus, whom he later baptised. The Nativity of John the Baptist on June 24 comes three months after the + * celebration on March 25 of the Annunciation, when the angel Gabriel told Mary that her cousin Elizabeth was in + * her sixth month of pregnancy. + * + * @see https://en.wikipedia.org/wiki/Saint-Jean-Baptiste_Day + * + * @param int $year the year for which St. John's Day need to be created + * @param string $timezone the timezone in which St. John's Day is celebrated + * @param string $locale the locale for which St. John's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function saintJeanBaptisteDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'saintJeanBaptisteDay', + [], + new \DateTime("{$year}-06-24", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * National Patriot's Day. + * + * @see https://en.wikipedia.org/wiki/National_Patriots%27_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalPatriotsDay(): void + { + if ($this->year < 2003) { + return; + } + + $this->addHoliday(new Holiday( + 'nationalPatriotsDay', + [], + new \DateTime("last monday front of {$this->year}-05-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Saskatchewan.php b/src/Yasumi/Provider/Canada/Saskatchewan.php new file mode 100644 index 000000000..aeda24bb4 --- /dev/null +++ b/src/Yasumi/Provider/Canada/Saskatchewan.php @@ -0,0 +1,80 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Saskatchewan (Canada). + * + * Saskatchewan is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Saskatchewan + */ +class Saskatchewan extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-SK'; + + /** + * Initialize holidays for Saskatchewan (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Regina'; + + $this->calculateSaskatchewanDay(); + $this->calculateFamilyDay(); + $this->calculateVictoriaDay(); + } + + /** + * Civic Holiday. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateSaskatchewanDay(): void + { + if ($this->year < 1879) { + return; + } + + $this->addHoliday(new Holiday( + 'saskatchewanDay', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Canada/Yukon.php b/src/Yasumi/Provider/Canada/Yukon.php new file mode 100644 index 000000000..0da8c9f60 --- /dev/null +++ b/src/Yasumi/Provider/Canada/Yukon.php @@ -0,0 +1,104 @@ + + */ + +namespace Yasumi\Provider\Canada; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\Canada; +use Yasumi\Provider\DateTimeZoneFactory; + +/** + * Provider for all holidays in Yukon (Canada). + * + * Yukon is a province of Canada. + * + * @see https://en.wikipedia.org/wiki/Yukon + */ +class Yukon extends Canada +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'CA-YT'; + + /** + * Initialize holidays for Yukon (Canada). + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + $this->timezone = 'America/Whitehorse'; + + $this->calculateDiscoveryDay(); + $this->calculateHeritageDay(); + $this->calculateNationalIndigenousPeoplesDay(); + $this->calculateVictoriaDay(); + } + + /** + * Discovery Day. + * + * @see https://en.wikipedia.org/wiki/Civic_Holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateDiscoveryDay(): void + { + if ($this->year < 1897) { + return; + } + + $this->addHoliday(new Holiday( + 'discoveryDay', + [], + new \DateTime("third monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Yukon Heritage Day. + * + * @see https://en.wikipedia.org/wiki/Family_Day_(Canada) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateHeritageDay(): void + { + if ($this->year < 2009) { + return; + } + + $this->addHoliday(new Holiday( + 'yukonHeritageDay', + [], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/ChristianHolidays.php b/src/Yasumi/Provider/ChristianHolidays.php index 17fe0aa28..16792d1ee 100644 --- a/src/Yasumi/Provider/ChristianHolidays.php +++ b/src/Yasumi/Provider/ChristianHolidays.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,35 +24,292 @@ * Trait ChristianHolidays. * * Trait containing base Christian Western churches calendar based holidays. - * */ trait ChristianHolidays { /** - * Easter. + * Corpus Christi. * - * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated - * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council - * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * The Feast of Corpus Christi (Latin for Body of Christ), also known as Corpus Domini, is a Latin Rite liturgical + * solemnity celebrating the tradition and belief in the body and blood of Jesus Christ and his Real Presence in the + * Eucharist. The feast is liturgically celebrated on the Thursday after Trinity Sunday or, "where the Solemnity of + * The Most Holy Body and Blood of Christ is not a holy day of obligation, it is assigned to the Sunday after the + * Most Holy Trinity as its proper day". This is 60 days after Easter. * - * @link https://en.wikipedia.org/wiki/Easter + * @param int $year the year for which Corpus Christi need to be created + * @param string $timezone the timezone in which Corpus Christi is celebrated + * @param string $locale the locale for which Corpus Christi need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default a type of 'other' is considered. * - * @param int $year the year for which Easter need to be created - * @param string $timezone the timezone in which Easter is celebrated - * @param string $locale the locale for which Easter need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function corpusChristi( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OTHER, + ): Holiday { + return new Holiday( + 'corpusChristi', + [], + $this->calculateEaster($year, $timezone)->add(new \DateInterval('P60D')), + $locale, + $type + ); + } + + /** + * All Saints' Day. + * + * All Saints' Day, also known as All Hallows, Solemnity of All Saints, or Feast of All Saints is a solemnity + * celebrated on 1 November by the Catholic Church and various Protestant denominations, and on the first Sunday + * after Pentecost in Eastern Catholicism and Eastern Orthodoxy, in honour of all the saints, known and unknown. + * The liturgical celebration begins at Vespers on the evening of 31 October and ends at the close of 1 November. + * + * @see https://en.wikipedia.org/wiki/All_Saints%27_Day + * + * @param int $year the year for which All Saints' Day need to be created + * @param string $timezone the timezone in which All Saints' Day is celebrated + * @param string $locale the locale for which All Saints' Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function allSaintsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday('allSaintsDay', [], new \DateTime("{$year}-11-1", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); + } + + /** + * Day of the Assumption of Mary. + * + * The Assumption of the Virgin Mary into Heaven, informally known as the Assumption, was the bodily taking up + * of the Virgin Mary into Heaven at the end of her earthly life. In the churches that observe it, the + * Assumption is a major feast day, commonly celebrated on August 15. + * + * @see https://en.wikipedia.org/wiki/Assumption_of_Mary + * + * @param int $year the year for which the day of the Assumption of Mary need to be created + * @param string $timezone the timezone in which the day of the Assumption of Mary is celebrated + * @param string $locale the locale for which the day of the Assumption of Mary need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function assumptionOfMary( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'assumptionOfMary', + [], + new \DateTime("{$year}-8-15", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Good Friday. + * + * Good Friday is a Christian religious holiday commemorating the crucifixion of Jesus Christ and his death at + * Calvary. The holiday is observed during Holy Week as part of the Paschal Triduum on the Friday preceding Easter + * Sunday, and may coincide with the Jewish observance of Passover. + * + * @param int $year the year for which Good Friday need to be created + * @param string $timezone the timezone in which Good Friday is celebrated + * @param string $locale the locale for which Good Friday need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function goodFriday( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + $holiday = 'goodFriday'; + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P2D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $holiday)); + } + + return new Holiday($holiday, [], $date, $locale, $type); + } + + /** + * Epiphany. + * + * Epiphany is a Christian feast day that celebrates the revelation of God the Son as a human being in Jesus Christ. + * The traditional date for the feast is January 6. However, since 1970, the celebration is held in some countries + * on the Sunday after January 1. Eastern Churches following the Julian Calendar observe the Theophany feast on what + * for most countries is January 19 because of the 13-day difference today between that calendar and the generally + * used Gregorian calendar. + * + * @see https://en.wikipedia.org/wiki/Epiphany_(holiday) + * + * @param int $year the year for which Epiphany need to be created + * @param string $timezone the timezone in which Epiphany is celebrated + * @param string $locale the locale for which Epiphany need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function epiphany( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday('epiphany', [], new \DateTime("{$year}-1-6", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); + } + + /** + * St. Joseph's Day. + * + * Saint Joseph's Day, March 19, the Feast of St. Joseph is in Western Christianity the principal feast day of Saint + * Joseph, husband of the Blessed Virgin Mary. He is the foster-father of Jesus Christ. March 19 was dedicated to + * Saint Joseph in several Western calendars by the 10th century, and this custom was established in Rome by 1479. + * Pope St. Pius V extended its use to the entire Roman Rite by his Apostolic Constitution Quo primum + * (July 14, 1570). Since 1969, Episcopal Conferences may, if they wish, transfer it to a date outside Lent. + * + * @see https://en.wikipedia.org/wiki/St_Joseph's_Day + * + * @param int $year the year for which St. Joseph's Day need to be created + * @param string $timezone the timezone in which St. Joseph's Day is celebrated + * @param string $locale the locale for which St. Joseph's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function stJosephsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday('stJosephsDay', [], new \DateTime("{$year}-3-19", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); + } + + /** + * St. George's Day. + * + * Saint George's Day is the feast day of Saint George. It is celebrated by various Christian Churches and by the + * several nations, kingdoms, countries, and cities of which Saint George is the patron saint. Saint George's Day is + * celebrated on 23 April, the traditionally accepted date of Saint George's death in 303 AD. For Eastern Orthodox + * Churches (which use the Julian calendar), '23 April' currently falls on 6 May of the Gregorian calendar. + * + * @see https://en.wikipedia.org/wiki/St_George%27s_Day + * + * @param int $year the year for which St. George's Day need to be created + * @param string $timezone the timezone in which St. George's Day is celebrated + * @param string $locale the locale for which St. George's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function easter(int $year, string $timezone, string $locale, string $type = Holiday::TYPE_OFFICIAL): Holiday + protected function stGeorgesDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday('stGeorgesDay', [], new \DateTime("{$year}-4-23", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); + } + + /** + * Calculate the Easter date for Orthodox churches. + * + * @param int $year the year for which Easter needs to be calculated + * @param string $timezone the timezone in which Easter is celebrated + * + * @return \DateTime|\DateTimeImmutable date of Orthodox Easter + * + * @throws \Exception + * + * @see https://en.wikipedia.org/wiki/Computus#Meeus.27s_Julian_algorithm + * @see https://www.php.net/manual/en/function.easter-date.php#83794 + */ + protected function calculateOrthodoxEaster(int $year, string $timezone): \DateTimeInterface { - return new Holiday('easter', [], $this->calculateEaster($year, $timezone), $locale, $type); + $a = $year % 4; + $b = $year % 7; + $c = $year % 19; + $d = (19 * $c + 15) % 30; + $e = (2 * $a + 4 * $b - $d + 34) % 7; + $month = floor(($d + $e + 114) / 31); + $day = (($d + $e + 114) % 31) + 1; + + return (new \DateTime("{$year}-{$month}-{$day}", DateTimeZoneFactory::getDateTimeZone($timezone)))->add(new \DateInterval('P13D')); + } + + /** + * Calculates the day of the reformation. + * + * Reformation Day is a religious holiday celebrated on October 31, alongside All Hallows' Eve, in remembrance + * of the Reformation. It is celebrated among various Protestants, especially by Lutheran and Reformed church + * communities. + * It is a civic holiday in the German states of Brandenburg, Mecklenburg-Vorpommern, Saxony, Saxony-Anhalt and + * Thuringia. Slovenia celebrates it as well due to the profound contribution of the Reformation to that nation's + * cultural development, although Slovenes are mainly Roman Catholics. With the increasing influence of + * Protestantism in Latin America (particularly newer groups such as various Evangelical Protestants, Pentecostals + * or Charismatics), it has been declared a national holiday in Chile in 2009. + * + * @see https://en.wikipedia.org/wiki/Reformation_Day + * @see https://de.wikipedia.org/wiki/Reformationstag#Ursprung_und_Geschichte + * + * @param int $year the year for which St. John's Day need to be created + * @param string $timezone the timezone in which St. John's Day is celebrated + * @param string $locale the locale for which St. John's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function reformationDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'reformationDay', + [], + new \DateTime("{$year}-10-31", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** @@ -66,22 +324,22 @@ public function easter(int $year, string $timezone, string $locale, string $type * * Note: In calendrical calculations, frequently operations called integer division are used. * - * @param int $year the year for which Easter needs to be calculated + * @param int $year the year for which Easter needs to be calculated * @param string $timezone the timezone in which Easter is celebrated * - * @return DateTime date of Easter - * @throws \Exception - * @see easter_days + * @return \DateTime|\DateTimeImmutable date of Easter * - * @link https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/ext/calendar/easter.c - * @link http://www.gmarts.org/index.php?go=415#EasterMallen - * @link https://www.tondering.dk/claus/cal/easter.php + * @throws \Exception * + * @see easter_days + * @see https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/ext/calendar/easter.c + * @see http://www.gmarts.org/index.php?go=415#EasterMallen + * @see https://www.tondering.dk/claus/cal/easter.php */ - protected function calculateEaster(int $year, string $timezone): DateTime + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface { if (\extension_loaded('calendar')) { - $easter_days = \easter_days($year); + $easterDays = easter_days($year); } else { $golden = ($year % 19) + 1; // The Golden Number @@ -90,28 +348,26 @@ protected function calculateEaster(int $year, string $timezone): DateTime // 1583 AD to 4099 (A day adjustment is required in or shortly after 4100 AD). // After 1752, most western churches have adopted the current algorithm. if ($year <= 1752) { - $dom = ($year + (int)($year / 4) + 5) % 7; // The 'Dominical number' - finding a Sunday + $dom = ($year + (int) ($year / 4) + 5) % 7; // The 'Dominical number' - finding a Sunday if ($dom < 0) { $dom += 7; } $pfm = (3 - (11 * $golden) - 7) % 30; // Uncorrected date of the Paschal full moon - if ($pfm < 0) { - $pfm += 30; - } } else { - $dom = ($year + (int)($year / 4) - (int)($year / 100) + (int)($year / 400)) % 7; // The 'Dominical number' - finding a Sunday + $dom = ($year + (int) ($year / 4) - (int) ($year / 100) + (int) ($year / 400)) % 7; // The 'Dominical number' - finding a Sunday if ($dom < 0) { $dom += 7; } - $solar = (int)(($year - 1600) / 100) - (int)(($year - 1600) / 400); // The solar correction - $lunar = (int)(((int)(($year - 1400) / 100) * 8) / 25); // The lunar correction + $solar = (int) (($year - 1600) / 100) - (int) (($year - 1600) / 400); // The solar correction + $lunar = (int) (((int) (($year - 1400) / 100) * 8) / 25); // The lunar correction $pfm = (3 - (11 * $golden) + $solar - $lunar) % 30; // Uncorrected date of the Paschal full moon - if ($pfm < 0) { - $pfm += 30; - } + } + + if ($pfm < 0) { + $pfm += 30; } // Corrected date of the Paschal full moon, - days after 21st March @@ -124,189 +380,168 @@ protected function calculateEaster(int $year, string $timezone): DateTime $tmp += 7; } - $easter_days = $pfm + $tmp + 1; // Easter as the number of days after 21st March + $easterDays = $pfm + $tmp + 1; // Easter as the number of days after 21st March } - $easter = new DateTime("$year-3-21", new DateTimeZone($timezone)); - $easter->add(new DateInterval('P' . $easter_days . 'D')); + $easter = new \DateTime("{$year}-3-21", DateTimeZoneFactory::getDateTimeZone($timezone)); + $easter->add(new \DateInterval(sprintf('P%dD', $easterDays))); return $easter; } /** - * Easter Monday. + * Easter. * * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @link https://en.wikipedia.org/wiki/Easter + * @see https://en.wikipedia.org/wiki/Easter * - * @param int $year the year for which Easter Monday need to be created - * @param string $timezone the timezone in which Easter Monday is celebrated - * @param string $locale the locale for which Easter Monday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param int $year the year for which Easter need to be created + * @param string $timezone the timezone in which Easter is celebrated + * @param string $locale the locale for which Easter need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function easterMonday( + protected function easter( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { - return new Holiday( - 'easterMonday', - [], - $this->calculateEaster($year, $timezone)->add(new DateInterval('P1D')), - $locale, - $type - ); + return new Holiday('easter', [], $this->calculateEaster($year, $timezone), $locale, $type); } /** - * Ascension Day. - * - * Ascension Day commemorates the bodily Ascension of Jesus into heaven. It is one of the ecumenical feasts of - * Christian churches. Ascension Day is traditionally celebrated on a Thursday, the fortieth day of Easter although - * some Catholic provinces have moved the observance to the following Sunday. + * Pentecost (Whitsunday). * - * @link https://en.wikipedia.org/wiki/Feast_of_the_Ascension + * Pentecost a feast commemorating the descent of the Holy Spirit upon the Apostles and other followers of Jesus + * Christ. It is celebrated 49 days after Easter and always takes place on Sunday. * - * @param int $year the year for which Ascension need to be created - * @param string $timezone the timezone in which Ascension is celebrated - * @param string $locale the locale for which Ascension need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param int $year the year for which Pentecost need to be created + * @param string $timezone the timezone in which Pentecost is celebrated + * @param string $locale the locale for which Pentecost need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function ascensionDay( + protected function pentecost( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'ascensionDay', + 'pentecost', [], - $this->calculateEaster($year, $timezone)->add(new DateInterval('P39D')), + $this->calculateEaster($year, $timezone)->add(new \DateInterval('P49D')), $locale, $type ); } /** - * Pentecost (Whitsunday). + * Easter Monday. * - * Pentecost a feast commemorating the descent of the Holy Spirit upon the Apostles and other followers of Jesus - * Christ. It is celebrated 49 days after Easter and always takes place on Sunday. + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. * - * @param int $year the year for which Pentecost need to be created - * @param string $timezone the timezone in which Pentecost is celebrated - * @param string $locale the locale for which Pentecost need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @see https://en.wikipedia.org/wiki/Easter * - * @return Holiday + * @param int $year the year for which Easter Monday need to be created + * @param string $timezone the timezone in which Easter Monday is celebrated + * @param string $locale the locale for which Easter Monday need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function pentecost( + protected function easterMonday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'pentecost', + 'easterMonday', [], - $this->calculateEaster($year, $timezone)->add(new DateInterval('P49D')), + $this->calculateEaster($year, $timezone)->add(new \DateInterval('P1D')), $locale, $type ); } /** - * Pentecost (Whitmonday). + * Ascension Day. * - * Pentecost a feast commemorating the descent of the Holy Spirit upon the Apostles and other followers of Jesus - * Christ. It is celebrated 49 days after Easter and always takes place on Sunday. + * Ascension Day commemorates the bodily Ascension of Jesus into heaven. It is one of the ecumenical feasts of + * Christian churches. Ascension Day is traditionally celebrated on a Thursday, the fortieth day of Easter although + * some Catholic provinces have moved the observance to the following Sunday. * - * @param int $year the year for which Pentecost (Whitmonday) need to be created - * @param string $timezone the timezone in which Pentecost (Whitmonday) is celebrated - * @param string $locale the locale for which Pentecost (Whitmonday) need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * @see https://en.wikipedia.org/wiki/Feast_of_the_Ascension * - * @return Holiday + * @param int $year the year for which Ascension need to be created + * @param string $timezone the timezone in which Ascension is celebrated + * @param string $locale the locale for which Ascension need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function pentecostMonday( + protected function ascensionDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'pentecostMonday', + 'ascensionDay', [], - $this->calculateEaster($year, $timezone)->add(new DateInterval('P50D')), + $this->calculateEaster($year, $timezone)->add(new \DateInterval('P39D')), $locale, $type ); } /** - * Corpus Christi. - * - * The Feast of Corpus Christi (Latin for Body of Christ), also known as Corpus Domini, is a Latin Rite liturgical - * solemnity celebrating the tradition and belief in the body and blood of Jesus Christ and his Real Presence in the - * Eucharist. The feast is liturgically celebrated on the Thursday after Trinity Sunday or, "where the Solemnity of - * The Most Holy Body and Blood of Christ is not a holy day of obligation, it is assigned to the Sunday after the - * Most Holy Trinity as its proper day". This is 60 days after Easter. + * Pentecost (Whitmonday). * - * @param int $year the year for which Corpus Christi need to be created - * @param string $timezone the timezone in which Corpus Christi is celebrated - * @param string $locale the locale for which Corpus Christi need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default a type of 'other' is considered. + * Pentecost a feast commemorating the descent of the Holy Spirit upon the Apostles and other followers of Jesus + * Christ. It is celebrated 49 days after Easter and always takes place on Sunday. * - * @return Holiday + * @param int $year the year for which Pentecost (Whitmonday) need to be created + * @param string $timezone the timezone in which Pentecost (Whitmonday) is celebrated + * @param string $locale the locale for which Pentecost (Whitmonday) need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function corpusChristi( + protected function pentecostMonday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OTHER + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'corpusChristi', + 'pentecostMonday', [], - $this->calculateEaster($year, $timezone)->add(new DateInterval('P60D')), + $this->calculateEaster($year, $timezone)->add(new \DateInterval('P50D')), $locale, $type ); @@ -320,31 +555,28 @@ public function corpusChristi( * widely observed as a full or partial holiday in anticipation of Christmas Day. Together, both days are considered * one of the most culturally significant celebrations in Christendom and Western society. * - * @link https://en.wikipedia.org/wiki/Christmas_Eve + * @see https://en.wikipedia.org/wiki/Christmas_Eve * - * @param int $year the year for which Christmas Eve needs to be created + * @param int $year the year for which Christmas Eve needs to be created * @param string $timezone the timezone in which Christmas Eve is celebrated - * @param string $locale the locale for which Christmas Eve need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Christmas Eve need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default observance is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function christmasEve( + protected function christmasEve( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OBSERVANCE + string $type = Holiday::TYPE_OBSERVANCE, ): Holiday { return new Holiday( 'christmasEve', [], - new DateTime("$year-12-24", new DateTimeZone($timezone)), + new \DateTime("{$year}-12-24", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -357,29 +589,26 @@ public function christmasEve( * commemorating the birth of Jesus Christ, observed most commonly on December 25 as a religious and cultural * celebration among billions of people around the world. * - * @param int $year the year for which Christmas Day need to be created + * @param int $year the year for which Christmas Day need to be created * @param string $timezone the timezone in which Christmas Day is celebrated - * @param string $locale the locale for which Christmas Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Christmas Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function christmasDay( + protected function christmasDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'christmasDay', [], - new DateTime("$year-12-25", new DateTimeZone($timezone)), + new \DateTime("{$year}-12-25", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -392,171 +621,31 @@ public function christmasDay( * commemorating the birth of Jesus Christ, observed most commonly on December 25 as a religious and cultural * celebration among billions of people around the world. * - * @param int $year the year for which the Second Christmas Day / Boxing Day need to be created + * @param int $year the year for which the Second Christmas Day / Boxing Day need to be created * @param string $timezone the timezone in which the Second Christmas Day / Boxing Day is celebrated - * @param string $locale the locale for which the Second Christmas Day / Boxing Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which the Second Christmas Day / Boxing Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function secondChristmasDay( + protected function secondChristmasDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'secondChristmasDay', [], - new DateTime("$year-12-26", new DateTimeZone($timezone)), - $locale, - $type - ); - } - - /** - * All Saints' Day. - * - * All Saints' Day, also known as All Hallows, Solemnity of All Saints, or Feast of All Saints is a solemnity - * celebrated on 1 November by the Catholic Church and various Protestant denominations, and on the first Sunday - * after Pentecost in Eastern Catholicism and Eastern Orthodoxy, in honour of all the saints, known and unknown. - * The liturgical celebration begins at Vespers on the evening of 31 October and ends at the close of 1 November. - * - * @link https://en.wikipedia.org/wiki/All_Saints%27_Day - * - * @param int $year the year for which All Saints' Day need to be created - * @param string $timezone the timezone in which All Saints' Day is celebrated - * @param string $locale the locale for which All Saints' Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function allSaintsDay( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday('allSaintsDay', [], new DateTime("$year-11-1", new DateTimeZone($timezone)), $locale, $type); - } - - /** - * Day of the Assumption of Mary. - * - * The Assumption of the Virgin Mary into Heaven, informally known as the Assumption, was the bodily taking up - * of the Virgin Mary into Heaven at the end of her earthly life. In the churches that observe it, the - * Assumption is a major feast day, commonly celebrated on August 15. - * - * @link https://en.wikipedia.org/wiki/Assumption_of_Mary - * - * @param int $year the year for which the day of the Assumption of Mary need to be created - * @param string $timezone the timezone in which the day of the Assumption of Mary is celebrated - * @param string $locale the locale for which the day of the Assumption of Mary need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function assumptionOfMary( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday( - 'assumptionOfMary', - [], - new DateTime("$year-8-15", new DateTimeZone($timezone)), - $locale, - $type - ); - } - - /** - * Good Friday. - * - * Good Friday is a Christian religious holiday commemorating the crucifixion of Jesus Christ and his death at - * Calvary. The holiday is observed during Holy Week as part of the Paschal Triduum on the Friday preceding Easter - * Sunday, and may coincide with the Jewish observance of Passover. - * - * @param int $year the year for which Good Friday need to be created - * @param string $timezone the timezone in which Good Friday is celebrated - * @param string $locale the locale for which Good Friday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function goodFriday( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday( - 'goodFriday', - [], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P2D')), + new \DateTime("{$year}-12-26", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } - /** - * Epiphany. - * - * Epiphany is a Christian feast day that celebrates the revelation of God the Son as a human being in Jesus Christ. - * The traditional date for the feast is January 6. However, since 1970, the celebration is held in some countries - * on the Sunday after January 1. Eastern Churches following the Julian Calendar observe the Theophany feast on what - * for most countries is January 19 because of the 13-day difference today between that calendar and the generally - * used Gregorian calendar. - * - * @link https://en.wikipedia.org/wiki/Epiphany_(holiday) - * - * @param int $year the year for which Epiphany need to be created - * @param string $timezone the timezone in which Epiphany is celebrated - * @param string $locale the locale for which Epiphany need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function epiphany( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday('epiphany', [], new DateTime("$year-1-6", new DateTimeZone($timezone)), $locale, $type); - } - /** * Ash Wednesday. * @@ -564,34 +653,32 @@ public function epiphany( * days, if the 6 Sundays, which are not days of fast, are excluded) before Easter and can fall as early as 4 * February or as late as 10 March. * - * @link https://en.wikipedia.org/wiki/Ash_Wednesday + * @see https://en.wikipedia.org/wiki/Ash_Wednesday * - * @param int $year the year for which Ash Wednesday need to be created + * @param int $year the year for which Ash Wednesday need to be created * @param string $timezone the timezone in which Ash Wednesday is celebrated - * @param string $locale the locale for which Ash Wednesday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Ash Wednesday need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function ashWednesday( + protected function ashWednesday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { - return new Holiday( - 'ashWednesday', - [], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P46D')), - $locale, - $type - ); + $holiday = 'ashWednesday'; + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P46D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $holiday)); + } + + return new Holiday($holiday, [], $date, $locale, $type); } /** @@ -602,31 +689,28 @@ public function ashWednesday( * which is celebrated on September 8. It is one of the most important Marian feasts celebrated in the liturgical * calendar of the Roman Catholic Church. * - * @link https://en.wikipedia.org/wiki/Feast_of_the_Immaculate_Conception + * @see https://en.wikipedia.org/wiki/Feast_of_the_Immaculate_Conception * - * @param int $year the year for which Immaculate Conception need to be created + * @param int $year the year for which Immaculate Conception need to be created * @param string $timezone the timezone in which Immaculate Conception is celebrated - * @param string $locale the locale for which Immaculate Conception need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Immaculate Conception need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function immaculateConception( + protected function immaculateConception( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'immaculateConception', [], - new DateTime("$year-12-8", new DateTimeZone($timezone)), + new \DateTime("{$year}-12-8", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -641,69 +725,33 @@ public function immaculateConception( * December according to that calendar, which places it on 8 January of the Gregorian calendar used in secular * contexts. * - * @link https://en.wikipedia.org/wiki/St._Stephen%27s_Day + * @see https://en.wikipedia.org/wiki/St._Stephen%27s_Day * - * @param int $year the year for which St. Stephen's Day need to be created + * @param int $year the year for which St. Stephen's Day need to be created * @param string $timezone the timezone in which St. Stephen's Day is celebrated - * @param string $locale the locale for which St. Stephen's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which St. Stephen's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function stStephensDay( + protected function stStephensDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'stStephensDay', [], - new DateTime("$year-12-26", new DateTimeZone($timezone)), + new \DateTime("{$year}-12-26", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } - /** - * St. Joseph's Day. - * - * Saint Joseph's Day, March 19, the Feast of St. Joseph is in Western Christianity the principal feast day of Saint - * Joseph, husband of the Blessed Virgin Mary. He is the foster-father of Jesus Christ. March 19 was dedicated to - * Saint Joseph in several Western calendars by the 10th century, and this custom was established in Rome by 1479. - * Pope St. Pius V extended its use to the entire Roman Rite by his Apostolic Constitution Quo primum - * (July 14, 1570). Since 1969, Episcopal Conferences may, if they wish, transfer it to a date outside Lent. - * - * @link https://en.wikipedia.org/wiki/St_Joseph's_Day - * - * @param int $year the year for which St. Joseph's Day need to be created - * @param string $timezone the timezone in which St. Joseph's Day is celebrated - * @param string $locale the locale for which St. Joseph's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function stJosephsDay( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday('stJosephsDay', [], new DateTime("$year-3-19", new DateTimeZone($timezone)), $locale, $type); - } - /** * Maundy Thursday. * @@ -712,66 +760,32 @@ public function stJosephsDay( * Maundy and Last Supper of Jesus Christ with the Apostles as described in the Canonical gospels. It is the fifth * day of Holy Week, and is preceded by Holy Wednesday and followed by Good Friday. * - * @link https://en.wikipedia.org/wiki/Maundy_Thursday + * @see https://en.wikipedia.org/wiki/Maundy_Thursday * - * @param int $year the year for which Maundy Thursday need to be created + * @param int $year the year for which Maundy Thursday need to be created * @param string $timezone the timezone in which Maundy Thursday is celebrated - * @param string $locale the locale for which Maundy Thursday need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Maundy Thursday need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function maundyThursday( + protected function maundyThursday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { - return new Holiday( - 'maundyThursday', - [], - $this->calculateEaster($year, $timezone)->sub(new DateInterval('P3D')), - $locale, - $type - ); - } + $holiday = 'maundyThursday'; + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P3D')); - /** - * St. George's Day. - * - * Saint George's Day is the feast day of Saint George. It is celebrated by various Christian Churches and by the - * several nations, kingdoms, countries, and cities of which Saint George is the patron saint. Saint George's Day is - * celebrated on 23 April, the traditionally accepted date of Saint George's death in 303 AD. For Eastern Orthodox - * Churches (which use the Julian calendar), '23 April' currently falls on 6 May of the Gregorian calendar. - * - * @link https://en.wikipedia.org/wiki/St_George%27s_Day - * - * @param int $year the year for which St. George's Day need to be created - * @param string $timezone the timezone in which St. George's Day is celebrated - * @param string $locale the locale for which St. George's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function stGeorgesDay( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday('stGeorgesDay', [], new DateTime("$year-4-23", new DateTimeZone($timezone)), $locale, $type); + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $holiday)); + } + + return new Holiday($holiday, [], $date, $locale, $type); } /** @@ -783,28 +797,25 @@ public function stGeorgesDay( * celebration on March 25 of the Annunciation, when the angel Gabriel told Mary that her cousin Elizabeth was in * her sixth month of pregnancy. * - * @link https://en.wikipedia.org/wiki/Nativity_of_St_John_the_Baptist + * @see https://en.wikipedia.org/wiki/Nativity_of_St_John_the_Baptist * - * @param int $year the year for which St. John's Day need to be created + * @param int $year the year for which St. John's Day need to be created * @param string $timezone the timezone in which St. John's Day is celebrated - * @param string $locale the locale for which St. John's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which St. John's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function stJohnsDay( + protected function stJohnsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { - return new Holiday('stJohnsDay', [], new DateTime("$year-06-24", new DateTimeZone($timezone)), $locale, $type); + return new Holiday('stJohnsDay', [], new \DateTime("{$year}-06-24", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } /** @@ -816,99 +827,28 @@ public function stJohnsDay( * Many Christians observe this event with the Feast of the Annunciation on 25 March, an approximation of the * northern vernal equinox nine full months before Christmas, the ceremonial birthday of Jesus. * - * @link https://en.wikipedia.org/wiki/Annunciation + * @see https://en.wikipedia.org/wiki/Annunciation * - * @param int $year the year for which the Annunciation needs to be created + * @param int $year the year for which the Annunciation needs to be created * @param string $timezone the timezone in which the Annunciation is celebrated - * @param string $locale the locale for which the Annunciation need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which the Annunciation need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function annunciation( + protected function annunciation( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'annunciation', [], - new DateTime("$year-03-25", new DateTimeZone($timezone)), - $locale, - $type - ); - } - - /** - * Calculate the Easter date for Orthodox churches. - * - * @param int $year the year for which Easter needs to be calculated - * @param string $timezone the timezone in which Easter is celebrated - * - * @return DateTime date of Orthodox Easter - * - * @throws \Exception - * @link https://en.wikipedia.org/wiki/Computus#Meeus.27s_Julian_algorithm - * @link https://www.php.net/manual/en/function.easter-date.php#83794 - */ - public function calculateOrthodoxEaster(int $year, string $timezone): DateTime - { - $a = $year % 4; - $b = $year % 7; - $c = $year % 19; - $d = (19 * $c + 15) % 30; - $e = (2 * $a + 4 * $b - $d + 34) % 7; - $month = \floor(($d + $e + 114) / 31); - $day = (($d + $e + 114) % 31) + 1; - - return (new DateTime("$year-$month-$day", new DateTimeZone($timezone)))->add(new DateInterval('P13D')); - } - - /** - * Calculates the day of the reformation. - * - * Reformation Day is a religious holiday celebrated on October 31, alongside All Hallows' Eve, in remembrance - * of the Reformation. It is celebrated among various Protestants, especially by Lutheran and Reformed church - * communities. - * It is a civic holiday in the German states of Brandenburg, Mecklenburg-Vorpommern, Saxony, Saxony-Anhalt and - * Thuringia. Slovenia celebrates it as well due to the profound contribution of the Reformation to that nation's - * cultural development, although Slovenes are mainly Roman Catholics. With the increasing influence of - * Protestantism in Latin America (particularly newer groups such as various Evangelical Protestants, Pentecostals - * or Charismatics), it has been declared a national holiday in Chile in 2009. - * - * @link https://en.wikipedia.org/wiki/Reformation_Day - * @link https://de.wikipedia.org/wiki/Reformationstag#Ursprung_und_Geschichte - * - * @param int $year the year for which St. John's Day need to be created - * @param string $timezone the timezone in which St. John's Day is celebrated - * @param string $locale the locale for which St. John's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function reformationDay( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday( - 'reformationDay', - [], - new DateTime("$year-10-31", new DateTimeZone($timezone)), + new \DateTime("{$year}-03-25", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); diff --git a/src/Yasumi/Provider/CommonHolidays.php b/src/Yasumi/Provider/CommonHolidays.php index a5481722e..41be414db 100644 --- a/src/Yasumi/Provider/CommonHolidays.php +++ b/src/Yasumi/Provider/CommonHolidays.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -25,38 +27,6 @@ */ trait CommonHolidays { - /** - * New Year's Eve. - * - * New Year's Eve is observed on December 31, the last day of the year on the modern Gregorian calendar as well as - * the Julian calendar. In present day, with most countries now using the Gregorian calendar as their de facto - * calendar, New Year's Eve is probably the most celebrated holiday, often observed with fireworks at the stroke of - * midnight as the new year starts in each time zone. - * - * @link https://en.wikipedia.org/wiki/New_Year%27s_Eve - * - * @param int $year the year for which New Year's Eve need to be created - * @param string $timezone the timezone in which New Year's Eve is celebrated - * @param string $locale the locale for which New Year's Eve need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday - * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function newYearsEve( - int $year, - string $timezone, - string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday('newYearsEve', [], new DateTime("$year-12-31", new DateTimeZone($timezone)), $locale, $type); - } - /** * New Year's Day. * @@ -67,28 +37,25 @@ public function newYearsEve( * is probably the most celebrated public holiday, often observed with fireworks at the stroke of midnight as the * new year starts in each time zone. * - * @link https://en.wikipedia.org/wiki/New_Year%27s_Day + * @see https://en.wikipedia.org/wiki/New_Year%27s_Day * - * @param int $year the year for which New Year's Day need to be created + * @param int $year the year for which New Year's Day need to be created * @param string $timezone the timezone in which New Year's Day is celebrated - * @param string $locale the locale for which New Year's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which New Year's Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function newYearsDay( + protected function newYearsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { - return new Holiday('newYearsDay', [], new DateTime("$year-1-1", new DateTimeZone($timezone)), $locale, $type); + return new Holiday('newYearsDay', [], new \DateTime("{$year}-1-1", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } /** @@ -100,146 +67,195 @@ public function newYearsDay( * Workers' Day by the Socialists and Communists of the Second International to commemorate the Haymarket affair in * Chicago that occurred on 4 May, 1886. * - * @link https://en.wikipedia.org/wiki/International_Workers%27_Day + * @see https://en.wikipedia.org/wiki/International_Workers%27_Day * - * @param int $year the year for which International Workers' Day need to be created + * @param int $year the year for which International Workers' Day need to be created * @param string $timezone the timezone in which International Workers' Day is celebrated - * @param string $locale the locale for which International Workers' Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which International Workers' Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function internationalWorkersDay( + protected function internationalWorkersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'internationalWorkersDay', [], - new DateTime("$year-5-1", new DateTimeZone($timezone)), + new \DateTime("{$year}-5-1", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } /** - * Valentine's Day. + * St. Martin's Day. * - * Valentine's Day, also known as Saint Valentine's Day or the Feast of Saint Valentine, is a celebration observed - * on February 14 each year. It is celebrated in many countries around the world, although it is not a public - * holiday in most of them. In 18th-century England, it evolved into an occasion in which lovers expressed their - * love for each other by presenting flowers, offering confectionery, and sending greeting cards (known as - * "valentines"). + * St. Martin's Day, also known as the Feast of St. Martin, Martinstag or Martinmas, the Feast of St Martin of Tours + * or Martin le Miséricordieux, is a time for feasting celebrations. This is the time when autumn wheat seeding was + * completed, and the annual slaughter of fattened cattle produced "Martinmas beef". Historically, hiring fairs were + * held where farm laborers would seek new posts. November 11 is the feast day of St. Martin of Tours, who started + * out as a Roman soldier. * - * @link https://en.wikipedia.org/wiki/Valentine%27s_Day + * @see https://en.wikipedia.org/wiki/St._Martin%27s_Day * - * @param int $year the year for which Valentine's Day need to be created - * @param string $timezone the timezone in which Valentine's Day is celebrated - * @param string $locale the locale for which Valentine's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param int $year the year for which St. Martin's Day need to be created + * @param string $timezone the timezone in which St. Martin's Day is celebrated + * @param string $locale the locale for which St. Martin's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function stMartinsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'stMartinsDay', + [], + new \DateTime("{$year}-11-11", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * International Women's Day. + * + * International Women's Day (IWD) is celebrated on March 8 every year.[3] It is a focal point in the movement for women's rights. + * + * @see https://en.wikipedia.org/wiki/International_Women%27s_Day + * + * @param int $year the year for which International Women's Day need to be created + * @param string $timezone the timezone in which International Women's Day is celebrated + * @param string $locale the locale for which International Women's Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function valentinesDay( + protected function internationalWomensDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'valentinesDay', + 'internationalWomensDay', [], - new DateTime("$year-2-14", new DateTimeZone($timezone)), + new \DateTime("{$year}-03-08", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } /** - * World Animal Day. + * New Year's Eve. * - * World Animal Day is an international day of action for animal rights and welfare celebrated annually on October - * 4, the Feast Day of St Francis of Assisi, the patron saint of animals. It started in 1931 at a convention of - * ecologists in Florence, Italy who wished to highlight the plight of endangered species. + * New Year's Eve is observed on December 31, the last day of the year on the modern Gregorian calendar as well as + * the Julian calendar. In present day, with most countries now using the Gregorian calendar as their de facto + * calendar, New Year's Eve is probably the most celebrated holiday, often observed with fireworks at the stroke of + * midnight as the new year starts in each time zone. * - * @link https://en.wikipedia.org/wiki/World_Animal_Day + * @see https://en.wikipedia.org/wiki/New_Year%27s_Eve * - * @param int $year the year for which World Animal Day need to be created - * @param string $timezone the timezone in which World Animal Day is celebrated - * @param string $locale the locale for which World Animal Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param int $year the year for which New Year's Eve need to be created + * @param string $timezone the timezone in which New Year's Eve is celebrated + * @param string $locale the locale for which New Year's Eve need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function newYearsEve( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday('newYearsEve', [], new \DateTime("{$year}-12-31", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); + } + + /** + * Valentine's Day. + * + * Valentine's Day, also known as Saint Valentine's Day or the Feast of Saint Valentine, is a celebration observed + * on February 14 each year. It is celebrated in many countries around the world, although it is not a public + * holiday in most of them. In 18th-century England, it evolved into an occasion in which lovers expressed their + * love for each other by presenting flowers, offering confectionery, and sending greeting cards (known as + * "valentines"). + * + * @see https://en.wikipedia.org/wiki/Valentine%27s_Day + * + * @param int $year the year for which Valentine's Day need to be created + * @param string $timezone the timezone in which Valentine's Day is celebrated + * @param string $locale the locale for which Valentine's Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function worldAnimalDay( + protected function valentinesDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'worldAnimalDay', + 'valentinesDay', [], - new DateTime("$year-10-4", new DateTimeZone($timezone)), + new \DateTime("{$year}-2-14", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } /** - * St. Martin's Day. + * World Animal Day. * - * St. Martin's Day, also known as the Feast of St. Martin, Martinstag or Martinmas, the Feast of St Martin of Tours - * or Martin le Miséricordieux, is a time for feasting celebrations. This is the time when autumn wheat seeding was - * completed, and the annual slaughter of fattened cattle produced "Martinmas beef". Historically, hiring fairs were - * held where farm laborers would seek new posts. November 11 is the feast day of St. Martin of Tours, who started - * out as a Roman soldier. + * World Animal Day is an international day of action for animal rights and welfare celebrated annually on October + * 4, the Feast Day of St Francis of Assisi, the patron saint of animals. It started in 1931 at a convention of + * ecologists in Florence, Italy who wished to highlight the plight of endangered species. * - * @link https://en.wikipedia.org/wiki/St._Martin%27s_Day + * @see https://en.wikipedia.org/wiki/World_Animal_Day * - * @param int $year the year for which St. Martin's Day need to be created - * @param string $timezone the timezone in which St. Martin's Day is celebrated - * @param string $locale the locale for which St. Martin's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param int $year the year for which World Animal Day need to be created + * @param string $timezone the timezone in which World Animal Day is celebrated + * @param string $locale the locale for which World Animal Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function stMartinsDay( + protected function worldAnimalDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( - 'stMartinsDay', + 'worldAnimalDay', [], - new DateTime("$year-11-11", new DateTimeZone($timezone)), + new \DateTime("{$year}-10-4", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -253,31 +269,28 @@ public function stMartinsDay( * on other days by many other countries. Father's Day was created to complement Mother's Day, a celebration that * honors mothers and motherhood. * - * @link https://en.wikipedia.org/wiki/Father%27s_Day + * @see https://en.wikipedia.org/wiki/Father%27s_Day * - * @param int $year the year for which Father's Day need to be created + * @param int $year the year for which Father's Day need to be created * @param string $timezone the timezone in which Father's Day is celebrated - * @param string $locale the locale for which Father's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Father's Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function fathersDay( + protected function fathersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'fathersDay', [], - new DateTime("third sunday of june $year", new DateTimeZone($timezone)), + new \DateTime("third sunday of june {$year}", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -291,31 +304,28 @@ public function fathersDay( * the months of March or May. It complements similar celebrations honoring family members, such as Father's Day and * Siblings Day. * - * @link https://en.wikipedia.org/wiki/Mother%27s_Day + * @see https://en.wikipedia.org/wiki/Mother%27s_Day * - * @param int $year the year for which Mother's Day need to be created + * @param int $year the year for which Mother's Day need to be created * @param string $timezone the timezone in which Mother's Day is celebrated - * @param string $locale the locale for which Mother's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Mother's Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function mothersDay( + protected function mothersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'mothersDay', [], - new DateTime("second sunday of may $year", new DateTimeZone($timezone)), + new \DateTime("second sunday of may {$year}", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -329,31 +339,28 @@ public function mothersDay( * Germany's unconditional surrender of its armed forces. It thus marked the end of World War II in Europe. Some * countries commemorate the end of the war on a different date. * - * @link https://en.wikipedia.org/wiki/Victory_in_Europe_Day + * @see https://en.wikipedia.org/wiki/Victory_in_Europe_Day * - * @param int $year the year for which Victory in Europe Day need to be created + * @param int $year the year for which Victory in Europe Day need to be created * @param string $timezone the timezone in which Victory in Europe Day is celebrated - * @param string $locale the locale for which Victory in Europe Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Victory in Europe Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function victoryInEuropeDay( + protected function victoryInEuropeDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'victoryInEuropeDay', [], - new DateTime("$year-5-8", new DateTimeZone($timezone)), + new \DateTime("{$year}-5-8", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); @@ -369,95 +376,91 @@ public function victoryInEuropeDay( * day of the Armistice of Villa Giusti. In the Netherlands, Denmark and Norway World War I is not commemorated as * the three countries all remained neutral. * - * @link https://en.wikipedia.org/wiki/Armistice_Day + * @see https://en.wikipedia.org/wiki/Armistice_Day * - * @param int $year the year for which Armistice Day need to be created + * @param int $year the year for which Armistice Day need to be created * @param string $timezone the timezone in which Armistice Day is celebrated - * @param string $locale the locale for which Armistice Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * @param string $locale the locale for which Armistice Day need to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @return Holiday - * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function armisticeDay( + protected function armisticeDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'armisticeDay', [], - new DateTime("$year-11-11", new DateTimeZone($timezone)), + new \DateTime("{$year}-11-11", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); } /** - * International Women's Day - * - * International Women's Day (IWD) is celebrated on March 8 every year.[3] It is a focal point in the movement for women's rights. - * - * @link https://en.wikipedia.org/wiki/International_Women%27s_Day + * The beginning of summer time. * - * @param int $year the year for which International Women's Day need to be created - * @param string $timezone the timezone in which International Women's Day is celebrated - * @param string $locale the locale for which International Women's Day need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * Summer time is also known as daylight save time. * - * @return Holiday + * @param int $year the year for which summer time need to be created + * @param string $timezone the timezone in which summer time transition occurs + * @param string $locale the locale for which summer time need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws InvalidDateException - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - public function internationalWomensDay( + protected function summerTime( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL - ): Holiday { - return new Holiday( - 'internationalWomensDay', - [], - new DateTime("$year-03-08", new DateTimeZone($timezone)), - $locale, - $type - ); + ?string $type = null, + ): ?Holiday { + $date = $this->calculateSummerWinterTime($year, $timezone, true); + + if ($date instanceof \DateTimeImmutable) { + return new Holiday( + 'summerTime', + [], + $date, + $locale, + $type ?? Holiday::TYPE_SEASON + ); + } + + return null; } /** - * The beginning of summer time. - * - * Summer time is also known as daylight save time. + * The beginning of winter time. * - * @param int $year the year for which summer time need to be created - * @param string $timezone the timezone in which summer time transition occurs - * @param string $locale the locale for which summer time need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * Winter time is also known as standard time. * - * @return Holiday|null + * @param int $year the year for which summer time need to be created + * @param string $timezone the timezone in which summer time transition occurs + * @param string $locale the locale for which summer time need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException * @throws \Exception */ - public function summerTime($year, $timezone, $locale, $type = null): ?Holiday - { - $date = $this->calculateSummerWinterTime($year, $timezone, true); + protected function winterTime( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): ?Holiday { + $date = $this->calculateSummerWinterTime($year, $timezone, false); - if ($date) { + if ($date instanceof \DateTimeImmutable) { return new Holiday( - 'summerTime', + 'winterTime', [], $date, $locale, @@ -481,64 +484,48 @@ public function summerTime($year, $timezone, $locale, $type = null): ?Holiday * On the northern hemisphere, summer time starts around March/April. On the southern hemisphere it happens 6 * months later. * - * @param int $year the year for which Easter needs to be calculated + * @param int $year the year for which Easter needs to be calculated * @param string $timezone the timezone in which Easter is celebrated - * @param bool $summer whether to calculate the start of summer or winter time + * @param bool $summer whether to calculate the start of summer or winter time + * + * @return \DateTimeImmutable|null A DateTime object representing the summer or winter transition time for the given + * timezone. If no transition time is found, a null value is returned. * - * @return DateTime|null A DateTime object representing the summer or winter transition time for the given - * timezone. If no transition time is found, a null value is returned. * @throws \Exception */ - protected function calculateSummerWinterTime($year, $timezone, $summer): ?DateTime - { - $zone = new DateTimeZone($timezone); + private function calculateSummerWinterTime( + int $year, + string $timezone, + bool $summer, + ): ?\DateTimeImmutable { + $zone = DateTimeZoneFactory::getDateTimeZone($timezone); + + $tsBegin = strtotime(sprintf('%u-01-01 00:00:00', $year)); + if (false === $tsBegin) { + throw new \RuntimeException(sprintf('unable to create a beginning timestamp for the year `%u`', $year)); + } - $transitions = $zone->getTransitions(\mktime(0, 0, 0, 1, 1, $year), \mktime(23, 59, 59, 12, 31, $year)); + $tsEnd = strtotime(sprintf('%u-12-31 23:59:59', $year)); + if (false === $tsEnd) { + throw new \RuntimeException(sprintf('unable to create an ending timestamp for the year `%u`', $year)); + } + + $transitions = $zone->getTransitions($tsBegin, $tsEnd); + + $transition = array_shift($transitions); + if (! is_array($transition)) { + throw new \RuntimeException('unable to get transition details'); + } - $transition = \array_shift($transitions); $dst = $transition['isdst']; foreach ($transitions as $transition) { if ($transition['isdst'] !== $dst && $transition['isdst'] === $summer) { - return new DateTime(\substr($transition['time'], 0, 10), $zone); + return new \DateTimeImmutable(substr($transition['time'], 0, 10), $zone); } $dst = $transition['isdst']; } return null; } - - /** - * The beginning of winter time. - * - * Winter time is also known as standard time. - * - * @param int $year the year for which summer time need to be created - * @param string $timezone the timezone in which summer time transition occurs - * @param string $locale the locale for which summer time need to be displayed in. - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, - * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. - * - * @return Holiday|null - * - * @throws UnknownLocaleException - * @throws \InvalidArgumentException - * @throws \Exception - */ - public function winterTime($year, $timezone, $locale, $type = null): ?Holiday - { - $date = $this->calculateSummerWinterTime($year, $timezone, false); - - if ($date) { - return new Holiday( - 'winterTime', - [], - $date, - $locale, - $type ?? Holiday::TYPE_SEASON - ); - } - - return null; - } } diff --git a/src/Yasumi/Provider/Croatia.php b/src/Yasumi/Provider/Croatia.php index c59ae4f2e..b215825bc 100644 --- a/src/Yasumi/Provider/Croatia.php +++ b/src/Yasumi/Provider/Croatia.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -25,10 +27,11 @@ */ class Croatia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'HR'; @@ -36,7 +39,6 @@ class Croatia extends AbstractProvider /** * Initialize holidays for Croatia. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -59,44 +61,116 @@ public function initialize(): void $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->stStephensDay($this->year, $this->timezone, $this->locale)); - /** - * Day of Antifascist Struggle - */ - if ($this->year >= 1941) { - $this->addHoliday(new Holiday('antifascistStruggleDay', [ - 'en' => 'Day of Antifascist Struggle', - 'hr' => 'Dan antifašističke borbe', - ], new DateTime("$this->year-6-22", new DateTimeZone($this->timezone)), $this->locale)); - } + // Add other holidays + $this->calculateAntiFascistsStruggleDay(); + $this->calculateStatehoodDay(); + $this->calculateHomelandThanksgivingDay(); + $this->calculateIndependenceDay(); + $this->calculateRemembranceDayForHomelandWarVictims(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Croatia', + 'https://sh.wikipedia.org/wiki/Praznici_u_Hrvatskoj', + 'https://hr.wikipedia.org/wiki/Blagdani_i_spomendani_u_Hrvatskoj', + ]; + } - /** - * Croatian Statehood Day - */ + /** + * Starting from the year 2020. statehood day is celebrated at a new date + * Source: https://narodne-novine.nn.hr/clanci/sluzbeni/2019_11_110_2212.html. + * + * @throws \Exception + */ + protected function calculateStatehoodDay(): void + { if ($this->year >= 1991) { + $statehoodDayDate = new \DateTime($this->year >= 2020 ? "{$this->year}-5-30" : "{$this->year}-6-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('statehoodDay', [ 'en' => 'Statehood Day', 'hr' => 'Dan državnosti', - ], new DateTime("$this->year-6-25", new DateTimeZone($this->timezone)), $this->locale)); + ], $statehoodDayDate, $this->locale)); } + } - /** - * Homeland Thanksgiving Day - */ - if ($this->year >= 1995) { - $this->addHoliday(new Holiday('homelandThanksgiving', [ - 'en' => 'Homeland Thanksgiving Day', - 'hr' => 'Dan domovinske zahvalnosti', - ], new DateTime("$this->year-8-5", new DateTimeZone($this->timezone)), $this->locale)); + /** + * Starting from the year 2020. Homeland Thanksgiving Day name is slightly changed + * Source: https://narodne-novine.nn.hr/clanci/sluzbeni/2019_11_110_2212.html. + * + * @throws \Exception + */ + protected function calculateHomelandThanksgivingDay(): void + { + $names = []; + if ($this->year >= 1995 && $this->year < 2020) { + $names['en'] = 'Homeland Thanksgiving Day'; + $names['hr'] = 'Dan domovinske zahvalnosti'; + } elseif ($this->year >= 2020) { + $names['en'] = 'Victory and Homeland Thanksgiving Day and the Day of Croatian Defenders'; + $names['hr'] = 'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja'; } - /** - * Independence Day - */ - if ($this->year >= 1991) { - $this->addHoliday(new Holiday('independenceDay', [ - 'en' => 'Independence Day', - 'hr' => 'Dan neovisnosti', - ], new DateTime("$this->year-10-8", new DateTimeZone($this->timezone)), $this->locale)); + if ([] !== $names) { + $this->addHoliday(new Holiday( + 'homelandThanksgiving', + $names, + new \DateTime("{$this->year}-8-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Starting from the year 2020. Independence Day is no longer an official holiday, + * but is still remembered under a different name as Croatian Parliament Day (Dan Hrvatskog sabora) + * Source: https://narodne-novine.nn.hr/clanci/sluzbeni/2019_11_110_2212.html. + * + * @throws \Exception + */ + protected function calculateIndependenceDay(): void + { + if ($this->year < 1991) { + return; + } + + if ($this->year >= 2020) { + return; + } + + $this->addHoliday(new Holiday('independenceDay', [ + 'en' => 'Independence Day', + 'hr' => 'Dan neovisnosti', + ], new \DateTime("{$this->year}-10-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Starting from the year 2020. a new holiday was added + * Source: https://narodne-novine.nn.hr/clanci/sluzbeni/2019_11_110_2212.html. + * + * @throws \Exception + */ + protected function calculateRemembranceDayForHomelandWarVictims(): void + { + if ($this->year >= 2020) { + $this->addHoliday(new Holiday('remembranceDay', [ + 'en' => 'Remembrance Day for Homeland War Victims and Remembrance Day for the Victims of Vukovar and Skabrnja', + 'hr' => 'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje', + ], new \DateTime("{$this->year}-11-18", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /* + * Day of Antifascist Struggle + */ + protected function calculateAntiFascistsStruggleDay(): void + { + if ($this->year >= 1941) { + $this->addHoliday(new Holiday('antifascistStruggleDay', [ + 'en' => 'Day of Antifascist Struggle', + 'hr' => 'Dan antifašističke borbe', + ], new \DateTime("{$this->year}-6-22", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } } diff --git a/src/Yasumi/Provider/CzechRepublic.php b/src/Yasumi/Provider/CzechRepublic.php index 2e01b3b91..1119e8e7e 100644 --- a/src/Yasumi/Provider/CzechRepublic.php +++ b/src/Yasumi/Provider/CzechRepublic.php @@ -1,19 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -21,15 +24,16 @@ * Provider for all holidays in Czech republic. * * Class CzechRepublic - * @package Yasumi\Provider + * * @author Dennis Fridrich */ class CzechRepublic extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CZ'; @@ -37,7 +41,6 @@ class CzechRepublic extends AbstractProvider /** * Initialize holidays for the Czech Republic. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -57,22 +60,30 @@ public function initialize(): void $this->calculateCzechStatehoodDay(); $this->calculateIndependentCzechoslovakStateDay(); $this->calculateStruggleForFreedomAndDemocracyDay(); - $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic', + 'https://cs.wikipedia.org/wiki/%C4%8Cesk%C3%BD_st%C3%A1tn%C3%AD_sv%C3%A1tek', + 'https://www.e-sbirka.cz/sb/2000/245/0000-00-00?zalozka=text#par_2', + ]; + } + /** - * Day of renewal of independent Czech state + * Day of renewal of independent Czech state. * * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateRenewalOfCzechIndependenceDay(): void + protected function calculateRenewalOfCzechIndependenceDay(): void { $this->addHoliday(new Holiday( 'czechRenewalOfIndependentStateDay', @@ -80,13 +91,13 @@ private function calculateRenewalOfCzechIndependenceDay(): void 'cs' => 'Den obnovy samostatného českého státu', 'en' => 'Day of renewal of the independent Czech state', ], - new DateTime($this->year . '-01-01', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-01-01", new \DateTimeZone($this->timezone)), $this->locale )); } /** - * Saints Cyril and Methodius Day + * Saints Cyril and Methodius Day. * * Saints Cyril and Methodius were two Byzantine Christian theologians and Christian missionaries who were brothers. * Through their work they influenced the cultural development of all Slavs, for which they received the title @@ -101,12 +112,11 @@ private function calculateRenewalOfCzechIndependenceDay(): void * @see https://en.wikipedia.org/wiki/Saints_Cyril_and_Methodius * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSaintsCyrilAndMethodiusDay(): void + protected function calculateSaintsCyrilAndMethodiusDay(): void { $this->addHoliday(new Holiday( 'saintsCyrilAndMethodiusDay', @@ -114,13 +124,13 @@ private function calculateSaintsCyrilAndMethodiusDay(): void 'cs' => 'Den slovanských věrozvěstů Cyrila a Metoděje', 'en' => 'Saints Cyril and Methodius Day', ], - new DateTime($this->year . '-07-5', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-07-5", new \DateTimeZone($this->timezone)), $this->locale )); } /** - * Jan Hus Day + * Jan Hus Day. * * Jan Hus, often referred to in English as John Hus or John Huss, was a Czech priest, philosopher, early Christian * reformer and Master at Charles University in Prague. After John Wycliffe, the theorist of ecclesiastical @@ -129,23 +139,22 @@ private function calculateSaintsCyrilAndMethodiusDay(): void * @see https://en.wikipedia.org/wiki/Jan_Hus * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateJanHusDay(): void + protected function calculateJanHusDay(): void { $this->addHoliday(new Holiday( 'janHusDay', ['cs' => 'Den upálení mistra Jana Husa', 'en' => 'Jan Hus Day'], - new DateTime($this->year . '-07-6', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-07-6", new \DateTimeZone($this->timezone)), $this->locale )); } /** - * St. Wenceslas Day (Czech Statehood Day) + * St. Wenceslas Day (Czech Statehood Day). * * Wenceslaus I, Wenceslas I, or Vaclav the Good was the duke of Bohemia from 921 until his assassination in 935, * in a plot by his brother, Boleslav the Cruel. @@ -157,12 +166,11 @@ private function calculateJanHusDay(): void * @see https://en.wikipedia.org/wiki/Wenceslaus_I,_Duke_of_Bohemia * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCzechStatehoodDay(): void + protected function calculateCzechStatehoodDay(): void { $this->addHoliday(new Holiday( 'czechStateHoodDay', @@ -170,40 +178,38 @@ private function calculateCzechStatehoodDay(): void 'cs' => 'Den české státnosti', 'en' => 'St. Wenceslas Day (Czech Statehood Day)', ], - new DateTime($this->year . '-09-28', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-09-28", new \DateTimeZone($this->timezone)), $this->locale )); } /** - * Independent Czechoslovak State Day + * Independent Czechoslovak State Day. * * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateIndependentCzechoslovakStateDay(): void + protected function calculateIndependentCzechoslovakStateDay(): void { $this->addHoliday(new Holiday('independentCzechoslovakStateDay', [ 'cs' => 'Den vzniku samostatného československého státu', 'en' => 'Independent Czechoslovak State Day', - ], new DateTime($this->year . '-10-28', new \DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-10-28", new \DateTimeZone($this->timezone)), $this->locale)); } /** - * Struggle for Freedom and Democracy Day + * Struggle for Freedom and Democracy Day. * * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_Czech_Republic * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStruggleForFreedomAndDemocracyDay(): void + protected function calculateStruggleForFreedomAndDemocracyDay(): void { $this->addHoliday(new Holiday( 'struggleForFreedomAndDemocracyDay', @@ -211,7 +217,7 @@ private function calculateStruggleForFreedomAndDemocracyDay(): void 'cs' => 'Den boje za svobodu a demokracii', 'en' => 'Struggle for Freedom and Democracy Day', ], - new DateTime($this->year . '-11-17', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-17", new \DateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Czechia.php b/src/Yasumi/Provider/Czechia.php new file mode 100644 index 000000000..7cb5d4498 --- /dev/null +++ b/src/Yasumi/Provider/Czechia.php @@ -0,0 +1,29 @@ + + */ + +namespace Yasumi\Provider; + +/** + * Provider for all holidays in Czechia. "Czechia" is the official short-name for "Czech Republic". + * + * Class Czechia + * + * @author Pascal Paulis + */ +class Czechia extends CzechRepublic +{ +} diff --git a/src/Yasumi/Provider/DateTimeZoneFactory.php b/src/Yasumi/Provider/DateTimeZoneFactory.php new file mode 100644 index 000000000..4176f82dd --- /dev/null +++ b/src/Yasumi/Provider/DateTimeZoneFactory.php @@ -0,0 +1,38 @@ + + */ + +namespace Yasumi\Provider; + +/** + * This factory keep references to already instantiated DateTimeZone to save CPU time resources. + * + * @author Pierrick VIGNAND + */ +final class DateTimeZoneFactory +{ + /** @var array */ + private static array $dateTimeZones = []; + + public static function getDateTimeZone(string $timezone): \DateTimeZone + { + if (! isset(self::$dateTimeZones[$timezone])) { + self::$dateTimeZones[$timezone] = new \DateTimeZone($timezone); + } + + return self::$dateTimeZones[$timezone]; + } +} diff --git a/src/Yasumi/Provider/Denmark.php b/src/Yasumi/Provider/Denmark.php index 689b21deb..e37fd9693 100644 --- a/src/Yasumi/Provider/Denmark.php +++ b/src/Yasumi/Provider/Denmark.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Denmark extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DK'; @@ -35,7 +37,6 @@ class Denmark extends AbstractProvider /** * Initialize holidays for Denmark. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -59,23 +60,22 @@ public function initialize(): void $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); $this->calculateGreatPrayerDay(); + // Add other holidays $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->calculateConstitutionDay(); + } - $summerTime = $this->summerTime($this->year, $this->timezone, $this->locale); - if ($summerTime instanceof Holiday) { - $this->addHoliday($summerTime); - } - $winterTime = $this->winterTime($this->year, $this->timezone, $this->locale); - if ($winterTime instanceof Holiday) { - $this->addHoliday($winterTime); - } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Denmark', + ]; } /** - * Great Prayer Day + * Great Prayer Day. * * Store Bededag, translated literally as Great Prayer Day or more loosely as General Prayer Day, "All Prayers" Day, * Great Day of Prayers or Common Prayer Day, is a Danish holiday celebrated on the 4th Friday after Easter. It is a @@ -83,29 +83,34 @@ public function initialize(): void * Denmark in 1686 by King Christian V as a consolidation of several minor (or local) Roman Catholic holidays which * the Church observed that had survived the Reformation. * - * @link https://en.wikipedia.org/wiki/Store_Bededag + * @see https://en.wikipedia.org/wiki/Store_Bededag * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateGreatPrayerDay(): void + protected function calculateGreatPrayerDay(): void { $easter = $this->calculateEaster($this->year, $this->timezone)->format('Y-m-d'); - if ($this->year >= 1686) { - $this->addHoliday(new Holiday( - 'greatPrayerDay', - ['da' => 'Store bededag'], - new DateTime("fourth friday $easter", new DateTimeZone($this->timezone)), - $this->locale - )); + if ($this->year < 1686) { + return; } + + if ($this->year >= 2024) { + return; + } + + $this->addHoliday(new Holiday( + 'greatPrayerDay', + ['da' => 'store bededag'], + new \DateTime("fourth friday {$easter}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); } /** - * Constitution Day + * Constitution Day. * * Denmark’s Constitution Day is June 5 and commemorates the signing of Denmark's constitution * on June 5 1849, when Denmark peacefully became as a constitutional monarchy. @@ -113,20 +118,19 @@ private function calculateGreatPrayerDay(): void * While not a public holiday, some companies and public offices are closed. Traditionally, * members of parliament gives political speeches around the country. * - * @link https://en.wikipedia.org/wiki/Constitution_Day_(Denmark) + * @see https://en.wikipedia.org/wiki/Constitution_Day_(Denmark) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateConstitutionDay(): void + protected function calculateConstitutionDay(): void { if ($this->year >= 1849) { $this->addHoliday(new Holiday( 'constitutionDay', - ['da' => 'Grundlovsdag'], - new DateTime("$this->year-6-5", new DateTimeZone($this->timezone)), + ['da' => 'grundlovsdag'], + new \DateTime("{$this->year}-6-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); diff --git a/src/Yasumi/Provider/Estonia.php b/src/Yasumi/Provider/Estonia.php index 3a51713c7..9b59ca4e6 100644 --- a/src/Yasumi/Provider/Estonia.php +++ b/src/Yasumi/Provider/Estonia.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; @@ -22,7 +26,8 @@ */ class Estonia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; public const DECLARATION_OF_INDEPENDENCE_YEAR = 1918; @@ -31,7 +36,7 @@ class Estonia extends AbstractProvider public const RESTORATION_OF_INDEPENDENCE_YEAR = 1991; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'EE'; @@ -61,11 +66,19 @@ public function initialize(): void $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Estonia', + 'https://et.wikipedia.org/wiki/Eesti_riigip%C3%BChad', + ]; + } + /** * @throws \InvalidArgumentException * @throws \Exception */ - private function addIndependenceDay(): void + protected function addIndependenceDay(): void { if ($this->year >= self::DECLARATION_OF_INDEPENDENCE_YEAR) { $this->addHoliday(new Holiday('independenceDay', [ @@ -79,7 +92,7 @@ private function addIndependenceDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addVictoryDay(): void + protected function addVictoryDay(): void { if ($this->year >= self::VICTORY_DAY_START_YEAR) { $this->addHoliday(new Holiday('victoryDay', [ @@ -93,12 +106,12 @@ private function addVictoryDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addRestorationOfIndependenceDay(): void + protected function addRestorationOfIndependenceDay(): void { if ($this->year >= self::RESTORATION_OF_INDEPENDENCE_YEAR) { $this->addHoliday(new Holiday('restorationOfIndependenceDay', [ 'en' => 'Day of Restoration of Independence', - 'et' => 'Tasiseseisvumispäev', + 'et' => 'Taasiseseisvumispäev', ], new \DateTime("{$this->year}-08-20", new \DateTimeZone($this->timezone)))); } } diff --git a/src/Yasumi/Provider/Finland.php b/src/Yasumi/Provider/Finland.php index 00f861a9c..ae41e1c77 100644 --- a/src/Yasumi/Provider/Finland.php +++ b/src/Yasumi/Provider/Finland.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Finland extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'FI'; @@ -34,7 +37,6 @@ class Finland extends AbstractProvider /** * Initialize holidays for Finland. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -63,6 +65,14 @@ public function initialize(): void $this->calculateIndependenceDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Finland', + 'https://fi.wikipedia.org/wiki/Suomen_juhlap%C3%A4iv%C3%A4t', + ]; + } + /** * St. John's Day / Midsummer. * @@ -76,21 +86,20 @@ public function initialize(): void * always on June 24. Many of the celebrations of midsummer take place on midsummer eve, when many workplaces are * closed and shops must close their doors at noon. * - * @link https://en.wikipedia.org/wiki/Midsummer#Finland + * @see https://en.wikipedia.org/wiki/Midsummer#Finland * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStJohnsDay(): void + protected function calculateStJohnsDay(): void { - $stJohnsDay = ($this->year < 1955) ? "$this->year-6-24" : "$this->year-6-20 this saturday"; + $stJohnsDay = $this->year < 1955 ? "{$this->year}-6-24" : "{$this->year}-6-20 this saturday"; $this->addHoliday(new Holiday( 'stJohnsDay', [], - new DateTime($stJohnsDay, new DateTimeZone($this->timezone)), + new \DateTime($stJohnsDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -109,26 +118,25 @@ private function calculateStJohnsDay(): void * the dead. In the Swedish and Finnish calendar, the observance takes place on the Saturday between 31 October and * 6 November. In many Lutheran Churches, it is moved to the first Sunday of November. * - * @link https://en.wikipedia.org/wiki/All_Saints%27_Day - * @link https://fi.wikipedia.org/wiki/Pyh%C3%A4inp%C3%A4iv%C3%A4 + * @see https://en.wikipedia.org/wiki/All_Saints%27_Day + * @see https://fi.wikipedia.org/wiki/Pyh%C3%A4inp%C3%A4iv%C3%A4 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAllSaintsDay(): void + protected function calculateAllSaintsDay(): void { $this->addHoliday(new Holiday( 'allSaintsDay', [], - new DateTime("$this->year-10-31 this saturday", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-31 this saturday", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } /** - * Independence Day + * Independence Day. * * Finland's Independence Day (Finnish: itsenäisyyspäivä, Swedish: självständighetsdagen) is a national public * holiday, and a flag day, held on 6 December to celebrate Finland's declaration of independence from the Russian @@ -138,20 +146,19 @@ private function calculateAllSaintsDay(): void * some parts of Finland was only a minor holiday compared to 16 May, the Whites' day of celebration for prevailing * in the Finnish Civil War. * - * @link https://en.wikipedia.org/wiki/Independence_Day_(Finland) + * @see https://en.wikipedia.org/wiki/Independence_Day_(Finland) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateIndependenceDay(): void + protected function calculateIndependenceDay(): void { if ($this->year >= 1917) { $this->addHoliday(new Holiday( 'independenceDay', ['fi' => 'Itsenäisyyspäivä'], - new DateTime("$this->year-12-6", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-6", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/France.php b/src/Yasumi/Provider/France.php old mode 100755 new mode 100644 index b6668b6a9..cfb9a81c0 --- a/src/Yasumi/Provider/France.php +++ b/src/Yasumi/Provider/France.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,18 +25,20 @@ */ class France extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'FR'; + public const EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY = 2004; + /** * Initialize holidays for France. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -54,7 +58,6 @@ public function initialize(): void $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); @@ -66,6 +69,15 @@ public function initialize(): void // Calculate other holidays $this->calculateBastilleDay(); + $this->calculatePentecostMonday(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_France', + 'https://fr.wikipedia.org/wiki/F%C3%AAtes_et_jours_f%C3%A9ri%C3%A9s_en_France', + ]; } /** @@ -77,20 +89,42 @@ public function initialize(): void * is held on the morning of 14 July, on the Champs-Élysées in Paris in front of the President of the Republic, * French officials and foreign guests. * - * @link https://en.wikipedia.org/wiki/Bastille_Day + * @see https://en.wikipedia.org/wiki/Bastille_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateBastilleDay(): void + protected function calculateBastilleDay(): void { if ($this->year >= 1790) { $this->addHoliday(new Holiday('bastilleDay', [ 'en' => 'Bastille Day', 'fr' => 'La Fête nationale', - ], new DateTime("$this->year-7-14", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-7-14", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Pentecost Monday. + * + * Until 2004, Pentecost Monday was an official holiday. Since 2004, the holiday is considered a 'working holiday', + * imposed by law to be by default on Pentecost Monday. Pentecost Monday is still a holiday (but a working holiday). + * + * @see: https://en.wikipedia.org/wiki/Journ%C3%A9e_de_solidarit%C3%A9_envers_les_personnes_%C3%A2g%C3%A9es + * + * @see: https://fr.wikipedia.org/w/index.php?title=Journ%C3%A9e_de_solidarit%C3%A9_envers_les_personnes_%C3%A2g%C3%A9es_et_handicap%C3%A9es&tableofcontents=0 + * + * @throws \Exception + */ + protected function calculatePentecostMonday(): void + { + $type = Holiday::TYPE_OFFICIAL; + + if ($this->year >= 2004) { + $type = Holiday::TYPE_OBSERVANCE; } + + $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, $type)); } } diff --git a/src/Yasumi/Provider/France/BasRhin.php b/src/Yasumi/Provider/France/BasRhin.php old mode 100755 new mode 100644 index bd4fbb1a7..57204b0ad --- a/src/Yasumi/Provider/France/BasRhin.php +++ b/src/Yasumi/Provider/France/BasRhin.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\France; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\ChristianHolidays; use Yasumi\Provider\France; @@ -24,14 +28,14 @@ * It is the more populous and densely populated of the two departments of the traditional Alsace region, with 1,109,460 * inhabitants in 2013. The prefecture and the General Council are based in Strasbourg. * - * @link https://en.wikipedia.org/wiki/Bas-Rhin + * @see https://en.wikipedia.org/wiki/Bas-Rhin */ class BasRhin extends France { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'FR-67'; @@ -39,7 +43,6 @@ class BasRhin extends France /** * Initialize holidays for Bas-Rhin (France). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/France/HautRhin.php b/src/Yasumi/Provider/France/HautRhin.php old mode 100755 new mode 100644 index 3b416bc46..05dc87fc0 --- a/src/Yasumi/Provider/France/HautRhin.php +++ b/src/Yasumi/Provider/France/HautRhin.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\France; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\ChristianHolidays; use Yasumi\Provider\France; @@ -24,14 +28,14 @@ * Its name means Upper Rhine. Haut-Rhin is the smaller and less populated of the two departments of the traditional * Alsace region, although it is still densely populated compared to the rest of France. * - * @link https://en.wikipedia.org/wiki/Haut-Rhin + * @see https://en.wikipedia.org/wiki/Haut-Rhin */ class HautRhin extends France { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'FR-68'; @@ -39,7 +43,6 @@ class HautRhin extends France /** * Initialize holidays for Haut-Rhin (France). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/France/Moselle.php b/src/Yasumi/Provider/France/Moselle.php old mode 100755 new mode 100644 index 48680b98f..58d8c9d93 --- a/src/Yasumi/Provider/France/Moselle.php +++ b/src/Yasumi/Provider/France/Moselle.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\France; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\ChristianHolidays; use Yasumi\Provider\France; @@ -25,14 +29,14 @@ * Momerstroff, and Créhange (Kriechingen) - all possessions of princes of the German Holy Roman Empire - and * incorporated them into the Moselle département. * - * @link https://en.wikipedia.org/wiki/Moselle_(department) + * @see https://en.wikipedia.org/wiki/Moselle_(department) */ class Moselle extends France { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'FR-57'; @@ -40,7 +44,6 @@ class Moselle extends France /** * Initialize holidays for Moselle (France). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Georgia.php b/src/Yasumi/Provider/Georgia.php new file mode 100644 index 000000000..38107eeb9 --- /dev/null +++ b/src/Yasumi/Provider/Georgia.php @@ -0,0 +1,242 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Holiday; + +/** + * Provider for all holidays in Georgia. + * + * @author Zurab Sardarov + */ +class Georgia extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + public const PROCLAMATION_OF_INDEPENDENCE_YEAR = 1918; + + public const APRIL_NINE_TRAGEDY_YEAR = 1989; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'GE'; + + /** + * Initialize holidays for Georgia. + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Asia/Tbilisi'; + + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); + + $this->addSecondNewYearDay(); + $this->addOrthodoxChristmasDay(); + $this->addIndependenceDay(); + $this->addMothersDay(); + $this->addUnityDay(); + $this->addVictoryDay(); + $this->addStAndrewsDay(); + $this->addOrthodoxEpiphanyDay(); + $this->addMtskhetobaDay(); + $this->addStMarysDay(); + $this->addStGeorgesDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Georgia_(country)', + 'https://ka.wikipedia.org/wiki/%E1%83%A3%E1%83%A5%E1%83%9B%E1%83%94_%E1%83%93%E1%83%A6%E1%83%94%E1%83%94%E1%83%91%E1%83%98_%E1%83%A1%E1%83%90%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%95%E1%83%94%E1%83%9A%E1%83%9D%E1%83%A8%E1%83%98', + 'https://xmf.wikipedia.org/wiki/%E1%83%9D%E1%83%A4%E1%83%98%E1%83%AA%E1%83%98%E1%83%90%E1%83%9A%E1%83%A3%E1%83%A0%E1%83%98_%E1%83%A3%E1%83%A5%E1%83%95%E1%83%98_%E1%83%93%E1%83%A6%E1%83%90%E1%83%9A%E1%83%94%E1%83%A4%E1%83%98_%E1%83%A1%E1%83%90%E1%83%A5%E1%83%9D%E1%83%A0%E1%83%97%E1%83%A3%E1%83%9D%E1%83%A1', + ]; + } + + /** + * @return \DateTime|\DateTimeImmutable + * + * @throws \Exception + */ + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface + { + return $this->calculateOrthodoxEaster($year, $timezone); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addOrthodoxChristmasDay(): void + { + $date = new \DateTime("{$this->year}-01-07", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('orthodoxChristmasDay', [ + 'en' => 'Orthodox Christmas Day', + 'ka' => 'ქრისტეს შობა', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addIndependenceDay(): void + { + if ($this->year >= self::PROCLAMATION_OF_INDEPENDENCE_YEAR) { + $date = new \DateTime("{$this->year}-05-26", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('independenceDay', [ + 'en' => 'Independence Day', + 'ka' => 'საქართველოს დამოუკიდებლობის დღე', + ], $date, $this->locale)); + } + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addUnityDay(): void + { + if ($this->year >= self::APRIL_NINE_TRAGEDY_YEAR) { + $date = new \DateTime("{$this->year}-04-09", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('unityDay', [ + 'en' => 'National Unity Day', + 'ka' => 'ეროვნული ერთიანობის დღე', + ], $date, $this->locale)); + } + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addMothersDay(): void + { + $date = new \DateTime("{$this->year}-03-03", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('mothersDay', [], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addVictoryDay(): void + { + $date = new \DateTime("{$this->year}-05-09", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('victoryDay', [ + 'en' => 'Day of Victory over Fascism', + 'ka' => 'ფაშიზმზე გამარჯვების დღე', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addStAndrewsDay(): void + { + $date = new \DateTime("{$this->year}-05-12", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('stAndrewsDay', [ + 'en' => 'Saint Andrew the First-Called Day', + 'ka' => 'წმინდა ანდრია პირველწოდებულის ხსენების დღე', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addOrthodoxEpiphanyDay(): void + { + $date = new \DateTime("{$this->year}-01-19", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('orthodoxEpiphanyDay', [ + 'en' => 'Orthodox Epiphany Day', + 'ka' => 'ნათლისღება', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addStMarysDay(): void + { + $date = new \DateTime("{$this->year}-08-28", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('stMarysDay', [ + 'en' => 'Saint Marys Day', + 'ka' => 'მარიამობა', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addMtskhetobaDay(): void + { + $date = new \DateTime("{$this->year}-10-14", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('mtskhetobaDay', [ + 'en' => 'Day of Svetitskhoveli Cathedral', + 'ka' => 'მცხეთობა', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addStGeorgesDay(): void + { + $date = new \DateTime("{$this->year}-11-23", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('stGeorgesDay', [ + 'en' => 'Saint Georges Day', + 'ka' => 'გიორგობა', + ], $date, $this->locale)); + } + + /** + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addSecondNewYearDay(): void + { + $date = new \DateTime("{$this->year}-01-02", new \DateTimeZone($this->timezone)); + + $this->addHoliday(new Holiday('secondDayOfNewYear', [ + 'en' => 'Second day of the New Year', + 'ka' => 'ბედობა', + ], $date, $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Germany.php b/src/Yasumi/Provider/Germany.php index a1f68d2a8..1f88998f0 100644 --- a/src/Yasumi/Provider/Germany.php +++ b/src/Yasumi/Provider/Germany.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Germany extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE'; @@ -34,7 +37,6 @@ class Germany extends AbstractProvider /** * Initialize holidays for Germany. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -45,6 +47,7 @@ public function initialize(): void // Add common holidays $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); // Add common Christian holidays (common in Germany) $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale)); @@ -52,6 +55,7 @@ public function initialize(): void $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); @@ -64,6 +68,14 @@ public function initialize(): void } } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Germany', + 'https://de.wikipedia.org/wiki/Gesetzliche_Feiertage_in_Deutschland', + ]; + } + /** * German Unity Day. * @@ -74,20 +86,19 @@ public function initialize(): void * 3 October has been the German national holiday since 1990, when the reunification was formally completed. It * is a legal holiday for the Federal Republic of Germany. * - * @link https://en.wikipedia.org/wiki/German_Unity_Day + * @see https://en.wikipedia.org/wiki/German_Unity_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateGermanUnityDay(): void + protected function calculateGermanUnityDay(): void { if ($this->year >= 1990) { $this->addHoliday(new Holiday( 'germanUnityDay', ['de' => 'Tag der Deutschen Einheit'], - new DateTime($this->year . '-10-3', new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-3", new \DateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Germany/BadenWurttemberg.php b/src/Yasumi/Provider/Germany/BadenWurttemberg.php old mode 100755 new mode 100644 index 288b6d7f4..6f9f548b1 --- a/src/Yasumi/Provider/Germany/BadenWurttemberg.php +++ b/src/Yasumi/Provider/Germany/BadenWurttemberg.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -20,16 +24,16 @@ /** * Provider for all holidays in Baden-Württemberg (Germany). * - * Baden-Württemberg is a state in Germany located in the southwest, east of the Upper Rhine. It is Germany’s third - * largest state in terms of size and population, with an area of 36,410 square kilometres (14,060 sq mi) and 10.7 + * Baden-Württemberg is a state in Germany located in the southwest, east of the Upper Rhine. It is Germany’s + * third-largest state in terms of size and population, with an area of 36,410 square kilometres (14,060 sq mi) and 10.7 * million inhabitants. The state capital and largest city is Stuttgart. * - * @link https://en.wikipedia.org/wiki/Baden-W%C3%BCrttemberg + * @see https://en.wikipedia.org/wiki/Baden-W%C3%BCrttemberg */ class BadenWurttemberg extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-BW'; @@ -37,7 +41,6 @@ class BadenWurttemberg extends Germany /** * Initialize holidays for Baden-Württemberg (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -47,8 +50,8 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); } } diff --git a/src/Yasumi/Provider/Germany/Bavaria.php b/src/Yasumi/Provider/Germany/Bavaria.php old mode 100755 new mode 100644 index e154a6e2a..a5bfd5c81 --- a/src/Yasumi/Provider/Germany/Bavaria.php +++ b/src/Yasumi/Provider/Germany/Bavaria.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -22,23 +26,20 @@ * * Bavaria is a federal state of Germany. In the southeast of the country with an area of 70,548 square kilometres * (27,200 sq mi), it is the largest state, making up almost a fifth of the total land area of Germany, and, with 12.6 - * million inhabitants, Germany's second most populous state. Munich, Bavaria's capital and largest city, is the third - * largest city in Germany. + * million inhabitants, Germany's second most populous state. Munich, Bavaria's capital and largest city, is the + * third-largest city in Germany. * - * @link https://en.wikipedia.org/wiki/Bavaria + * @see https://en.wikipedia.org/wiki/Bavaria */ class Bavaria extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-BY'; /** - * Initialize holidays for Bavaria (Germany). - * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -48,8 +49,9 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); } } diff --git a/src/Yasumi/Provider/Germany/Berlin.php b/src/Yasumi/Provider/Germany/Berlin.php old mode 100755 new mode 100644 index 625542d79..54a2e49de --- a/src/Yasumi/Provider/Germany/Berlin.php +++ b/src/Yasumi/Provider/Germany/Berlin.php @@ -1,19 +1,25 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Germany; /** @@ -24,12 +30,12 @@ * Located in northeastern Germany on the banks of Rivers Spree and Havel, it is the centre of the Berlin-Brandenburg * Metropolitan Region, which has about six million residents from over 180 nations. * - * @link https://en.wikipedia.org/wiki/Berlin + * @see https://en.wikipedia.org/wiki/Berlin */ class Berlin extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-BE'; @@ -37,7 +43,6 @@ class Berlin extends Germany /** * Initialize holidays for Berlin (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -49,5 +54,42 @@ public function initialize(): void if ($this->year >= 2019) { $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); } + + if (2020 === $this->year || 2025 === $this->year) { + $this->addHoliday($this->dayOfLiberation($this->year, $this->timezone, $this->locale)); + } + } + + /** + * Day of Liberation. + * + * Day of Liberation (Tag der Befreiung) is celebrated on May 8 2020 to commemorate the 75th anniversary + * of the German Instrument of Surrender. + * + * @see https://de.wikipedia.org/wiki/Tag_der_Befreiung + * + * @param int $year the year in which Day of Liberation is celebrated + * @param string $timezone the timezone in which Day of Liberation is celebrated + * @param string $locale the locale for which Day of Liberation needs to be displayed in + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function dayOfLiberation( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'dayOfLiberation', + [], + new \DateTime("{$year}-05-08", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } } diff --git a/src/Yasumi/Provider/Germany/Brandenburg.php b/src/Yasumi/Provider/Germany/Brandenburg.php old mode 100755 new mode 100644 index a01bdedcb..5506dadee --- a/src/Yasumi/Provider/Germany/Brandenburg.php +++ b/src/Yasumi/Provider/Germany/Brandenburg.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\Germany; @@ -23,12 +27,12 @@ * area of 29,478 square kilometers and has 2.45 million inhabitants. The capital and largest city is Potsdam. * Brandenburg surrounds but does not include the national capital and city-state Berlin forming a metropolitan area. * - * @link https://en.wikipedia.org/wiki/Brandenburg + * @see https://en.wikipedia.org/wiki/Brandenburg */ class Brandenburg extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-BB'; @@ -36,7 +40,6 @@ class Brandenburg extends Germany /** * Initialize holidays for Brandenburg (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -57,12 +60,11 @@ public function initialize(): void * For the German state of Brandenburg, Reformation Day was celebrated since 1517. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 1517) { return; diff --git a/src/Yasumi/Provider/Germany/Bremen.php b/src/Yasumi/Provider/Germany/Bremen.php old mode 100755 new mode 100644 index 343c0b3a3..91e16f887 --- a/src/Yasumi/Provider/Germany/Bremen.php +++ b/src/Yasumi/Provider/Germany/Bremen.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\Germany; @@ -23,12 +27,12 @@ * official contexts, is Land Bremen ('State of Bremen'). The state consists of two enclaves with two cities (Bremen * and Bremerhaven) in the North of Germany, surrounded by the larger state of Lower Saxony. * - * @link https://en.wikipedia.org/wiki/Bremen_(state) + * @see https://en.wikipedia.org/wiki/Bremen_(state) */ class Bremen extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-HB'; @@ -36,7 +40,6 @@ class Bremen extends Germany /** * Initialize holidays for Bremen (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -53,12 +56,11 @@ public function initialize(): void * For the German state of Bremen, Reformation Day is celebrated since 2018. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 2018) { return; diff --git a/src/Yasumi/Provider/Germany/Hamburg.php b/src/Yasumi/Provider/Germany/Hamburg.php old mode 100755 new mode 100644 index 0e2d6f1d8..113ba28dc --- a/src/Yasumi/Provider/Germany/Hamburg.php +++ b/src/Yasumi/Provider/Germany/Hamburg.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -25,12 +29,12 @@ * population is over 1.7 million people, and the Hamburg Metropolitan Region (including parts of the neighbouring * Federal States of Lower Saxony and Schleswig-Holstein) has more than 5 million inhabitants. * - * @link https://en.wikipedia.org/wiki/Hamburg + * @see https://en.wikipedia.org/wiki/Hamburg */ class Hamburg extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-HH'; @@ -38,7 +42,6 @@ class Hamburg extends Germany /** * Initialize holidays for Schleswig-Holstein (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -52,14 +55,13 @@ public function initialize(): void /** * Since 2018 Hamburg celebrates the "Day of Reformation". - * It is not called "Reformation Day" like other states to prevent church-based associations + * It is not called "Reformation Day" like other states to prevent church-based associations. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayOfReformation(): void + protected function calculateDayOfReformation(): void { if ($this->year < 2018) { return; diff --git a/src/Yasumi/Provider/Germany/Hesse.php b/src/Yasumi/Provider/Germany/Hesse.php old mode 100755 new mode 100644 index ed0995811..921580a7f --- a/src/Yasumi/Provider/Germany/Hesse.php +++ b/src/Yasumi/Provider/Germany/Hesse.php @@ -1,19 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; use Yasumi\Provider\Germany; /** @@ -25,12 +30,12 @@ * modern federal state does not cover the entire cultural region of Hesse which includes both the State of Hesse and * the area known as Rhenish Hesse (Rheinhessen) in the neighbouring state of Rhineland-Palatinate. * - * @link https://en.wikipedia.org/wiki/Hesse + * @see https://en.wikipedia.org/wiki/Hesse */ class Hesse extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-HE'; @@ -38,7 +43,6 @@ class Hesse extends Germany /** * Initialize holidays for Hesse (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -48,6 +52,6 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); } } diff --git a/src/Yasumi/Provider/Germany/LowerSaxony.php b/src/Yasumi/Provider/Germany/LowerSaxony.php old mode 100755 new mode 100644 index d41fa0a3f..255827212 --- a/src/Yasumi/Provider/Germany/LowerSaxony.php +++ b/src/Yasumi/Provider/Germany/LowerSaxony.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\Germany; @@ -24,12 +28,12 @@ * of Germany. In rural areas Northern Low Saxon, a dialect of Low German, and Saterland Frisian, a variety of Frisian, * are still spoken, but the number of speakers is declining. * - * @link https://en.wikipedia.org/wiki/Lower_Saxony + * @see https://en.wikipedia.org/wiki/Lower_Saxony */ class LowerSaxony extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-NI'; @@ -37,7 +41,6 @@ class LowerSaxony extends Germany /** * Initialize holidays for Lower Saxony (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -54,14 +57,13 @@ public function initialize(): void * For the German state of Lower Saxony, Reformation Day is celebrated since 2018. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @link https://www.zeit.de/gesellschaft/zeitgeschehen/2018-06/reformationstag-niedersachsen-neuer-feiertag + * @see https://www.zeit.de/gesellschaft/zeitgeschehen/2018-06/reformationstag-niedersachsen-neuer-feiertag * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 2018) { return; diff --git a/src/Yasumi/Provider/Germany/MecklenburgWesternPomerania.php b/src/Yasumi/Provider/Germany/MecklenburgWesternPomerania.php old mode 100755 new mode 100644 index abebf8685..d465fc615 --- a/src/Yasumi/Provider/Germany/MecklenburgWesternPomerania.php +++ b/src/Yasumi/Provider/Germany/MecklenburgWesternPomerania.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\Germany; @@ -24,12 +28,12 @@ * and Vorpommern after the Second World War, dissolved in 1952 and recreated at the time of the German reunification in * 1990. * - * @link https://en.wikipedia.org/wiki/Mecklenburg-Vorpommern + * @see https://en.wikipedia.org/wiki/Mecklenburg-Vorpommern */ class MecklenburgWesternPomerania extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-MV'; @@ -37,7 +41,6 @@ class MecklenburgWesternPomerania extends Germany /** * Initialize holidays for Mecklenburg-Western Pomerania (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -46,20 +49,31 @@ public function initialize(): void { parent::initialize(); + if ($this->year >= 2023) { + $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); + } + // Add custom Christian holidays $this->calculateReformationDay(); } + public function getSources(): array + { + return array_merge( + ['https://www.ndr.de/nachrichten/mecklenburg-vorpommern/Frauentag-in-MV-Landtag-beschliesst-neuen-Feiertag,frauentag370.html'], + parent::getSources(), + ); + } + /** * For the German state of Mecklenburg-Western Pomerania, Reformation Day was celebrated since 1517. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 1517) { return; diff --git a/src/Yasumi/Provider/Germany/NorthRhineWestphalia.php b/src/Yasumi/Provider/Germany/NorthRhineWestphalia.php old mode 100755 new mode 100644 index 58dcc71d8..164642eb7 --- a/src/Yasumi/Provider/Germany/NorthRhineWestphalia.php +++ b/src/Yasumi/Provider/Germany/NorthRhineWestphalia.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -21,16 +25,16 @@ * Provider for all holidays in North Rhine-Westphalia (Germany). * * North Rhine-Westphalia (German: Nordrhein-Westfalen), commonly shortened NRW) is the most populous state of Germany, - * with a population of approximately 18 million, and the fourth largest by area. Its capital is Düsseldorf; the biggest + * with a population of approximately 18 million, and the fourth-largest by area. Its capital is Düsseldorf; the biggest * city is Cologne. Four of Germany's ten biggest cities—Cologne, Düsseldorf, Dortmund, and Essen—are located within the * state, as well as the biggest metropolitan area of the European continent, Rhine-Ruhr. * - * @link https://en.wikipedia.org/wiki/North_Rhine-Westphalia + * @see https://en.wikipedia.org/wiki/North_Rhine-Westphalia */ class NorthRhineWestphalia extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-NW'; @@ -38,7 +42,6 @@ class NorthRhineWestphalia extends Germany /** * Initialize holidays for North Rhine-Westphalia (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -48,7 +51,7 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); } } diff --git a/src/Yasumi/Provider/Germany/RhinelandPalatinate.php b/src/Yasumi/Provider/Germany/RhinelandPalatinate.php old mode 100755 new mode 100644 index 57e0001c7..9a3ef59a4 --- a/src/Yasumi/Provider/Germany/RhinelandPalatinate.php +++ b/src/Yasumi/Provider/Germany/RhinelandPalatinate.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -24,12 +28,12 @@ * of Germany. It has an area of 19,846 square kilometres (7,663 sq mi) and about four million inhabitants. The city of * Mainz functions as the state capital. * - * @link https://en.wikipedia.org/wiki/Rhineland-Palatinate + * @see https://en.wikipedia.org/wiki/Rhineland-Palatinate */ class RhinelandPalatinate extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-RP'; @@ -37,7 +41,6 @@ class RhinelandPalatinate extends Germany /** * Initialize holidays for Rhineland Palatinate (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -47,7 +50,7 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); } } diff --git a/src/Yasumi/Provider/Germany/Saarland.php b/src/Yasumi/Provider/Germany/Saarland.php old mode 100755 new mode 100644 index b0033c6df..95672d2cc --- a/src/Yasumi/Provider/Germany/Saarland.php +++ b/src/Yasumi/Provider/Germany/Saarland.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\Germany; @@ -25,12 +29,12 @@ * 1,012,000. In terms of both area and population size – apart from the city-states of Berlin, Bremen and Hamburg – it * is Germany's smallest federal state. * - * @link https://en.wikipedia.org/wiki/Saarland + * @see https://en.wikipedia.org/wiki/Saarland */ class Saarland extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-SL'; @@ -38,7 +42,6 @@ class Saarland extends Germany /** * Initialize holidays for Saarland (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -48,8 +51,8 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); } } diff --git a/src/Yasumi/Provider/Germany/Saxony.php b/src/Yasumi/Provider/Germany/Saxony.php old mode 100755 new mode 100644 index 1e7c1665b..ec5544ba8 --- a/src/Yasumi/Provider/Germany/Saxony.php +++ b/src/Yasumi/Provider/Germany/Saxony.php @@ -1,22 +1,25 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Germany; /** @@ -26,19 +29,19 @@ * states of Brandenburg, Saxony Anhalt, Thuringia, and Bavaria, as well as the countries of Poland and the Czech * Republic. Its capital is Dresden, and its largest city is Leipzig. * - * @link https://en.wikipedia.org/wiki/Saxony + * @see https://en.wikipedia.org/wiki/Saxony */ class Saxony extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-SN'; /** * Initialize holidays for Saxony (Germany). - * @throws InvalidDateException + * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -56,12 +59,11 @@ public function initialize(): void * For the German state of Saxony, Reformation Day was celebrated since 1517. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 1517) { return; @@ -80,20 +82,19 @@ private function calculateReformationDay(): void * it is the Wednesday that falls between 16th and 22nd November. However, it is not a statutory non-working holiday * any more, except in the Free State of Saxony. * - * @link https://en.wikipedia.org/wiki/Bu%C3%9F-_und_Bettag + * @see https://en.wikipedia.org/wiki/Bu%C3%9F-_und_Bettag * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateRepentanceAndPrayerDay(): void + protected function calculateRepentanceAndPrayerDay(): void { if ($this->year >= 1995) { $this->addHoliday(new Holiday( 'repentanceAndPrayerDay', ['de' => 'Buß- und Bettag'], - new DateTime("next wednesday $this->year-11-15", new DateTimeZone($this->timezone)), + new \DateTime("next wednesday {$this->year}-11-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OFFICIAL )); diff --git a/src/Yasumi/Provider/Germany/SaxonyAnhalt.php b/src/Yasumi/Provider/Germany/SaxonyAnhalt.php old mode 100755 new mode 100644 index 5df91305a..096b2dc41 --- a/src/Yasumi/Provider/Germany/SaxonyAnhalt.php +++ b/src/Yasumi/Provider/Germany/SaxonyAnhalt.php @@ -1,20 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; -use Yasumi\Holiday; use Yasumi\Provider\Germany; /** @@ -24,12 +27,12 @@ * Lower Saxony, Brandenburg, Saxony and Thuringia. Its capital is Magdeburg and its largest city is Halle (Saale). * Saxony-Anhalt covers an area of 20,447.7 square kilometres (7,894.9 sq mi)[4] and has a population of 2.34 million. * - * @link https://en.wikipedia.org/wiki/Saxony-Anhalt + * @see https://en.wikipedia.org/wiki/Saxony-Anhalt */ class SaxonyAnhalt extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-ST'; @@ -37,7 +40,6 @@ class SaxonyAnhalt extends Germany /** * Initialize holidays for Saxony-Anhalt (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -47,7 +49,7 @@ public function initialize(): void parent::initialize(); // Add custom Christian holidays - $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); $this->calculateReformationDay(); } @@ -55,12 +57,11 @@ public function initialize(): void * For the German state of Saxony-Anhalt, Reformation Day was celebrated since 1517. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 1517) { return; diff --git a/src/Yasumi/Provider/Germany/SchleswigHolstein.php b/src/Yasumi/Provider/Germany/SchleswigHolstein.php old mode 100755 new mode 100644 index 25fbcdffe..9d4e54d8f --- a/src/Yasumi/Provider/Germany/SchleswigHolstein.php +++ b/src/Yasumi/Provider/Germany/SchleswigHolstein.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Provider\Germany; @@ -23,12 +27,12 @@ * Holstein and the southern part of the former Duchy of Schleswig. Its capital city is Kiel; other notable cities are * Lübeck and Flensburg. * - * @link https://en.wikipedia.org/wiki/Schleswig-Holstein + * @see https://en.wikipedia.org/wiki/Schleswig-Holstein */ class SchleswigHolstein extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-SH'; @@ -36,7 +40,6 @@ class SchleswigHolstein extends Germany /** * Initialize holidays for Schleswig-Holstein (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -53,12 +56,11 @@ public function initialize(): void * For the German state of Schleswig-Holstein, Reformation Day is celebrated since 2018. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 2018) { return; diff --git a/src/Yasumi/Provider/Germany/Thuringia.php b/src/Yasumi/Provider/Germany/Thuringia.php old mode 100755 new mode 100644 index f7b1e9bc8..c0795b4e1 --- a/src/Yasumi/Provider/Germany/Thuringia.php +++ b/src/Yasumi/Provider/Germany/Thuringia.php @@ -1,35 +1,41 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Germany; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Germany; /** * Provider for all holidays in Thuringia (Germany). * * The Free State of Thuringia is a federal state of Germany, located in the central part of the country. It has an area - * of 16,171 square kilometres (6,244 sq mi) and 2.29 million inhabitants, making it the sixth smallest by area and the - * fifth smallest by population of Germany's sixteen states. Most of Thuringia is within the watershed of the Saale, a + * of 16,171 square kilometres (6,244 sq mi) and 2.29 million inhabitants, making it the sixth-smallest by area and the + * fifth-smallest by population of Germany's sixteen states. Most of Thuringia is within the watershed of the Saale, a * left tributary of the Elbe. Its capital is Erfurt. * - * @link https://en.wikipedia.org/wiki/Thuringia + * @see https://en.wikipedia.org/wiki/Thuringia */ class Thuringia extends Germany { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'DE-TH'; @@ -37,7 +43,6 @@ class Thuringia extends Germany /** * Initialize holidays for Thuringia (Germany). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -48,18 +53,20 @@ public function initialize(): void // Add custom Christian holidays $this->calculateReformationDay(); + + // Other holidays + $this->calculateWorldChildrensDay(); } /** * For the German state of Thuringia, Reformation Day was celebrated since 1517. * Note: In 2017 all German states will celebrate Reformation Day for its 500th anniversary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateReformationDay(): void + protected function calculateReformationDay(): void { if ($this->year < 1517) { return; @@ -67,4 +74,24 @@ private function calculateReformationDay(): void $this->addHoliday($this->reformationDay($this->year, $this->timezone, $this->locale)); } + + /** + * For the German state of Thuringia, World Children's Day is celebrated since 2019. + * + * @throws \Exception + */ + protected function calculateWorldChildrensDay(): void + { + if ($this->year < 2019) { + return; + } + + $this->addHoliday(new Holiday( + 'worldChildrensDay', + ['de' => 'Weltkindertag'], + new \DateTimeImmutable(sprintf('%d-09-20', $this->year), DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } } diff --git a/src/Yasumi/Provider/Greece.php b/src/Yasumi/Provider/Greece.php index c29132560..7438ea28b 100644 --- a/src/Yasumi/Provider/Greece.php +++ b/src/Yasumi/Provider/Greece.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Greece extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GR'; @@ -35,7 +37,6 @@ class Greece extends AbstractProvider /** * Initialize holidays for Greece. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,6 +69,14 @@ public function initialize(): void $this->calculatePolytechnio(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Greece', + 'https://el.wikipedia.org/wiki/%CE%95%CF%80%CE%AF%CF%83%CE%B7%CE%BC%CE%B5%CF%82_%CE%B1%CF%81%CE%B3%CE%AF%CE%B5%CF%82_%CF%83%CF%84%CE%B7%CE%BD_%CE%95%CE%BB%CE%BB%CE%AC%CE%B4%CE%B1', + ]; + } + /** * The Three Holy Hierarchs. * @@ -76,17 +85,16 @@ public function initialize(): void * * @see https://en.wikipedia.org/wiki/Three_Holy_Hierarchs * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateThreeHolyHierarchs(): void + protected function calculateThreeHolyHierarchs(): void { $this->addHoliday(new Holiday( 'threeHolyHierarchs', ['el' => 'Τριών Ιεραρχών'], - new DateTime("$this->year-1-30", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-1-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); @@ -101,32 +109,32 @@ private function calculateThreeHolyHierarchs(): void * * @see https://en.wikipedia.org/wiki/Clean_Monday * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCleanMonday(): void + protected function calculateCleanMonday(): void { - $this->addHoliday(new Holiday( - 'cleanMonday', - ['el' => 'Καθαρά Δευτέρα'], - $this->calculateEaster($this->year, $this->timezone)->sub(new DateInterval('P48D')), - $this->locale - )); + $holiday = 'cleanMonday'; + $date = $this->calculateEaster($this->year, $this->timezone)->sub(new \DateInterval('P48D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $holiday)); + } + + $this->addHoliday( + new Holiday($holiday, ['el' => 'Καθαρά Δευτέρα'], $date, $this->locale) + ); } /** - * Orthodox Easter - * - * @param int $year - * @param string $timezone + * Orthodox Easter. * - * @return DateTime + * @return \DateTime|\DateTimeImmutable * * @throws \Exception */ - private function calculateEaster($year, $timezone): DateTime + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface { return $this->calculateOrthodoxEaster($year, $timezone); } @@ -136,21 +144,19 @@ private function calculateEaster($year, $timezone): DateTime * * Anniversary of the declaration of the start of Greek War of Independence from the Ottoman Empire, in 1821. * - * @link https://en.wikipedia.org/wiki/Greek_War_of_Independence + * @see https://en.wikipedia.org/wiki/Greek_War_of_Independence * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - - private function calculateIndependenceDay(): void + protected function calculateIndependenceDay(): void { if ($this->year >= 1821) { $this->addHoliday(new Holiday( 'independenceDay', ['el' => 'Εικοστή Πέμπτη Μαρτίου'], - new DateTime("$this->year-3-25", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-3-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -161,20 +167,19 @@ private function calculateIndependenceDay(): void * * Celebration of the Greek refusal to the Italian ultimatum of 1940. * - * @link https://en.wikipedia.org/wiki/Ohi_Day + * @see https://en.wikipedia.org/wiki/Ohi_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateOhiDay(): void + protected function calculateOhiDay(): void { if ($this->year >= 1940) { $this->addHoliday(new Holiday( 'ohiDay', ['el' => 'Επέτειος του Όχι'], - new DateTime("$this->year-10-28", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-28", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -185,20 +190,19 @@ private function calculateOhiDay(): void * * Anniversary of the 1973 students protests against the junta of the colonels (1967–1974). * - * @link https://en.wikipedia.org/wiki/Athens_Polytechnic_uprising + * @see https://en.wikipedia.org/wiki/Athens_Polytechnic_uprising * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePolytechnio(): void + protected function calculatePolytechnio(): void { if ($this->year >= 1973) { $this->addHoliday(new Holiday( 'polytechnio', ['el' => 'Πολυτεχνείο'], - new DateTime("$this->year-11-17", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); diff --git a/src/Yasumi/Provider/Hungary.php b/src/Yasumi/Provider/Hungary.php index 73c36cc53..6b7ab64c4 100644 --- a/src/Yasumi/Provider/Hungary.php +++ b/src/Yasumi/Provider/Hungary.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -25,10 +27,11 @@ */ class Hungary extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'HU'; @@ -36,7 +39,6 @@ class Hungary extends AbstractProvider /** * Initialize holidays for Hungary. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -61,34 +63,42 @@ public function initialize(): void $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); - /** + /* * Day of Memorial day of the 1848 Revolution */ if ($this->year >= 1927) { $this->addHoliday(new Holiday('memorialDay1848', [ 'en' => 'Memorial day of the 1848 Revolution', 'hu' => 'Az 1848-as forradalom ünnepe', - ], new DateTime("$this->year-3-15", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-3-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } - /** + /* * State Foundation Day */ if ($this->year >= 1891) { $this->addHoliday(new Holiday('stateFoundation', [ 'en' => 'State Foundation Day', 'hu' => 'Az államalapítás ünnepe', - ], new DateTime("$this->year-8-20", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-8-20", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } - /** + /* * Memorial day of the 1956 Revolution */ if ($this->year >= 1991) { $this->addHoliday(new Holiday('memorialDay1956', [ 'en' => 'Memorial day of the 1956 Revolution', 'hu' => 'Az 1956-os forradalom ünnepe', - ], new DateTime("$this->year-10-23", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-10-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Hungary', + 'https://hu.wikipedia.org/wiki/Magyarorsz%C3%A1gi_%C3%BCnnepek_%C3%A9s_eml%C3%A9knapok_list%C3%A1ja', + ]; + } } diff --git a/src/Yasumi/Provider/Iran.php b/src/Yasumi/Provider/Iran.php new file mode 100644 index 000000000..213c59b52 --- /dev/null +++ b/src/Yasumi/Provider/Iran.php @@ -0,0 +1,152 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Note: Any Islamic holidays are not part of this provider yet. Islamic holidays are quite complex and at first, + * only Jalali holidays are implemented. + */ +class Iran extends AbstractProvider +{ + /** {@inheritdoc} */ + public const ID = 'IR'; + + /** + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Asia/Tehran'; + + $this->addNowruz(); + $this->addIslamicRepublicDay(); + $this->addSizdahBedar(); + $this->addDeathOfKhomeini(); + $this->addRevoltOfKhordad15(); + $this->addAnniversaryOfIslamicRevolution(); + $this->addNationalizationOfTheIranianOilIndustry(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Iran', + 'https://fa.wikipedia.org/wiki/%D8%AA%D8%B9%D8%B7%DB%8C%D9%84%D8%A7%D8%AA_%D8%B1%D8%B3%D9%85%DB%8C_%D8%AF%D8%B1_%D8%A7%DB%8C%D8%B1%D8%A7%D9%86', + ]; + } + + protected function addNowruz(): void + { + foreach ([21, 22, 23, 24] as $index => $day) { + ++$index; + $this->addHoliday(new Holiday("nowruz{$index}", [ + 'en' => 'Nowruz', + 'fa' => 'نوروز', + ], new \DateTime("{$this->year}-03-{$day}", new \DateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * The day usually falls on 1 April, however, as it is determined by the vernal equinox, the date can change if the equinox does not fall on 21 March. + * In 2016, it was on 31 March, and in 2017, 2019, 2021, 2022 and 2023 the date was back to 1 April. + * + * @see https://en.wikipedia.org/wiki/Iranian_Islamic_Republic_Day + * + * @throws \Exception + */ + protected function addIslamicRepublicDay(): void + { + if (1979 > $this->year) { + return; + } + + $month = '04'; + $day = '01'; + + if (2016 === $this->year) { + $month = '03'; + $day = '31'; + } + + $this->addHoliday(new Holiday('islamicRepublicDay', [ + 'en' => 'Ruz e Jomhuri ye Eslami', + 'fa' => 'روز جمهوری اسلامی', + ], new \DateTime("{$this->year}-{$month}-{$day}", new \DateTimeZone($this->timezone)), $this->locale)); + } + + protected function addSizdahBedar(): void + { + $this->addHoliday(new Holiday('sizdahBedar', [ + 'en' => 'Sizdah be dar', + 'fa' => 'سیزده بدر', + ], new \DateTime("{$this->year}-04-02", new \DateTimeZone($this->timezone)), $this->locale)); + } + + protected function addDeathOfKhomeini(): void + { + if (1989 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('deathOfKhomeini', [ + 'en' => 'Marg e Khomeini', + 'fa' => 'مرگ خمینی', + ], new \DateTime("{$this->year}-06-04", new \DateTimeZone($this->timezone)), $this->locale)); + } + + protected function addRevoltOfKhordad15(): void + { + if (1979 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('revoltOfKhordad15', [ + 'en' => 'Qiam e Panzdah e Khordad', + 'fa' => 'قیام ۱۵ خرداد', + ], new \DateTime("{$this->year}-06-05", new \DateTimeZone($this->timezone)), $this->locale)); + } + + protected function addAnniversaryOfIslamicRevolution(): void + { + if (1979 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('anniversaryOfIslamicRevolution', [ + 'en' => 'Enqelab e Eslami', + 'fa' => 'انقلاب اسلامی پنجاه و هفت', + ], new \DateTime("{$this->year}-02-11", new \DateTimeZone($this->timezone)), $this->locale)); + } + + protected function addNationalizationOfTheIranianOilIndustry(): void + { + if (1951 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('nationalizationOfTheIranianOilIndustry', [ + 'en' => 'Melli Shodan e Saneat e Naft', + 'fa' => 'ملی شدن صنعت نفت', + ], new \DateTime("{$this->year}-03-20", new \DateTimeZone($this->timezone)), $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Ireland.php b/src/Yasumi/Provider/Ireland.php index 0fd211222..6263c1959 100644 --- a/src/Yasumi/Provider/Ireland.php +++ b/src/Yasumi/Provider/Ireland.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -23,17 +24,18 @@ /** * Provider for all holidays in Ireland. * - * Note: All calculations are based on the schedule published in the Holidays (Employees) Act, 1973 and its amendments - * thereafter. + * The public holidays of Ireland are defined in the Organisation of Working Time Act, 1993, + * or in statutory instruments issued pursuant on this act. * - * @link: http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1 + * @see https://www.irishstatutebook.ie/eli/1997/act/20 */ class Ireland extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'IE'; @@ -41,7 +43,6 @@ class Ireland extends AbstractProvider /** * Initialize holidays for Ireland. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -52,10 +53,11 @@ public function initialize(): void // Add common holidays $this->calculateNewYearsDay(); + $this->calculateStBrigidsDay(); // Add common Christian holidays (common in Ireland) $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); - $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); $this->calculatePentecostMonday(); @@ -69,12 +71,21 @@ public function initialize(): void $this->addHoliday(new Holiday( 'augustHoliday', ['en' => 'August Holiday', 'ga' => 'Lá Saoire i mí Lúnasa'], - new DateTime("next monday $this->year-7-31", new DateTimeZone($this->timezone)), + new \DateTime("next monday {$this->year}-7-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); $this->calculateOctoberHoliday(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Ireland', + 'https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html', + 'https://www.irishstatutebook.ie/eli/2022/si/50/made/en/html', + ]; + } + /** * New Years Day. * @@ -82,19 +93,14 @@ public function initialize(): void * Ireland. It became a public holiday following the Holidays (Employees) Act 1973. The public holiday was first * observed in 1974. * - * @link https://www.timeanddate.com/holidays/ireland/new-year-day - * @link http://www.irishstatutebook.ie/eli/1974/si/341 - * - * @TODO : Check substitution of New Years Day when it falls on a Saturday. The Holidays (Employees) Act 1973 - * states that New Years Day is substituted the *next* day if it does not fall on a weekday. So what if it - * falls on a Saturday? + * @see https://www.timeanddate.com/holidays/ireland/new-year-day + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNewYearsDay(): void + protected function calculateNewYearsDay(): void { if ($this->year < 1974) { return; @@ -103,8 +109,8 @@ private function calculateNewYearsDay(): void $holiday = $this->newYearsDay($this->year, $this->timezone, $this->locale); $this->addHoliday($holiday); - // Substitute holiday is on the next available weekday if a holiday falls on a Sunday. - if (0 === (int)$holiday->format('w')) { + // Substitute holiday is on the next available weekday if a holiday falls on a weekend. + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); @@ -117,20 +123,47 @@ private function calculateNewYearsDay(): void } } + /** + * Saint Brigid's Day. + * + * Saint Brigid's Day, also known as Imbolc, is a Gaelic traditional festival. It became an official public + * holiday in 2023. + * + * @see https://www.irishstatutebook.ie/eli/2022/si/50/made/en/html + * @see https://en.wikipedia.org/wiki/Imbolc + */ + protected function calculateStBrigidsDay(): void + { + if ($this->year < 2023) { + return; + } + + $dateTime = new \DateTime("{$this->year}-02-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + if (5 !== (int) $dateTime->format('w')) { + $dateTime->modify('next monday'); + } + + $this->addHoliday(new Holiday( + 'stBrigidsDay', + ['en' => 'Saint Brigid’s Day', 'ga' => 'Lá Fhéile Bríde'], + $dateTime, + $this->locale + )); + } + /** * Pentecost Monday. * * Whitmonday (Pentecost Monday) was considered a public holiday in Ireland until 1973. * - * @link http://www.irishstatutebook.ie/eli/1939/act/1/section/8/enacted/en/html - * @link http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1 + * @see https://www.irishstatutebook.ie/eli/1939/act/1/section/8/enacted/en/html + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePentecostMonday(): void + protected function calculatePentecostMonday(): void { if ($this->year > 1973) { return; @@ -145,27 +178,25 @@ private function calculatePentecostMonday(): void * Most people in Ireland start Christmas celebrations on Christmas Eve (Oíche Nollag), including taking time * off work. * - * @link http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1 + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateChristmasDay(): void + protected function calculateChristmasDay(): void { $holiday = new Holiday( 'christmasDay', ['en' => 'Christmas Day', 'ga' => 'Lá Nollag'], - new DateTime($this->year . '-12-25', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale ); $this->addHoliday($holiday); // Whenever Christmas Day does not fall on a weekday, the Tuesday following on it shall be a public holiday. - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next tuesday'); @@ -183,29 +214,27 @@ private function calculateChristmasDay(): void * * The day after Christmas celebrating the feast day of Saint Stephen. * - * @link http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1 - * @link https://en.wikipedia.org/wiki/St._Stephen%27s_Day + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html + * @see https://en.wikipedia.org/wiki/St._Stephen%27s_Day * @see ChristianHolidays * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateStStephensDay(): void + protected function calculateStStephensDay(): void { $holiday = new Holiday( 'stStephensDay', [], - new DateTime($this->year . '-12-26', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale ); $this->addHoliday($holiday); // Whenever St. Stephens Day does not fall on a weekday, the Monday following on it shall be a public holiday. - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); @@ -227,30 +256,29 @@ private function calculateStStephensDay(): void * of Ireland, Northern Ireland, the Canadian province of Newfoundland and Labrador, and the British Overseas * Territory of Montserrat. * - * @link https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day + * @see https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateStPatricksDay(): void + protected function calculateStPatricksDay(): void { if ($this->year < 1903) { return; } $holiday = new Holiday( 'stPatricksDay', - ['en' => 'St. Patrick\'s Day', 'ga' => 'Lá Fhéile Pádraig'], - new DateTime($this->year . '-3-17', new DateTimeZone($this->timezone)), + ['en' => 'St. Patrick’s Day', 'ga' => 'Lá Fhéile Pádraig'], + new \DateTime("{$this->year}-3-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale ); $this->addHoliday($holiday); // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); @@ -272,15 +300,14 @@ private function calculateStPatricksDay(): void * longer widely observed, though the practice still persists in some places across the country. Limerick, Clare * and many other people in other counties still keep on this tradition. * - * @link https://en.wikipedia.org/wiki/May_Day + * @see https://en.wikipedia.org/wiki/May_Day + * @see https://www.irishstatutebook.ie/eli/1993/si/91/made/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateMayDay(): void + protected function calculateMayDay(): void { if ($this->year < 1994) { return; @@ -289,7 +316,7 @@ private function calculateMayDay(): void $this->addHoliday(new Holiday( 'mayDay', ['en' => 'May Day', 'ga' => 'Lá Bealtaine'], - new DateTime("next monday $this->year-4-30", new DateTimeZone($this->timezone)), + new \DateTime("next monday {$this->year}-4-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -300,15 +327,13 @@ private function calculateMayDay(): void * The first Monday in June is considered a public holiday since 1974. Previously observed as Whit Monday until * 1973. * - * @link http://www.irishstatutebook.ie/eli/1961/act/33/section/8/enacted/en/html + * @see http://www.irishstatutebook.ie/eli/1961/act/33/section/8/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateJuneHoliday(): void + protected function calculateJuneHoliday(): void { if ($this->year < 1974) { return; @@ -317,7 +342,7 @@ private function calculateJuneHoliday(): void $this->addHoliday(new Holiday( 'juneHoliday', ['en' => 'June Holiday', 'ga' => 'Lá Saoire i mí an Mheithimh'], - new DateTime("next monday $this->year-5-31", new DateTimeZone($this->timezone)), + new \DateTime("next monday {$this->year}-5-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -327,15 +352,14 @@ private function calculateJuneHoliday(): void * * The last Monday in October is considered a public holiday since 1977. * - * @link http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1 + * @see https://www.irishstatutebook.ie/eli/1977/si/193/made/en/html + * @see https://www.irishstatutebook.ie/eli/1997/act/20/schedule/2/enacted/en/html * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateOctoberHoliday(): void + protected function calculateOctoberHoliday(): void { if ($this->year < 1977) { return; @@ -344,7 +368,7 @@ private function calculateOctoberHoliday(): void $this->addHoliday(new Holiday( 'octoberHoliday', ['en' => 'October Holiday', 'ga' => 'Lá Saoire i mí Dheireadh Fómhair'], - new DateTime("previous monday $this->year-11-01", new DateTimeZone($this->timezone)), + new \DateTime("previous monday {$this->year}-11-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Italy.php b/src/Yasumi/Provider/Italy.php old mode 100755 new mode 100644 index 1e4bd58ac..d11a96dde --- a/src/Yasumi/Provider/Italy.php +++ b/src/Yasumi/Provider/Italy.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Italy extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'IT'; @@ -34,7 +37,6 @@ class Italy extends AbstractProvider /** * Initialize holidays for Italy. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -62,6 +64,14 @@ public function initialize(): void $this->calculateRepublicDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Italy', + 'https://it.wikipedia.org/wiki/Festivit%C3%A0_in_Italia', + ]; + } + /** * Liberation Day. * @@ -71,21 +81,19 @@ public function initialize(): void * Nazi occupation of the country. On May 27, 1949, bill 260 made the anniversary a permanent, annual national * holiday. * - * @link https://en.wikipedia.org/wiki/Liberation_Day_%28Italy%29 + * @see https://en.wikipedia.org/wiki/Liberation_Day_%28Italy%29 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateLiberationDay(): void + protected function calculateLiberationDay(): void { if ($this->year >= 1949) { $this->addHoliday(new Holiday( 'liberationDay', ['it' => 'Festa della Liberazione'], - new DateTime("$this->year-4-25", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-4-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -99,21 +107,19 @@ private function calculateLiberationDay(): void * in 1946, in which the Italian people were called to the polls to decide on the form of government, following * the Second World War and the fall of Fascism. * - * @link https://en.wikipedia.org/wiki/Festa_della_Repubblica + * @see https://en.wikipedia.org/wiki/Festa_della_Repubblica * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateRepublicDay(): void + protected function calculateRepublicDay(): void { if ($this->year >= 1946) { $this->addHoliday(new Holiday( 'republicDay', ['it' => 'Festa della Repubblica'], - new DateTime("$this->year-6-2", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-6-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Japan.php b/src/Yasumi/Provider/Japan.php old mode 100755 new mode 100644 index 60f187909..8aeafe3f5 --- a/src/Yasumi/Provider/Japan.php +++ b/src/Yasumi/Provider/Japan.php @@ -1,23 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeInterface; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -30,7 +29,7 @@ class Japan extends AbstractProvider use CommonHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'JP'; @@ -73,7 +72,6 @@ class Japan extends AbstractProvider /** * Initialize holidays for Japan. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -109,12 +107,20 @@ public function initialize(): void $this->calculateBridgeHolidays(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Japan', + 'https://ja.wikipedia.org/wiki/%E5%9B%BD%E6%B0%91%E3%81%AE%E7%A5%9D%E6%97%A5', + ]; + } + /** * National Foundation Day. National Foundation Day is held on February 11th and established since 1966. * * @throws \Exception */ - private function calculateNationalFoundationDay(): void + protected function calculateNationalFoundationDay(): void { if ($this->year >= 1966) { $this->addHoliday(new Holiday( @@ -123,7 +129,7 @@ private function calculateNationalFoundationDay(): void 'en' => 'National Foundation Day', 'ja' => '建国記念の日', ], - new DateTime("$this->year-2-11", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-2-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -134,7 +140,7 @@ private function calculateNationalFoundationDay(): void * * @throws \Exception */ - private function calculateShowaDay(): void + protected function calculateShowaDay(): void { if ($this->year >= 2007) { $this->addHoliday(new Holiday( @@ -143,7 +149,7 @@ private function calculateShowaDay(): void 'en' => 'Showa Day', 'ja' => '昭和の日', ], - new DateTime("$this->year-4-29", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-4-29", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -154,7 +160,7 @@ private function calculateShowaDay(): void * * @throws \Exception */ - private function calculateConstitutionMemorialDay(): void + protected function calculateConstitutionMemorialDay(): void { if ($this->year >= 1948) { $this->addHoliday(new Holiday( @@ -163,7 +169,7 @@ private function calculateConstitutionMemorialDay(): void 'en' => 'Constitution Memorial Day', 'ja' => '憲法記念日', ], - new DateTime("$this->year-5-3", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-3", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -174,16 +180,16 @@ private function calculateConstitutionMemorialDay(): void * * @throws \Exception */ - private function calculateChildrensDay(): void + protected function calculateChildrensDay(): void { if ($this->year >= 1948) { $this->addHoliday(new Holiday( 'childrensDay', [ - 'en' => 'Children\'s Day', + 'en' => 'Children’s Day', 'ja' => 'こどもの日', ], - new DateTime("$this->year-5-5", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -194,13 +200,13 @@ private function calculateChildrensDay(): void * * @throws \Exception */ - private function calculateCultureDay(): void + protected function calculateCultureDay(): void { if ($this->year >= 1948) { $this->addHoliday(new Holiday( 'cultureDay', ['en' => 'Culture Day', 'ja' => '文化の日'], - new DateTime("$this->year-11-3", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-3", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -211,13 +217,13 @@ private function calculateCultureDay(): void * * @throws \Exception */ - private function calculateLaborThanksgivingDay(): void + protected function calculateLaborThanksgivingDay(): void { if ($this->year >= 1948) { $this->addHoliday(new Holiday( 'laborThanksgivingDay', ['en' => 'Labor Thanksgiving Day', 'ja' => '勤労感謝の日'], - new DateTime("$this->year-11-23", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -227,26 +233,26 @@ private function calculateLaborThanksgivingDay(): void * Emperors Birthday. * The Emperors Birthday is on April 29rd and celebrated as such since 1949 to 1988. * December 23rd and celebrated as such since 1989 to 2018. - * February 23rd and celebrated as such since 2020.(Coronation Day of the new Emperor, May 1, 2019) + * February 23rd and celebrated as such since 2020.(Coronation Day of the new Emperor, May 1, 2019). * * @throws \Exception */ - private function calculateEmperorsBirthday(): void + protected function calculateEmperorsBirthday(): void { - $emperorsBirthday = false; + $emperorsBirthday = null; if ($this->year >= 2020) { - $emperorsBirthday = "$this->year-2-23"; + $emperorsBirthday = "{$this->year}-2-23"; } elseif ($this->year >= 1989 && $this->year < 2019) { - $emperorsBirthday = "$this->year-12-23"; - } elseif ($this->year >= 1949 && $this->year < 1988) { - $emperorsBirthday = "$this->year-4-29"; + $emperorsBirthday = "{$this->year}-12-23"; + } elseif ($this->year >= 1949 && $this->year <= 1988) { + $emperorsBirthday = "{$this->year}-4-29"; } - if (\is_string($emperorsBirthday)) { + if (null !== $emperorsBirthday) { $this->addHoliday(new Holiday( 'emperorsBirthday', ['en' => 'Emperors Birthday', 'ja' => '天皇誕生日'], - new DateTime($emperorsBirthday, new DateTimeZone($this->timezone)), + new \DateTime($emperorsBirthday, DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -259,31 +265,32 @@ private function calculateEmperorsBirthday(): void * of nature and the love of living things. Prior to 1948, the vernal equinox was an imperial ancestor worship * festival called Shunki kōrei-sai (春季皇霊祭). * - * @link http://www.h3.dion.ne.jp/~sakatsu/holiday_topic.htm (in Japanese) + * @see http://www.h3.dion.ne.jp/~sakatsu/holiday_topic.htm (in Japanese) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateVernalEquinoxDay(): void + protected function calculateVernalEquinoxDay(): void { $day = null; - if ($this->year < 1948 || $this->year > 2150) { - $day = null; - } elseif ($this->year >= 1948 && $this->year <= 1979) { - $day = \floor(self::VERNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1983) / 4)); + if ($this->year >= 1948 && $this->year <= 1979) { + $day = floor(self::VERNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1983) / 4)); } elseif ($this->year <= 2099) { - $day = \floor(self::VERNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4)); + $day = floor(self::VERNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1980) / 4)); } elseif ($this->year <= 2150) { - $day = \floor(self::VERNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4)); + $day = floor(self::VERNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1980) / 4)); + } + + if ($this->year < 1948 || $this->year > 2150) { + $day = null; } - if (\is_numeric($day)) { + if (is_numeric($day)) { $this->addHoliday(new Holiday( 'vernalEquinoxDay', ['en' => 'Vernal Equinox Day', 'ja' => '春分の日'], - new DateTime("$this->year-3-$day", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-3-{$day}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -295,22 +302,17 @@ private function calculateVernalEquinoxDay(): void * Coming of Age Day was established after 1948 on January 15th. After 2000 it was changed to be the second monday * of January. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateComingOfAgeDay(): void + protected function calculateComingOfAgeDay(): void { - $date = null; - if ($this->year >= 2000) { - $date = new DateTime("second monday of january $this->year", new DateTimeZone($this->timezone)); - } elseif ($this->year >= 1948) { - $date = new DateTime("$this->year-1-15", new DateTimeZone($this->timezone)); - } + if ($this->year >= 1948) { + $date = $this->year >= 2000 ? + new \DateTime("second monday of january {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) : + new \DateTime("{$this->year}-1-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)); - if ($date instanceof DateTimeInterface) { $this->addHoliday(new Holiday( 'comingOfAgeDay', ['en' => 'Coming of Age Day', 'ja' => '成人の日'], @@ -325,22 +327,20 @@ private function calculateComingOfAgeDay(): void * * Greenery Day was established from 1989 on April 29th. After 2007 it was changed to be May 4th. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateGreeneryDay(): void + protected function calculateGreeneryDay(): void { $date = null; if ($this->year >= 2007) { - $date = new DateTime("$this->year-5-4", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-5-4", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } elseif ($this->year >= 1989) { - $date = new DateTime("$this->year-4-29", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-4-29", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } - if ($date instanceof DateTimeInterface) { + if ($date instanceof \DateTimeInterface) { $this->addHoliday(new Holiday( 'greeneryDay', ['en' => 'Greenery Day', 'ja' => 'みどりの日'], @@ -356,54 +356,63 @@ private function calculateGreeneryDay(): void * Marine Day was established since 1996 on July 20th. After 2003 it was changed to be the third monday of July.In * 2020 is July 23th. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception - * @throws \Exception */ - private function calculateMarineDay(): void + protected function calculateMarineDay(): void { - $date = null; + if (1996 > $this->year) { + return; + } + + $date = "{$this->year}-7-20"; + + if ($this->year >= 2003) { + $date = "third monday of july {$this->year}"; + } + if (2020 === $this->year) { - $date = new DateTime("$this->year-7-23", new DateTimeZone($this->timezone)); - } elseif ($this->year >= 2003) { - $date = new DateTime("third monday of july $this->year", new DateTimeZone($this->timezone)); - } elseif ($this->year >= 1996) { - $date = new DateTime("$this->year-7-20", new DateTimeZone($this->timezone)); + // For the 2020 Tokyo Olympics, Marine Day was rescheduled. + $date = "{$this->year}-7-23"; } - if ($date instanceof DateTimeInterface) { - $this->addHoliday(new Holiday( - 'marineDay', - ['en' => 'Marine Day', 'ja' => '海の日'], - $date, - $this->locale - )); + if (2021 === $this->year) { + // Due to the COVID-19 pandemic, the 2020 Tokyo Olympics were rescheduled and hence Marine Day as well. + $date = "{$this->year}-7-22"; } + + $this->addHoliday(new Holiday( + 'marineDay', + ['en' => 'Marine Day', 'ja' => '海の日'], + new \DateTime($date, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); } /** - * Calculates MountainDay + * Calculates MountainDay. * * Mountain Day. Mountain Day is held on August 11th and established since 2016.In 2020 is August 10th. * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateMountainDay(): void + protected function calculateMountainDay(): void { $date = null; - if (2020 === $this->year) { - $date = new DateTime("$this->year-8-10", new DateTimeZone($this->timezone)); + if (2021 === $this->year) { + // For Olympic 2021 Tokyo (after COVID-19) + $date = new \DateTime("{$this->year}-8-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + } elseif (2020 === $this->year) { + // For Olympic 2020 Tokyo + $date = new \DateTime("{$this->year}-8-10", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } elseif ($this->year >= 2016) { - $date = new DateTime("$this->year-8-11", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-8-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } - if ($date instanceof DateTimeInterface) { + if ($date instanceof \DateTimeInterface) { $this->addHoliday(new Holiday( 'mountainDay', ['en' => 'Mountain Day', 'ja' => '山の日'], @@ -419,22 +428,20 @@ private function calculateMountainDay(): void * Respect for the Age Day was established since 1996 on September 15th. After 2003 it was changed to be the third * monday of September. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateRespectForTheAgeDay(): void + protected function calculateRespectForTheAgeDay(): void { $date = null; if ($this->year >= 2003) { - $date = new DateTime("third monday of september $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("third monday of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } elseif ($this->year >= 1996) { - $date = new DateTime("$this->year-9-15", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-9-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } - if ($date instanceof DateTimeInterface) { + if ($date instanceof \DateTimeInterface) { $this->addHoliday(new Holiday( 'respectfortheAgedDay', ['en' => 'Respect for the Aged Day', 'ja' => '敬老の日'], @@ -450,33 +457,34 @@ private function calculateRespectForTheAgeDay(): void * Health And Sports Day was established since 1966 on October 10th. After 2000 it was changed to be the second * monday of October.In 2020 is July 24th. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception - * @throws \Exception */ - private function calculateSportsDay(): void + protected function calculateSportsDay(): void { $date = null; - if (2020 === $this->year) { - $date = new DateTime("$this->year-7-24", new DateTimeZone($this->timezone)); + if (2021 === $this->year) { + // For Olympic 2021 Tokyo (after COVID-19) + $date = new \DateTime("{$this->year}-7-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + } elseif (2020 === $this->year) { + // For Olympic 2020 Tokyo + $date = new \DateTime("{$this->year}-7-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } elseif ($this->year >= 2000) { - $date = new DateTime("second monday of october $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } elseif ($this->year >= 1996) { - $date = new DateTime("$this->year-10-10", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-10-10", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } - $holiday_name = ['en' => 'Health And Sports Day', 'ja' => '体育の日']; + $holidayName = ['en' => 'Health And Sports Day', 'ja' => '体育の日']; if ($this->year >= 2020) { - $holiday_name = ['en' => 'Sports Day', 'ja' => 'スポーツの日']; + $holidayName = ['en' => 'Sports Day', 'ja' => 'スポーツの日']; } - if ($date instanceof DateTimeInterface) { + if ($date instanceof \DateTimeInterface) { $this->addHoliday(new Holiday( 'sportsDay', - $holiday_name, + $holidayName, $date, $this->locale )); @@ -490,31 +498,32 @@ private function calculateSportsDay(): void * one's ancestors and remember the dead. Prior to 1948, the autumnal equinox was an imperial ancestor worship * festival called Shūki kōrei-sai (秋季皇霊祭). * - * @link http://www.h3.dion.ne.jp/~sakatsu/holiday_topic.htm (in Japanese) + * @see http://www.h3.dion.ne.jp/~sakatsu/holiday_topic.htm (in Japanese) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAutumnalEquinoxDay(): void + protected function calculateAutumnalEquinoxDay(): void { $day = null; - if ($this->year < 1948 || $this->year > 2150) { - $day = null; - } elseif ($this->year >= 1948 && $this->year <= 1979) { - $day = \floor(self::AUTUMNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1983) / 4)); + if ($this->year >= 1948 && $this->year <= 1979) { + $day = floor(self::AUTUMNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1983) / 4)); } elseif ($this->year <= 2099) { - $day = \floor(self::AUTUMNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4)); + $day = floor(self::AUTUMNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1980) / 4)); } elseif ($this->year <= 2150) { - $day = \floor(self::AUTUMNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4)); + $day = floor(self::AUTUMNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * (float) ($this->year - 1980) - floor(($this->year - 1980) / 4)); } - if (\is_numeric($day)) { + if ($this->year < 1948 || $this->year > 2150) { + $day = null; + } + + if (is_numeric($day)) { $this->addHoliday(new Holiday( 'autumnalEquinoxDay', ['en' => 'Autumnal Equinox Day', 'ja' => '秋分の日'], - new DateTime("$this->year-9-$day", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-9-{$day}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -526,30 +535,31 @@ private function calculateAutumnalEquinoxDay(): void * Generally if a national holiday falls on a Sunday, the holiday is observed the next working day (not being * another holiday). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSubstituteHolidays(): void + protected function calculateSubstituteHolidays(): void { // Get initial list of holiday dates $dates = $this->getHolidayDates(); // Loop through all holidays - foreach ($this->getHolidays() as $shortName => $holiday) { + foreach ($this->getHolidays() as $holiday) { + if (! $holiday instanceof Holiday) { + continue; + } $date = clone $holiday; // If holidays falls on a Sunday - if (0 === (int)$holiday->format('w')) { + if (0 === (int) $holiday->format('w')) { if ($this->year >= 2007) { // Find next week day (not being another holiday) while (\in_array($date, $dates, false)) { - $date->add(new DateInterval('P1D')); - continue; + $date->add(new \DateInterval('P1D')); } } elseif ($holiday >= '1973-04-12') { - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); if (\in_array($date, $dates, false)) { continue; // @codeCoverageIgnore } @@ -576,13 +586,13 @@ private function calculateSubstituteHolidays(): void * * @throws \Exception */ - private function calculateCoronationDay(): void + protected function calculateCoronationDay(): void { if (2019 === $this->year) { $this->addHoliday(new Holiday( 'coronationDay', ['en' => 'Coronation Day', 'ja' => '即位の日'], - new DateTime("$this->year-5-1", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -594,13 +604,13 @@ private function calculateCoronationDay(): void * * @throws \Exception */ - private function calculateEnthronementProclamationCeremony(): void + protected function calculateEnthronementProclamationCeremony(): void { if (2019 === $this->year) { $this->addHoliday(new Holiday( 'enthronementProclamationCeremony', ['en' => 'Enthronement Proclamation Ceremony', 'ja' => '即位礼正殿の儀'], - new DateTime("$this->year-10-22", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-22", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -611,12 +621,11 @@ private function calculateEnthronementProclamationCeremony(): void * * Any day that falls between two other national holidays also becomes a holiday, known as a bridge holiday. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateBridgeHolidays(): void + protected function calculateBridgeHolidays(): void { // Get initial list of holidays and iterator $datesIterator = $this->getIterator(); @@ -633,15 +642,19 @@ private function calculateBridgeHolidays(): void } // Determine if gap between holidays is one day and create bridge holiday - if (2 === (int)$previous->diff($datesIterator->current())->format('%a')) { + if (2 === (int) $previous->diff($datesIterator->current())->format('%a')) { + if (! $previous instanceof Holiday) { + throw new \RuntimeException('unable to determine the difference between dates'); + } + $bridgeDate = clone $previous; - $bridgeDate->add(new DateInterval('P1D')); + $bridgeDate->add(new \DateInterval('P1D')); - $this->addHoliday(new Holiday('bridgeDay' . $counter, [ + $this->addHoliday(new Holiday("bridgeDay{$counter}", [ 'en' => 'Bridge Public holiday', 'ja' => '国民の休日', ], $bridgeDate, $this->locale)); - $counter++; + ++$counter; } } } diff --git a/src/Yasumi/Provider/Latvia.php b/src/Yasumi/Provider/Latvia.php index 89b81bf0b..3bf459fd3 100644 --- a/src/Yasumi/Provider/Latvia.php +++ b/src/Yasumi/Provider/Latvia.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; @@ -22,14 +26,17 @@ */ class Latvia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; public const RESTORATION_OF_INDEPENDENCE_YEAR = 1990; + public const MOTHERS_DAY_YEAR = 1992; + public const PROCLAMATION_OF_INDEPENDENCE_YEAR = 1918; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'LV'; @@ -49,8 +56,10 @@ public function initialize(): void $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); $this->addRestorationOfIndependenceDay(); + $this->addMothersDay(); $this->addMidsummerEveDay(); $this->addHoliday($this->stJohnsDay($this->year, $this->timezone, $this->locale)); $this->addProclamationDay(); @@ -60,6 +69,16 @@ public function initialize(): void $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Latvia', + 'https://lt.wikipedia.org/wiki/S%C4%85ra%C5%A1as:Latvijos_%C5%A1vent%C4%97s', + 'https://www.mfa.gov.lv/en/11-national-hollidays-and-remembrance-days', + 'https://likumi.lv/ta/id/72608-par-svetku-atceres-un-atzimejamam-dienam', + ]; + } + /** * On 4 May 1990. Latvia proclaimed its independence from the USSR, and restoration of the Republic of Latvia. * If the day is on the weekend the next Monday is a holiday. @@ -67,12 +86,12 @@ public function initialize(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addRestorationOfIndependenceDay(): void + protected function addRestorationOfIndependenceDay(): void { if ($this->year >= self::RESTORATION_OF_INDEPENDENCE_YEAR) { $date = new \DateTime("{$this->year}-05-04", new \DateTimeZone($this->timezone)); - if (!$this->isWorkingDay($date)) { + if (! $this->isWorkingDay($date)) { $date->modify('next monday'); } @@ -83,11 +102,21 @@ private function addRestorationOfIndependenceDay(): void } } + /** + * Mother's day is celebrated on the 2nd Sunday of May. + */ + protected function addMothersDay(): void + { + if ($this->year >= self::MOTHERS_DAY_YEAR) { + $this->addHoliday($this->mothersDay($this->year, $this->timezone, $this->locale)); + } + } + /** * @throws \InvalidArgumentException * @throws \Exception */ - private function addMidsummerEveDay(): void + protected function addMidsummerEveDay(): void { $this->addHoliday(new Holiday('midsummerEveDay', [ 'en' => 'Midsummer Eve', @@ -102,12 +131,12 @@ private function addMidsummerEveDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addProclamationDay(): void + protected function addProclamationDay(): void { if ($this->year >= self::PROCLAMATION_OF_INDEPENDENCE_YEAR) { $date = new \DateTime("{$this->year}-11-18", new \DateTimeZone($this->timezone)); - if (!$this->isWorkingDay($date)) { + if (! $this->isWorkingDay($date)) { $date->modify('next monday'); } diff --git a/src/Yasumi/Provider/Lithuania.php b/src/Yasumi/Provider/Lithuania.php index c112f4418..190737538 100644 --- a/src/Yasumi/Provider/Lithuania.php +++ b/src/Yasumi/Provider/Lithuania.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; @@ -22,10 +26,11 @@ */ class Lithuania extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'LT'; @@ -45,6 +50,11 @@ class Lithuania extends AbstractProvider */ public const STATEHOOD_YEAR = 1253; + /** + * The year when All Souls Day became a holiday. + */ + public const ALL_SOULS_DAY = 2020; + /** * Initialize holidays for Lithuania. * @@ -62,22 +72,34 @@ public function initialize(): void $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addMothersDay(); + $this->addFathersDay(); $this->addHoliday($this->stJohnsDay($this->year, $this->timezone, $this->locale)); $this->addStatehoodDay(); $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); + $this->addAllSoulsDay(); $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Lithuania', + 'https://lt.wikipedia.org/wiki/S%C4%85ra%C5%A1as:Lietuvos_%C5%A1vent%C4%97s', + 'https://e-seimas.lrs.lt/portal/legalAct/lt/TAD/10c6bfd07bd511e6a0f68fd135e6f40c/asr', + ]; + } + /** * The Act of Reinstating Independence of Lithuania was signed on February 16, 1918. * * @throws \InvalidArgumentException * @throws \Exception */ - private function addRestorationOfTheStateDay(): void + protected function addRestorationOfTheStateDay(): void { if ($this->year >= self::RESTORATION_OF_THE_STATE_YEAR) { $this->addHoliday(new Holiday('restorationOfTheStateOfLithuaniaDay', [ @@ -93,7 +115,7 @@ private function addRestorationOfTheStateDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addRestorationOfIndependenceDay(): void + protected function addRestorationOfIndependenceDay(): void { if ($this->year >= self::RESTORATION_OF_INDEPENDENCE_YEAR) { $this->addHoliday(new Holiday('restorationOfIndependenceOfLithuaniaDay', [ @@ -103,6 +125,36 @@ private function addRestorationOfIndependenceDay(): void } } + /** + * Mother's Day. + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addMothersDay(): void + { + $this->addHoliday(new Holiday( + 'mothersDay', + [], + new \DateTime("first sunday of may {$this->year}", new \DateTimeZone($this->timezone)) + )); + } + + /** + * Father's Day. + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addFathersDay(): void + { + $this->addHoliday(new Holiday( + 'fathersDay', + [], + new \DateTime("first sunday of june {$this->year}", new \DateTimeZone($this->timezone)) + )); + } + /** * Statehood Day is an annual public holiday in Lithuania celebrated on July 6 to commemorate * the coronation in 1253 of Mindaugas as the only King of Lithuania. @@ -110,7 +162,7 @@ private function addRestorationOfIndependenceDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addStatehoodDay(): void + protected function addStatehoodDay(): void { if ($this->year >= self::STATEHOOD_YEAR) { $this->addHoliday(new Holiday('statehoodDay', [ @@ -119,4 +171,22 @@ private function addStatehoodDay(): void ], new \DateTime("{$this->year}-07-06", new \DateTimeZone($this->timezone)), $this->locale)); } } + + /** + * All Souls Day, also known as the Commemoration of All the Faithful Departed and the Day of the Dead. + * + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function addAllSoulsDay(): void + { + if ($this->year >= self::ALL_SOULS_DAY) { + $this->addHoliday(new Holiday( + 'allSoulsDay', + [], + new \DateTime("{$this->year}-11-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } } diff --git a/src/Yasumi/Provider/Luxembourg.php b/src/Yasumi/Provider/Luxembourg.php new file mode 100644 index 000000000..7b584d9c8 --- /dev/null +++ b/src/Yasumi/Provider/Luxembourg.php @@ -0,0 +1,119 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Luxembourg. + */ +class Luxembourg extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + public const EUROPE_DAY_START_YEAR = 2019; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'LU'; + + /** + * Initialize holidays for Luxembourg. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Europe/Luxembourg'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->calculateEuropeDay(); + $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); + $this->calculateNationalDay(); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Luxembourg', + 'https://lb.wikipedia.org/wiki/Gesetzlech_Feierdeeg_zu_L%C3%ABtzebuerg', + ]; + } + + /** + * Europe Day. + * + * Europe Day is celebrated on 5 May by the Council of Europe and on 9 May by the European Union. + * The first recognition of Europe Day was by the Council of Europe, introduced in 1964. + * The European Union later started to celebrate its own European Day in commemoration of the 1950 + * Schuman Declaration, leading it to be referred to by some as "Schuman Day". + * Both days are celebrated by displaying the Flag of Europe. + * + * @see https://en.wikipedia.org/wiki/Europe_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateEuropeDay(): void + { + if ($this->year >= 2019) { + $this->addHoliday(new Holiday('europeDay', [ + 'en_US' => 'Europe day', + 'fr' => 'La Journée de l’Europe', + ], new \DateTime("{$this->year}-5-9", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Luxembourgish National Day. + * + * The Grand Duke's Official Birthday (French: Célébration publique de l'anniversaire du souverain), + * also known as Luxembourgish National Day (French: Fête nationale luxembourgeoise, Luxembourgish: + * Lëtzebuerger Nationalfeierdag), is celebrated as the annual national holiday of Luxembourg. + * It is celebrated on 23 June, although this has never been the actual birthday of any ruler of Luxembourg. + * When the monarch of Luxembourg is female, it is known as the Grand Duchess' Official Birthday. + * + * @see https://en.wikipedia.org/wiki/Grand_Duke%27s_Official_Birthday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalDay(): void + { + $this->addHoliday(new Holiday('nationalDay', [ + 'en_US' => 'National day', + 'fr' => 'La Fête nationale', + ], new \DateTime("{$this->year}-6-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } +} diff --git a/src/Yasumi/Provider/Mexico.php b/src/Yasumi/Provider/Mexico.php new file mode 100644 index 000000000..46790b72f --- /dev/null +++ b/src/Yasumi/Provider/Mexico.php @@ -0,0 +1,295 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Mexico. + */ +class Mexico extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + public const PROCLAMATION_OF_INDEPENDENCE_YEAR = 1810; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'MX'; + + /** + * Initialize holidays for Mexico. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'America/Mexico_City'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + + // Mexican holidays + $this->calculateConstitutionDay(); + $this->calculateBenitoJuarezBirthday(); + $this->calculateRevolutionDay(); + $this->calculateDiscoveryOfAmerica(); + $this->addIndependenceDay(); + $this->calculateTransmissionOfFederalPowerDay(); + $this->calculateDayOfTheDead(); + $this->calculateChristmasEve(); + $this->calculateNewYearsEve(); + $this->calculateVirginOfGuadalupe(); + } + + /** + * The source of the holidays. + * + * @return string[] The source URL + */ + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Mexico', + ]; + } + + /* + * Independence Day. + * + * Anniversary of the Declaration of Independence in 1810. + * + * @link https://en.wikipedia.org/wiki/Mexican_War_of_Independence + */ + protected function addIndependenceDay(): void + { + if ($this->year >= 1810) { + $this->addHoliday(new Holiday( + 'independenceDay', + [ + 'en' => 'Independence Day', + 'es' => 'Día de la Independencia', + ], + new \DateTime("{$this->year}-09-16", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /* + * Constitution Day. + * + * Anniversary of the Constitution of 1917, originally February 5, observed on the first Monday of February. + */ + protected function calculateConstitutionDay(): void + { + if ($this->year >= 1917) { + $this->addHoliday(new Holiday( + 'constitutionDay', + [ + 'en' => 'Constitution Day', + 'es' => 'Día de la Constitución', + ], + new \DateTime("first monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale) + ); + } + } + + /* + * Benito Juárez's birthday. + * + * Anniversary of the birth of Benito Juárez on March 21, 1806, observed on the third Monday of March. + */ + protected function calculateBenitoJuarezBirthday(): void + { + if ($this->year >= 1806 && $this->year < 2010) { + $this->addHoliday(new Holiday( + 'benitoJuarezBirthday', + [ + 'en' => 'Benito Juárez’s birthday', + 'es' => 'Natalicio de Benito Juárez', + ], + new \DateTime("{$this->year}-03-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale) + ); + } + + if ($this->year >= 2010) { + $this->addHoliday(new Holiday( + 'benitoJuarezBirthday', + [ + 'en' => 'Benito Juárez’s birthday', + 'es' => 'Natalicio de Benito Juárez', + ], + new \DateTime("third monday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale) + ); + } + } + + /** + * Transmission of Federal Executive Power. + * + * In years of presidential elections (every 6 years), the new president is inaugurated on 1 October. Prior to 2024, this happened on 1 December. + */ + protected function calculateTransmissionOfFederalPowerDay(): void + { + if ($this->year >= 1934 && 2 === $this->year % 6) { + $day = $this->year < 2024 ? "{$this->year}-12-01" : "{$this->year}-10-01"; + $this->addHoliday(new Holiday( + 'transmissionOfFederalPowerDay', + [ + 'en' => 'Transmission of Federal Executive Power', + 'es' => 'Transmisión de Poder Ejecutivo Federal', + ], + new \DateTime($day, DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale) + ); + } + } + + /* + * Revolution Day. + * + * Anniversary of the start of the Mexican Revolution on November 20, 1910, observed on the third Monday of November. + */ + protected function calculateRevolutionDay(): void + { + if ($this->year >= 1910) { + $this->addHoliday(new Holiday( + 'revolutionDay', + [ + 'en' => 'Revolution Day', + 'es' => 'Día de la Revolución', + ], + new \DateTime("third monday of november {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale) + ); + } + } + + /* + * Discovery of America. + * + * Anniversary of the Discovery of America on October 12, 1492, observed on the second Monday of October. + */ + protected function calculateDiscoveryOfAmerica(): void + { + if ($this->year >= 1492) { + $this->addHoliday(new Holiday( + 'discoveryOfAmerica', + [ + 'en' => 'Discovery of America', + 'es' => 'Día de la Raza', + ], + new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE) + ); + } + } + + /* + * Christmas Eve. + * + * Christmas Eve is the day before Christmas Day, which is annually on December 24, according to the Gregorian + * calendar. + */ + protected function calculateChristmasEve(): void + { + $this->addHoliday(new Holiday( + 'christmasEve', + [ + 'en' => 'Christmas Eve', + 'es' => 'Nochebuena', + ], + new \DateTime("{$this->year}-12-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE) + ); + } + + /* + * New Year's Eve. + * + * New Year's Eve is the last day of the year, December 31, in the Gregorian calendar. + */ + protected function calculateNewYearsEve(): void + { + $this->addHoliday(new Holiday( + 'newYearsEve', + [ + 'en' => 'New Year’s Eve', + 'es' => 'Nochevieja', + ], + new \DateTime("{$this->year}-12-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } + + /** + * Day of the Deaths. + * + * Day of the Deaths is a Mexican holiday celebrated throughout Mexico, in particular the Central and South regions, + * and by people of Mexican heritage elsewhere. + */ + protected function calculateDayOfTheDead(): void + { + if ($this->year >= 1800) { + $this->addHoliday(new Holiday( + 'dayOfTheDeaths', + [ + 'en' => 'Day of the Deaths', + 'es' => 'Día de los Muertos', + ], + new \DateTime("{$this->year}-11-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } + } + + /* + * Virgin of Guadalupe. + * + * The Virgin of Guadalupe (Día de la Virgen de Guadalupe) is a celebration of the Virgin Mary, + * who is the patron saint of Mexico. It is observed on December 12th. + */ + protected function calculateVirginOfGuadalupe(): void + { + if ($this->year >= 1531) { + $this->addHoliday(new Holiday( + 'virginOfGuadalupe', + ['es' => 'Día de la Virgen de Guadalupe'], + new \DateTime("{$this->year}-12-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } + } +} diff --git a/src/Yasumi/Provider/Netherlands.php b/src/Yasumi/Provider/Netherlands.php old mode 100755 new mode 100644 index e589e62d3..7e1c476ad --- a/src/Yasumi/Provider/Netherlands.php +++ b/src/Yasumi/Provider/Netherlands.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Netherlands extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'NL'; @@ -35,7 +37,6 @@ class Netherlands extends AbstractProvider /** * Initialize holidays for the Netherlands. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -77,14 +78,21 @@ public function initialize(): void // Calculate other holidays $this->calculateCarnival(); - $this->calculateWinterTime(); - $this->calculateSummerTime(); $this->calculateStNicholasDay(); $this->calculateHalloween(); $this->calculatePrincesDay(); $this->calculateQueensday(); $this->calculateKingsday(); $this->calculateCommemorationLiberationDay(); + $this->addEquivalentDays(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_the_Netherlands', + 'https://nl.wikipedia.org/wiki/Feestdagen_in_Nederland', + ]; } /** @@ -96,121 +104,77 @@ public function initialize(): void * * @throws \Exception */ - private function calculateCarnival(): void + protected function calculateCarnival(): void { $easter = $this->calculateEaster($this->year, $this->timezone); - $carnivalDay1 = clone $easter; - $this->addHoliday(new Holiday( - 'carnivalDay', - ['en' => 'Carnival', 'nl' => 'Carnaval'], - $carnivalDay1->sub(new DateInterval('P49D')), - $this->locale, - Holiday::TYPE_OBSERVANCE - )); - /** - * Second Day of Carnival. - */ - $carnivalDay2 = clone $easter; - $this->addHoliday(new Holiday( - 'secondCarnivalDay', - ['en' => 'Carnival', 'nl' => 'Carnaval'], - $carnivalDay2->sub(new DateInterval('P48D')), - $this->locale, - Holiday::TYPE_OBSERVANCE - )); + $intervals = [ + 'carnivalDay' => 'P49D', + 'secondCarnivalDay' => 'P48D', + 'thirdCarnivalDay' => 'P47D', + ]; - /** - * Third Day of Carnival. - */ - $carnivalDay3 = clone $easter; - $this->addHoliday(new Holiday( - 'thirdCarnivalDay', - ['en' => 'Carnival', 'nl' => 'Carnaval'], - $carnivalDay3->sub(new DateInterval('P47D')), - $this->locale, - Holiday::TYPE_OBSERVANCE - )); - } + foreach ($intervals as $name => $interval) { + $date = (clone $easter)->sub(new \DateInterval($interval)); - /** - * Winter Time. - * - * The beginning of winter time. Winter time is also known as standard time. - * - * @throws \Exception - * @see \Yasumi\Provider\CommonHolidays::winterTime() - * - */ - private function calculateWinterTime(): void - { - $winterTime = $this->winterTime($this->year, $this->timezone, $this->locale); - if ($winterTime instanceof Holiday) { - $this->addHoliday($winterTime); - } - } + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $name)); + } - /** - * Summer Time. - * - * The beginning of summer time. Summer time is also known as day lights saving time. - * - * @throws \Exception - * @see \Yasumi\Provider\CommonHolidays::summerTime() - * - */ - private function calculateSummerTime(): void - { - $summerTime = $this->summerTime($this->year, $this->timezone, $this->locale); - if ($summerTime instanceof Holiday) { - $this->addHoliday($summerTime); + $this->addHoliday(new Holiday( + $name, + ['en' => 'Carnival', 'nl' => 'Carnaval'], + $date, + $this->locale, + Holiday::TYPE_OBSERVANCE + )); } } /** - * St. Nicholas' Day + * St. Nicholas' Day. * * The feast of Sinterklaas celebrates the name day of Saint Nicholas on 6 December. * The feast is celebrated annually with the giving of gifts on St. Nicholas' Eve (5 December) in the Netherlands * and on the morning of 6 December, Saint Nicholas Day, in Belgium, Luxembourg and northern France * (French Flanders, Lorraine and Artois). * - * @link https://en.wikipedia.org/wiki/Sinterklaas + * @see https://en.wikipedia.org/wiki/Sinterklaas * * @throws \Exception */ - private function calculateStNicholasDay(): void + protected function calculateStNicholasDay(): void { - /** + /* * St. Nicholas' Day */ $this->addHoliday(new Holiday( 'stNicholasDay', - ['en' => 'St. Nicholas\' Day', 'nl' => 'Sinterklaas'], - new DateTime("$this->year-12-5", new DateTimeZone($this->timezone)), + ['en' => 'St. Nicholas’ Day', 'nl' => 'Sinterklaas'], + new \DateTime("{$this->year}-12-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); } /** - * Halloween + * Halloween. * * Halloween or Hallowe'en (a contraction of Hallows' Even or Hallows' Evening), is a celebration observed in * several countries on 31 October, the eve of the Western Christian feast of All Hallows' Day. * It begins the three-day observance of Allhallowtide, the time in the liturgical year dedicated to remembering the * dead, including saints (hallows), martyrs, and all the faithful departed. * - * @link https://en.wikipedia.org/wiki/Halloween + * @see https://en.wikipedia.org/wiki/Halloween * * @throws \Exception */ - private function calculateHalloween(): void + protected function calculateHalloween(): void { $this->addHoliday(new Holiday( 'halloween', ['en' => 'Halloween', 'nl' => 'Halloween'], - new DateTime("$this->year-10-31", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); @@ -224,12 +188,12 @@ private function calculateHalloween(): void * * @throws \Exception */ - private function calculatePrincesDay(): void + protected function calculatePrincesDay(): void { $this->addHoliday(new Holiday( 'princesDay', - ['en' => 'Prince\'s Day', 'nl' => 'Prinsjesdag'], - new DateTime("third tuesday of september $this->year", new DateTimeZone($this->timezone)), + ['en' => 'Prince’s Day', 'nl' => 'Prinsjesdag'], + new \DateTime("third tuesday of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); @@ -244,22 +208,22 @@ private function calculatePrincesDay(): void * * @throws \Exception */ - private function calculateQueensday(): void + protected function calculateQueensday(): void { if ($this->year >= 1891 && $this->year <= 2013) { - $date = new DateTime("$this->year-4-30", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-4-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if ($this->year <= 1948) { - $date = new DateTime("$this->year-8-31", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-8-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } // Determine substitution day - if (0 === (int)$date->format('w')) { - $this->year < 1980 ? $date->add(new DateInterval('P1D')) : $date->sub(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $this->year < 1980 ? $date->add(new \DateInterval('P1D')) : $date->sub(new \DateInterval('P1D')); } $this->addHoliday(new Holiday( 'queensDay', - ['en' => 'Queen\'s Day', 'nl' => 'Koninginnedag'], + ['en' => 'Queen’s Day', 'nl' => 'Koninginnedag'], $date, $this->locale )); @@ -274,13 +238,13 @@ private function calculateQueensday(): void * * @throws \Exception */ - private function calculateKingsday(): void + protected function calculateKingsday(): void { if ($this->year >= 2014) { - $date = new DateTime("$this->year-4-27", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-4-27", DateTimeZoneFactory::getDateTimeZone($this->timezone)); - if (0 === (int)$date->format('w')) { - $date->sub(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->sub(new \DateInterval('P1D')); } $this->addHoliday(new Holiday( @@ -299,22 +263,77 @@ private function calculateKingsday(): void * * @throws \Exception */ - private function calculateCommemorationLiberationDay(): void + protected function calculateCommemorationLiberationDay(): void { if ($this->year >= 1947) { $this->addHoliday(new Holiday( 'commemorationDay', - ['en' => 'Commemoration Day', 'nl' => 'Dodenherdenking'], - new DateTime("$this->year-5-4", new DateTimeZone($this->timezone)), + ['en' => 'Commemoration Day', 'nl' => 'dodenherdenking'], + new \DateTime("{$this->year}-5-4", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); + // Liberation day is only an official holiday every 5 years + $holidayType = 0 === $this->year % 5 ? Holiday::TYPE_OFFICIAL : Holiday::TYPE_OBSERVANCE; $this->addHoliday(new Holiday( 'liberationDay', ['en' => 'Liberation Day', 'nl' => 'Bevrijdingsdag'], - new DateTime("$this->year-5-5", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + $holidayType + )); + } + } + + /** + * Extra days that are added for the "Algemene termijnenwet". + * These extra days are in the current cases the Friday after an official holiday, but these "day after" + * are not official and just administrative. + * + * @see https://wetten.overheid.nl/BWBR0002448/2010-10-10/ + * @see https://wetten.overheid.nl/BWBR0051300/2025-07-22 + */ + protected function addEquivalentDays(): void + { + if (2026 === $this->year) { + $this->addHoliday(new Holiday( + 'dayAfterNewYearsDay', + [], + new \DateTime("{$this->year}-1-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + $this->addHoliday(new Holiday( + 'dayAfterAscensionDay', + ['en' => 'Day after Ascension Day', 'nl' => 'Dag na Hemelvaart'], + new \DateTime("{$this->year}-5-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + } + if (2027 === $this->year) { + $this->addHoliday(new Holiday( + 'dayAfterAscensionDay', + ['en' => 'Day after Ascension Day', 'nl' => 'Dag na Hemelvaart'], + new \DateTime("{$this->year}-5-7", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + } + if (2028 === $this->year) { + $this->addHoliday(new Holiday( + 'dayAfterKingsDay', + ['en' => 'Day after Kings Day', 'nl' => 'Dag na Koningsdag'], + new \DateTime("{$this->year}-4-28", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + $this->addHoliday(new Holiday( + 'dayAfterAscensionDay', + ['en' => 'Day after Ascension Day', 'nl' => 'Dag na Hemelvaart'], + new \DateTime("{$this->year}-5-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, - Holiday::TYPE_OFFICIAL + Holiday::TYPE_OTHER )); } } diff --git a/src/Yasumi/Provider/NewZealand.php b/src/Yasumi/Provider/NewZealand.php index f190cc6fe..00612ceb8 100644 --- a/src/Yasumi/Provider/NewZealand.php +++ b/src/Yasumi/Provider/NewZealand.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class NewZealand extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'NZ'; @@ -35,7 +37,6 @@ class NewZealand extends AbstractProvider /** * Initialize holidays for New Zealand. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -49,6 +50,7 @@ public function initialize(): void $this->calculateWaitangiDay(); $this->calculateAnzacDay(); $this->calculateQueensBirthday(); + $this->calculateMatariki(); $this->calculateLabourDay(); // Add Christian holidays @@ -57,38 +59,44 @@ public function initialize(): void $this->calculateChristmasHolidays(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand', + ]; + } + /** * Holidays associated with the start of the modern Gregorian calendar. * * New Zealanders celebrate New Years Day and The Day After New Years Day, * if either of these holidays occur on a weekend, the dates need to be adjusted. * - * @link https://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand#Statutory_holidays - * @link https://www.timeanddate.com/holidays/new-zealand/new-year-day - * @link https://www.timeanddate.com/holidays/new-zealand/day-after-new-years-day - * @link https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ + * @see https://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand#Statutory_holidays + * @see https://www.timeanddate.com/holidays/new-zealand/new-year-day + * @see https://www.timeanddate.com/holidays/new-zealand/day-after-new-years-day + * @see https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNewYearHolidays(): void + protected function calculateNewYearHolidays(): void { - $newYearsDay = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)); - $dayAfterNewYearsDay = new DateTime("$this->year-01-02", new DateTimeZone($this->timezone)); + $newYearsDay = new \DateTime("{$this->year}-01-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $dayAfterNewYearsDay = new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)); switch ($newYearsDay->format('w')) { case 0: - $newYearsDay->add(new DateInterval('P1D')); - $dayAfterNewYearsDay->add(new DateInterval('P1D')); + $newYearsDay->add(new \DateInterval('P1D')); + $dayAfterNewYearsDay->add(new \DateInterval('P1D')); break; case 5: - $dayAfterNewYearsDay->add(new DateInterval('P2D')); + $dayAfterNewYearsDay->add(new \DateInterval('P2D')); break; case 6: - $newYearsDay->add(new DateInterval('P2D')); - $dayAfterNewYearsDay->add(new DateInterval('P2D')); + $newYearsDay->add(new \DateInterval('P2D')); + $dayAfterNewYearsDay->add(new \DateInterval('P2D')); break; } @@ -105,23 +113,22 @@ private function calculateNewYearHolidays(): void * on that date in 1840. In recent legislation, if 6 February falls on a Saturday or Sunday, * the Monday that immediately follows becomes a public holiday. * - * @link https://en.wikipedia.org/wiki/Waitangi_Day - * @link https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ + * @see https://en.wikipedia.org/wiki/Waitangi_Day + * @see https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateWaitangiDay(): void + protected function calculateWaitangiDay(): void { if ($this->year < 1974) { return; } - $date = new DateTime("$this->year-02-6", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-02-6", DateTimeZoneFactory::getDateTimeZone($this->timezone)); - if ($this->year >= 2015 && !$this->isWorkingDay($date)) { + if ($this->year >= 2015 && ! $this->isWorkingDay($date)) { $date->modify('next monday'); } @@ -135,23 +142,22 @@ private function calculateWaitangiDay(): void * and New Zealanders "who served and died in all wars, conflicts, and peacekeeping operations" * Observed on 25 April each year. * - * @link https://en.wikipedia.org/wiki/Anzac_Day - * @link https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ + * @see https://en.wikipedia.org/wiki/Anzac_Day + * @see https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAnzacDay(): void + protected function calculateAnzacDay(): void { if ($this->year < 1921) { return; } - $date = new DateTime("$this->year-04-25", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); - if ($this->year >= 2015 && !$this->isWorkingDay($date)) { + if ($this->year >= 2015 && ! $this->isWorkingDay($date)) { $date->modify('next monday'); } @@ -169,14 +175,13 @@ private function calculateAnzacDay(): void * * Her actual birthday is on April 21, but it's celebrated as a public holiday on the first Monday of June. * - * @link https://www.timeanddate.com/holidays/new-zealand/queen-birthday + * @see https://www.timeanddate.com/holidays/new-zealand/queen-birthday * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateQueensBirthday(): void + protected function calculateQueensBirthday(): void { if ($this->year < 1952) { return; @@ -184,12 +189,77 @@ private function calculateQueensBirthday(): void $this->addHoliday(new Holiday( 'queensBirthday', - ['en' => 'Queens Birthday'], - new DateTime("first monday of june $this->year", new DateTimeZone($this->timezone)), + [], + new \DateTime("first monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } + /** + * Matariki – te Mātahi o te Tau + * Matariki – the Māori New Year + * + * The Matariki public holiday is based on the winter rising of the Matariki cluster in the early + * morning sky during the Tangaroa period of the lunar month of Pipiri. + * + * The dates are predetermined by the Matariki Advisory Committee, currently for the years 2022-2052 inclusive + * + * @see https://www.tepapa.govt.nz/discover-collections/read-watch-play/matariki-maori-new-year/dates-for-matariki-public-holiday + * @see https://www.mbie.govt.nz/business-and-employment/employment-and-skills/employment-legislation-reviews/matariki/matariki-public-holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateMatariki(): void + { + if ($this->year < 2022 || 2052 < $this->year) { + return; + } + + $matarikiDates = [ + 2022 => ['month' => 6, 'day' => 24], + 2023 => ['month' => 7, 'day' => 14], + 2024 => ['month' => 6, 'day' => 28], + 2025 => ['month' => 6, 'day' => 20], + 2026 => ['month' => 7, 'day' => 10], + 2027 => ['month' => 6, 'day' => 25], + 2028 => ['month' => 7, 'day' => 14], + 2029 => ['month' => 7, 'day' => 6], + 2030 => ['month' => 6, 'day' => 21], + 2031 => ['month' => 7, 'day' => 11], + 2032 => ['month' => 7, 'day' => 2], + 2033 => ['month' => 6, 'day' => 24], + 2034 => ['month' => 7, 'day' => 7], + 2035 => ['month' => 6, 'day' => 29], + 2036 => ['month' => 7, 'day' => 18], + 2037 => ['month' => 7, 'day' => 10], + 2038 => ['month' => 6, 'day' => 25], + 2039 => ['month' => 7, 'day' => 15], + 2040 => ['month' => 7, 'day' => 6], + 2041 => ['month' => 7, 'day' => 19], + 2042 => ['month' => 7, 'day' => 11], + 2043 => ['month' => 7, 'day' => 3], + 2044 => ['month' => 6, 'day' => 24], + 2045 => ['month' => 7, 'day' => 7], + 2046 => ['month' => 6, 'day' => 29], + 2047 => ['month' => 7, 'day' => 19], + 2048 => ['month' => 7, 'day' => 3], + 2049 => ['month' => 6, 'day' => 25], + 2050 => ['month' => 7, 'day' => 15], + 2051 => ['month' => 6, 'day' => 30], + 2052 => ['month' => 6, 'day' => 21], + ]; + + $date = new \DateTime( + sprintf('%04d-%02d-%02d', $this->year, $matarikiDates[$this->year]['month'], + $matarikiDates[$this->year]['day']), + DateTimeZoneFactory::getDateTimeZone($this->timezone) + ); + + $this->addHoliday(new Holiday('matariki', [], $date, $this->locale)); + } + /** * During the 19th century, workers in New Zealand tried to claim the right for an 8-hour working day. * In 1840 carpenter Samuel Parnell fought for this right in Wellington, NZ, and won. @@ -202,22 +272,21 @@ private function calculateQueensBirthday(): void * second Wednesday in October in 1900. The holiday was moved to the fourth Monday of October in 1910 * has remained on this date since then. * - * @link https://www.timeanddate.com/holidays/new-zealand/labour-day + * @see https://www.timeanddate.com/holidays/new-zealand/labour-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateLabourDay(): void + protected function calculateLabourDay(): void { if ($this->year < 1900) { return; } - $date = new DateTime( - ($this->year < 1910 ? 'second wednesday of october' : 'fourth monday of october') . " $this->year", - new DateTimeZone($this->timezone) + $date = new \DateTime( + ($this->year < 1910 ? 'second wednesday of october' : 'fourth monday of october') . " {$this->year}", + DateTimeZoneFactory::getDateTimeZone($this->timezone) ); $this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); @@ -229,30 +298,29 @@ private function calculateLabourDay(): void * Christmas day, and Boxing day are public holidays in New Zealand, * they are subject to mondayisation rules. * - * @link https://www.timeanddate.com/holidays/new-zealand/boxing-day - * @link https://www.timeanddate.com/holidays/new-zealand/christmas-day - * @link https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ + * @see https://www.timeanddate.com/holidays/new-zealand/boxing-day + * @see https://www.timeanddate.com/holidays/new-zealand/christmas-day + * @see https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateChristmasHolidays(): void + protected function calculateChristmasHolidays(): void { - $christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone)); - $boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone)); + $christmasDay = new \DateTime("{$this->year}-12-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $boxingDay = new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)); switch ($christmasDay->format('w')) { case 0: - $christmasDay->add(new DateInterval('P2D')); + $christmasDay->add(new \DateInterval('P2D')); break; case 5: - $boxingDay->add(new DateInterval('P2D')); + $boxingDay->add(new \DateInterval('P2D')); break; case 6: - $christmasDay->add(new DateInterval('P2D')); - $boxingDay->add(new DateInterval('P2D')); + $christmasDay->add(new \DateInterval('P2D')); + $boxingDay->add(new \DateInterval('P2D')); break; } diff --git a/src/Yasumi/Provider/Norway.php b/src/Yasumi/Provider/Norway.php index 39e02ba38..a186f1da0 100644 --- a/src/Yasumi/Provider/Norway.php +++ b/src/Yasumi/Provider/Norway.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Norway extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'NO'; @@ -34,7 +37,6 @@ class Norway extends AbstractProvider /** * Initialize holidays for Norway. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -62,8 +64,16 @@ public function initialize(): void $this->calculateConstitutionDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Norway', + 'https://no.wikipedia.org/wiki/Helligdager_i_Norge', + ]; + } + /** - * Constitution Day + * Constitution Day. * * Norway’s Constitution Day is May 17 and commemorates the signing of Norways's constitution at Eidsvoll on * May 17, 1814. It’s usually referred to as Grunnlovsdag(en) ((The) Constitution Day), syttende mai (May 17) or @@ -73,20 +83,19 @@ public function initialize(): void * coalition with Sweden, proceeded by nearly 400 years of Danish rule. The Norwegian Parliament, known as * Stortinget, held the first May 17 celebrations in 1836, and since it has been regarded as Norway’s National Day. * - * @link https://en.wikipedia.org/wiki/Norwegian_Constitution_Day + * @see https://en.wikipedia.org/wiki/Norwegian_Constitution_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateConstitutionDay(): void + protected function calculateConstitutionDay(): void { if ($this->year >= 1836) { $this->addHoliday(new Holiday( 'constitutionDay', - ['nb' => 'Grunnlovsdagen'], - new DateTime("$this->year-5-17", new DateTimeZone($this->timezone)), + ['nb' => 'grunnlovsdagen'], + new \DateTime("{$this->year}-5-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Poland.php b/src/Yasumi/Provider/Poland.php old mode 100755 new mode 100644 index 8794aa0c1..d5717d82b --- a/src/Yasumi/Provider/Poland.php +++ b/src/Yasumi/Provider/Poland.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Poland extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'PL'; @@ -34,7 +37,6 @@ class Poland extends AbstractProvider /** * Initialize holidays for Poland. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -58,11 +60,23 @@ public function initialize(): void $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); + if ($this->year >= 2025) { + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + } + // Add other holidays $this->calculateIndependenceDay(); $this->calculateConstitutionDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Poland', + 'https://pl.wikipedia.org/wiki/Dni_wolne_od_pracy_w_Polsce', + ]; + } + /** * Constitution Day. * @@ -71,15 +85,13 @@ public function initialize(): void * May 3, 1791. Festivities date back to the Duchy of Warsaw early in the 19th century, but it became an official * holiday only in 1919 in the Second Polish Republic. * - * @link https://en.wikipedia.org/wiki/May_3rd_Constitution_Day + * @see https://en.wikipedia.org/wiki/May_3rd_Constitution_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - - private function calculateIndependenceDay(): void + protected function calculateIndependenceDay(): void { if ($this->year < 1918) { return; @@ -88,7 +100,7 @@ private function calculateIndependenceDay(): void $this->addHoliday(new Holiday('independenceDay', [ 'en' => 'Independence Day', 'pl' => 'Narodowe Święto Niepodległości', - ], new DateTime("$this->year-11-11", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-11-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } /** @@ -99,15 +111,13 @@ private function calculateIndependenceDay(): void * Republic in 1918, after 123 years of partition by the Russian Empire, the Kingdom of Prussia and the Habsburg * Empire. * - * @link https://en.wikipedia.org/wiki/National_Independence_Day_(Poland) + * @see https://en.wikipedia.org/wiki/National_Independence_Day_(Poland) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - - private function calculateConstitutionDay(): void + protected function calculateConstitutionDay(): void { if ($this->year < 1791) { return; @@ -116,6 +126,6 @@ private function calculateConstitutionDay(): void $this->addHoliday(new Holiday('constitutionDay', [ 'en' => 'Constitution Day', 'pl' => 'Święto Narodowe Trzeciego Maja', - ], new DateTime("$this->year-5-3", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-5-3", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } diff --git a/src/Yasumi/Provider/Portugal.php b/src/Yasumi/Provider/Portugal.php index f0dc6873b..36e975adf 100644 --- a/src/Yasumi/Provider/Portugal.php +++ b/src/Yasumi/Provider/Portugal.php @@ -1,36 +1,35 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; /** * Holidays for Portugal. - * - * @link https://pt.wikipedia.org/wiki/Feriados_em_Portugal - * - * @package Yasumi\Provider */ class Portugal extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'PT'; @@ -38,7 +37,6 @@ class Portugal extends AbstractProvider /** * Initialize holidays for Portugal. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -62,8 +60,17 @@ public function initialize(): void $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Portugal', + 'https://pt.wikipedia.org/wiki/Feriados_em_Portugal', + 'https://diariodarepublica.pt/dr/legislacao-consolidada/lei/2009-34546475-73982045', + ]; + } + /** - * Carnation Revolution (25th of April 1974) / Revolução dos Cravos (25 de Abril 1974) + * Carnation Revolution (25th of April 1974) / Revolução dos Cravos (25 de Abril 1974). * * The Carnation Revolution (Portuguese: Revolução dos Cravos), also referred to as the 25 April (Portuguese: 25 de * Abril), was initially a military coup in Lisbon, Portugal, on 25 April 1974 which overthrew the regime of the @@ -76,20 +83,19 @@ public function initialize(): void * of rifles and on the uniforms of the army men. In Portugal, the 25th of April is a national holiday, known as * Freedom Day (Portuguese: Dia da Liberdade), to celebrate the event. * - * @link https://en.wikipedia.org/wiki/Carnation_Revolution + * @see https://en.wikipedia.org/wiki/Carnation_Revolution * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCarnationRevolutionDay(): void + protected function calculateCarnationRevolutionDay(): void { if ($this->year >= 1974) { $this->addHoliday(new Holiday( '25thApril', ['pt' => 'Dia da Liberdade'], - new DateTime("$this->year-04-25", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OFFICIAL )); @@ -97,23 +103,22 @@ private function calculateCarnationRevolutionDay(): void } /** - * In Portugal, between 2013 andd 2015 (inclusive) this holiday did not happen due to government deliberation. + * In Portugal, between 2013 and 2015 (inclusive) this holiday did not happen due to government deliberation. * It was restored in 2016. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCorpusChristi(): void + protected function calculateCorpusChristi(): void { if ($this->year <= 2012 || $this->year >= 2016) { - $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); } } /** - * Day of Portugal, Camões and the Portuguese Communities / Dia de Portugal, de Camões e das Comunidades Portuguesas + * Day of Portugal, Camões and the Portuguese Communities / Dia de Portugal, de Camões e das Comunidades Portuguesas. * * The Wikipedia article mentions that this holiday changed names during the Portuguese dictatorship that ran * between 1933 and 1974 (ended with the Carnation Revolution). This is the name that is currently standing. @@ -123,27 +128,26 @@ private function calculateCorpusChristi(): void * officially observed only in Portugal, Portuguese citizens and emigrants throughout the world celebrate this * holiday. The date commemorates the death of national literary icon Luís de Camões on 10 June 1580. * - * @link https://en.wikipedia.org/wiki/Portugal_Day + * @see https://en.wikipedia.org/wiki/Portugal_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePortugalDay(): void + protected function calculatePortugalDay(): void { if ($this->year <= 1932 || $this->year >= 1974) { $this->addHoliday(new Holiday( 'portugalDay', ['pt' => 'Dia de Portugal'], - new DateTime("$this->year-06-10", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-06-10", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } } /** - * Establishment of the Portuguese Republic / Implantação da República Portuguesa + * Establishment of the Portuguese Republic / Implantação da República Portuguesa. * * The establishment of the Portuguese Republic was the result of a coup d'état organised by the Portuguese * Republican Party which, on 5 October 1910, deposed the constitutional monarchy and established a republican @@ -157,20 +161,19 @@ private function calculatePortugalDay(): void * * The holiday was revoked in 2013 due to government deliberation. It was restored in 2016. * - * @link https://en.wikipedia.org/wiki/5_October_1910_revolution + * @see https://en.wikipedia.org/wiki/5_October_1910_revolution * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePortugueseRepublicDay(): void + protected function calculatePortugueseRepublicDay(): void { if (($this->year >= 1910 && $this->year <= 2012) || $this->year >= 2016) { $this->addHoliday(new Holiday( 'portugueseRepublic', ['pt' => 'Implantação da República Portuguesa'], - new DateTime("$this->year-10-05", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-10-05", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -180,12 +183,11 @@ private function calculatePortugueseRepublicDay(): void * In Portugal, between 2013 and 2015 (inclusive) this holiday did not happen due to government deliberation. * It was restored in 2016. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAllSaintsDay(): void + protected function calculateAllSaintsDay(): void { if ($this->year <= 2012 || $this->year >= 2016) { $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); @@ -193,7 +195,7 @@ private function calculateAllSaintsDay(): void } /** - * Restoration of Independence / Reguesstauração da Independência + * Restoration of Independence / Reguesstauração da Independência. * * There is no Wikipedia article referencing this holiday directly so we are using the War that motivated the * holiday instead until we can find something better. @@ -211,22 +213,21 @@ private function calculateAllSaintsDay(): void * * The holiday was revoked in 2013 due to government deliberation. It was restored in 2016. * - * @link https://pt.wikipedia.org/wiki/Restauração_da_Independência (portuguese link) - * @link https://pt.wikipedia.org/wiki/Guerra_da_Restauração (english link) + * @see https://pt.wikipedia.org/wiki/Restauração_da_Independência (portuguese link) + * @see https://pt.wikipedia.org/wiki/Guerra_da_Restauração (english link) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateRestorationOfIndependenceDay(): void + protected function calculateRestorationOfIndependenceDay(): void { // The Wikipedia article mentions that this has been a holiday since the second of half of the XIX century. if (($this->year >= 1850 && $this->year <= 2012) || $this->year >= 2016) { $this->addHoliday(new Holiday( 'restorationOfIndependence', ['pt' => 'Restauração da Independência'], - new DateTime("$this->year-12-01", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OFFICIAL )); diff --git a/src/Yasumi/Provider/Romania.php b/src/Yasumi/Provider/Romania.php old mode 100755 new mode 100644 index 41f069077..daff5d479 --- a/src/Yasumi/Provider/Romania.php +++ b/src/Yasumi/Provider/Romania.php @@ -1,45 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; /** * Provider for all holidays in Romania. - * https://en.wikipedia.org/wiki/Public_holidays_in_Romania + * https://en.wikipedia.org/wiki/Public_holidays_in_Romania. * * Class Romania - * @package Yasumi\Provider + * * @author Angelin Calu */ class Romania extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** * Code to identify this Holiday Provider. - * Typically this is the ISO3166 code corresponding to the respective country or sub-region. + * Typically, this is the ISO3166 code corresponding to the respective country or sub-region. */ public const ID = 'RO'; /** * Initialize holidays for Romania. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -58,7 +60,12 @@ public function initialize(): void $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); - // Pentecost (50th and 51st day after Easter) and Asumption of Mary (15.08) were added as legal holidays acc. to the Law '202/2008' + if ($this->year >= 2024) { + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); + $this->calculateStJohnsDay(); + } + + // Pentecost (50th and 51st day after Easter) and Assumption of Mary (15.08) were added as legal holidays acc. to the Law '202/2008' if ($this->year >= 2008) { $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); @@ -66,81 +73,95 @@ public function initialize(): void } // Add other holidays - $this->calculateDayAfterNewYearsDay(); //2nd of January - $this->calculateUnitedPrincipalitiesDay(); //since 21.12.2014 (Law 171/2014), celebrated on 24th of January - $this->calculateStAndrewDay(); //since 24.07.2012 (Law 147/2012), celebrated on 30th of November - $this->calculateNationalDay(); //after 1990, celebrated on December 1st + $this->calculateDayAfterNewYearsDay(); // 2nd of January + $this->calculateUnitedPrincipalitiesDay(); // since 21.12.2014 (Law 171/2014), celebrated on 24th of January + $this->calculateStAndrewDay(); // since 24.07.2012 (Law 147/2012), celebrated on 30th of November + $this->calculateNationalDay(); // after 1990, celebrated on December 1st $this->calculateConstantinBrancusiDay(); $this->calculateChildrensDay(); // Since 18.11.2016 (Law 220/2016), Celebrated on 1st of June } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Romania', + 'https://ro.wikipedia.org/wiki/S%C4%83rb%C4%83tori_publice_%C3%AEn_Rom%C3%A2nia', + ]; + } + /** - * Day after New Year's Day + * @return \DateTime|\DateTimeImmutable + * + * @throws \Exception + */ + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface + { + return $this->calculateOrthodoxEaster($year, $timezone); + } + + /** + * Day after New Year's Day. * * 2nd of January one of Romania's official non-working holidays * - * @link https://en.wikipedia.org/wiki/Public_holidays_in_Romania + * @see https://en.wikipedia.org/wiki/Public_holidays_in_Romania * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayAfterNewYearsDay(): void + protected function calculateDayAfterNewYearsDay(): void { $this->addHoliday(new Holiday( 'dayAfterNewYearsDay', [], - new DateTime("$this->year-01-02", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } /** - * Celebration of United Principalities + * Celebration of United Principalities. * * On 24 January 1862, the Principality of Moldavia and the Principality of Wallachia * formally united to create the Romanian United Principalities. * It is officially a non-working holiday since 7 October 2016. * + * @see https://en.wikipedia.org/wiki/United_Principalities * - * @link https://en.wikipedia.org/wiki/United_Principalities - * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateUnitedPrincipalitiesDay(): void + protected function calculateUnitedPrincipalitiesDay(): void { // The law is official since 21.12.2014. if ($this->year > 2014) { $this->addHoliday(new Holiday('unitedPrincipalitiesDay', [ 'en' => 'Union Day / Small Union', 'ro' => 'Unirea Principatelor Române / Mica Unire', - ], new DateTime("$this->year-01-24", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-01-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } /** - * St. Andrew's day + * St. Andrew's day. * * Saint Andrew is the patron saint of Romania. * - * @link https://en.wikipedia.org/wiki/St._Andrew%27s_Day + * @see https://en.wikipedia.org/wiki/St._Andrew%27s_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStAndrewDay(): void + protected function calculateStAndrewDay(): void { if ($this->year >= 2012) { $this->addHoliday(new Holiday( 'stAndrewsDay', [], - new DateTime($this->year . '-11-30', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -154,51 +175,73 @@ private function calculateStAndrewDay(): void * It commemorates the assembly of the delegates of ethnic Romanians held in Alba Iulia, * which declared the Union of Transylvania with Romania. * - * @link https://en.wikipedia.org/wiki/Great_Union_Day - * @link https://ro.wikipedia.org/wiki/Ziua_na%C8%9Bional%C4%83_a_Rom%C3%A2niei + * @see https://en.wikipedia.org/wiki/Great_Union_Day + * @see https://ro.wikipedia.org/wiki/Ziua_na%C8%9Bional%C4%83_a_Rom%C3%A2niei * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalDay(): void + protected function calculateNationalDay(): void { - $national_day = null; + $nationalDay = null; - //@link https://en.wikipedia.org/wiki/Great_Union_Day + // @link https://en.wikipedia.org/wiki/Great_Union_Day if ($this->year >= 1990) { - $national_day = "$this->year-12-01"; + $nationalDay = "{$this->year}-12-01"; } if ($this->year >= 1948 && $this->year <= 1989) { - $national_day = "$this->year-08-23"; + $nationalDay = "{$this->year}-08-23"; } if ($this->year >= 1866 && $this->year <= 1947) { - $national_day = "$this->year-05-10"; + $nationalDay = "{$this->year}-05-10"; } - if (\is_string($national_day)) { + if (\is_string($nationalDay)) { $this->addHoliday(new Holiday('nationalDay', [ 'en' => 'National Day', 'ro' => 'Ziua Națională', - ], new DateTime($national_day, new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime($nationalDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } /** - * Constantin Brancusi Day + * /** + * St. John the Baptist. + * + * @see https://en.wikipedia.org/wiki/John_the_Baptist + * @see https://ro.wikipedia.org/wiki/Ioan_Botez%C4%83torul + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateStJohnsDay(): void + { + if ($this->year >= 2024) { + $this->addHoliday(new Holiday( + 'stJohnsDay', + [], + new \DateTime("{$this->year}-01-07", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Constantin Brancusi Day. * * Constantin Brâncuși (February 19, 1876 – March 16, 1957) was a Romanian sculptor, painter and photographer. * - * @link https://en.wikipedia.org/wiki/Constantin_Br%C3%A2ncu%C8%99i - * @throws InvalidDateException + * @see https://en.wikipedia.org/wiki/Constantin_Br%C3%A2ncu%C8%99i + * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateConstantinBrancusiDay(): void + protected function calculateConstantinBrancusiDay(): void { if ($this->year >= 2016) { $this->addHoliday(new Holiday( @@ -207,7 +250,7 @@ private function calculateConstantinBrancusiDay(): void 'en' => 'Constantin Brâncuși day', 'ro' => 'Ziua Constantin Brâncuși', ], - new DateTime("$this->year-02-19", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-02-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); @@ -215,28 +258,27 @@ private function calculateConstantinBrancusiDay(): void } /** - * Children's Day + * Children's Day. * * International Children's Day becamed a public Holiday in Romania starting with 2017 * according to the Law 220/2016 (18.11.2016) * - * @link https://en.wikipedia.org/wiki/Children%27s_Day - * @throws InvalidDateException + * @see https://en.wikipedia.org/wiki/Children%27s_Day + * * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateChildrensDay(): void + protected function calculateChildrensDay(): void { if ($this->year >= 1950 && $this->year <= 2016) { $this->addHoliday(new Holiday( 'childrensDay', [ - 'en' => 'International Children\'s Day', + 'en' => 'International Children’s Day', 'ro' => 'Ziua Copilului', ], - new DateTime("$this->year-06-01", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-06-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); @@ -244,22 +286,9 @@ private function calculateChildrensDay(): void if ($this->year >= 2017) { $this->addHoliday(new Holiday('childrensDay', [ - 'en' => 'International Children\'s Day', + 'en' => 'International Children’s Day', 'ro' => 'Ziua Copilului', - ], new DateTime("$this->year-06-01", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-06-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } - - /** - * @param int $year - * @param string $timezone - * - * @return DateTime - * - * @throws \Exception - */ - public function calculateEaster($year, $timezone): DateTime - { - return $this->calculateOrthodoxEaster($year, $timezone); - } } diff --git a/src/Yasumi/Provider/Russia.php b/src/Yasumi/Provider/Russia.php index 61393d8df..abbc88777 100644 --- a/src/Yasumi/Provider/Russia.php +++ b/src/Yasumi/Provider/Russia.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; @@ -30,7 +35,7 @@ class Russia extends AbstractProvider public const UNITY_DAY_START_YEAR = 2005; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'RU'; @@ -57,17 +62,25 @@ public function initialize(): void $this->addUnityDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Russia', + 'https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B0%D0%B7%D0%B4%D0%BD%D0%B8%D0%BA%D0%B8_%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B8', + ]; + } + /** * @throws \InvalidArgumentException * @throws \Exception */ - private function addNewYearsHolidays(): void + protected function addNewYearsHolidays(): void { $holidayDays = [2, 3, 4, 5, 6, 8]; foreach ($holidayDays as $day) { - $this->addHoliday(new Holiday('newYearHolidaysDay' . $day, [ - 'en' => 'New Year\'s holidays', + $this->addHoliday(new Holiday("newYearHolidaysDay{$day}", [ + 'en' => 'New Year’s holidays', 'ru' => 'Новогодние каникулы', ], new \DateTime("{$this->year}-01-{$day}", new \DateTimeZone($this->timezone)), $this->locale)); } @@ -77,7 +90,7 @@ private function addNewYearsHolidays(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addOrthodoxChristmasDay(): void + protected function addOrthodoxChristmasDay(): void { $this->addHoliday(new Holiday('orthodoxChristmasDay', [ 'en' => 'Orthodox Christmas Day', @@ -89,7 +102,7 @@ private function addOrthodoxChristmasDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addDefenceOfTheFatherlandDay(): void + protected function addDefenceOfTheFatherlandDay(): void { if ($this->year < self::DEFENCE_OF_THE_FATHERLAND_START_YEAR) { return; @@ -105,7 +118,7 @@ private function addDefenceOfTheFatherlandDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addInternationalWomensDay(): void + protected function addInternationalWomensDay(): void { $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); } @@ -114,7 +127,7 @@ private function addInternationalWomensDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addSpringAndLabourDay(): void + protected function addSpringAndLabourDay(): void { $this->addHoliday(new Holiday('springAndLabourDay', [ 'en' => 'Spring and Labour Day', @@ -126,7 +139,7 @@ private function addSpringAndLabourDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addVictoryDay(): void + protected function addVictoryDay(): void { $this->addHoliday(new Holiday('victoryDay', [ 'en' => 'Victory Day', @@ -138,7 +151,7 @@ private function addVictoryDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addRussiaDay(): void + protected function addRussiaDay(): void { if ($this->year < self::RUSSIA_DAY_START_YEAR) { return; @@ -154,7 +167,7 @@ private function addRussiaDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - private function addUnityDay(): void + protected function addUnityDay(): void { if ($this->year < self::UNITY_DAY_START_YEAR) { return; diff --git a/src/Yasumi/Provider/SanMarino.php b/src/Yasumi/Provider/SanMarino.php new file mode 100644 index 000000000..7a25626f6 --- /dev/null +++ b/src/Yasumi/Provider/SanMarino.php @@ -0,0 +1,283 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in San Marino. + * + * San Marino observes 18 national public holidays. The official language is Italian (it_SM). + * The Most Serene Republic of San Marino is one of the world's oldest republics, traditionally + * founded on 3 September 301 AD by Saint Marinus of Rab. + * + * @see https://en.wikipedia.org/wiki/Public_holidays_in_San_Marino + */ +class SanMarino extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + /** + * The year the Arengo (popular assembly) was reconvened, establishing democratic rights. + */ + public const ARENGO_YEAR = 1906; + + /** + * The year the Fall of Fascism holiday was first observed. + */ + public const FALL_OF_FASCISM_YEAR = 1944; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'SM'; + + /** + * Initialize holidays for San Marino. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Europe/San_Marino'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->stStephensDay($this->year, $this->timezone, $this->locale)); + + // Add San Marino-specific holidays + $this->calculateFeastOfSaintAgatha(); + $this->calculateAnniversaryOfArengo(); + $this->calculateInvestitureCaptainsRegentApril(); + $this->calculateFallOfFascism(); + $this->calculateFoundationDay(); + $this->calculateInvestitureCaptainsRegentOctober(); + $this->calculateCommemorationOfTheFallen(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_San_Marino', + 'https://it.wikipedia.org/wiki/Festivit%C3%A0_di_San_Marino', + ]; + } + + /** + * Feast of Saint Agatha. + * + * The Feast of Saint Agatha (Italian: Festa di Sant'Agata) is celebrated on 5 February. Saint Agatha is the + * patron saint of San Marino. The day also commemorates the anniversary of the liberation of San Marino from + * the occupation by Cardinal Giulio Alberoni on 5 February 1740. + * + * @see https://en.wikipedia.org/wiki/Saint_Agatha + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateFeastOfSaintAgatha(): void + { + $this->addHoliday(new Holiday( + 'feastOfSaintAgatha', + [ + 'it' => "Festa di Sant\u{2019}Agata", + 'en' => 'Feast of Saint Agatha', + ], + new \DateTime("{$this->year}-2-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Anniversary of the Arengo. + * + * The Anniversary of the Arengo (Italian: Anniversario dell'Arengo) is celebrated on 25 March. The Arengo is + * the ancient popular assembly of San Marino. On 25 March 1906, the Arengo was reconvened after centuries, + * granting democratic rights including universal suffrage, marking a pivotal moment in San Marino's history. + * + * @see https://en.wikipedia.org/wiki/Arengo_(San_Marino) + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateAnniversaryOfArengo(): void + { + if ($this->year >= self::ARENGO_YEAR) { + $this->addHoliday(new Holiday( + 'anniversaryOfArengo', + [ + 'it' => "Anniversario dell\u{2019}Arengo", + 'en' => 'Anniversary of the Arengo', + ], + new \DateTime("{$this->year}-3-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Investiture of the Captains Regent (April). + * + * The Investiture of the Captains Regent (Italian: Investitura dei Capitani Reggenti) on 1 April marks the + * formal investiture ceremony of the two newly elected Captains Regent who serve as heads of state. The + * Captains Regent are elected twice yearly and serve a six-month term. This ceremony has been observed since + * the 13th century. + * + * @see https://en.wikipedia.org/wiki/Captain_Regent + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateInvestitureCaptainsRegentApril(): void + { + $this->addHoliday(new Holiday( + 'investitureCaptainsRegentApril', + [ + 'it' => 'Investitura dei Capitani Reggenti', + 'en' => 'Investiture of the Captains Regent', + ], + new \DateTime("{$this->year}-4-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Fall of Fascism. + * + * The Fall of Fascism (Italian: Caduta del Fascismo) is observed on 28 July, commemorating the coup d'état of + * 28 July 1943 when San Marino's Great and General Council voted to overthrow the Fascist government, ending + * the Fascist regime in the republic. The holiday has been observed since 1944. + * + * @see https://en.wikipedia.org/wiki/San_Marino_in_World_War_II + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateFallOfFascism(): void + { + if ($this->year >= self::FALL_OF_FASCISM_YEAR) { + $this->addHoliday(new Holiday( + 'fallOfFascism', + [ + 'it' => 'Caduta del Fascismo', + 'en' => 'Fall of Fascism', + ], + new \DateTime("{$this->year}-7-28", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Foundation Day (San Marino Day). + * + * Foundation Day (Italian: Anniversario della Fondazione della Repubblica), observed on 3 September, + * commemorates the traditional founding of the Republic of San Marino on 3 September 301 AD by Saint Marinus + * of Rab, a Christian stonemason from the island of Rab. It is also known as San Marino Day. + * + * @see https://en.wikipedia.org/wiki/San_Marino + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateFoundationDay(): void + { + $this->addHoliday(new Holiday( + 'foundationDay', + [ + 'it' => 'Anniversario della Fondazione della Repubblica', + 'en' => 'Foundation Day', + ], + new \DateTime("{$this->year}-9-3", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Investiture of the Captains Regent (October). + * + * The Investiture of the Captains Regent (Italian: Investitura dei Capitani Reggenti) on 1 October marks the + * formal investiture ceremony of the two newly elected Captains Regent. The ceremony is held twice yearly, + * on 1 April and 1 October. + * + * @see https://en.wikipedia.org/wiki/Captain_Regent + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateInvestitureCaptainsRegentOctober(): void + { + $this->addHoliday(new Holiday( + 'investitureCaptainsRegentOctober', + [ + 'it' => 'Investitura dei Capitani Reggenti', + 'en' => 'Investiture of the Captains Regent', + ], + new \DateTime("{$this->year}-10-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * Commemoration of the Fallen. + * + * The Commemoration of the Fallen (Italian: Commemorazione dei Defunti), observed on 2 November, is a day + * to honour and remember all deceased persons. It coincides with All Souls' Day in the Catholic tradition + * and is an official public holiday in San Marino. + * + * @see https://en.wikipedia.org/wiki/All_Souls%27_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateCommemorationOfTheFallen(): void + { + $this->addHoliday(new Holiday( + 'commemorationOfTheFallen', + [ + 'it' => 'Commemorazione dei Defunti', + 'en' => 'Commemoration of the Fallen', + ], + new \DateTime("{$this->year}-11-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/Provider/Slovakia.php b/src/Yasumi/Provider/Slovakia.php index 79d9773e1..1b20072c2 100644 --- a/src/Yasumi/Provider/Slovakia.php +++ b/src/Yasumi/Provider/Slovakia.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -41,18 +42,18 @@ * * Note: Slovak holidays are valid since 1993-01-01, the day od dissolution of Czechoslovakia into Czech republic and * Slovakia. - * @see https://en.wikipedia.org/wiki/Dissolution_of_Czechoslovakia * + * @see https://en.wikipedia.org/wiki/Dissolution_of_Czechoslovakia * - * @package Yasumi\Provider * @author Andrej Rypak (dakujem) */ class Slovakia extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'SK'; @@ -60,7 +61,6 @@ class Slovakia extends AbstractProvider /** * Initialize holidays for Slovakia. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -80,19 +80,23 @@ public function initialize(): void $this->locale, Holiday::TYPE_BANK )); - // 8.5. - $this->addHoliday($this->victoryInEuropeDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); + // 8.5. (<2025, >2026) + if ($this->year < 2025 || $this->year > 2026) { + $this->addHoliday($this->victoryInEuropeDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); + } // 5.7. $this->calculateSaintsCyrilAndMethodiusDay(); // 29.8. $this->calculateSlovakNationalUprisingDay(); - // 1.9. + // 1.9.(<2024) $this->calculateSlovakConstitutionDay(); - // 15.9. + // 15.9. (<2025, >2026) $this->calculateOurLadyOfSorrowsDay(); + // 30.10.2018 + $this->calculateDeclarationOfTheSlovakNation(); // 1.11. $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); - // 17.11. + // 17.11.(<2025) $this->calculateStruggleForFreedomAndDemocracyDay(); // 24.12. $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); @@ -106,18 +110,49 @@ public function initialize(): void $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Slovakia', + 'https://cs.wikipedia.org/wiki/St%C3%A1tn%C3%AD_sv%C3%A1tky_Slovenska', + ]; + } + + /** + * Anniversary of the Declaration of the Slovak Nation. + * In 2018, October 30 was a one-time public holiday. For this reason, it was not a commemorative day in 2018. + * + * @see https://sk.wikipedia.org/wiki/Zoznam_sviatkov_na_Slovensku#endnote_pozn-01 + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateDeclarationOfTheSlovakNation(): void + { + if (2018 === $this->year) { + $this->addHoliday(new Holiday( + 'declarationOfTheSlovakNation', + [ + 'sk' => 'Výročie Deklarácie slovenského národa', + 'en' => 'Anniversary of the Declaration of the Slovak Nation', + ], + new \DateTime("{$this->year}-10-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } /** - * New Year's Day + * New Year's Day. * * @see https://en.wikipedia.org/wiki/Public_holidays_in_Slovakia * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSlovakIndependenceDay(): void + protected function calculateSlovakIndependenceDay(): void { $this->addHoliday(new Holiday( 'slovakIndependenceDay', @@ -125,24 +160,23 @@ private function calculateSlovakIndependenceDay(): void 'sk' => 'Deň vzniku Slovenskej republiky', 'en' => 'Day of the Establishment of the Slovak Republic', ], - new DateTime($this->year . '-01-01', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-01-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } /** - * Saints Cyril and Methodius Day + * Saints Cyril and Methodius Day. * * @see https://en.wikipedia.org/wiki/Saints_Cyril_and_Methodius * * Note: this holiday is common for Czech republic and Slovakia. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSaintsCyrilAndMethodiusDay(): void + protected function calculateSaintsCyrilAndMethodiusDay(): void { $this->addHoliday(new Holiday( 'saintsCyrilAndMethodiusDay', @@ -151,23 +185,22 @@ private function calculateSaintsCyrilAndMethodiusDay(): void 'cs' => 'Den slovanských věrozvěstů Cyrila a Metoděje', 'en' => 'Saints Cyril and Methodius Day', ], - new DateTime($this->year . '-07-05', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-07-05", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OFFICIAL )); } /** - * Slovak National Uprising Day + * Slovak National Uprising Day. * * @see https://en.wikipedia.org/wiki/Slovak_National_Uprising * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSlovakNationalUprisingDay(): void + protected function calculateSlovakNationalUprisingDay(): void { $this->addHoliday(new Holiday( 'slovakNationalUprisingDay', @@ -175,34 +208,37 @@ private function calculateSlovakNationalUprisingDay(): void 'sk' => 'Výročie Slovenského národného povstania', 'en' => 'Slovak National Uprising Day', ], - new DateTime($this->year . '-08-29', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-08-29", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OFFICIAL )); } /** - * Day of the Constitution of the Slovak Republic + * Day of the Constitution of the Slovak Republic. * * @see https://en.wikipedia.org/wiki/Constitution_of_Slovakia + * Removed since 2024 + * @see https://www.slov-lex.sk/pravne-predpisy/SK/ZZ/1993/241/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSlovakConstitutionDay(): void + protected function calculateSlovakConstitutionDay(): void { - $this->addHoliday(new Holiday( - 'slovakConstitutionDay', - [ - 'sk' => 'Deň Ústavy Slovenskej republiky', - 'en' => 'Day of the Constitution of the Slovak Republic', - ], - new DateTime($this->year . '-09-01', new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + if ($this->year < 2024) { + $this->addHoliday(new Holiday( + 'slovakConstitutionDay', + [ + 'sk' => 'Deň Ústavy Slovenskej republiky', + 'en' => 'Day of the Constitution of the Slovak Republic', + ], + new \DateTime("{$this->year}-09-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } } /** @@ -213,42 +249,45 @@ private function calculateSlovakConstitutionDay(): void * * @see https://en.wikipedia.org/wiki/Our_Lady_of_Sorrows * @see https://sk.wikipedia.org/wiki/Sedembolestn%C3%A1_Panna_M%C3%A1ria + * @see https://spravy.stvr.sk/2025/09/poslanci-definitivne-schvalili-zrusenie-niektorych-dni-pracovneho-pokoja-pozrite-si-ich-prehlad-na-rok-2026/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateOurLadyOfSorrowsDay(): void + protected function calculateOurLadyOfSorrowsDay(): void { - $this->addHoliday(new Holiday('ourLadyOfSorrowsDay', [ - 'sk' => 'Sviatok Sedembolestnej Panny Márie', - 'en' => 'Our Lady of Sorrows Day', - ], new DateTime($this->year . '-09-15', new DateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK)); + if ($this->year < 2025 || $this->year > 2026) { + $this->addHoliday(new Holiday('ourLadyOfSorrowsDay', [ + 'sk' => 'Sviatok Sedembolestnej Panny Márie', + 'en' => 'Our Lady of Sorrows Day', + ], new \DateTime("{$this->year}-09-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK)); + } } /** - * Struggle for Freedom and Democracy Day + * Struggle for Freedom and Democracy Day. * * Note: this national day is common for Czech republic and Slovakia. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStruggleForFreedomAndDemocracyDay(): void + protected function calculateStruggleForFreedomAndDemocracyDay(): void { - $this->addHoliday(new Holiday( - 'struggleForFreedomAndDemocracyDay', - [ - 'sk' => 'Deň boja za slobodu a demokraciu', - 'cs' => 'Den boje za svobodu a demokracii', - 'en' => 'Struggle for Freedom and Democracy Day', - ], - new DateTime($this->year . '-11-17', new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + if ($this->year < 2025) { + $this->addHoliday(new Holiday( + 'struggleForFreedomAndDemocracyDay', + [ + 'sk' => 'Deň boja za slobodu a demokraciu', + 'cs' => 'Den boje za svobodu a demokracii', + 'en' => 'Struggle for Freedom and Democracy Day', + ], + new \DateTime("{$this->year}-11-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } } } diff --git a/src/Yasumi/Provider/Slovenia.php b/src/Yasumi/Provider/Slovenia.php new file mode 100644 index 000000000..2d2827cd5 --- /dev/null +++ b/src/Yasumi/Provider/Slovenia.php @@ -0,0 +1,198 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Slovenia. + */ +class Slovenia extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'SI'; + + /** + * Initialize holidays for Slovenia. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Europe/Ljubljana'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + + // Add Slovenia-specific holidays + $this->calculateSecondNewYearsDay(); + $this->calculatePreserenDay(); + $this->calculateUprisingAgainstOccupation(); + $this->calculateLabourDay(); + $this->calculateStatehoodDay(); + $this->calculateReformationDay(); + $this->calculateRemembranceDay(); + $this->calculateIndependenceDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Slovenia', + 'https://www.gov.si/en/topics/public-holidays/', + ]; + } + + /** + * Second New Year's Day (January 2). + * + * @throws \Exception + */ + protected function calculateSecondNewYearsDay(): void + { + $this->addHoliday(new Holiday('secondNewYearsDay', [ + 'en' => 'Second New Year’s Day', + 'sl' => 'Novo leto (2. dan)', + ], new \DateTime("{$this->year}-1-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Prešeren Day, the Slovenian Cultural Holiday (February 8). + * Established in 1945, became a work-free holiday in 1991. + * + * @throws \Exception + */ + protected function calculatePreserenDay(): void + { + if ($this->year >= 1991) { + $this->addHoliday(new Holiday('preserenDay', [ + 'en' => 'Prešeren Day, Slovenian Cultural Holiday', + 'sl' => 'Prešernov dan, slovenski kulturni praznik', + ], new \DateTime("{$this->year}-2-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Day of Uprising Against Occupation (April 27). + * Commemorates the Slovenian resistance against the Axis occupation in 1941. + * + * @throws \Exception + */ + protected function calculateUprisingAgainstOccupation(): void + { + if ($this->year >= 1945) { + $this->addHoliday(new Holiday('uprisingAgainstOccupation', [ + 'en' => 'Day of Uprising Against Occupation', + 'sl' => 'Dan upora proti okupatorju', + ], new \DateTime("{$this->year}-4-27", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Labour Day (May 2). + * Slovenia celebrates two consecutive Labour Days (May 1 and May 2). + * + * @throws \Exception + */ + protected function calculateLabourDay(): void + { + $this->addHoliday(new Holiday('labourDay', [ + 'en' => 'Labour Day', + 'sl' => 'Praznik dela (2. dan)', + ], new \DateTime("{$this->year}-5-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Statehood Day (June 25). + * Commemorates Slovenia's declaration of independence from Yugoslavia in 1991. + * + * @throws \Exception + */ + protected function calculateStatehoodDay(): void + { + if ($this->year >= 1991) { + $this->addHoliday(new Holiday('statehoodDay', [ + 'en' => 'Statehood Day', + 'sl' => 'Dan državnosti', + ], new \DateTime("{$this->year}-6-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Reformation Day (October 31). + * Added as a public holiday in 1992 to commemorate the Protestant Reformation. + * + * @throws \Exception + */ + protected function calculateReformationDay(): void + { + if ($this->year >= 1992) { + $this->addHoliday(new Holiday('reformationDay', [ + 'en' => 'Reformation Day', + 'sl' => 'Dan reformacije', + ], new \DateTime("{$this->year}-10-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } + + /** + * Day of Remembrance for the Dead (November 1). + * Slovenia's version of All Saints' Day. + * + * @throws \Exception + */ + protected function calculateRemembranceDay(): void + { + $this->addHoliday(new Holiday('remembranceDay', [ + 'en' => 'Day of Remembrance for the Dead', + 'sl' => 'Dan spomina na mrtve', + ], new \DateTime("{$this->year}-11-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Independence and Unity Day (December 26). + * Commemorates the 1990 plebiscite results and the 1991 formal independence. + * + * @throws \Exception + */ + protected function calculateIndependenceDay(): void + { + if ($this->year >= 1991) { + $this->addHoliday(new Holiday('independenceDay', [ + 'en' => 'Independence and Unity Day', + 'sl' => 'Dan samostojnosti in enotnosti', + ], new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + } + } +} diff --git a/src/Yasumi/Provider/SouthAfrica.php b/src/Yasumi/Provider/SouthAfrica.php index 15e9f7422..5cb028698 100644 --- a/src/Yasumi/Provider/SouthAfrica.php +++ b/src/Yasumi/Provider/SouthAfrica.php @@ -1,22 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -30,10 +30,11 @@ */ class SouthAfrica extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ZA'; @@ -41,7 +42,6 @@ class SouthAfrica extends AbstractProvider /** * Initialize holidays for South Africa. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -78,6 +78,15 @@ public function initialize(): void $this->calculateSubstituteHolidays(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_South_Africa', + 'https://af.wikipedia.org/wiki/Lys_van_openbare_vakansiedae_in_Suid-Afrika', + 'https://zu.wikipedia.org/wiki/Amaholide_omphakathi_eNingizimu_Afrika', + ]; + } + /** * Human Rights Day. * @@ -88,19 +97,18 @@ public function initialize(): void * 1996, 35 years after the fateful events of 21 March 1960 when demonstrators in Sharpeville were gunned down by * police. * - * @link https://www.gov.za/about-sa/public-holidays#21march + * @see https://www.gov.za/about-sa/public-holidays#21march * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateHumanRightsDay(): void + protected function calculateHumanRightsDay(): void { $this->addHoliday(new Holiday( 'humanRightsDay', ['en' => 'Human Rights Day'], - new DateTime($this->year . '-3-21', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-3-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -110,19 +118,18 @@ private function calculateHumanRightsDay(): void * * Family Day in South Africa takes place on the Monday following Easter Sunday. * - * @link https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/documents/public-holidays-act * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateFamilyDay(): void + protected function calculateFamilyDay(): void { $this->addHoliday(new Holiday( 'familyDay', ['en' => 'Family Day'], - $this->calculateEaster($this->year, $this->timezone)->add(new DateInterval('P1D')), + $this->calculateEaster($this->year, $this->timezone)->add(new \DateInterval('P1D')), $this->locale )); } @@ -132,20 +139,19 @@ private function calculateFamilyDay(): void * * Freedom Day commemorates the first democratic elections held in South Africa on 27 April 1994. * - * @link https://www.gov.za/documents/public-holidays-act - * @link https://www.gov.za/freedom-day-2014 + * @see https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/freedom-day-2014 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateFreedomDay(): void + protected function calculateFreedomDay(): void { $this->addHoliday(new Holiday( 'freedomDay', ['en' => 'Freedom Day'], - new DateTime($this->year . '-4-27', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-4-27", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -159,20 +165,19 @@ private function calculateFreedomDay(): void * police, and the violence that ensued during the next few weeks, approximately 700 hundred people, many of them * youths, were killed and property destroyed. Youth Day, previously known as Soweto Day, commemorates these events. * - * @link https://www.gov.za/documents/public-holidays-act - * @link https://www.gov.za/youth-day-2014 + * @see https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/youth-day-2014 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateYouthDay(): void + protected function calculateYouthDay(): void { $this->addHoliday(new Holiday( 'youthDay', ['en' => 'Youth Day'], - new DateTime($this->year . '-6-16', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-6-16", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -183,14 +188,13 @@ private function calculateYouthDay(): void * President Jacob Zuma has declared 3 August 2016, the date of the 2016 Municipal Elections, a public holiday. The * purpose is to enable all South Africans who are eligible to vote to exercise their right on 3 August 2016. * - * @link https://www.gov.za/speeches/president-jacob-zuma-declares-3-august-2016-public-holiday-24-jun-2016-0000 + * @see https://www.gov.za/speeches/president-jacob-zuma-declares-3-august-2016-public-holiday-24-jun-2016-0000 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculate2016MunicipalElectionsDay(): void + protected function calculate2016MunicipalElectionsDay(): void { if (2016 !== $this->year) { return; @@ -199,7 +203,7 @@ private function calculate2016MunicipalElectionsDay(): void $this->addHoliday(new Holiday( '2016MunicipalElectionsDay', ['en' => '2016 Municipal Elections Day'], - new DateTime('2016-8-3', new DateTimeZone($this->timezone)), + new \DateTime('2016-8-3', DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -211,20 +215,19 @@ private function calculate2016MunicipalElectionsDay(): void * (legislation that required African persons to carry a document on them to 'prove' that they were allowed to enter * a 'white area'). * - * @link https://www.gov.za/about-sa/public-holidays#women - * @link https://www.gov.za/womens-day + * @see https://www.gov.za/about-sa/public-holidays#women + * @see https://www.gov.za/womens-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalWomensDay(): void + protected function calculateNationalWomensDay(): void { $this->addHoliday(new Holiday( 'nationalWomensDay', - ['en' => 'National Women\'s Day'], - new DateTime($this->year . '-8-9', new DateTimeZone($this->timezone)), + ['en' => 'National Women’s Day'], + new \DateTime("{$this->year}-8-9", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -236,20 +239,19 @@ private function calculateNationalWomensDay(): void * Africans celebrate the day by remembering the cultural heritage of the many cultures that make up the population * of South Africa. * - * @link https://www.gov.za/documents/public-holidays-act - * @link https://www.gov.za/heritage-day-2014 + * @see https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/heritage-day-2014 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateHeritageDay(): void + protected function calculateHeritageDay(): void { $this->addHoliday(new Holiday( 'heritageDay', ['en' => 'Heritage Day'], - new DateTime($this->year . '-9-24', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-9-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -263,20 +265,19 @@ private function calculateHeritageDay(): void * of democracy in South Africa 16 December retained its status as a public holiday, however, this time with the * purpose of fostering reconciliation and national unity. * - * @link https://www.gov.za/documents/public-holidays-act - * @link https://www.gov.za/day-reconciliation-2014 + * @see https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/day-reconciliation-2014 * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayOfReconciliation(): void + protected function calculateDayOfReconciliation(): void { $this->addHoliday(new Holiday( 'reconciliationDay', ['en' => 'Day of Reconciliation'], - new DateTime($this->year . '-12-16', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-16", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -290,14 +291,13 @@ private function calculateDayOfReconciliation(): void * Note: Not entirely sure if this is a common rule as the Public Holidays Act doesn't mention such specific * situation. * - * @link https://www.gov.za/documents/public-holidays-act + * @see https://www.gov.za/documents/public-holidays-act * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSubstituteDayOfGoodwill(): void + protected function calculateSubstituteDayOfGoodwill(): void { if (2016 !== $this->year) { return; @@ -306,7 +306,7 @@ private function calculateSubstituteDayOfGoodwill(): void $this->addHoliday(new Holiday( 'substituteDayOfGoodwill', ['en' => 'Day of Goodwill observed'], - new DateTime('2016-12-27', new DateTimeZone($this->timezone)), + new \DateTime('2016-12-27', DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -317,19 +317,22 @@ private function calculateSubstituteDayOfGoodwill(): void * The Public Holidays Act (Act No 36 of 1994) determines whenever any public holiday falls on a Sunday, the Monday * following on it shall be a public holiday. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSubstituteHolidays(): void + protected function calculateSubstituteHolidays(): void { // Loop through all defined holidays foreach ($this->getHolidays() as $holiday) { + if (! $holiday instanceof Holiday) { + continue; + } + // Substitute holiday is on a Monday in case the holiday falls on a Sunday - if (0 === (int)$holiday->format('w')) { + if (0 === (int) $holiday->format('w')) { $date = clone $holiday; - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); $this->addHoliday(new SubstituteHoliday( $holiday, diff --git a/src/Yasumi/Provider/SouthKorea.php b/src/Yasumi/Provider/SouthKorea.php index 94886454a..1cb84e59b 100644 --- a/src/Yasumi/Provider/SouthKorea.php +++ b/src/Yasumi/Provider/SouthKorea.php @@ -1,22 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -24,34 +24,37 @@ /** * Provider for all holidays in the South Korea except for election day and temporary public holiday. * - * @link https://en.wikipedia.org/wiki/Public_holidays_in_South_Korea + * @see https://en.wikipedia.org/wiki/Public_holidays_in_South_Korea */ class SouthKorea extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'KR'; /** - * Dates in Gregorian calendar of Seollal, Buddha's Birthday, and Chuseok (~ 2050) + * Dates in Gregorian calendar of Seollal, Buddha's Birthday, and Chuseok (~ 2050). * * The Korean calendar is derived from the Chinese calendar. Although not being an official calendar, the * traditional Korean calendar is still maintained by the government. The current version is based on China's * Shixian calendar, which was in turn developed by Jesuit scholars. However, because the Korean calendar is now * based on the moon's shape seen from Korea, occasionally the calendar diverges from the traditional Chinese * calendar by one day, even though the underlying rule is the same. - * @link https://en.wikipedia.org/wiki/Korean_calendar + * + * @see https://en.wikipedia.org/wiki/Korean_calendar * * To convert from lunar calendar to Gregorian calendar, lunar observation is necessary. * There is no perfect formula, and as it moves away from the current date, the error becomes bigger. * Korea Astronomy and Space Science Institute (KASI) is supporting the converter until 2050. * For more information, please refer to the paper below. - * 박한얼, 민병희, 안영숙,(2017).한국 음력의 운용과 계산법 연구.천문학논총,32(3),407-420. - * @link https://www.kasi.re.kr/kor/research/paper/20170259 - Korea Astronomy and Space Science Institute + * 박(2017)총,32(3),407-420. + * @see https://koreascience.kr/article/JAKO201706163145174.pdf - Korea Astronomy and Space Science Institute + * @see https://astro.kasi.re.kr/life/pageView/8 - web utility for conversion and retrieve */ public const LUNAR_HOLIDAY = [ 'seollal' => [ @@ -65,7 +68,7 @@ class SouthKorea extends AbstractProvider 2020 => '2020-1-25', 2021 => '2021-2-12', 2022 => '2022-2-1', 2023 => '2023-1-22', 2024 => '2024-2-10', 2025 => '2025-1-29', 2026 => '2026-2-17', 2027 => '2027-2-7', 2028 => '2028-1-27', 2029 => '2029-2-13', 2030 => '2030-2-3', 2031 => '2031-1-23', 2032 => '2032-2-11', 2033 => '2033-1-31', 2034 => '2034-2-19', - 2035 => '2035-2-8', 2036 => '2036-1-28', 2037 => '2037-2-15', 2038 => '2038-2-4', 2039 => '2037-1-24', + 2035 => '2035-2-8', 2036 => '2036-1-28', 2037 => '2037-2-15', 2038 => '2038-2-4', 2039 => '2039-1-24', 2040 => '2040-2-12', 2041 => '2041-2-1', 2042 => '2042-1-22', 2043 => '2043-2-10', 2044 => '2044-1-30', 2045 => '2045-2-17', 2046 => '2046-2-6', 2047 => '2047-1-26', 2048 => '2048-2-14', 2049 => '2049-2-2', 2050 => '2050-1-23', @@ -76,7 +79,7 @@ class SouthKorea extends AbstractProvider 1985 => '1985-5-27', 1986 => '1986-5-16', 1987 => '1987-5-5', 1988 => '1988-5-23', 1989 => '1989-5-12', 1990 => '1990-5-2', 1991 => '1991-5-21', 1992 => '1992-5-10', 1993 => '1993-5-28', 1994 => '1994-5-18', 1995 => '1995-5-7', 1996 => '1996-5-24', 1997 => '1997-5-14', 1998 => '1998-5-3', 1999 => '1999-5-22', - 2000 => '2000-5-11', 2001 => '2001-4-30', 2002 => '2002-5-19', 2003 => '2003-5-8', 2004 => '2004-5-26', + 2000 => '2000-5-11', 2001 => '2001-5-1', 2002 => '2002-5-19', 2003 => '2003-5-8', 2004 => '2004-5-26', 2005 => '2005-5-15', 2006 => '2006-5-5', 2007 => '2007-5-24', 2008 => '2008-5-12', 2009 => '2009-5-2', 2010 => '2010-5-21', 2011 => '2011-5-10', 2012 => '2012-5-28', 2013 => '2013-5-17', 2014 => '2014-5-6', 2015 => '2015-5-25', 2016 => '2016-5-14', 2017 => '2017-5-3', 2018 => '2018-5-22', 2019 => '2019-5-12', @@ -98,7 +101,7 @@ class SouthKorea extends AbstractProvider 1979 => '1979-10-5', 1980 => '1980-9-23', 1981 => '1981-9-12', 1982 => '1982-10-1', 1983 => '1983-9-21', 1984 => '1984-9-10', 1985 => '1985-9-29', 1986 => '1986-9-18', 1987 => '1987-10-7', 1988 => '1988-9-25', 1989 => '1989-9-14', 1990 => '1990-10-3', 1991 => '1991-9-22', 1992 => '1992-9-11', 1993 => '1993-9-30', - 1994 => '1994-9-20', 1995 => '1950-9-9', 1996 => '1996-9-27', 1997 => '1997-9-16', 1998 => '1998-10-5', + 1994 => '1994-9-20', 1995 => '1995-9-9', 1996 => '1996-9-27', 1997 => '1997-9-16', 1998 => '1998-10-5', 1999 => '1999-9-24', 2000 => '2000-9-12', 2001 => '2001-10-1', 2002 => '2002-9-21', 2003 => '2003-9-11', 2004 => '2004-9-28', 2005 => '2005-9-18', 2006 => '2006-10-6', 2007 => '2007-9-25', 2008 => '2008-9-14', 2009 => '2009-10-3', 2010 => '2010-9-22', 2011 => '2011-9-12', 2012 => '2012-9-30', 2013 => '2013-9-19', @@ -113,10 +116,93 @@ class SouthKorea extends AbstractProvider ], ]; + /** + * Collection of all historically recognized holidays in South Korea. + * + * Aggregated collection of all historically recognized holidays of South Korea After the government was established. + * This collection also includes items that are now obsolete and excluded from holidays. + */ + public const HOLIDAY_NAMES = [ + 'newYearsDay' => [], + 'dayAfterNewYearsDay' => [], + 'twoDaysLaterNewYearsDay' => [ + 'en' => 'Two Days Later New Year’s Day', + 'ko' => '새해 연휴', + ], + 'seollal' => [ + 'en' => 'Seollal', + 'ko' => '설날', + ], + 'dayBeforeSeollal' => [ + 'en' => 'Day before Seollal', + 'ko' => '설날 연휴', + ], + 'dayAfterSeollal' => [ + 'en' => 'Day after Seollal', + 'ko' => '설날 연휴', + ], + 'independenceMovementDay' => [ + 'en' => 'Independence Movement Day', + 'ko' => '삼일절', + ], + 'arborDay' => [ + 'en' => 'Arbor Day', + 'ko' => '식목일', + ], + 'buddhasBirthday' => [ + 'en' => 'Buddha’s Birthday', + 'ko' => '부처님오신날', + ], + 'childrensDay' => [ + 'en' => 'Children’s Day', + 'ko' => '어린이날', + ], + 'memorialDay' => [ + 'en' => 'Memorial Day', + 'ko' => '현충일', + ], + 'constitutionDay' => [ + 'en' => 'Constitution Day', + 'ko' => '제헌절', + ], + 'liberationDay' => [ + 'en' => 'Liberation Day', + 'ko' => '광복절', + ], + 'chuseok' => [ + 'en' => 'Chuseok', + 'ko' => '추석', + ], + 'dayBeforeChuseok' => [ + 'en' => 'Day before Chuseok', + 'ko' => '추석 연휴', + ], + 'dayAfterChuseok' => [ + 'en' => 'Day after Chuseok', + 'ko' => '추석 연휴', + ], + 'armedForcesDay' => [ + 'en' => 'Armed Forces Day', + 'ko' => '국군의 날', + ], + 'nationalFoundationDay' => [ + 'en' => 'National Foundation Day', + 'ko' => '개천절', + ], + 'hangulDay' => [ + 'en' => 'Hangul Day', + 'ko' => '한글날', + ], + 'unitedNationsDay' => [ + 'en' => 'United Nations Day', + 'ko' => '유엔의 날', + ], + 'christmasDay' => [], + ]; + /** * Initialize holidays for South Korea. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -125,117 +211,318 @@ public function initialize(): void { $this->timezone = 'Asia/Seoul'; - // Add common holidays - $this->calculateNewYearsDay(); - if ($this->year >= 1949) { - $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + // Fast-fail when before 1949 + if ($this->year < 1949) { + return; } - // Calculate lunar holidays - $this->calculateSeollal(); - $this->calculateBuddhasBirthday(); - $this->calculateChuseok(); - - // Calculate other holidays - $this->calculateIndependenceMovementDay(); - $this->calculateArborDay(); - $this->calculateChildrensDay(); - $this->calculateMemorialDay(); - $this->calculateConstitutionDay(); - $this->calculateLiberationDay(); - $this->calculateArmedForcesDay(); - $this->calculateNationalFoundationDay(); - $this->calculateHangulDay(); - $this->calculateSubstituteHolidays(); + $officialHolidays = $this->year < 2013 ? $this->calculateBefore2013($this->year) : $this->calculateCurrent(); + + foreach ($officialHolidays as $holiday) { + $this->addHoliday($this->{$holiday}($this->year, $this->timezone, $this->locale)); + } + + // Substitute Holidays + $this->calculateSubstituteHolidays($this->year); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_South_Korea', + 'https://ko.wikipedia.org/wiki/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%EC%9D%98_%EA%B3%B5%ED%9C%B4%EC%9D%BC', + 'https://english.visitkorea.or.kr/enu/TRV/TV_ENG_1_1.jsp', + ]; + } + + public function addHoliday(?Holiday $holiday): void + { + if (isset($holiday)) { + parent::addHoliday($holiday); + } } /** - * New Year's Day. New Year's Day is held on January 1st and established since 1950. - * From the enactment of the First Law to 1998, there was a two or three-day break in the New Year. + * The day after New Year's Day (January 2) + * This day was established in 1949 and then removed as a public holiday in 1999. + */ + protected function dayAfterNewYearsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'dayAfterNewYearsDay', + $this->getTranslations('dayAfterNewYearsDay', $year), + new \DateTime("{$year}-1-2", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Two days after the New Year's (January 3) + * This day was established in 1949 and then removed as a public holiday in 1990. + */ + protected function twoDaysLaterNewYearsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'twoDaysLaterNewYearsDay', + $this->getTranslations('twoDaysLaterNewYearsDay', $year), + new \DateTime("{$year}-1-3", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Seollal (Korean New Year's Day). + * Seollal is held on the 1st day of the 1st lunar month and was established from 1985. * - * @link https://en.wikipedia.org/wiki/New_Year%27s_Day#East_Asian + * Seollal was celebrated with only one day off when it was established in 1985, and then changed to a three-day holiday in 1989. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Korean_New_Year */ - public function calculateNewYearsDay(): void - { - if ($this->year >= 1950) { - $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); - if ($this->year <= 1998) { - $this->addHoliday(new Holiday( - 'dayAfterNewYearsDay', - [], - new DateTime("$this->year-1-2", new DateTimeZone($this->timezone)), - $this->locale - )); - } - if ($this->year <= 1990) { - $this->addHoliday(new Holiday( - 'twoDaysLaterNewYearsDay', - ['en' => 'Two Days Later New Year\'s Day', 'ko' => '새해 연휴'], - new DateTime("$this->year-1-3", new DateTimeZone($this->timezone)), - $this->locale - )); - } + protected function seollal( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { + return null; + } + + $seollal = self::LUNAR_HOLIDAY['seollal'][$year]; + + return new Holiday( + 'seollal', + $this->getTranslations('seollal', $year), + new \DateTime($seollal, DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * The day before Seollal (Korean New Year's Day). + * Seollal is held on the 1st day of the 1st lunar month and was established from 1985. + * + * Seollal was celebrated with only one day off when it was established in 1985, and then changed to a three-day holiday in 1989. + * + * @see https://en.wikipedia.org/wiki/Korean_New_Year + */ + protected function dayBeforeSeollal( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { + return null; } + + $seollal = self::LUNAR_HOLIDAY['seollal'][$year]; + + return new Holiday( + 'dayBeforeSeollal', + $this->getTranslations('dayBeforeSeollal', $year), + new \DateTime("-1 day {$seollal}", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Seollal (Korean New Year's Day). + * The day after Seollal (Korean New Year's Day). * Seollal is held on the 1st day of the 1st lunar month and was established from 1985. * - * @link https://en.wikipedia.org/wiki/Korean_New_Year + * Seollal was celebrated with only one day off when it was established in 1985, and then changed to a three-day holiday in 1989. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Korean_New_Year */ - public function calculateSeollal(): void - { - if ($this->year >= 1985 && isset(self::LUNAR_HOLIDAY['seollal'][$this->year])) { - $seollal = new DateTime(self::LUNAR_HOLIDAY['seollal'][$this->year], new DateTimeZone($this->timezone)); - $this->addHoliday(new Holiday( - 'seollal', - ['en' => 'Seollal', 'ko' => '설날'], - $seollal, - $this->locale - )); - if ($this->year > 1989) { - $dayBeforeSeollal = clone $seollal; - $dayBeforeSeollal->sub(new DateInterval('P1D')); - $this->addHoliday(new Holiday( - 'dayBeforeSeollal', - ['en' => 'Day before Seollal', 'ko' => '설날 연휴'], - $dayBeforeSeollal, - $this->locale - )); - $dayAfterSeollal = clone $seollal; - $dayAfterSeollal->add(new DateInterval('P1D')); - $this->addHoliday(new Holiday( - 'dayAfterSeollal', - ['en' => 'Day after Seollal', 'ko' => '설날 연휴'], - $dayAfterSeollal, - $this->locale - )); - } + protected function dayAfterSeollal( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { + return null; } + + $seollal = self::LUNAR_HOLIDAY['seollal'][$year]; + + return new Holiday( + 'dayAfterSeollal', + $this->getTranslations('dayAfterSeollal', $year), + new \DateTime("+1 day {$seollal}", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Buddha's Birthday is held on the 8th day of the 4th lunar month and was established since 1975. + * Independence Movement Day. + * Independence Movement Day is held on March 1st and was established from 1949. * - * @link https://en.wikipedia.org/wiki/Buddha%27s_Birthday + * @see https://en.wikipedia.org/wiki/Independence_Movement_Day + */ + protected function independenceMovementDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'independenceMovementDay', + $this->getTranslations('independenceMovementDay', $year), + new \DateTime("{$year}-3-1", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Sikmogil (Arbor Day). + * Sikmogil is held on April 5th and established since 1949, but was removed as a public holiday in 2006. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Sikmogil */ - public function calculateBuddhasBirthday(): void - { - if ($this->year >= 1975 && isset(self::LUNAR_HOLIDAY['buddhasBirthday'][$this->year])) { - $this->addHoliday(new Holiday( - 'buddhasBirthday', - ['en' => 'Buddha\'s Birthday', 'ko' => '부처님오신날'], - new DateTime(self::LUNAR_HOLIDAY['buddhasBirthday'][$this->year], new DateTimeZone($this->timezone)), - $this->locale - )); + protected function arborDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + $datetime = 1960 === $year ? "{$year}-3-21" : "{$year}-4-5"; + + return new Holiday( + 'arborDay', + $this->getTranslations('arborDay', $year), + new \DateTime($datetime, DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Buddha's Birthday. + * Buddha's Birthday is held on the 8th day of the 4th lunar month and was established since 1975. + * + * @see https://en.wikipedia.org/wiki/Buddha%27s_Birthday + */ + protected function buddhasBirthday( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['buddhasBirthday'][$year])) { + return null; } + + $buddhasBirthday = self::LUNAR_HOLIDAY['buddhasBirthday'][$year]; + + return new Holiday( + 'buddhasBirthday', + $this->getTranslations('buddhasBirthday', $year), + new \DateTime($buddhasBirthday, DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Children's Day. + * Children's Day is held on May 5th and established since 1975. + * + * @see https://en.wikipedia.org/wiki/Children%27s_Day#South_Korea + */ + protected function childrensDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'childrensDay', + $this->getTranslations('childrensDay', $year), + new \DateTime("{$year}-5-5", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Memorial Day. + * Memorial Day is held on June 6th and established since 1956. + * + * @see https://en.wikipedia.org/wiki/Memorial_Day_(South_Korea) + */ + protected function memorialDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'memorialDay', + $this->getTranslations('memorialDay', $year), + new \DateTime("{$year}-6-6", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Constitution Day. + * Constitution Day is held on July 17th and established since 1949. + * + * It was originally a public holiday recognized by the South Korean government, + * but was removed as a public holiday in 2008 and is now a national day rather than a public holiday. + * + * @see https://en.wikipedia.org/wiki/Constitution_Day_(South_Korea) + */ + protected function constitutionDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'constitutionDay', + $this->getTranslations('constitutionDay', $year), + new \DateTime("{$year}-7-17", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Liberation Day. + * Liberation Day is held on August 15th and established since 1949. + * + * @see https://en.wikipedia.org/wiki/National_Liberation_Day_of_Korea + */ + protected function liberationDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'liberationDay', + $this->getTranslations('liberationDay', $year), + new \DateTime("{$year}-8-15", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** @@ -243,281 +530,486 @@ public function calculateBuddhasBirthday(): void * * Chuseok, one of the biggest holidays in Korea, is a major harvest festival and a three-day holiday celebrated on * the 15th day of the 8th month of the lunar calendar on the full moon. + * Chuseok was a one-day holiday when it was established in 1945, but was changed to a three-day holiday in 1989. * - * @link https://en.wikipedia.org/wiki/Chuseok - * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Chuseok */ - public function calculateChuseok(): void - { - if ($this->year >= 1949 && isset(self::LUNAR_HOLIDAY['chuseok'][$this->year])) { - // Chuseok - $chuseok = new Holiday( - 'chuseok', - ['en' => 'Chuseok', 'ko' => '추석'], - new DateTime(self::LUNAR_HOLIDAY['chuseok'][$this->year], new DateTimeZone($this->timezone)), - $this->locale - ); - $this->addHoliday($chuseok); - - // Day after Chuseok - if ($this->year >= 1986) { - $this->addHoliday(new Holiday( - 'dayAfterChuseok', - ['en' => 'Day after Chuseok', 'ko' => '추석 연휴'], - (clone $chuseok)->add(new DateInterval('P1D')), - $this->locale - )); - } - - // Day before Chuseok - if ($this->year >= 1989) { - $this->addHoliday(new Holiday( - 'dayBeforeChuseok', - ['en' => 'Day before Chuseok', 'ko' => '추석 연휴'], - (clone $chuseok)->sub(new DateInterval('P1D')), - $this->locale - )); - } + protected function chuseok( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { + return null; } + + $choseok = self::LUNAR_HOLIDAY['chuseok'][$year]; + + return new Holiday( + 'chuseok', + $this->getTranslations('chuseok', $year), + new \DateTime($choseok, DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Independence Movement Day. Independence Movement Day is held on March 1st and was established from 1949. + * The day before Chuseok (Korean Thanksgiving Day). * - * @link https://en.wikipedia.org/wiki/Independence_Movement_Day + * Chuseok, one of the biggest holidays in Korea, is a major harvest festival and a three-day holiday celebrated on + * the 15th day of the 8th month of the lunar calendar on the full moon. + * Chuseok was a one-day holiday when it was established in 1945, but was changed to a three-day holiday in 1989. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Chuseok */ - public function calculateIndependenceMovementDay(): void - { - if ($this->year >= 1949) { - $this->addHoliday(new Holiday( - 'independenceMovementDay', - ['en' => 'Independence Movement Day', 'ko' => '삼일절'], - new DateTime("$this->year-3-1", new DateTimeZone($this->timezone)), - $this->locale - )); + protected function dayBeforeChuseok( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { + return null; } + + $choseok = self::LUNAR_HOLIDAY['chuseok'][$year]; + + return new Holiday( + 'dayBeforeChuseok', + $this->getTranslations('dayBeforeChuseok', $year), + new \DateTime("-1 day {$choseok}", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Sikmogil (Arbor Day). Sikmogil is held on May 5th and established since 1949. + * The day after Chuseok (Korean Thanksgiving Day). * - * @link https://en.wikipedia.org/wiki/Sikmogil + * Chuseok, one of the biggest holidays in Korea, is a major harvest festival and a three-day holiday celebrated on + * the 15th day of the 8th month of the lunar calendar on the full moon. + * Chuseok was a one-day holiday when it was established in 1945, but was changed to a three-day holiday in 1989. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Chuseok */ - public function calculateArborDay(): void - { - if (($this->year >= 1949 && $this->year < 1960) || ($this->year > 1960 && $this->year < 2006)) { - $this->addHoliday(new Holiday( - 'arborDay', - ['en' => 'Arbor Day', 'ko' => '식목일'], - new DateTime("$this->year-4-5", new DateTimeZone($this->timezone)), - $this->locale - )); + protected function dayAfterChuseok( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): ?Holiday { + if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { + return null; } + + $choseok = self::LUNAR_HOLIDAY['chuseok'][$year]; + + return new Holiday( + 'dayAfterChuseok', + $this->getTranslations('dayAfterChuseok', $year), + new \DateTime("+1 day {$choseok}", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Children's Day. Children's Day is held on May 5th and established since 1970. + * Armed Forces Day. + * Armed Forces Day is held on October 1st and established since 1956. * - * @link https://en.wikipedia.org/wiki/Children%27s_Day#South_Korea + * Armed Forces Day, established in 1956, was made a public holiday in 1976 and then removed again in 1991. * - * @throws \Exception + * @see unitedNationsDay + * @see https://en.wikipedia.org/wiki/Armed_Forces_Day_(South_Korea) */ - public function calculateChildrensDay(): void - { - if ($this->year >= 1970) { - $this->addHoliday(new Holiday( - 'childrensDay', - ['en' => 'Children\'s Day', 'ko' => '어린이날'], - new DateTime("$this->year-5-5", new DateTimeZone($this->timezone)), - $this->locale - )); - } + protected function armedForcesDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'armedForcesDay', + $this->getTranslations('armedForcesDay', $year), + new \DateTime("{$year}-10-1", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Gaecheonjeol (National Foundation Day). + * Gaecheonjeol is held on October 3rd and established since 1949. + * + * @see https://en.wikipedia.org/wiki/Gaecheonjeol + */ + protected function nationalFoundationDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'nationalFoundationDay', + $this->getTranslations('nationalFoundationDay', $year), + new \DateTime("{$year}-10-3", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Memorial Day. Memorial Day is held on June 6th and established since 1956. + * Hangul Day. + * Hangul Day is held on October 9th and established since 1949. * - * @link https://en.wikipedia.org/wiki/Memorial_Day_(South_Korea) + * Hangul Day, established in 1949, was removed as a public holiday in 1991 and included again in 2013. * - * @throws \Exception + * @see https://en.wikipedia.org/wiki/Hangul_Day */ - public function calculateMemorialDay(): void - { - if ($this->year >= 1966) { - $this->addHoliday(new Holiday( - 'memorialDay', - ['en' => 'Memorial Day', 'ko' => '현충일'], - new DateTime("$this->year-6-6", new DateTimeZone($this->timezone)), - $this->locale - )); - } + protected function hangulDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'hangulDay', + $this->getTranslations('hangulDay', $year), + new \DateTime("{$year}-10-9", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); } /** - * Constitution Day. + * United Nations Day. * - * Constitution Day is held on July 17th and established since 1949. - * Officially, it is a strict national holiday, but government offices and banks work normally after 2008. + * On September 18, 1950, the day of the formation of the United Nations, International United Nations Day was established as a public holiday. + * Later, on September 3, 1976, United Nations Day was removed as a public holiday and Armed Forces Day was established as a new public holiday. * - * @link https://en.wikipedia.org/wiki/Constitution_Day_(South_Korea) + * @see https://ko.wikipedia.org/wiki/%EC%9C%A0%EC%97%94%EC%9D%98_%EB%82%A0#%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD + */ + protected function unitedNationsDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL, + ): Holiday { + return new Holiday( + 'unitedNationsDay', + $this->getTranslations('unitedNationsDay', $year), + new \DateTime("{$year}-10-24", DateTimeZoneFactory::getDateTimeZone($timezone)), + $locale, + $type + ); + } + + /** + * Get holiday names for translation. * - * @throws \Exception + * @return array */ - public function calculateConstitutionDay(): void + protected function getTranslations(string $key, int $year): array { - if ($this->year >= 1949 && $this->year < 2008) { - $this->addHoliday(new Holiday( - 'constitutionDay', - ['en' => 'Constitution Day', 'ko' => '제헌절'], - new DateTime("$this->year-7-17", new DateTimeZone($this->timezone)), - $this->locale - )); + if ('arborDay' === $key && 1960 === $year) { + return ['en' => 'Arbor Day', 'ko' => '사방의 날']; } + + return self::HOLIDAY_NAMES[$key] ?? []; } /** - * Liberation Day. Liberation Day is held on August 15th and established since 1949. - * - * @link https://en.wikipedia.org/wiki/National_Liberation_Day_of_Korea + * Holidays in used from 1949 until 2012. * - * @throws \Exception + * @return array list of holidays */ - public function calculateLiberationDay(): void + protected function calculateBefore2013(int $year): array { - if ($this->year >= 1949) { - $this->addHoliday(new Holiday( - 'liberationDay', - ['en' => 'Liberation Day', 'ko' => '광복절'], - new DateTime("$this->year-8-15", new DateTimeZone($this->timezone)), - $this->locale - )); + $officialHolidays = []; + + if ($year >= 1949) { + $officialHolidays[] = 'independenceMovementDay'; + $officialHolidays[] = 'liberationDay'; + $officialHolidays[] = 'nationalFoundationDay'; + $officialHolidays[] = 'newYearsDay'; + $officialHolidays[] = 'chuseok'; + $officialHolidays[] = 'christmasDay'; + + if ($year >= 1950 && $year < 1976) { + $officialHolidays[] = 'unitedNationsDay'; + } + + if ($year >= 1956) { + $officialHolidays[] = 'memorialDay'; + } + + if ($year >= 1975) { + $officialHolidays[] = 'childrensDay'; + $officialHolidays[] = 'buddhasBirthday'; + } + + if ($year >= 1976 && $year <= 1990) { + $officialHolidays[] = 'armedForcesDay'; + } + + if ($year >= 1985) { + $officialHolidays[] = 'seollal'; + } + + if ($year >= 1986) { + $officialHolidays[] = 'dayAfterChuseok'; + } + + if ($year >= 1989) { + $officialHolidays[] = 'dayBeforeChuseok'; + $officialHolidays[] = 'dayBeforeSeollal'; + $officialHolidays[] = 'dayAfterSeollal'; + } + + if ($year <= 1989) { + $officialHolidays[] = 'twoDaysLaterNewYearsDay'; + } + + if ($year <= 1990 || $year > 2012) { + $officialHolidays[] = 'hangulDay'; + } + + if ($year <= 1998) { + $officialHolidays[] = 'dayAfterNewYearsDay'; + } + + if ($year <= 2005) { + $officialHolidays[] = 'arborDay'; + } + + if ($year < 2008) { + $officialHolidays[] = 'constitutionDay'; + } } + + return $officialHolidays; } /** - * Armed Forces Day. Armed Forces Day is held on October 1st and established since 1956. + * Holidays in use since 2013. * - * @link https://en.wikipedia.org/wiki/Armed_Forces_Day_(South_Korea) + * @return array list of holidays + */ + protected function calculateCurrent(): array + { + return [ + 'newYearsDay', + 'dayBeforeSeollal', + 'seollal', + 'dayAfterSeollal', + 'independenceMovementDay', + 'buddhasBirthday', + 'childrensDay', + 'memorialDay', + 'liberationDay', + 'dayBeforeChuseok', + 'chuseok', + 'dayAfterChuseok', + 'nationalFoundationDay', + 'hangulDay', + 'christmasDay', + ]; + } + + /** + * Substitute Holidays up to 2022. + * Related statutes: Article 3 Alternative Statutory Holidays of the Regulations on Holidays of Government Offices. + * + * Since 2014, it has been applied only on Seollal, Chuseok and Children's Day. + * Due to the lunar calendar, public holidays can overlap even if it's not a Sunday. + * When public holidays fall on each other, the first non-public holiday after the holiday becomes a public holiday. + * As an exception, Children's Day also applies on Saturday. + * + * Since new legislation about public holiday was enacted in June 2021, + * this function is used to calculate the holidays up to 2022. * * @throws \Exception */ - public function calculateArmedForcesDay(): void + protected function calculateOldSubstituteHolidays(int $year): void { - if ($this->year >= 1956 && $this->year <= 1990) { - $this->addHoliday(new Holiday( - 'armedForcesDay', - ['en' => 'Armed Forces Day', 'ko' => '국군의 날'], - new DateTime("$this->year-10-1", new DateTimeZone($this->timezone)), - $this->locale - )); + // Add substitute holidays by fixed entries. + switch ($year) { + case 1959: + $this->addSubstituteHoliday($this->getHoliday('arborDay'), "{$year}-4-6"); + break; + case 1960: + $this->addSubstituteHoliday($this->getHoliday('constitutionDay'), "{$year}-7-18"); + $this->addSubstituteHoliday($this->getHoliday('hangulDay'), "{$year}-10-10"); + $this->addSubstituteHoliday($this->getHoliday('christmasDay'), "{$year}-12-26"); + break; + case 1989: + $this->addSubstituteHoliday($this->getHoliday('armedForcesDay'), "{$year}-10-2"); + break; + case 2014: + $this->addSubstituteHoliday($this->getHoliday('dayBeforeChuseok'), "{$year}-9-10"); + break; + case 2015: + $this->addSubstituteHoliday($this->getHoliday('chuseok'), "{$year}-9-29"); + break; + case 2016: + $this->addSubstituteHoliday($this->getHoliday('dayBeforeSeollal'), "{$year}-2-10"); + break; + case 2017: + $this->addSubstituteHoliday($this->getHoliday('dayAfterSeollal'), "{$year}-1-30"); + $this->addSubstituteHoliday($this->getHoliday('dayBeforeChuseok'), "{$year}-10-6"); + break; + case 2018: + $this->addSubstituteHoliday($this->getHoliday('childrensDay'), "{$year}-5-7"); + $this->addSubstituteHoliday($this->getHoliday('dayBeforeChuseok'), "{$year}-9-26"); + break; + case 2019: + $this->addSubstituteHoliday($this->getHoliday('childrensDay'), "{$year}-5-6"); + break; + case 2020: + $this->addSubstituteHoliday($this->getHoliday('dayAfterSeollal'), "{$year}-1-27"); + break; + case 2021: + $this->addSubstituteHoliday($this->getHoliday('liberationDay'), "{$year}-8-16"); + $this->addSubstituteHoliday($this->getHoliday('nationalFoundationDay'), "{$year}-10-4"); + $this->addSubstituteHoliday($this->getHoliday('hangulDay'), "{$year}-10-11"); + break; + case 2022: + $this->addSubstituteHoliday($this->getHoliday('dayAfterChuseok'), "{$year}-9-12"); + $this->addSubstituteHoliday($this->getHoliday('hangulDay'), "{$year}-10-10"); + break; } } /** - * Gaecheonjeol (National Foundation Day). Gaecheonjeol is held on October 3rd and established since 1949. + * Substitute Holidays. * - * @link https://en.wikipedia.org/wiki/Gaecheonjeol + * Since 2022, it has been applied for all public holidays. + * When public holidays overlap on each other or weekend, + * the first working day after the holiday becomes a substitute holiday. * * @throws \Exception */ - public function calculateNationalFoundationDay(): void + protected function calculateSubstituteHolidays(int $year): void { - if ($this->year >= 1949) { - $this->addHoliday(new Holiday( - 'nationalFoundationDay', - ['en' => 'National Foundation Day', 'ko' => '개천절'], - new DateTime("$this->year-10-3", new DateTimeZone($this->timezone)), - $this->locale - )); + if ($year < 2023) { + $this->calculateOldSubstituteHolidays($year); + + return; + } + + // List of holidays allowed for substitution. + $acceptedHolidays = $this->calculateAcceptedSubstituteHolidays($year); + + // Step 1. Build a temporary table that aggregates holidays by date. + $dates = []; + foreach ($this->getHolidayDates() as $name => $day) { + $holiday = $this->getHoliday((string) $name); + $dates[$day][] = $name; + + if (! isset($acceptedHolidays[$name])) { + continue; + } + + if (! $holiday instanceof Holiday) { + continue; + } + + $dayOfWeek = (int) $holiday->format('w'); + if (\in_array($dayOfWeek, $acceptedHolidays[$name], true)) { + $dates[$day]['weekend:' . $day] = $name; + } + } + + // Step 2. Add substitute holidays by referring to the temporary table. + $tz = DateTimeZoneFactory::getDateTimeZone($this->timezone); + foreach ($dates as $day => $names) { + $count = \count($names); + if ($count < 2) { + continue; + } + + // In a temporary table, public holidays are keyed by numeric number. + // And weekends are keyed by string start with 'weekend:'. + // For the substitute, we will use first item in queue. + $origin = $this->getHoliday((string) $names[0]); + $nextWorkingDay = \DateTime::createFromFormat('Y-m-d', $day, $tz); + if ($nextWorkingDay instanceof \DateTime) { + $workDay = $this->nextWorkingDay($nextWorkingDay); + $this->addSubstituteHoliday($origin, $workDay->format('Y-m-d')); + } } } /** - * Hangul Day. Hangul Day is held on October 9th and established since 1949. - * - * @link https://en.wikipedia.org/wiki/Hangul_Day + * Return a dictionary of substitute holiday + * Government-recognized holidays will be replaced with an alternative holiday if they overlap with a Saturday or Sunday. + * This dictionary contains information about which day of the week the holiday is replaced when it falls on. * - * @throws \Exception + * @return array> */ - public function calculateHangulDay(): void + protected function calculateAcceptedSubstituteHolidays(int $year): array { - if (($this->year >= 1949 && $this->year <= 1990) || $this->year > 2012) { - $this->addHoliday(new Holiday( - 'hangulDay', - ['en' => 'Hangul Day', 'ko' => '한글날'], - new DateTime("$this->year-10-9", new DateTimeZone($this->timezone)), - $this->locale - )); + // List of holidays allowed for substitution. + // This dictionary has key => value mappings. + // each key is key of holiday and value contains day of week (saturday or sunday or both) + // value meaning : 0 = saturday, 1 = sunday + $acceptedHolidays = []; + + if ($year < 2023) { + return $acceptedHolidays; } + + // When deciding on alternative holidays, place lunar holidays first for consistent rules. + // These holidays will substitute for the sunday only. + $acceptedHolidays += array_fill_keys([ + 'dayBeforeSeollal', 'seollal', 'dayAfterSeollal', + 'dayBeforeChuseok', 'chuseok', 'dayAfterChuseok', + ], [0]); + + // These holidays will substitute for any weekend days (Sunday and Saturday). + // 'buddhasBirthday' and 'christmasDay' included as alternative holiday in May 2023. + $acceptedHolidays += array_fill_keys([ + 'childrensDay', 'independenceMovementDay', 'liberationDay', + 'nationalFoundationDay', 'hangulDay', 'buddhasBirthday', 'christmasDay', + ], [0, 6]); + + return $acceptedHolidays; } /** - * Substitute Holidays. - * related statutes: Article 3 Alternative Statutory Holidays of the Regulations on Holidays of Government Offices + * Helper method to find a first working day after specific date. + */ + protected function nextWorkingDay(\DateTime $date): \DateTime + { + $interval = new \DateInterval('P1D'); + $next = clone $date; + do { + $next->add($interval); + } while (! $this->isWorkingDay($next)); + + return $next; + } + + /** + * Helper method to add substitute holiday. * - * Since 2014, it has been applied only on Seollal, Chuseok and Children's Day. - * Due to the lunar calendar, public holidays can overlap even if it's not a Sunday. - * When public holidays fall each other, the first non-public holiday after the holiday become as a public holiday. - * As an exception, Children's Day also applies on Saturday. + * Add a substitute holiday from origin holiday to different date. * * @throws \Exception */ - public function calculateSubstituteHolidays(): void + protected function addSubstituteHoliday(?Holiday $origin, string $date_str): void { - if ($this->year > 2013) { - // Initialize holidays variable - $holidays = $this->getHolidays(); - $acceptedHolidays = [ - 'dayBeforeSeollal', 'seollal', 'dayAfterSeollal', - 'dayBeforeChuseok', 'chuseok', 'dayAfterChuseok', - 'childrensDay', - ]; - - // Loop through all holidays - foreach ($holidays as $shortName => $holiday) { - // Get list of holiday dates except this - $holidayDates = \array_map(static function ($holiday) use ($shortName) { - return $holiday->shortName === $shortName ? false : (string)$holiday; - }, $holidays); - - // Only process accepted holidays and conditions - if (\in_array($shortName, $acceptedHolidays, true) - && ( - 0 === (int)$holiday->format('w') - || \in_array($holiday, $holidayDates, false) - || (6 === (int)$holiday->format('w') && 'childrensDay' === $shortName) - ) - ) { - $date = clone $holiday; - - // Find next week day (not being another holiday) - while (0 === (int)$date->format('w') - || (6 === (int)$date->format('w') && 'childrensDay' === $shortName) - || \in_array($date, $holidayDates, false)) { - $date->add(new DateInterval('P1D')); - continue; - } - - // Add a new holiday that is substituting the original holiday - $substitute = new SubstituteHoliday( - $holiday, - [], - $date, - $this->locale - ); - - // Add a new holiday that is substituting the original holiday - $this->addHoliday($substitute); - - // Add substitute holiday to the list - $holidays[] = $substitute; - } - } + if (! $origin instanceof Holiday) { + return; } + + $this->addHoliday(new SubstituteHoliday( + $origin, + [], + new \DateTime($date_str, DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); } } diff --git a/src/Yasumi/Provider/Spain.php b/src/Yasumi/Provider/Spain.php old mode 100755 new mode 100644 index 5f235d330..f518c93f3 --- a/src/Yasumi/Provider/Spain.php +++ b/src/Yasumi/Provider/Spain.php @@ -1,20 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -23,10 +25,11 @@ */ class Spain extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES'; @@ -34,7 +37,6 @@ class Spain extends AbstractProvider /** * Initialize holidays for Spain. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -62,6 +64,13 @@ public function initialize(): void $this->calculateConstitutionDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Spain', + ]; + } + /** * National Day. * @@ -71,20 +80,22 @@ public function initialize(): void * Hispanidad, the international Hispanic community. On November 27, 1981, a royal decree established Día de la * Hispanidad as a national holiday. * - * @link https://en.wikipedia.org/wiki/Fiesta_Nacional_de_España + * @see https://en.wikipedia.org/wiki/Fiesta_Nacional_de_España * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalDay(): void + protected function calculateNationalDay(): void { if ($this->year >= 1981) { $this->addHoliday(new Holiday( 'nationalDay', - ['es' => 'Fiesta Nacional de España'], - new DateTime("$this->year-10-12", new DateTimeZone($this->timezone)), + [ + 'ca' => 'Festa Nacional d’Espanya', + 'es' => 'Fiesta Nacional de España', + ], + new \DateTime("{$this->year}-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -97,20 +108,22 @@ private function calculateNationalDay(): void * 1978. In this referendum, a new constitution was approved. This was an important step in Spain's transition to * becoming a constitutional monarchy and democracy. * - * @link https://www.timeanddate.com/holidays/spain/constitution-day + * @see https://www.timeanddate.com/holidays/spain/constitution-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateConstitutionDay(): void + protected function calculateConstitutionDay(): void { if ($this->year >= 1978) { $this->addHoliday(new Holiday( 'constitutionDay', - ['es' => 'Día de la Constitución'], - new DateTime("$this->year-12-6", new DateTimeZone($this->timezone)), + [ + 'ca' => 'Dia de la Constitució', + 'es' => 'Día de la Constitución', + ], + new \DateTime("{$this->year}-12-6", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Andalusia.php b/src/Yasumi/Provider/Spain/Andalusia.php old mode 100755 new mode 100644 index a83456f93..17a403891 --- a/src/Yasumi/Provider/Spain/Andalusia.php +++ b/src/Yasumi/Provider/Spain/Andalusia.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -27,14 +30,14 @@ * autonomous community is officially recognized as a nationality of Spain. The territory is divided into eight * provinces: Almería, Cádiz, Córdoba, Granada, Huelva, Jaén, Málaga and Seville. Its capital is the city of Seville. * - * @link https://en.wikipedia.org/wiki/Andalusia + * @see https://en.wikipedia.org/wiki/Andalusia */ class Andalusia extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-AN'; @@ -42,7 +45,6 @@ class Andalusia extends Spain /** * Initialize holidays for Andalusia (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -66,20 +68,19 @@ public function initialize(): void * for the statute that made Andalusia an autonomous community of Andalusia (Spain). The Day of Andalucía is not a * public holiday in the rest of Spain on February 28. * - * @link https://en.wikipedia.org/wiki/D%C3%ADa_de_Andaluc%C3%ADa + * @see https://en.wikipedia.org/wiki/D%C3%ADa_de_Andaluc%C3%ADa * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAndalusiaDay(): void + protected function calculateAndalusiaDay(): void { if ($this->year >= 1980) { $this->addHoliday(new Holiday( 'andalusiaDay', ['es' => 'Día de Andalucía'], - new DateTime("$this->year-2-28", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-2-28", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Aragon.php b/src/Yasumi/Provider/Spain/Aragon.php old mode 100755 new mode 100644 index 4456608a1..9bdc37a7e --- a/src/Yasumi/Provider/Spain/Aragon.php +++ b/src/Yasumi/Provider/Spain/Aragon.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -26,14 +30,14 @@ * Teruel. Its capital is Zaragoza (also called Saragossa in English). The current Statute of Autonomy declares Aragon a * nationality of Spain. * - * @link https://en.wikipedia.org/wiki/Aragon + * @see https://en.wikipedia.org/wiki/Aragon */ class Aragon extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-AR'; @@ -41,7 +45,6 @@ class Aragon extends Spain /** * Initialize holidays for Aragon (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Spain/Asturias.php b/src/Yasumi/Provider/Spain/Asturias.php old mode 100755 new mode 100644 index 463e0a4dc..4ad6440c7 --- a/src/Yasumi/Provider/Spain/Asturias.php +++ b/src/Yasumi/Provider/Spain/Asturias.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -28,14 +31,14 @@ * Middle Ages. Divided into eight comarcas (counties), the autonomous community of Asturias is bordered by Cantabria to * the east, by Castile and León to the south, by Galicia to the west, and by the Bay of Biscay to the north. * - * @link https://en.wikipedia.org/wiki/Asturias + * @see https://en.wikipedia.org/wiki/Asturias */ class Asturias extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-AS'; @@ -43,7 +46,6 @@ class Asturias extends Spain /** * Initialize holidays for Asturias (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,20 +70,19 @@ public function initialize(): void * June 28, 1984. This date was chosen as it is the day on which the birth of Mary is traditionally celebrated. * The public holiday was first observed on September 8, 1984. * - * @link https://www.timeanddate.com/holidays/spain/asturias-day + * @see https://www.timeanddate.com/holidays/spain/asturias-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAsturiasDay(): void + protected function calculateAsturiasDay(): void { if ($this->year >= 1984) { $this->addHoliday(new Holiday( 'asturiasDay', ['es' => 'Día de Asturias'], - new DateTime("$this->year-9-8", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-9-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/BalearicIslands.php b/src/Yasumi/Provider/Spain/BalearicIslands.php old mode 100755 new mode 100644 index dc6466a91..e485a6522 --- a/src/Yasumi/Provider/Spain/BalearicIslands.php +++ b/src/Yasumi/Provider/Spain/BalearicIslands.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -27,14 +30,14 @@ * Iberian Peninsula. The four largest islands are Majorca, Minorca, Ibiza and Formentera. There are many minor islands * and islets in close proximity to the larger islands, including Cabrera, Dragonera and S'Espalmador. * - * @link https://en.wikipedia.org/wiki/Balearic_Islands + * @see https://en.wikipedia.org/wiki/Balearic_Islands */ class BalearicIslands extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-IB'; @@ -42,7 +45,6 @@ class BalearicIslands extends Spain /** * Initialize holidays for Balearic Islands (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,20 +70,22 @@ public function initialize(): void * which are part of Spain, on March 1 each year. This date commemorates when the Balearic Islands' Statute of * Autonomy came into effect on March 1, 1983. * - * @link https://www.timeanddate.com/holidays/spain/the-balearic-islands-day + * @see https://www.timeanddate.com/holidays/spain/the-balearic-islands-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateBalearicIslandsDay(): void + protected function calculateBalearicIslandsDay(): void { if ($this->year >= 1983) { $this->addHoliday(new Holiday( 'balearicIslandsDay', - ['es' => 'Día de les Illes Balears'], - new DateTime("$this->year-3-1", new DateTimeZone($this->timezone)), + [ + 'ca' => 'Diada de les Illes Balears', + 'es' => 'Día de les Illes Balears', + ], + new \DateTime("{$this->year}-3-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/BasqueCountry.php b/src/Yasumi/Provider/Spain/BasqueCountry.php old mode 100755 new mode 100644 index 1db204f40..d71738890 --- a/src/Yasumi/Provider/Spain/BasqueCountry.php +++ b/src/Yasumi/Provider/Spain/BasqueCountry.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -26,14 +29,14 @@ * The Basque Country is an autonomous community of northern Spain. It includes the Basque provinces of Álava, Biscay * and Gipuzkoa, also called Historical Territories. * - * @link https://en.wikipedia.org/wiki/Basque_Country_(autonomous_community) + * @see https://en.wikipedia.org/wiki/Basque_Country_(autonomous_community) */ class BasqueCountry extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-PV'; @@ -41,7 +44,6 @@ class BasqueCountry extends Spain /** * Initialize holidays for Basque Country (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,22 +70,27 @@ public function initialize(): void * * In 2016, this holiday is replaced by the Day of the First Constitiution of the Basque Country. * - * @link https://www.officeholidays.com/holidays/day-of-the-basque-country + * @see https://www.officeholidays.com/holidays/day-of-the-basque-country * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateBasqueCountryDay(): void + protected function calculateBasqueCountryDay(): void { - if ($this->year >= 2011 && $this->year <= 2013) { - $this->addHoliday(new Holiday( - 'basqueCountryDay', - ['es' => 'Euskadi Eguna'], - new DateTime("$this->year-10-25", new DateTimeZone($this->timezone)), - $this->locale - )); + if ($this->year < 2011) { + return; } + + if ($this->year > 2013) { + return; + } + + $this->addHoliday(new Holiday( + 'basqueCountryDay', + ['es' => 'Euskadi Eguna'], + new \DateTime("{$this->year}-10-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); } } diff --git a/src/Yasumi/Provider/Spain/CanaryIslands.php b/src/Yasumi/Provider/Spain/CanaryIslands.php old mode 100755 new mode 100644 index 84a33d556..78cb1f343 --- a/src/Yasumi/Provider/Spain/CanaryIslands.php +++ b/src/Yasumi/Provider/Spain/CanaryIslands.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -28,14 +31,14 @@ * Spain's 17 autonomous communities and are among the outermost regions of the European Union proper. The main islands * are (from largest to smallest) Tenerife, Fuerteventura, Gran Canaria, Lanzarote, La Palma, La Gomera and El Hierro. * - * @link https://en.wikipedia.org/wiki/Canary_Islands + * @see https://en.wikipedia.org/wiki/Canary_Islands */ class CanaryIslands extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CN'; @@ -43,7 +46,6 @@ class CanaryIslands extends Spain /** * Initialize holidays for Canary Islands (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -67,20 +69,19 @@ public function initialize(): void * year. This event celebrates the islands' culture and people. It also marks the anniversary of the autonomous * Canary Islands Parliament's first session, which was on May 30, 1983. * - * @link https://www.timeanddate.com/holidays/spain/canaries-day + * @see https://www.timeanddate.com/holidays/spain/canaries-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCanaryIslandsDay(): void + protected function calculateCanaryIslandsDay(): void { if ($this->year >= 1984) { $this->addHoliday(new Holiday( 'canaryIslandsDay', ['es' => 'Día de las Canarias'], - new DateTime("$this->year-5-30", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Cantabria.php b/src/Yasumi/Provider/Spain/Cantabria.php old mode 100755 new mode 100644 index c7fd37b68..dbfa036a5 --- a/src/Yasumi/Provider/Spain/Cantabria.php +++ b/src/Yasumi/Provider/Spain/Cantabria.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -28,14 +31,14 @@ * (provinces of León, Palencia and Burgos), on the west by the Principality of Asturias, and on the north by the * Cantabrian Sea (Bay of Biscay). * - * @link https://en.wikipedia.org/wiki/Cantabria + * @see https://en.wikipedia.org/wiki/Cantabria */ class Cantabria extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CB'; @@ -43,7 +46,6 @@ class Cantabria extends Spain /** * Initialize holidays for Cantabria (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -71,20 +73,19 @@ public function initialize(): void * "Special Regional Interest" in 1983. Following the establishment of the autonomous community of Cantabria in * 1982, the event became known as the Day of Cantabria. * - * @link https://www.timeanddate.com/holidays/spain/cantabria-day + * @see https://www.timeanddate.com/holidays/spain/cantabria-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCantabriaDay(): void + protected function calculateCantabriaDay(): void { if ($this->year >= 1967) { $this->addHoliday(new Holiday( 'cantabriaDay', ['es' => 'Día de Cantabria'], - new DateTime("second sunday of august $this->year", new DateTimeZone($this->timezone)), + new \DateTime("second sunday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/CastileAndLeon.php b/src/Yasumi/Provider/Spain/CastileAndLeon.php old mode 100755 new mode 100644 index 2c9609b5c..d12b3f907 --- a/src/Yasumi/Provider/Spain/CastileAndLeon.php +++ b/src/Yasumi/Provider/Spain/CastileAndLeon.php @@ -1,24 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -29,14 +31,14 @@ * 910 of the Kingdom of Castile appears in 1230 and again in 1230. It is the largest autonomous community in Spain and * the third largest region of the European Union * - * @link https://en.wikipedia.org/wiki/Castile_and_León + * @see https://en.wikipedia.org/wiki/Castile_and_León */ class CastileAndLeon extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CL'; @@ -44,7 +46,6 @@ class CastileAndLeon extends Spain /** * Initialize holidays for Castile and León (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,20 +69,19 @@ public function initialize(): void * Comuneros were dealt a crushing defeat by the royalist forces of King Charles I in the Revolt of the Comuneros on * April 23, 1521. * - * @link https://en.wikipedia.org/wiki/Castile_and_León_Day + * @see https://en.wikipedia.org/wiki/Castile_and_León_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCastileAndLeonDay(): void + protected function calculateCastileAndLeonDay(): void { if ($this->year >= 1976) { $this->addHoliday(new Holiday( 'castileAndLeonDay', ['es' => 'Día de Castilla y León'], - new DateTime("$this->year-4-23", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-4-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/CastillaLaMancha.php b/src/Yasumi/Provider/Spain/CastillaLaMancha.php old mode 100755 new mode 100644 index d3bd12912..0a9dd8edb --- a/src/Yasumi/Provider/Spain/CastillaLaMancha.php +++ b/src/Yasumi/Provider/Spain/CastillaLaMancha.php @@ -1,24 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -29,14 +31,14 @@ * communities. Albacete is the largest and most populous city. Its capital city is Toledo, and its judicial capital * city is Albacete. * - * @link https://en.wikipedia.org/wiki/Castilla-La_Mancha + * @see https://en.wikipedia.org/wiki/Castilla-La_Mancha */ class CastillaLaMancha extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CM'; @@ -44,7 +46,6 @@ class CastillaLaMancha extends Spain /** * Initialize holidays for Castilla-La Mancha (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -71,20 +72,19 @@ public function initialize(): void * first time on May 31, 1983. The Day of Castilla-La Mancha was a public holiday for the first time on * May 31, 1984. * - * @link https://www.timeanddate.com/holidays/spain/castile-la-mancha-day + * @see https://www.timeanddate.com/holidays/spain/castile-la-mancha-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateCastillaLaManchaDay(): void + protected function calculateCastillaLaManchaDay(): void { if ($this->year >= 1984) { $this->addHoliday(new Holiday( 'castillaLaManchaDay', ['es' => 'Día de la Región Castilla-La Mancha'], - new DateTime("$this->year-5-31", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Catalonia.php b/src/Yasumi/Provider/Spain/Catalonia.php old mode 100755 new mode 100644 index b7cba08c7..007f1d191 --- a/src/Yasumi/Provider/Spain/Catalonia.php +++ b/src/Yasumi/Provider/Spain/Catalonia.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -30,14 +33,14 @@ * Catalonia is bordered by France and Andorra to the north, the Mediterranean Sea to the east, and the Spanish regions * of Aragon and the Valencian Community to west and south respectively. * - * @link https://en.wikipedia.org/wiki/Catalonia + * @see https://en.wikipedia.org/wiki/Catalonia */ class Catalonia extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CT'; @@ -45,7 +48,6 @@ class Catalonia extends Spain /** * Initialize holidays for Catalonia (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -71,20 +73,22 @@ public function initialize(): void * on 11 September 1886, was suppressed by the Franco dictatorship in 1939 and reinstated in 1980 by the autonomous * government of Catalonia, the Generalitat de Catalunya, upon its restoration after the Franco dictatorship. * - * @link https://en.wikipedia.org/wiki/National_Day_of_Catalonia + * @see https://en.wikipedia.org/wiki/National_Day_of_Catalonia * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalDayOfCatalonia(): void + protected function calculateNationalDayOfCatalonia(): void { if ($this->year >= 1886) { $this->addHoliday(new Holiday( 'nationalCataloniaDay', - ['es' => 'Diada Nacional de Catalunya'], - new DateTime("$this->year-9-11", new DateTimeZone($this->timezone)), + [ + 'ca' => 'Diada Nacional de Catalunya', + 'es' => 'Diada Nacional de Cataluña', + ], + new \DateTime("{$this->year}-9-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Ceuta.php b/src/Yasumi/Provider/Spain/Ceuta.php old mode 100755 new mode 100644 index 5c6c70bac..699dbb547 --- a/src/Yasumi/Provider/Spain/Ceuta.php +++ b/src/Yasumi/Provider/Spain/Ceuta.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -27,14 +30,14 @@ * Africa, sharing a western border with Morocco. Separated from the Iberian peninsula by the Strait of Gibraltar, Ceuta * lies along the boundary between the Mediterranean Sea and the Atlantic Ocean. * - * @link https://en.wikipedia.org/wiki/Ceuta + * @see https://en.wikipedia.org/wiki/Ceuta */ class Ceuta extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-CE'; @@ -42,7 +45,6 @@ class Ceuta extends Spain /** * Initialize holidays for Ceuta (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -65,20 +67,19 @@ public function initialize(): void * This local holiday marks the date when Pedro de Menezes (or Meneses), Count of Viana do Alentejo, took control of * the city from King John I of Portugal on September 2, 1415. * - * @link https://www.timeanddate.com/holidays/spain/the-independent-city-ceuta-day + * @see https://www.timeanddate.com/holidays/spain/the-independent-city-ceuta-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayOfCeuta(): void + protected function calculateDayOfCeuta(): void { if ($this->year >= 1416) { $this->addHoliday(new Holiday( 'ceutaDay', ['es' => 'Día de Ceuta'], - new DateTime("$this->year-9-2", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-9-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/CommunityOfMadrid.php b/src/Yasumi/Provider/Spain/CommunityOfMadrid.php old mode 100755 new mode 100644 index 699b35de3..aaa400e7d --- a/src/Yasumi/Provider/Spain/CommunityOfMadrid.php +++ b/src/Yasumi/Provider/Spain/CommunityOfMadrid.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -29,14 +32,14 @@ * city of Madrid, which is also the national capital of Spain. It is bounded to the south and east by Castile–La Mancha * and to the north and west by Castile and León. * - * @link https://en.wikipedia.org/wiki/Community_of_Madrid + * @see https://en.wikipedia.org/wiki/Community_of_Madrid */ class CommunityOfMadrid extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-MD'; @@ -44,7 +47,6 @@ class CommunityOfMadrid extends Spain /** * Initialize holidays for the Community Of Madrid (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -72,19 +74,18 @@ public function initialize(): void * Malasaña in memory of one of the heroines of the revolt, the teenager Manuela Malasaña, who was executed by * French troops in the aftermath of the revolt. * - * @link https://en.wikipedia.org/wiki/Dos_de_Mayo_Uprising + * @see https://en.wikipedia.org/wiki/Dos_de_Mayo_Uprising * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDosdeMayoUprisingDay(): void + protected function calculateDosdeMayoUprisingDay(): void { $this->addHoliday(new Holiday( 'dosdeMayoUprisingDay', ['es' => 'Fiesta de la Comunidad de Madrid'], - new DateTime("$this->year-5-2", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Extremadura.php b/src/Yasumi/Provider/Spain/Extremadura.php old mode 100755 new mode 100644 index 912778ccf..bd62e23da --- a/src/Yasumi/Provider/Spain/Extremadura.php +++ b/src/Yasumi/Provider/Spain/Extremadura.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -28,14 +31,14 @@ * Salamanca and Ávila); to the south, it borders Andalusia (provinces of Huelva, Seville, and Córdoba); and to the * east, it borders Castile–La Mancha (provinces of Toledo and Ciudad Real). * - * @link https://en.wikipedia.org/wiki/Extremadura + * @see https://en.wikipedia.org/wiki/Extremadura */ class Extremadura extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-EX'; @@ -43,7 +46,6 @@ class Extremadura extends Spain /** * Initialize holidays for Extremadura (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -68,20 +70,19 @@ public function initialize(): void * A law enacted on June 3, 1985, proclaimed September 8 to be a public holiday known as the Day of Extremadura. * The public holiday was first observed on September 8, 1985. * - * @link https://www.timeanddate.com/holidays/spain/extremadura-day + * @see https://www.timeanddate.com/holidays/spain/extremadura-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayOfExtremadura(): void + protected function calculateDayOfExtremadura(): void { if ($this->year >= 1985) { $this->addHoliday(new Holiday( 'extremaduraDay', ['es' => 'Día de Extremadura'], - new DateTime("$this->year-9-8", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-9-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Spain/Galicia.php b/src/Yasumi/Provider/Spain/Galicia.php old mode 100755 new mode 100644 index a03815983..314d44a72 --- a/src/Yasumi/Provider/Spain/Galicia.php +++ b/src/Yasumi/Provider/Spain/Galicia.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -28,14 +31,14 @@ * Spanish autonomous communities of Castile and León and Asturias to the east, and the Atlantic Ocean to the west and * the north. * - * @link https://en.wikipedia.org/wiki/Galicia_(Spain) + * @see https://en.wikipedia.org/wiki/Galicia_(Spain) */ class Galicia extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-GA'; @@ -43,7 +46,6 @@ class Galicia extends Spain /** * Initialize holidays for Galicia (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -69,20 +71,19 @@ public function initialize(): void * taken place on May 17 each year since 1963. In the year 1991 Galician Literature Day was declared a public * holiday in all Galicia. * - * @link https://en.wikipedia.org/wiki/Galician_Literature_Day + * @see https://en.wikipedia.org/wiki/Galician_Literature_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateGalicianLiteratureDay(): void + protected function calculateGalicianLiteratureDay(): void { if ($this->year >= 1991) { $this->addHoliday(new Holiday('galicianLiteratureDay', [ 'es' => 'Día de las Letras Gallegas', 'gl' => 'Día das Letras Galegas', - ], new DateTime("$this->year-5-17", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-5-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } @@ -97,19 +98,18 @@ private function calculateGalicianLiteratureDay(): void * Sunday. If July 25 falls on a Tuesday or Thursday, many businesses and organizations are also closed on Monday, * July 24, or Friday, July 26. In the rest of Spain, July 25 is not a public holiday. * - * @link https://www.timeanddate.com/holidays/spain/santiago-apostle + * @see https://www.timeanddate.com/holidays/spain/santiago-apostle * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStJamesDay(): void + protected function calculateStJamesDay(): void { if ($this->year >= 2000) { $this->addHoliday(new Holiday('stJamesDay', [ 'es' => 'Santiago Apostol', - ], new DateTime("$this->year-7-25", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-7-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } } diff --git a/src/Yasumi/Provider/Spain/LaRioja.php b/src/Yasumi/Provider/Spain/LaRioja.php old mode 100755 new mode 100644 index 488dcf66a..75b17f6ad --- a/src/Yasumi/Provider/Spain/LaRioja.php +++ b/src/Yasumi/Provider/Spain/LaRioja.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -27,14 +30,14 @@ * capital is Logroño. Other cities and towns in the province include Calahorra, Arnedo, Alfaro, Haro, Santo Domingo de * la Calzada, and Nájera. It has an estimated population of 322,415 inhabitants. * - * @link https://en.wikipedia.org/wiki/La_Rioja_(Spain) + * @see https://en.wikipedia.org/wiki/La_Rioja_(Spain) */ class LaRioja extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-RI'; @@ -42,7 +45,6 @@ class LaRioja extends Spain /** * Initialize holidays for La Rioja (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -65,19 +67,18 @@ public function initialize(): void * La Rioja, on June 9. It marks the anniversary of when the autonomous community of La Rioja's statute was approved * on June 9, 1982. The Day of La Rioja was first observed on June 9, 1983. * - * @link https://www.timeanddate.com/holidays/spain/rioja-day + * @see https://www.timeanddate.com/holidays/spain/rioja-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateLaRiojaDay(): void + protected function calculateLaRiojaDay(): void { if ($this->year >= 1983) { $this->addHoliday(new Holiday('laRiojaDay', [ 'es' => 'Día de La Rioja', - ], new DateTime("$this->year-6-9", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-6-9", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } } diff --git a/src/Yasumi/Provider/Spain/Melilla.php b/src/Yasumi/Provider/Spain/Melilla.php old mode 100755 new mode 100644 index 4584a0cb2..5bfb3fd9d --- a/src/Yasumi/Provider/Spain/Melilla.php +++ b/src/Yasumi/Provider/Spain/Melilla.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -25,14 +29,14 @@ * square kilometres (4.7 sq mi). Melilla, along with Ceuta, is one of two permanently inhabited Spanish cities in * mainland Africa. It was part of Málaga province until 14 March 1995, when the city's Statute of Autonomy was passed. * - * @link https://en.wikipedia.org/wiki/Melilla + * @see https://en.wikipedia.org/wiki/Melilla */ class Melilla extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-ML'; @@ -40,7 +44,6 @@ class Melilla extends Spain /** * Initialize holidays for Melilla (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Spain/Navarre.php b/src/Yasumi/Provider/Spain/Navarre.php old mode 100755 new mode 100644 index 1a1a8f4e2..b71c29ac8 --- a/src/Yasumi/Provider/Spain/Navarre.php +++ b/src/Yasumi/Provider/Spain/Navarre.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -25,14 +29,14 @@ * Basque Country, La Rioja, and Aragon in Spain and Aquitaine in France. The capital city is Pamplona (or Iruña in * Basque). * - * @link https://en.wikipedia.org/wiki/Navarre + * @see https://en.wikipedia.org/wiki/Navarre */ class Navarre extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-NC'; @@ -40,7 +44,6 @@ class Navarre extends Spain /** * Initialize holidays for Navarre (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Spain/RegionOfMurcia.php b/src/Yasumi/Provider/Spain/RegionOfMurcia.php old mode 100755 new mode 100644 index 2a79d2ebc..f33e92adb --- a/src/Yasumi/Provider/Spain/RegionOfMurcia.php +++ b/src/Yasumi/Provider/Spain/RegionOfMurcia.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -27,14 +30,14 @@ * Valencian Community, on the Mediterranean coast. The city of Murcia is the capital of the region and seat of * government organs, except for the parliament, the Regional Assembly of Murcia, which is located in Cartagena. * - * @link https://en.wikipedia.org/wiki/Region_of_Murcia + * @see https://en.wikipedia.org/wiki/Region_of_Murcia */ class RegionOfMurcia extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-MC'; @@ -42,7 +45,6 @@ class RegionOfMurcia extends Spain /** * Initialize holidays for the Region of Murcia (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -66,19 +68,18 @@ public function initialize(): void * community of Murcia, Spain, on June 9. It marks the anniversary of the approval of the statute of autonomy of * Murcia on June 9, 1982. The Day of the Region of Murcia was first celebrated on June 9, 1983. * - * @link https://www.timeanddate.com/holidays/spain/murcia-day + * @see https://www.timeanddate.com/holidays/spain/murcia-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDayOfMurcia(): void + protected function calculateDayOfMurcia(): void { if ($this->year >= 1983) { $this->addHoliday(new Holiday('murciaDay', [ 'es' => 'Día de la Región de Murcia', - ], new DateTime("$this->year-6-9", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-6-9", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } } diff --git a/src/Yasumi/Provider/Spain/ValencianCommunity.php b/src/Yasumi/Provider/Spain/ValencianCommunity.php old mode 100755 new mode 100644 index 24bc2566d..b20735dd1 --- a/src/Yasumi/Provider/Spain/ValencianCommunity.php +++ b/src/Yasumi/Provider/Spain/ValencianCommunity.php @@ -1,23 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Spain; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Spain; /** @@ -30,14 +33,14 @@ * Castile–La Mancha to the west, and Murcia to the south. It is formed by the provinces of Castelló, València and * Alacant. * - * @link https://en.wikipedia.org/wiki/Valencian_Community + * @see https://en.wikipedia.org/wiki/Valencian_Community */ class ValencianCommunity extends Spain { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'ES-VC'; @@ -45,7 +48,6 @@ class ValencianCommunity extends Spain /** * Initialize holidays for the Valencian Community (Spain). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -73,19 +75,24 @@ public function initialize(): void * autonomous communities of Catalonia, Aragon, Castile-La Mancha, and Mercia. The Balearic Islands are close by in * the Mediterranean. The Valencia region gained some autonomy in 1977 and full autonomy in 1982. * - * @link https://www.timeanddate.com/holidays/spain/the-valencian-community-day + * @see https://www.timeanddate.com/holidays/spain/the-valencian-community-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateValencianCommunityDay(): void + protected function calculateValencianCommunityDay(): void { if ($this->year >= 1239) { - $this->addHoliday(new Holiday('valencianCommunityDay', [ - 'es' => 'Día de la Comunidad Valenciana', - ], new DateTime("$this->year-10-9", new DateTimeZone($this->timezone)), $this->locale)); + $this->addHoliday(new Holiday( + 'valencianCommunityDay', + [ + 'ca' => 'Diada Nacional del País Valencià', + 'es' => 'Día de la Comunidad Valenciana', + ], + new \DateTime("{$this->year}-10-9", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); } } } diff --git a/src/Yasumi/Provider/Sweden.php b/src/Yasumi/Provider/Sweden.php index 6df730215..69200cce7 100644 --- a/src/Yasumi/Provider/Sweden.php +++ b/src/Yasumi/Provider/Sweden.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Sweden extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'SE'; @@ -35,7 +37,6 @@ class Sweden extends AbstractProvider /** * Initialize holidays for Sweden. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -69,6 +70,14 @@ public function initialize(): void $this->calculateNationalDay(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Sweden', + 'https://sv.wikipedia.org/wiki/Helgdagar_i_Sverige', + ]; + } + /** * Epiphany Eve. * @@ -78,25 +87,23 @@ public function initialize(): void * * Epiphany Eve is often treated with the afternoon off, but this varies depending on employer. * - * @link https://en.wikipedia.org/wiki/Twelfth_Night_(holiday) + * @see https://en.wikipedia.org/wiki/Twelfth_Night_(holiday) * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function calculateEpiphanyEve(): void + protected function calculateEpiphanyEve(): void { $this->addHoliday(new Holiday( 'epiphanyEve', [], - new DateTime("$this->year-1-5", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-1-5", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); } - /** * Walpurgis Night. * @@ -106,19 +113,18 @@ public function calculateEpiphanyEve(): void * * Walpurgis Night is often treated with the afternoon off, but this varies depending on employer. * - * @link https://en.wikipedia.org/wiki/Walpurgis_Night + * @see https://en.wikipedia.org/wiki/Walpurgis_Night * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception */ - public function calculateWalpurgisEve(): void + protected function calculateWalpurgisEve(): void { $this->addHoliday(new Holiday( 'walpurgisEve', [], - new DateTime("$this->year-4-30", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-4-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE )); @@ -136,16 +142,15 @@ public function calculateWalpurgisEve(): void * In Sweden the holiday has always been on a Saturday (between June 20 and June 26). Many of the celebrations of * midsummer take place on midsummer eve, when many workplaces are closed and shops must close their doors at noon. * - * @link https://en.wikipedia.org/wiki/Midsummer#Sweden + * @see https://en.wikipedia.org/wiki/Midsummer#Sweden * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStJohnsHolidays(): void + protected function calculateStJohnsHolidays(): void { - $date = new DateTime("$this->year-6-20 this saturday", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-6-20 this saturday", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday( 'stJohnsDay', [], @@ -153,7 +158,7 @@ private function calculateStJohnsHolidays(): void $this->locale )); - $date->sub(new DateInterval('P1D')); + $date->sub(new \DateInterval('P1D')); $this->addHoliday(new Holiday( 'stJohnsEve', [], @@ -176,17 +181,16 @@ private function calculateStJohnsHolidays(): void * the dead. In the Swedish calendar, the observance takes place on the Saturday between 31 October and 6 November. * In many Lutheran Churches, it is moved to the first Sunday of November. * - * @link https://en.wikipedia.org/wiki/All_Saints%27_Day - * @link https://www.timeanddate.com/holidays/sweden/all-saints-day + * @see https://en.wikipedia.org/wiki/All_Saints%27_Day + * @see https://www.timeanddate.com/holidays/sweden/all-saints-day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateAllSaintsHolidays(): void + protected function calculateAllSaintsHolidays(): void { - $date = new DateTime("$this->year-10-31 this saturday", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-10-31 this saturday", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday( 'allSaintsDay', [], @@ -194,7 +198,7 @@ private function calculateAllSaintsHolidays(): void $this->locale )); - $date->sub(new DateInterval('P1D')); + $date->sub(new \DateInterval('P1D')); $this->addHoliday(new Holiday( 'allSaintsEve', [], @@ -205,7 +209,7 @@ private function calculateAllSaintsHolidays(): void } /** - * National Day + * National Day. * * National Day of Sweden (Sveriges nationaldag) is a national holiday observed in Sweden on 6 June every year. * Prior to 1983, the day was celebrated as Svenska flaggans dag (Swedish flag day). At that time, the day was @@ -213,28 +217,27 @@ private function calculateAllSaintsHolidays(): void * Olympic Stadium, in honour of the election of King Gustav Vasa in 1523, as this was considered the foundation of * modern Sweden. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNationalDay(): void + protected function calculateNationalDay(): void { if ($this->year < 1916) { return; } - $holiday_name = 'Svenska flaggans dag'; + $holidayName = 'Svenska flaggans dag'; // Since 1983 this day was named 'Sveriges nationaldag' if ($this->year >= 1983) { - $holiday_name = 'Sveriges nationaldag'; + $holidayName = 'Sveriges nationaldag'; } $this->addHoliday(new Holiday( 'nationalDay', - ['sv' => $holiday_name], - new DateTime("$this->year-6-6", new DateTimeZone($this->timezone)), + ['sv' => $holidayName], + new \DateTime("{$this->year}-6-6", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Switzerland.php b/src/Yasumi/Provider/Switzerland.php index f0c0d268c..eeb294d5c 100644 --- a/src/Yasumi/Provider/Switzerland.php +++ b/src/Yasumi/Provider/Switzerland.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -24,10 +25,11 @@ */ class Switzerland extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH'; @@ -35,7 +37,6 @@ class Switzerland extends AbstractProvider /** * Initialize holidays for Switzerland. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -47,64 +48,29 @@ public function initialize(): void $this->calculateNationalDay(); } - /** - * Swiss National Day. - * - * The Swiss National Day is set on 1 August. It has been an official national holiday - * since 1994 only, although the day had been used for the celebration of the foundation - * of the Swiss Confederacy for the first time in 1891, and than repeated annually since 1899. - * - * @link https://en.wikipedia.org/wiki/Swiss_National_Day - * - * @throws InvalidDateException - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - * @throws \Exception - */ - private function calculateNationalDay(): void + public function getSources(): array { - $translations = [ - 'en' => 'National Day', - 'fr' => 'Jour de la fête nationale', - 'de' => 'Bundesfeiertag', - 'it' => 'Giorno festivo federale', - 'rm' => 'Fiasta naziunala', + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Switzerland', + 'https://fr.wikipedia.org/wiki/Jours_f%C3%A9ri%C3%A9s_en_Suisse', + 'https://it.wikipedia.org/wiki/Festivit%C3%A0_in_Svizzera', ]; - if ($this->year >= 1994) { - $this->addHoliday(new Holiday( - 'swissNationalDay', - $translations, - new DateTime($this->year . '-08-01', new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); - } elseif ($this->year >= 1899 || 1891 === $this->year) { - $this->addHoliday(new Holiday( - 'swissNationalDay', - $translations, - new DateTime($this->year . '-08-01', new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OBSERVANCE - )); - } } /** - * Berchtoldstag + * Berchtoldstag. * * Berchtoldstag is an Alemannic holiday, known in Switzerland and Liechtenstein. It is near * New Year's Day, during the Rauhnächte, in Switzerland nearly always on 2 January, * with the status of a public holiday in a number of cantons * - * @link https://en.wikipedia.org/wiki/Berchtoldstag + * @see https://en.wikipedia.org/wiki/Berchtoldstag * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - public function calculateBerchtoldsTag(): void + protected function calculateBerchtoldsTag(): void { $this->addHoliday(new Holiday( 'berchtoldsTag', @@ -113,34 +79,33 @@ public function calculateBerchtoldsTag(): void 'fr' => 'Jour de la Saint-Berthold', 'en' => 'Berchtoldstag', ], - new DateTime($this->year . '-01-02', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); } /** - * Federal Day of Thanksgiving, Repentance and Prayer + * Federal Day of Thanksgiving, Repentance and Prayer. * * The Federal Day of Thanksgiving, Repentance and Prayer is a public holiday in Switzerland. * It is an interfaith feast observed by Roman Catholic dioceses, the Old Catholic Church, * the Jewish congregations and the Reformed church bodies as well as other Christian denominations. * The subsequent Monday (Lundi du Jeûne) is a public holiday in the canton of Vaud and Neuchâtel. * - * @link https://en.wikipedia.org/wiki/Federal_Day_of_Thanksgiving,_Repentance_and_Prayer + * @see https://en.wikipedia.org/wiki/Federal_Day_of_Thanksgiving,_Repentance_and_Prayer * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - public function calculateBettagsMontag(): void + protected function calculateBettagsMontag(): void { if ($this->year >= 1832) { // Find third Sunday of September - $date = new DateTime('Third Sunday of ' . $this->year . '-09', new DateTimeZone($this->timezone)); + $date = new \DateTime("Third Sunday of {$this->year}-09", DateTimeZoneFactory::getDateTimeZone($this->timezone)); // Go to next Thursday - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); $this->addHoliday(new Holiday('bettagsMontag', [ 'fr' => 'Jeûne fédéral', @@ -149,4 +114,45 @@ public function calculateBettagsMontag(): void ], $date, $this->locale, Holiday::TYPE_OTHER)); } } + + /** + * Swiss National Day. + * + * The Swiss National Day is set on 1 August. It has been an official national holiday + * since 1994 only, although the day had been used for the celebration of the foundation + * of the Swiss Confederacy for the first time in 1891, and than repeated annually since 1899. + * + * @see https://en.wikipedia.org/wiki/Swiss_National_Day + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNationalDay(): void + { + $translations = [ + 'en' => 'National Day', + 'fr' => 'Jour de la fête nationale', + 'de' => 'Bundesfeiertag', + 'it' => 'Giorno festivo federale', + 'rm' => 'Fiasta naziunala', + ]; + if ($this->year >= 1994) { + $this->addHoliday(new Holiday( + 'swissNationalDay', + $translations, + new \DateTime("{$this->year}-08-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } elseif ($this->year >= 1899 || 1891 === $this->year) { + $this->addHoliday(new Holiday( + 'swissNationalDay', + $translations, + new \DateTime("{$this->year}-08-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } + } } diff --git a/src/Yasumi/Provider/Switzerland/Aargau.php b/src/Yasumi/Provider/Switzerland/Aargau.php index ae03c1812..6451b83f8 100644 --- a/src/Yasumi/Provider/Switzerland/Aargau.php +++ b/src/Yasumi/Provider/Switzerland/Aargau.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Aargau (Switzerland). * - * @link https://en.wikipedia.org/wiki/Aargau + * @see https://en.wikipedia.org/wiki/Aargau */ class Aargau extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-AG'; @@ -36,7 +40,6 @@ class Aargau extends Switzerland /** * Initialize holidays for Aargau (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/AppenzellAusserrhoden.php b/src/Yasumi/Provider/Switzerland/AppenzellAusserrhoden.php index cb43366eb..389f3c732 100644 --- a/src/Yasumi/Provider/Switzerland/AppenzellAusserrhoden.php +++ b/src/Yasumi/Provider/Switzerland/AppenzellAusserrhoden.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Appenzell Ausserrhoden (Switzerland). * - * @link https://en.wikipedia.org/wiki/Appenzell_Ausserrhoden + * @see https://en.wikipedia.org/wiki/Appenzell_Ausserrhoden */ class AppenzellAusserrhoden extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-AR'; @@ -36,7 +40,6 @@ class AppenzellAusserrhoden extends Switzerland /** * Initialize holidays for Appenzell Ausserrhoden (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/AppenzellInnerrhoden.php b/src/Yasumi/Provider/Switzerland/AppenzellInnerrhoden.php index fbcfe2fba..985e45bd6 100644 --- a/src/Yasumi/Provider/Switzerland/AppenzellInnerrhoden.php +++ b/src/Yasumi/Provider/Switzerland/AppenzellInnerrhoden.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Appenzell Innerrhoden (Switzerland). * - * @link https://en.wikipedia.org/wiki/Appenzell_Innerrhoden + * @see https://en.wikipedia.org/wiki/Appenzell_Innerrhoden */ class AppenzellInnerrhoden extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-AI'; @@ -36,7 +40,6 @@ class AppenzellInnerrhoden extends Switzerland /** * Initialize holidays for Appenzell Innerrhoden (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/BaselLandschaft.php b/src/Yasumi/Provider/Switzerland/BaselLandschaft.php index 749d287b8..b71ddabf0 100644 --- a/src/Yasumi/Provider/Switzerland/BaselLandschaft.php +++ b/src/Yasumi/Provider/Switzerland/BaselLandschaft.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Basel-Landschaft (Switzerland). * - * @link https://en.wikipedia.org/wiki/Basel-Landschaft + * @see https://en.wikipedia.org/wiki/Basel-Landschaft */ class BaselLandschaft extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-BL'; @@ -36,7 +40,6 @@ class BaselLandschaft extends Switzerland /** * Initialize holidays for Basel-Landschaft (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/BaselStadt.php b/src/Yasumi/Provider/Switzerland/BaselStadt.php index fe1c86e21..a4625d9b6 100644 --- a/src/Yasumi/Provider/Switzerland/BaselStadt.php +++ b/src/Yasumi/Provider/Switzerland/BaselStadt.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Basel-Stadt (Switzerland). * - * @link https://en.wikipedia.org/wiki/Basel-Stadt + * @see https://en.wikipedia.org/wiki/Basel-Stadt */ class BaselStadt extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-BS'; @@ -36,7 +40,6 @@ class BaselStadt extends Switzerland /** * Initialize holidays for Basel-Stadt (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Bern.php b/src/Yasumi/Provider/Switzerland/Bern.php index 26fd4ba0a..15bdd616a 100644 --- a/src/Yasumi/Provider/Switzerland/Bern.php +++ b/src/Yasumi/Provider/Switzerland/Bern.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,15 @@ /** * Provider for all holidays in Bern (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Bern + * @see https://en.wikipedia.org/wiki/Canton_of_Bern + * @see https://www.fin.be.ch/fin/fr/index/personal/personalrecht/wdb.thema.212.html */ class Bern extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-BE'; @@ -36,7 +41,6 @@ class Bern extends Switzerland /** * Initialize holidays for Bern (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Fribourg.php b/src/Yasumi/Provider/Switzerland/Fribourg.php index 0f76e6392..7a13979ad 100644 --- a/src/Yasumi/Provider/Switzerland/Fribourg.php +++ b/src/Yasumi/Provider/Switzerland/Fribourg.php @@ -1,34 +1,40 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Fribourg (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Fribourg + * @see https://en.wikipedia.org/wiki/Canton_of_Fribourg + * @see https://www.fr.ch/travail-et-entreprises/employes/jour-ferie-jour-chome-quelle-difference */ class Fribourg extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-FR'; @@ -36,7 +42,6 @@ class Fribourg extends Switzerland /** * Initialize holidays for Fribourg (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -45,11 +50,43 @@ public function initialize(): void { parent::initialize(); + // For the whole canton $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + + // For the roman catholic communes + $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + + // For the reformed evangelical communes $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->calculateBerchtoldsTag(); + $this->calculateDecember26th(); + } + + /** + * December 26th. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateDecember26th(): void + { + $this->addHoliday(new Holiday( + 'december26th', + [ + 'en' => 'December 26th', + 'fr' => '26 décembre', + ], + new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); } } diff --git a/src/Yasumi/Provider/Switzerland/Geneva.php b/src/Yasumi/Provider/Switzerland/Geneva.php index 0a4b08c9d..520b5621f 100644 --- a/src/Yasumi/Provider/Switzerland/Geneva.php +++ b/src/Yasumi/Provider/Switzerland/Geneva.php @@ -1,45 +1,49 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Geneva (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Geneva + * @see https://en.wikipedia.org/wiki/Canton_of_Geneva + * @see https://www.ge.ch/legislation/rsg/f/s/rsg_j1_45.html */ class Geneva extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-GE'; + public const JEUNE_GENEVOIS_ESTABLISHMENT_YEAR = 1840; + /** * Initialize holidays for Geneva (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -60,52 +64,53 @@ public function initialize(): void } /** - * Jeûne genevois + * Jeûne genevois. * * Jeûne genevois (meaning Genevan fast) is a public holiday in the canton of Geneva which occurs * on the Thursday following the first Sunday of September. It dates back to the 16th century. * - * @link https://en.wikipedia.org/wiki/Je%C3%BBne_genevois + * @see https://en.wikipedia.org/wiki/Je%C3%BBne_genevois * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateJeuneGenevois(): void + protected function calculateJeuneGenevois(): void { + if (self::JEUNE_GENEVOIS_ESTABLISHMENT_YEAR > $this->year) { + return; + } + // Find first Sunday of September - $date = new DateTime('First Sunday of ' . $this->year . '-09', new DateTimeZone($this->timezone)); + $date = new \DateTime("First Sunday of {$this->year}-09", DateTimeZoneFactory::getDateTimeZone($this->timezone)); // Go to next Thursday - $date->add(new DateInterval('P4D')); + $date->add(new \DateInterval('P4D')); - if (($this->year >= 1840 && $this->year <= 1869) || $this->year >= 1966) { - $this->addHoliday(new Holiday('jeuneGenevois', [ - 'fr' => 'Jeûne genevois', - ], $date, $this->locale, Holiday::TYPE_OTHER)); - } elseif ($this->year > 1869 && $this->year < 1966) { - $this->addHoliday(new Holiday('jeuneGenevois', [ - 'fr' => 'Jeûne genevois', - ], $date, $this->locale, Holiday::TYPE_OBSERVANCE)); + $type = Holiday::TYPE_OTHER; + if ($this->year > 1869 && $this->year < 1966) { + $type = Holiday::TYPE_OBSERVANCE; } + + $this->addHoliday(new Holiday('jeuneGenevois', [ + 'fr' => 'Jeûne genevois', + ], $date, $this->locale, $type)); } /** - * Restauration de la République + * Restauration de la République. * * On April 15, 1798, French troops entered Geneva; the annexation of the canton by France would * last more than fifteen years, until 1813. On December 30, 1813, the last of Napoleon’s troops * left Geneva, and the last French warden departed the next day. On December 31, 1813, the * Restoration of the Republic of Geneva was declared. * - * @link https://fr.wikipedia.org/wiki/Restauration_genevoise + * @see https://fr.wikipedia.org/wiki/Restauration_genevoise * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateRestaurationGenevoise(): void + protected function calculateRestaurationGenevoise(): void { if ($this->year > 1813) { $this->addHoliday(new Holiday( @@ -113,7 +118,7 @@ private function calculateRestaurationGenevoise(): void [ 'fr' => 'Restauration de la République', ], - new DateTime($this->year . '-12-31', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-12-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); diff --git a/src/Yasumi/Provider/Switzerland/Glarus.php b/src/Yasumi/Provider/Switzerland/Glarus.php index 15163b4b1..cb0a6648c 100644 --- a/src/Yasumi/Provider/Switzerland/Glarus.php +++ b/src/Yasumi/Provider/Switzerland/Glarus.php @@ -1,36 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Glarus (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Glarus + * @see https://en.wikipedia.org/wiki/Canton_of_Glarus */ class Glarus extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-GL'; @@ -38,7 +41,6 @@ class Glarus extends Switzerland /** * Initialize holidays for Glarus (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -61,23 +63,22 @@ public function initialize(): void } /** - * Näfelser Fahrt + * Näfelser Fahrt. * * The Battle of Näfels was fought on 9 April 1388 between Glarus with their allies, the Old Swiss * Confederation, and the Habsburgs. In 1389, the first Näfelser Fahrt, a pilgrimage to the site * of the battle was held. * - * @link https://en.wikipedia.org/wiki/Battle_of_N%C3%A4fels + * @see https://en.wikipedia.org/wiki/Battle_of_N%C3%A4fels * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateNafelserFahrt(): void + protected function calculateNafelserFahrt(): void { if ($this->year >= 1389) { - $date = new DateTime('First Thursday of ' . $this->year . '-04', new DateTimeZone($this->timezone)); + $date = new \DateTime("First Thursday of {$this->year}-04", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday('nafelserFahrt', [ 'de' => 'Näfelser Fahrt', ], $date, $this->locale, Holiday::TYPE_OTHER)); diff --git a/src/Yasumi/Provider/Switzerland/Grisons.php b/src/Yasumi/Provider/Switzerland/Grisons.php index f14f2f4fe..fcac20b1b 100644 --- a/src/Yasumi/Provider/Switzerland/Grisons.php +++ b/src/Yasumi/Provider/Switzerland/Grisons.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Grisons (Switzerland). * - * @link https://en.wikipedia.org/wiki/Grisons + * @see https://en.wikipedia.org/wiki/Grisons */ class Grisons extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-GR'; @@ -36,7 +40,6 @@ class Grisons extends Switzerland /** * Initialize holidays for Grisons (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Jura.php b/src/Yasumi/Provider/Switzerland/Jura.php index 0600f5e63..a95fc1b89 100644 --- a/src/Yasumi/Provider/Switzerland/Jura.php +++ b/src/Yasumi/Provider/Switzerland/Jura.php @@ -1,36 +1,40 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Jura (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Jura + * @see https://en.wikipedia.org/wiki/Canton_of_Jura + * @see https://rsju.jura.ch/fr/viewdocument.html?idn=20105&id=26766 */ class Jura extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-JU'; @@ -38,7 +42,6 @@ class Jura extends Switzerland /** * Initialize holidays for Jura (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -60,24 +63,26 @@ public function initialize(): void $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); + $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->calculateBerchtoldsTag(); $this->calculatePlebisciteJurassien(); + $this->calculateBettagsMontag(); } /** - * Plébiscite jurassien + * Plébiscite jurassien. * - * @link https://fr.wikipedia.org/wiki/Pl%C3%A9biscite_jurassien + * @see https://fr.wikipedia.org/wiki/Pl%C3%A9biscite_jurassien * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculatePlebisciteJurassien(): void + protected function calculatePlebisciteJurassien(): void { if ($this->year > 1974) { $this->addHoliday(new Holiday( @@ -85,7 +90,7 @@ private function calculatePlebisciteJurassien(): void [ 'fr' => 'Commémoration du plébiscite jurassien', ], - new DateTime($this->year . '-06-23', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-06-23", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); diff --git a/src/Yasumi/Provider/Switzerland/Lucerne.php b/src/Yasumi/Provider/Switzerland/Lucerne.php index 36d283e2e..fe9903b2b 100644 --- a/src/Yasumi/Provider/Switzerland/Lucerne.php +++ b/src/Yasumi/Provider/Switzerland/Lucerne.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Lucerne (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Lucerne + * @see https://en.wikipedia.org/wiki/Canton_of_Lucerne */ class Lucerne extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-LU'; @@ -36,7 +40,6 @@ class Lucerne extends Switzerland /** * Initialize holidays for Lucerne (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Neuchatel.php b/src/Yasumi/Provider/Switzerland/Neuchatel.php index 2c5e85342..d3ed66410 100644 --- a/src/Yasumi/Provider/Switzerland/Neuchatel.php +++ b/src/Yasumi/Provider/Switzerland/Neuchatel.php @@ -1,36 +1,41 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Neuchâtel (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Neuch%C3%A2tel + * @see https://en.wikipedia.org/wiki/Canton_of_Neuch%C3%A2tel + * @see http://rsn.ne.ch/DATA/program/books/RSN2017/20171/htm/94102.htm + * @see https://www.ne.ch/themes/travail/Pages/jours-feries.aspx */ class Neuchatel extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-NE'; @@ -38,7 +43,6 @@ class Neuchatel extends Switzerland /** * Initialize holidays for Neuchâtel (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -54,28 +58,38 @@ public function initialize(): void $this->locale, Holiday::TYPE_OTHER )); - $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); - $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); - $this->calculateBerchtoldsTag(); $this->calculateBettagsMontag(); $this->calculateInstaurationRepublique(); + + $newYearsDay = $this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER); + $this->addHoliday($newYearsDay); + if ('7' === $newYearsDay->format('N')) { + // If the New Year's Day is a sunday, the next day is an holiday + $this->calculateJanuary2nd(); + } + + $christmasDay = $this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER); + $this->addHoliday($christmasDay); + if ('7' === $christmasDay->format('N')) { + // If the Christmas Day is a sunday, the next day is an holiday + $this->calculateDecember26th(); + } } /** - * Instauration de la République + * Instauration de la République. * - * @link https://www.feiertagskalender.ch/feiertag.php?ft_id=11&geo=3056&hl=fr + * @see https://www.feiertagskalender.ch/feiertag.php?ft_id=11&geo=3056&hl=fr * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateInstaurationRepublique(): void + protected function calculateInstaurationRepublique(): void { if ($this->year > 1848) { $this->addHoliday(new Holiday( @@ -83,10 +97,52 @@ private function calculateInstaurationRepublique(): void [ 'fr' => 'Instauration de la République', ], - new DateTime($this->year . '-03-01', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-03-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); } } + + /** + * January 2nd. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateJanuary2nd(): void + { + $this->addHoliday(new Holiday( + 'january2nd', + [ + 'en' => 'January 2nd', + 'fr' => '2 janvier', + ], + new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + } + + /** + * December 26th. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateDecember26th(): void + { + $this->addHoliday(new Holiday( + 'december26th', + [ + 'en' => 'December 26th', + 'fr' => '26 décembre', + ], + new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OTHER + )); + } } diff --git a/src/Yasumi/Provider/Switzerland/Nidwalden.php b/src/Yasumi/Provider/Switzerland/Nidwalden.php index cef28e01d..19f3ec3a9 100644 --- a/src/Yasumi/Provider/Switzerland/Nidwalden.php +++ b/src/Yasumi/Provider/Switzerland/Nidwalden.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Nidwalden (Switzerland). * - * @link https://en.wikipedia.org/wiki/Nidwalden + * @see https://en.wikipedia.org/wiki/Nidwalden */ class Nidwalden extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-NW'; @@ -36,7 +40,6 @@ class Nidwalden extends Switzerland /** * Initialize holidays for Nidwalden (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Obwalden.php b/src/Yasumi/Provider/Switzerland/Obwalden.php index 32ed25a09..764236ea2 100644 --- a/src/Yasumi/Provider/Switzerland/Obwalden.php +++ b/src/Yasumi/Provider/Switzerland/Obwalden.php @@ -1,36 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Obwalden (Switzerland). * - * @link https://en.wikipedia.org/wiki/Obwalden + * @see https://en.wikipedia.org/wiki/Obwalden */ class Obwalden extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-OW'; @@ -38,7 +41,6 @@ class Obwalden extends Switzerland /** * Initialize holidays for Obwalden (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -69,17 +71,15 @@ public function initialize(): void } /** - * Bruder-Klausen-Fest + * Bruder-Klausen-Fest. * - * @link http://www.lebendigetraditionen.ch/traditionen/00210/index.html?lang=en + * @see http://www.lebendigetraditionen.ch/traditionen/00210/index.html?lang=en * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateBruderKlausenFest(): void + protected function calculateBruderKlausenFest(): void { if ($this->year >= 1947) { $this->addHoliday(new Holiday( @@ -87,7 +87,7 @@ private function calculateBruderKlausenFest(): void [ 'de' => 'Bruder-Klausen-Fest', ], - new DateTime($this->year . '-09-25', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-09-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); @@ -97,7 +97,7 @@ private function calculateBruderKlausenFest(): void [ 'de' => 'Bruder-Klausen-Fest', ], - new DateTime($this->year . '-09-21', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-09-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); diff --git a/src/Yasumi/Provider/Switzerland/Schaffhausen.php b/src/Yasumi/Provider/Switzerland/Schaffhausen.php index 211e25a0e..be7604f23 100644 --- a/src/Yasumi/Provider/Switzerland/Schaffhausen.php +++ b/src/Yasumi/Provider/Switzerland/Schaffhausen.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Schaffhausen (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Schaffhausen + * @see https://en.wikipedia.org/wiki/Canton_of_Schaffhausen */ class Schaffhausen extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-SH'; @@ -36,7 +40,6 @@ class Schaffhausen extends Switzerland /** * Initialize holidays for Schaffhausen (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Schwyz.php b/src/Yasumi/Provider/Switzerland/Schwyz.php index 3e51df020..f53887051 100644 --- a/src/Yasumi/Provider/Switzerland/Schwyz.php +++ b/src/Yasumi/Provider/Switzerland/Schwyz.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Schwyz (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Schwyz + * @see https://en.wikipedia.org/wiki/Canton_of_Schwyz */ class Schwyz extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-SZ'; @@ -36,7 +40,6 @@ class Schwyz extends Switzerland /** * Initialize holidays for Schwyz (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Solothurn.php b/src/Yasumi/Provider/Switzerland/Solothurn.php index 37bacf45c..7c5591ad7 100644 --- a/src/Yasumi/Provider/Switzerland/Solothurn.php +++ b/src/Yasumi/Provider/Switzerland/Solothurn.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Solothurn (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Solothurn + * @see https://en.wikipedia.org/wiki/Canton_of_Solothurn */ class Solothurn extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-SO'; @@ -36,7 +40,6 @@ class Solothurn extends Switzerland /** * Initialize holidays for Solothurn (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/StGallen.php b/src/Yasumi/Provider/Switzerland/StGallen.php index 9ba88bf8a..08640cba7 100644 --- a/src/Yasumi/Provider/Switzerland/StGallen.php +++ b/src/Yasumi/Provider/Switzerland/StGallen.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in St. Gallen (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_St._Gallen + * @see https://en.wikipedia.org/wiki/Canton_of_St._Gallen */ class StGallen extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-SG'; @@ -36,7 +40,6 @@ class StGallen extends Switzerland /** * Initialize holidays for St. Gallen (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Thurgau.php b/src/Yasumi/Provider/Switzerland/Thurgau.php index d66fb453c..99c3b3fac 100644 --- a/src/Yasumi/Provider/Switzerland/Thurgau.php +++ b/src/Yasumi/Provider/Switzerland/Thurgau.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Thurgau (Switzerland). * - * @link https://en.wikipedia.org/wiki/Thurgau + * @see https://en.wikipedia.org/wiki/Thurgau */ class Thurgau extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-TG'; @@ -36,7 +40,6 @@ class Thurgau extends Switzerland /** * Initialize holidays for Thurgau (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Ticino.php b/src/Yasumi/Provider/Switzerland/Ticino.php index 57c92c0d2..f8f72334b 100644 --- a/src/Yasumi/Provider/Switzerland/Ticino.php +++ b/src/Yasumi/Provider/Switzerland/Ticino.php @@ -1,36 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\Switzerland; /** * Provider for all holidays in Ticino (Switzerland). * - * @link https://en.wikipedia.org/wiki/Ticino + * @see https://en.wikipedia.org/wiki/Ticino */ class Ticino extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-TI'; @@ -38,7 +41,6 @@ class Ticino extends Switzerland /** * Initialize holidays for Ticino (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -75,16 +77,15 @@ public function initialize(): void } /** - * Feast of Saints Peter and Paul + * Feast of Saints Peter and Paul. * - * @link https://en.wikipedia.org/wiki/Feast_of_Saints_Peter_and_Paul + * @see https://en.wikipedia.org/wiki/Feast_of_Saints_Peter_and_Paul * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateStPeterPaul(): void + protected function calculateStPeterPaul(): void { $this->addHoliday(new Holiday( 'stPeterPaul', @@ -94,7 +95,7 @@ private function calculateStPeterPaul(): void 'fr' => 'Solennité des saints Pierre et Paul', 'de' => 'St. Peter und Paul', ], - new DateTime($this->year . '-06-29', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-06-29", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OTHER )); diff --git a/src/Yasumi/Provider/Switzerland/Uri.php b/src/Yasumi/Provider/Switzerland/Uri.php index 3758f1f5a..6548d2bb7 100644 --- a/src/Yasumi/Provider/Switzerland/Uri.php +++ b/src/Yasumi/Provider/Switzerland/Uri.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Uri (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Uri + * @see https://en.wikipedia.org/wiki/Canton_of_Uri */ class Uri extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-UR'; @@ -36,7 +40,6 @@ class Uri extends Switzerland /** * Initialize holidays for Uri (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Valais.php b/src/Yasumi/Provider/Switzerland/Valais.php index f000a49ff..ab2c3f12a 100644 --- a/src/Yasumi/Provider/Switzerland/Valais.php +++ b/src/Yasumi/Provider/Switzerland/Valais.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,15 @@ /** * Provider for all holidays in Valais (Switzerland). * - * @link https://en.wikipedia.org/wiki/Valais + * @see https://en.wikipedia.org/wiki/Valais + * @see https://www.vs.ch/web/spt/jours-feries */ class Valais extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-VS'; @@ -36,7 +41,6 @@ class Valais extends Switzerland /** * Initialize holidays for Valais (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Vaud.php b/src/Yasumi/Provider/Switzerland/Vaud.php index cecbd1552..04339a210 100644 --- a/src/Yasumi/Provider/Switzerland/Vaud.php +++ b/src/Yasumi/Provider/Switzerland/Vaud.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,15 @@ /** * Provider for all holidays in Vaud (Switzerland). * - * @link https://en.wikipedia.org/wiki/Vaud + * @see https://en.wikipedia.org/wiki/Vaud + * @see https://www.vd.ch/themes/formation/jours-feries-et-vacances-scolaires/ */ class Vaud extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-VD'; @@ -36,7 +41,6 @@ class Vaud extends Switzerland /** * Initialize holidays for Vaud (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Zug.php b/src/Yasumi/Provider/Switzerland/Zug.php index 001fafaa5..b645bf13f 100644 --- a/src/Yasumi/Provider/Switzerland/Zug.php +++ b/src/Yasumi/Provider/Switzerland/Zug.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,14 @@ /** * Provider for all holidays in Zug (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Zug + * @see https://en.wikipedia.org/wiki/Canton_of_Zug */ class Zug extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-ZG'; @@ -36,7 +40,6 @@ class Zug extends Switzerland /** * Initialize holidays for Zug (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception diff --git a/src/Yasumi/Provider/Switzerland/Zurich.php b/src/Yasumi/Provider/Switzerland/Zurich.php index f3f733b2b..a7e8a59bd 100644 --- a/src/Yasumi/Provider/Switzerland/Zurich.php +++ b/src/Yasumi/Provider/Switzerland/Zurich.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\Switzerland; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; @@ -21,14 +25,15 @@ /** * Provider for all holidays in Zürich (Switzerland). * - * @link https://en.wikipedia.org/wiki/Canton_of_Z%C3%BCrich + * @see https://en.wikipedia.org/wiki/Canton_of_Z%C3%BCrich + * @see https://www.zh.ch/de/wirtschaft-arbeit/arbeitsbedingungen/arbeitsssicherheit-gesundheitsschutz/arbeits-ruhezeiten/feiertage.html */ class Zurich extends Switzerland { use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'CH-ZH'; @@ -36,7 +41,6 @@ class Zurich extends Switzerland /** * Initialize holidays for Zürich (Switzerland). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -58,7 +62,5 @@ public function initialize(): void $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER)); - - $this->calculateBerchtoldsTag(); } } diff --git a/src/Yasumi/Provider/Turkey.php b/src/Yasumi/Provider/Turkey.php new file mode 100644 index 000000000..0bdc455f5 --- /dev/null +++ b/src/Yasumi/Provider/Turkey.php @@ -0,0 +1,187 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Note: Any Islamic holidays are not part of this provider yet. Islamic holidays are quite complex and at first, + * only other holidays are implemented. + */ +class Turkey extends AbstractProvider +{ + use CommonHolidays; + + /** {@inheritdoc} */ + public const ID = 'TR'; + + /** + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'Europe/Istanbul'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addNationalSovereigntyDay(); + $this->addLabourDay(); + $this->addCommemorationOfAtaturk(); + $this->addDemocracyDay(); + $this->addVictoryDay(); + $this->addRepublicDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Turkey', + 'https://tr.wikipedia.org/wiki/T%C3%BCrkiye%27deki_resm%C3%AE_tatiller', + ]; + } + + /** + * @throws \Exception + */ + protected function addLabourDay(): void + { + $this->addHoliday(new Holiday('labourDay', [ + 'tr' => 'Emek ve Dayanışma Günü', + ], new \DateTime("{$this->year}-05-01", new \DateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Commemoration of the first opening of the Grand National Assembly of Turkey at Ankara in 1920. + * Dedicated to the children. + * + * Not sure if 1920 is the first year of celebration as above source mentions Law No. 3466 that "May 19" was + * made official June 20, 1938. + * + * @see https://en.wikipedia.org/wiki/Commemoration_of_Atat%C3%BCrk,_Youth_and_Sports_Day + * + * @throws \Exception + */ + protected function addCommemorationOfAtaturk(): void + { + if (1920 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('commemorationAtaturk', [ + 'tr' => 'Atatürk’ü Anma, Gençlik ve Spor Bayramı', + ], new \DateTime("{$this->year}-05-19", new \DateTimeZone($this->timezone)), $this->locale)); + } + + /** + * National Sovereignty and Children's Day (Turkish: Ulusal Egemenlik ve Çocuk Bayramı) is a public holiday in + * Turkey commemorating the foundation of the Grand National Assembly of Turkey, on 23 April 1920. + * Since 1927, the holiday has also been celebrated as a children's day. + * + * @see https://en.wikipedia.org/wiki/National_Sovereignty_and_Children%27s_Day + * + * @throws \Exception + */ + protected function addNationalSovereigntyDay(): void + { + if (1922 > $this->year) { + return; + } + + $holidayName = 'Ulusal Egemenlik Bayramı'; + + // In 1981 this day was officially named 'Ulusal Egemenlik ve Çocuk Bayramı' + if (1981 <= $this->year) { + $holidayName = 'Ulusal Egemenlik ve Çocuk Bayramı'; + } + + $this->addHoliday(new Holiday('nationalSovereigntyDay', [ + 'tr' => $holidayName, + ], new \DateTime("{$this->year}-04-23", new \DateTimeZone($this->timezone)), $this->locale)); + } + + /** + * The Democracy and National Unity Day of Turkey (Turkish: Demokrasi ve Milli Birlik Günü) is one of the public + * holidays in Turkey, commemorating the national unity against the coup d'état attempt for democracy in 2016. + * + * @see https://en.wikipedia.org/wiki/Democracy_and_National_Unity_Day + * + * @throws \Exception + */ + protected function addDemocracyDay(): void + { + if (2017 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('democracyDay', [ + 'tr' => 'Demokrasi ve Millî Birlik Günü', + ], new \DateTime("{$this->year}-07-15", new \DateTimeZone($this->timezone)), $this->locale)); + } + + /** + * Victory Day (Turkish: Zafer Bayramı), also known as Turkish Armed Forces Day, is a public holiday in Turkey + * commemorating the decisive victory in the Battle of Dumlupınar, on 30 August 1922. + * + * @see https://en.wikipedia.org/wiki/Victory_Day_(Turkey) + * + * @throws \Exception + */ + protected function addVictoryDay(): void + { + if (1923 > $this->year) { + return; + } + + $holidayType = Holiday::TYPE_OFFICIAL; + + // Victory Day has been celebrated as an official holiday since 1926, and was first celebrated on 30 August + // 1923. + if (1923 <= $this->year && 1926 > $this->year) { + $holidayType = Holiday::TYPE_OBSERVANCE; + } + + $this->addHoliday(new Holiday('victoryDay', [ + 'tr' => 'Zafer Bayramı', + ], new \DateTime("{$this->year}-08-30", new \DateTimeZone($this->timezone)), $this->locale, $holidayType)); + } + + /** + * Republic Day (Turkish: Cumhuriyet Bayramı) is a public holiday in Turkey commemorating the proclamation of the + * Republic of Turkey, on 29 October 1923. The annual celebrations start at 1:00 pm on 28 October and continue for + * 35 hours. + * + * Note: the start of the celebrations the preceding day at 1:00pm is not covered in this library. + * + * @see https://en.wikipedia.org/wiki/Republic_Day_(Turkey) + * + * @throws \Exception + */ + protected function addRepublicDay(): void + { + if (1924 > $this->year) { + return; + } + + $this->addHoliday(new Holiday('republicDay', [ + 'tr' => 'Cumhuriyet Bayramı', + ], new \DateTime("{$this->year}-10-29", new \DateTimeZone($this->timezone)), $this->locale)); + } +} diff --git a/src/Yasumi/Provider/USA.php b/src/Yasumi/Provider/USA.php old mode 100755 new mode 100644 index ef4eceb06..cc1b559e5 --- a/src/Yasumi/Provider/USA.php +++ b/src/Yasumi/Provider/USA.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -25,10 +26,11 @@ */ class USA extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'US'; @@ -36,7 +38,6 @@ class USA extends AbstractProvider /** * Initialize holidays for the USA. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -55,6 +56,7 @@ public function initialize(): void $this->calculateMartinLutherKingday(); $this->calculateWashingtonsBirthday(); $this->calculateMemorialDay(); + $this->calculateJuneteenth(); $this->calculateIndependenceDay(); $this->calculateLabourDay(); $this->calculateColumbusDay(); @@ -64,22 +66,29 @@ public function initialize(): void $this->calculateSubstituteHolidays(); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_the_United_States', + ]; + } + /** * Dr. Martin Luther King Day. * * Honors Dr. Martin Luther King, Jr., Civil Rights leader, who was actually born on January 15, 1929; combined * with other holidays in several states. It is observed on the third Monday of January since 1986. * - * @link https://en.wikipedia.org/wiki/Martin_Luther_King,_Jr._Day + * @see https://en.wikipedia.org/wiki/Martin_Luther_King,_Jr._Day * * @throws \Exception */ - private function calculateMartinLutherKingday(): void + protected function calculateMartinLutherKingday(): void { if ($this->year >= 1986) { $this->addHoliday(new Holiday('martinLutherKingDay', [ - 'en' => 'Dr. Martin Luther King Jr\'s Birthday', - ], new DateTime("third monday of january $this->year", new DateTimeZone($this->timezone)), $this->locale)); + 'en' => 'Dr. Martin Luther King Jr’s Birthday', + ], new \DateTime("third monday of january {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } @@ -94,19 +103,19 @@ private function calculateMartinLutherKingday(): void * Act, 1968 shifted the date of the commemoration of Washington's Birthday from February 22 to the third Monday * in February. * - * @link https://en.wikipedia.org/wiki/Washington%27s_Birthday + * @see https://en.wikipedia.org/wiki/Washington%27s_Birthday * * @throws \Exception */ - private function calculateWashingtonsBirthday(): void + protected function calculateWashingtonsBirthday(): void { if ($this->year >= 1879) { - $date = new DateTime("$this->year-2-22", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-2-22", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if ($this->year >= 1968) { - $date = new DateTime("third monday of february $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("third monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } $this->addHoliday(new Holiday('washingtonsBirthday', [ - 'en' => 'Washington\'s Birthday', + 'en' => 'Washington’s Birthday', ], $date, $this->locale)); } } @@ -119,16 +128,16 @@ private function calculateWashingtonsBirthday(): void * Memorial Day was first declared a federal holiday on May 1, 1865. The Uniform Holidays Act, 1968 shifted the * date of the commemoration of Memorial Day from May 30 to the last Monday in May. * - * @link https://en.wikipedia.org/wiki/Memorial_Day + * @see https://en.wikipedia.org/wiki/Memorial_Day * * @throws \Exception */ - private function calculateMemorialDay(): void + protected function calculateMemorialDay(): void { if ($this->year >= 1865) { - $date = new DateTime("$this->year-5-30", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-5-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if ($this->year >= 1968) { - $date = new DateTime("last monday of may $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("last monday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } $this->addHoliday(new Holiday('memorialDay', [ 'en' => 'Memorial Day', @@ -136,6 +145,51 @@ private function calculateMemorialDay(): void } } + /** + * Juneteenth National Independence Day. + * + * Juneteenth National Independence Day, commonly known simply as Juneteenth, is a federal holiday in the United + * States commemorating the end of slavery. Established as a federal holiday on June 17, 2021, Juneteenth is + * celebrated annually on June 19. In case Juneteenth falls on a Sunday, a substituted holiday is observed + * the following Monday. If it falls on a Saturday, a substituted holiday is observed the previous Friday. + * + * @see https://en.wikipedia.org/wiki/Juneteenth + * + * @throws \Exception + */ + protected function calculateJuneteenth(): void + { + if ($this->year >= 2021) { + $date = new \DateTime("{$this->year}-6-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $label = 'Juneteenth'; + + $holiday = new Holiday('juneteenth', [ + 'en' => $label, + ], $date, $this->locale); + $this->addHoliday($holiday); + + $day_of_week = (int) $date->format('w'); + + if (0 === $day_of_week || 6 === $day_of_week) { + $date = clone $holiday; + $date->modify('previous friday'); + + if (0 === $day_of_week) { + $date->modify('next monday'); + } + + $this->addHoliday(new SubstituteHoliday( + $holiday, + [ + 'en' => $label . ' (observed)', + ], + $date, + $this->locale + )); + } + } + } + /** * Independence Day. * @@ -144,16 +198,16 @@ private function calculateMemorialDay(): void * from Great Britain. In case Independence Day falls on a Sunday, a substituted holiday is observed the * following Monday. If it falls on a Saturday, a substituted holiday is observed the previous Friday. * - * @link https://en.wikipedia.org/wiki/Independence_Day_(United_States) + * @see https://en.wikipedia.org/wiki/Independence_Day_(United_States) * * @throws \Exception */ - private function calculateIndependenceDay(): void + protected function calculateIndependenceDay(): void { if ($this->year >= 1776) { $this->addHoliday(new Holiday('independenceDay', [ 'en' => 'Independence Day', - ], new DateTime("$this->year-7-4", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-7-4", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } @@ -163,11 +217,11 @@ private function calculateIndependenceDay(): void * Labor Day in the United States is a holiday celebrated on the first Monday in September. It is a celebration * of the American labor movement and is dedicated to the social and economic achievements of workers. * - * @link https://en.wikipedia.org/wiki/Labor_Day + * @see https://en.wikipedia.org/wiki/Labor_Day * * @throws \Exception */ - private function calculateLabourDay(): void + protected function calculateLabourDay(): void { if ($this->year >= 1887) { $this->addHoliday(new Holiday( @@ -175,7 +229,7 @@ private function calculateLabourDay(): void [ 'en' => 'Labour Day', ], - new DateTime("first monday of september $this->year", new DateTimeZone($this->timezone)), + new \DateTime("first monday of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -190,16 +244,16 @@ private function calculateLabourDay(): void * though people have celebrated Columbus's voyage since the colonial period. Since 1970 (Oct. 12), the holiday * has been fixed to the second Monday in October. * - * @link https://en.wikipedia.org/wiki/Columbus_Day + * @see https://en.wikipedia.org/wiki/Columbus_Day * * @throws \Exception */ - private function calculateColumbusDay(): void + protected function calculateColumbusDay(): void { if ($this->year >= 1937) { - $date = new DateTime("$this->year-10-12", new DateTimeZone($this->timezone)); + $date = new \DateTime("{$this->year}-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)); if ($this->year >= 1970) { - $date = new DateTime("second monday of october $this->year", new DateTimeZone($this->timezone)); + $date = new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)); } $this->addHoliday(new Holiday('columbusDay', [ 'en' => 'Columbus Day', @@ -214,18 +268,18 @@ private function calculateColumbusDay(): void * also known as veterans. It is a federal holiday that is observed on November 11 since 1919. Congress amended * a bill on June 1, 1954, replacing "Armistice" with "Veterans," and it has been known as Veterans Day since. * - * @link https://en.wikipedia.org/wiki/Veterans_Day + * @see https://en.wikipedia.org/wiki/Veterans_Day * * @throws \Exception */ - private function calculateVeteransDay(): void + protected function calculateVeteransDay(): void { if ($this->year >= 1919) { $name = $this->year < 1954 ? 'Armistice Day' : 'Veterans Day'; $this->addHoliday(new Holiday('veteransDay', [ 'en' => $name, - ], new DateTime("$this->year-11-11", new DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-11-11", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); } } @@ -237,11 +291,11 @@ private function calculateVeteransDay(): void * President Abraham Lincoln proclaimed a national day of "Thanksgiving and Praise to our beneficent Father who * dwelleth in the Heavens", to be celebrated on the last Thursday in November. * - * @link https://en.wikipedia.org/wiki/Thanksgiving_(United_States) + * @see https://en.wikipedia.org/wiki/Thanksgiving_(United_States) * * @throws \Exception */ - private function calculateThanksgivingDay(): void + protected function calculateThanksgivingDay(): void { if ($this->year >= 1863) { $this->addHoliday(new Holiday( @@ -249,7 +303,7 @@ private function calculateThanksgivingDay(): void [ 'en' => 'Thanksgiving Day', ], - new DateTime("fourth thursday of november $this->year", new DateTimeZone($this->timezone)), + new \DateTime("fourth thursday of november {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } @@ -261,27 +315,30 @@ private function calculateThanksgivingDay(): void * When New Year's Day, Independence Day, or Christmas Day falls on a Saturday, the previous day is also a holiday. * When one of these holidays fall on a Sunday, the next day is also a holiday. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSubstituteHolidays(): void + protected function calculateSubstituteHolidays(): void { // Loop through all defined holidays foreach ($this->getHolidays() as $holiday) { + if (! $holiday instanceof Holiday) { + continue; + } + $date = null; // Substitute holiday is on a Monday in case the holiday falls on a Sunday - if (0 === (int)$holiday->format('w')) { + if (0 === (int) $holiday->format('w')) { $date = clone $holiday; - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); } // Substitute holiday is on a Friday in case the holiday falls on a Saturday - if (6 === (int)$holiday->format('w')) { + if (6 === (int) $holiday->format('w')) { $date = clone $holiday; - $date->sub(new DateInterval('P1D')); + $date->sub(new \DateInterval('P1D')); } // Add substitute holiday diff --git a/src/Yasumi/Provider/USA/NYSE.php b/src/Yasumi/Provider/USA/NYSE.php new file mode 100644 index 000000000..37c827c32 --- /dev/null +++ b/src/Yasumi/Provider/USA/NYSE.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\Provider\USA; + +use Yasumi\Holiday; +use Yasumi\Provider\USA; + +/** + * Class NYSE in addition to regular holidays observed by the New York Stock + * Exchange (NYSE), includes full day special closure events due to: + * weather, national emergencies and presidential proclamations. + * All trading closure events are included from year 2000. + * + * @author Art Kurbakov + */ +class NYSE extends USA +{ + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'US-NYSE'; + + /** + * Initialize holidays for the NYSE. + * + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'America/New_York'; + + // Add exchange-specific holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->calculateMartinLutherKingday(); + $this->calculateWashingtonsBirthday(); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->calculateMemorialDay(); + if (2021 < $this->year) { + $this->calculateJuneteenth(); + } + $this->calculateIndependenceDay(); + $this->calculateLabourDay(); + $this->calculateThanksgivingDay(); + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + + $this->calculateSubstituteHolidays(); + + // Add other full-day closure events + $this->addWeatherEvents(); + $this->addEmergencies(); + $this->addProclamations(); + } + + public function getSources(): array + { + return [ + 'https://www.nyse.com/trader-update/history#11507', + 'https://s3.amazonaws.com/armstrongeconomics-wp/2013/07/NYSE-Closings.pdf', + 'https://ir.theice.com/press/news-details/2018/New-York-Stock-Exchange-to-Honor-President-George-H-W-Bush/default.aspx', + 'https://ir.theice.com/press/news-details/2024/The-New-York-Stock-Exchange-Will-Close-Markets-on-January-9-to-Honor-the-Passing-of-Former-President-Jimmy-Carter-on-National-Day-of-Mourning/default.aspx', + 'https://www.thecorporatecounsel.net/blog/2021/10/nyse-makes-juneteenth-a-new-market-holiday.html', + ]; + } + + private function addWeatherEvents(): void + { + if (2012 === $this->year) { + $this->addHoliday(new Holiday('hurricaneSandy1', [], new \DateTime('2012-10-29', new \DateTimeZone($this->timezone)))); + $this->addHoliday(new Holiday('hurricaneSandy2', [], new \DateTime('2012-10-30', new \DateTimeZone($this->timezone)))); + } + } + + private function addEmergencies(): void + { + if (2001 === $this->year) { + $this->addHoliday(new Holiday('groundZero1', [], new \DateTime('2001-09-11', new \DateTimeZone($this->timezone)))); + $this->addHoliday(new Holiday('groundZero2', [], new \DateTime('2001-09-12', new \DateTimeZone($this->timezone)))); + $this->addHoliday(new Holiday('groundZero3', [], new \DateTime('2001-09-13', new \DateTimeZone($this->timezone)))); + $this->addHoliday(new Holiday('groundZero4', [], new \DateTime('2001-09-14', new \DateTimeZone($this->timezone)))); + } + } + + private function addProclamations(): void + { + if (2004 === $this->year) { + $this->addHoliday(new Holiday('ReaganMourning', [], new \DateTime('2004-06-11', new \DateTimeZone($this->timezone)))); + } + if (2007 === $this->year) { + $this->addHoliday(new Holiday('GRFordMourning', [], new \DateTime('2007-01-02', new \DateTimeZone($this->timezone)))); + } + if (2018 === $this->year) { + $this->addHoliday(new Holiday('HWBushMourning', [], new \DateTime('2018-12-05', new \DateTimeZone($this->timezone)))); + } + if (2025 === $this->year) { + $this->addHoliday(new Holiday('CarterMourning', [], new \DateTime('2025-01-09', new \DateTimeZone($this->timezone)))); + } + } +} diff --git a/src/Yasumi/Provider/Ukraine.php b/src/Yasumi/Provider/Ukraine.php index 4a18bfe6d..f6b72627c 100644 --- a/src/Yasumi/Provider/Ukraine.php +++ b/src/Yasumi/Provider/Ukraine.php @@ -1,43 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; +use Yasumi\SubstituteHoliday; /** * Provider for all holidays in Ukraine. - * https://en.wikipedia.org/wiki/Public_holidays_in_Ukraine * * Class Ukraine - * @package Yasumi\Provider + * * @author Dmitry Machin */ class Ukraine extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** * Code to identify this Holiday Provider. - * Typically this is the ISO3166 code corresponding to the respective country or sub-region. + * Typically, this is the ISO3166 code corresponding to the respective country or sub-region. */ public const ID = 'UA'; /** * Initialize holidays for Ukraine. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -47,7 +51,8 @@ public function initialize(): void $this->timezone = 'Europe/Kiev'; // Add common holidays - $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + // New Years Day will not be substituted to an monday if it's on a weekend! + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale), false); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); @@ -56,117 +61,189 @@ public function initialize(): void $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale)); // Add other holidays - $this->calculateChristmasDay(); + $this->calculateOrthodoxChristmasDay(); $this->calculateSecondInternationalWorkersDay(); $this->calculateVictoryDay(); $this->calculateConstitutionDay(); $this->calculateIndependenceDay(); $this->calculateDefenderOfUkraineDay(); + $this->calculateCatholicChristmasDay(); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Ukraine', + 'https://uk.wikipedia.org/wiki/%D0%9D%D0%B5%D1%80%D0%BE%D0%B1%D0%BE%D1%87%D1%96_%D0%B4%D0%BD%D1%96_%D0%B2_%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%96', + 'https://zakon.rada.gov.ua/laws/show/322-08', + ]; + } + + /** + * Adds a holiday to the holidays providers (i.e. country/state) list of holidays. + * + * @param Holiday $holiday holiday instance (representing a holiday) to be added to the internal list + * of holidays of this country + * @param bool $substitutable holidays on a weekend will be substituted to the next monday + * + * @throws UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + public function addHoliday(Holiday $holiday, bool $substitutable = true): void + { + parent::addHoliday($holiday); + + if (! $substitutable) { + return; + } + + // Substitute holiday is on the next available weekday + // if a holiday falls on a Saturday or Sunday. + if ($this->isWeekendDay($holiday)) { + $date = clone $holiday; + $date->modify('next monday'); + + parent::addHoliday(new SubstituteHoliday( + $holiday, + [], + $date, + $this->locale + )); + } + } + + /** + * @return \DateTime|\DateTimeImmutable + * + * @throws \Exception + */ + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface + { + return $this->calculateOrthodoxEaster($year, $timezone); } /** * Christmas Day. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateChristmasDay(): void + protected function calculateOrthodoxChristmasDay(): void { + if ($this->year >= 2024) { + return; + } + $this->addHoliday(new Holiday( 'christmasDay', [], - new \DateTime("$this->year-01-07", new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-01-07", new \DateTimeZone($this->timezone)), $this->locale )); } /** * International Workers' Day. + * National holiday until 2018. * - * @link https://en.wikipedia.org/wiki/International_Workers%27_Day#Ukraine + * @see https://en.wikipedia.org/wiki/International_Workers%27_Day#Ukraine * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateSecondInternationalWorkersDay(): void + protected function calculateSecondInternationalWorkersDay(): void { + if ($this->year >= 2018) { + return; + } + $this->addHoliday(new Holiday('secondInternationalWorkersDay', [ 'uk' => 'День міжнародної солідарності трудящих', 'ru' => 'День международной солидарности трудящихся', - ], new \DateTime("$this->year-05-02", new \DateTimeZone($this->timezone)), $this->locale)); + ], new \DateTime("{$this->year}-05-02", new \DateTimeZone($this->timezone)), $this->locale)); } /** - * Victory Day over Nazism in World War II + * Victory Day over Nazism in World War II. * * Victory Day over Nazism in World War II (Ukrainian: День перемоги над нацизмом у Другій світовій війні) * or Victory Day (Ukrainian: День перемоги) is a national holiday and a day off in Ukraine. * It was first celebrated on 9 May 2015 and follows the Day of Remembrance and Reconciliation on May 8. * The holiday replaced the Soviet "Victory Day", which was celebrated in the post-Soviet Union states, including - * Ukraine, until 2014 inclusive. + * Ukraine, until 2014 inclusive. Since 2024, it has been celebrated on May 8. * - * @link https://en.wikipedia.org/wiki/Victory_Day_over_Nazism_in_World_War_II + * @see https://en.wikipedia.org/wiki/Victory_Day_over_Nazism_in_World_War_II * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateVictoryDay(): void + protected function calculateVictoryDay(): void { - $this->addHoliday(new Holiday( - 'victoryDay', - ['uk' => 'День перемоги', 'ru' => 'День победы'], - new \DateTime("$this->year-05-09", new \DateTimeZone($this->timezone)), - $this->locale - )); + if ($this->year >= 2024) { + $this->addHoliday(new Holiday( + 'victoryDay', + ['uk' => 'День перемоги', 'ru' => 'День победы'], + new \DateTime("{$this->year}-05-08", new \DateTimeZone($this->timezone)), + $this->locale + )); + } elseif ($this->year >= 2015) { + $this->addHoliday(new Holiday( + 'victoryDay', + ['uk' => 'День перемоги', 'ru' => 'День победы'], + new \DateTime("{$this->year}-05-09", new \DateTimeZone($this->timezone)), + $this->locale + )); + } } /** - * Constitution Day + * Constitution Day. * * Constitution Day (Ukrainian: День Конституції) is an Ukrainian public holiday celebrated on 28 June since 1996. * - * @link https://en.wikipedia.org/wiki/Constitution_Day_(Ukraine) + * @see https://en.wikipedia.org/wiki/Constitution_Day_(Ukraine) * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateConstitutionDay(): void + protected function calculateConstitutionDay(): void { - if ($this->year < 1996) { - return; + if ($this->year >= 2024) { + $this->addHoliday(new Holiday( + 'constitutionDay', + ['uk' => 'День Конституції', 'ru' => 'День Конституции'], + new \DateTime("{$this->year}-06-15", new \DateTimeZone($this->timezone)), + $this->locale + )); + } elseif ($this->year >= 1996) { + $this->addHoliday(new Holiday( + 'constitutionDay', + ['uk' => 'День Конституції', 'ru' => 'День Конституции'], + new \DateTime("{$this->year}-06-28", new \DateTimeZone($this->timezone)), + $this->locale + )); } - - $this->addHoliday(new Holiday( - 'constitutionDay', - ['uk' => 'День Конституції', 'ru' => 'День Конституции'], - new \DateTime("$this->year-06-28", new \DateTimeZone($this->timezone)), - $this->locale - )); } /** - * Independence Day + * Independence Day. * * The Act of Declaration of Independence of Ukraine (Ukrainian: Акт проголошення незалежності України, translit. * Akt proholoshennya nezalezhnosti Ukrayiny) was adopted by the Ukrainian parliament on 24 August 1991. * The Act established Ukraine as an independent state. * - * @link https://en.wikipedia.org/wiki/Declaration_of_Independence_of_Ukraine + * @see https://en.wikipedia.org/wiki/Declaration_of_Independence_of_Ukraine * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateIndependenceDay(): void + protected function calculateIndependenceDay(): void { if ($this->year < 1991) { return; @@ -175,49 +252,71 @@ private function calculateIndependenceDay(): void $this->addHoliday(new Holiday( 'independenceDay', ['uk' => 'День Незалежності', 'ru' => 'День Независимости'], - new \DateTime("$this->year-08-24", new \DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-08-24", new \DateTimeZone($this->timezone)), $this->locale )); } /** - * Defender of Ukraine Day + * Defender of Ukraine Day. * * Defender of Ukraine Day (Ukrainian: День захисника України, Denʹ zakhysnyka Ukrayiny) * is a state holiday in Ukraine celebrated annually on October 14. * Its first celebration was in 2015. * Starting from 2015, this day is considered a public holiday (this is thus a day off in Ukraine) * - * @link https://en.wikipedia.org/wiki/Defender_of_Ukraine_Day + * @see https://en.wikipedia.org/wiki/Defender_of_Ukraine_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - private function calculateDefenderOfUkraineDay(): void + protected function calculateDefenderOfUkraineDay(): void { - if ($this->year < 2015) { - return; + if ($this->year >= 2023) { + $this->addHoliday(new Holiday( + 'defenderOfUkraineDay', + ['uk' => 'День захисника України', 'ru' => 'День Защитника Украины'], + new \DateTime("{$this->year}-10-01", new \DateTimeZone($this->timezone)), + $this->locale + )); + } elseif ($this->year >= 2015) { + $this->addHoliday(new Holiday( + 'defenderOfUkraineDay', + ['uk' => 'День захисника України', 'ru' => 'День Защитника Украины'], + new \DateTime("{$this->year}-10-14", new \DateTimeZone($this->timezone)), + $this->locale + )); } - - $this->addHoliday(new Holiday( - 'defenderOfUkraineDay', - ['uk' => 'День захисника України', 'ru' => 'День Защитника Украины'], - new \DateTime("$this->year-10-14", new \DateTimeZone($this->timezone)), - $this->locale - )); } /** - * @param int $year - * @param string $timezone + * Catholic Christmas Day. + * (since 2017 instead of International Workers' Day 2. May). * - * @return \DateTime + * @see https://en.wikipedia.org/wiki/Christmas_in_Ukraine + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException * @throws \Exception */ - public function calculateEaster($year, $timezone): \DateTime + protected function calculateCatholicChristmasDay(): void { - return $this->calculateOrthodoxEaster($year, $timezone); + if ($this->year < 2017) { + return; + } + + $this->addHoliday( + new Holiday( + 'catholicChristmasDay', + [ + 'uk' => 'Католицький день Різдва', + 'ru' => 'Католическое рождество', + ], + new \DateTime("{$this->year}-12-25", new \DateTimeZone($this->timezone)), + $this->locale + ), + false // Catholic Christmas Day will not be substituted to an monday if it's on a weekend! + ); } } diff --git a/src/Yasumi/Provider/UnitedKingdom.php b/src/Yasumi/Provider/UnitedKingdom.php index e1f4c0417..8744d1694 100644 --- a/src/Yasumi/Provider/UnitedKingdom.php +++ b/src/Yasumi/Provider/UnitedKingdom.php @@ -1,21 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\SubstituteHoliday; @@ -26,20 +27,20 @@ */ class UnitedKingdom extends AbstractProvider { - use CommonHolidays, ChristianHolidays; + use CommonHolidays; + use ChristianHolidays; /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GB'; - public $timezone = 'Europe/London'; + public string $timezone = 'Europe/London'; /** * Initialize holidays for the United Kingdom. * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -54,47 +55,21 @@ public function initialize(): void // Add common Christian holidays (common in the United Kingdom) $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); - $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); $this->calculateChristmasHolidays(); + + // Add any other holidays + $this->calculatePlatinumJubileeBankHoliday(); + $this->calculateMotheringSunday(); + $this->calculateQueenElizabethFuneralBankHoliday(); + $this->calculateKingCharlesCoronationBankHoliday(); } - /** - * New Year's Day is a public holiday in the United Kingdom on January 1 each year. It marks - * the start of the New Year in the Gregorian calendar. For many people have a quiet day on - * January 1, which marks the end of the Christmas break before they return to work. - * - * If New Years Day falls on a Saturday or Sunday, it is observed the next Monday (January 2nd or 3rd) - * Before 1871 it was not an observed or statutory holiday, after 1871 only an observed holiday. - * Since 1974 (by Royal Proclamation) it was established as a bank holiday. - * - * @link https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom - * @link https://www.timeanddate.com/holidays/uk/new-year-day - * - * @throws InvalidDateException - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - protected function calculateNewYearsDay(): void + public function getSources(): array { - // Before 1871 it was not an observed or statutory holiday - if ($this->year < 1871) { - return; - } - - $type = Holiday::TYPE_BANK; - if ($this->year <= 1974) { - $type = Holiday::TYPE_OBSERVANCE; - } - - $newYearsDay = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)); - - // If New Years Day falls on a Saturday or Sunday, it is observed the next Monday (January 2nd or 3rd) - if (\in_array((int)$newYearsDay->format('w'), [0, 6], true)) { - $newYearsDay->modify('next monday'); - } - - $this->addHoliday(new Holiday('newYearsDay', [], $newYearsDay, $this->locale, $type)); + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom', + 'https://bank-holidays.uk/history-of-bank-holidays/', + ]; } /** @@ -107,9 +82,9 @@ protected function calculateNewYearsDay(): void * and schools are closed, while stores may be open or closed, according to local custom. Public transport systems * often run to a holiday timetable. * - * @link https://www.timeanddate.com/holidays/uk/early-may-bank-holiday + * @see https://www.timeanddate.com/holidays/uk/early-may-bank-holiday + * @see https://bank-holidays.uk/history-of-bank-holidays/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -126,7 +101,7 @@ protected function calculateMayDayBankHoliday(): void $this->addHoliday(new Holiday( 'mayDayBankHoliday', ['en' => 'May Day Bank Holiday'], - new DateTime("$this->year-5-8", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-5-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK )); @@ -137,7 +112,7 @@ protected function calculateMayDayBankHoliday(): void $this->addHoliday(new Holiday( 'mayDayBankHoliday', ['en' => 'May Day Bank Holiday'], - new DateTime("first monday of may $this->year", new DateTimeZone($this->timezone)), + new \DateTime("first monday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK )); @@ -151,10 +126,10 @@ protected function calculateMayDayBankHoliday(): void * The last Monday in May is a bank holiday. Many organizations, businesses and schools are closed. Stores may be * open or closed, according to local custom. Public transport systems often run to a holiday timetable. * - * @link https://www.timeanddate.com/holidays/uk/spring-bank-holiday - * @link https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom + * @see https://www.timeanddate.com/holidays/uk/spring-bank-holiday + * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom + * @see https://bank-holidays.uk/history-of-bank-holidays/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -172,7 +147,20 @@ protected function calculateSpringBankHoliday(): void $this->addHoliday(new Holiday( 'springBankHoliday', ['en' => 'Spring Bank Holiday'], - new DateTime("$this->year-6-4", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-6-4", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + + return; + } + + // Moved to 2 June in 2022 for the celebration of the Platinum Jubilee of Elizabeth II. + if (2022 === $this->year) { + $this->addHoliday(new Holiday( + 'springBankHoliday', + ['en' => 'Spring Bank Holiday'], + new \DateTime("{$this->year}-6-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK )); @@ -183,65 +171,85 @@ protected function calculateSpringBankHoliday(): void $this->addHoliday(new Holiday( 'springBankHoliday', ['en' => 'Spring Bank Holiday'], - new DateTime("last monday of may $this->year", new DateTimeZone($this->timezone)), + new \DateTime("last monday of may {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK )); } /** - * The Summer Bank holiday, also known as the Late Summer bank holiday, is a time for people in the United Kingdom - * to have a day off work or school. It falls on the last Monday of August replacing the first Monday in August - * (formerly commonly known as "August Bank Holiday"). + * The Platinum Jubilee bank holiday is an extra bank holiday added on 3 June 2022 + * for the celebration of the Platinum Jubilee of Elizabeth II. * - * Many organizations, businesses and schools are closed. Stores may be open or closed, according to local custom. - * Public transport systems often run to a holiday timetable. + * @see https://www.timeanddate.com/holidays/uk/queen-platinum-jubilee + * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom#Special_holidays * - * @link https://www.timeanddate.com/holidays/uk/summer-bank-holiday - * @link https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom - * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception */ - protected function calculateSummerBankHoliday(): void + protected function calculatePlatinumJubileeBankHoliday(): void { - if ($this->year < 1871) { + if (2022 !== $this->year) { return; } - if ($this->year < 1965) { - $this->addHoliday(new Holiday( - 'summerBankHoliday', - ['en' => 'August Bank Holiday'], - new DateTime("first monday of august $this->year", new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_BANK - )); + $this->addHoliday(new Holiday( + 'platinumJubileeBankHoliday', + ['en' => 'Platinum Jubilee Bank Holiday'], + new \DateTime("{$this->year}-6-3", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + } + /** + * Queen Elizabeth II’s funeral is an extra bank holiday added on 10 September 2022 + * to mark the last day of the period of national mourning. + * + * @see https://www.timeanddate.com/holidays/uk/queen-elizabeth-funeral + * @see https://www.gov.uk/government/news/bank-holiday-announced-for-her-majesty-queen-elizabeth-iis-state-funeral-on-monday-19-september + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateQueenElizabethFuneralBankHoliday(): void + { + if (2022 !== $this->year) { return; } - // Statutory bank holiday from 1971, following a trial period from 1965 to 1970. - // During the trial period, the definition was different than today, causing exceptions - // in 1968 and 1969. - if (1968 === $this->year || 1969 === $this->year) { - $this->addHoliday(new Holiday( - 'summerBankHoliday', - ['en' => 'Summer Bank Holiday'], - new DateTime("first monday of september $this->year", new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_BANK - )); + $this->addHoliday(new Holiday( + 'queenElizabethFuneralBankHoliday', + ['en' => 'Queen Elizabeth II’s State Funeral Bank Holiday'], + new \DateTime("{$this->year}-9-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + } + /** + * The coronation of King Charles III is an extra bank holiday added on 6 November 2022 + * to mark the Coronation of His Majesty King Charles III. + * + * @see https://www.timeanddate.com/holidays/uk/king-coronation-day-holiday + * @see https://www.gov.uk/government/news/bank-holiday-proclaimed-in-honour-of-the-coronation-of-his-majesty-king-charles-iii + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateKingCharlesCoronationBankHoliday(): void + { + if (2023 !== $this->year) { return; } $this->addHoliday(new Holiday( - 'summerBankHoliday', - ['en' => 'Summer Bank Holiday'], - new DateTime("last monday of august $this->year", new DateTimeZone($this->timezone)), + 'kingCharlesCoronationBankHoliday', + ['en' => 'King Charles III’s Coronation Bank Holiday'], + new \DateTime("{$this->year}-5-8", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK )); @@ -261,14 +269,14 @@ protected function calculateSummerBankHoliday(): void * If Christmas Day falls on a Saturday, the following Monday and Tuesday are bank holidays. All schools and many * organizations are closed in this period. Some may close for the whole week between Christmas and New Year. * - * @link https://www.timeanddate.com/holidays/uk/christmas-day - * @link https://www.timeanddate.com/holidays/uk/boxing-day + * @see https://www.timeanddate.com/holidays/uk/christmas-day + * @see https://www.timeanddate.com/holidays/uk/boxing-day * * @param string|null $type the Holiday Type (e.g. Official, Seasonal, etc.) * * @throws \Exception */ - protected function calculateChristmasHolidays(string $type = null): void + protected function calculateChristmasHolidays(?string $type = null): void { $christmasDay = $this->christmasDay($this->year, $this->timezone, $this->locale, $type ?? Holiday::TYPE_OFFICIAL); $secondChristmasDay = $this->secondChristmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK); @@ -276,9 +284,9 @@ protected function calculateChristmasHolidays(string $type = null): void $this->addHoliday($christmasDay); $this->addHoliday($secondChristmasDay); - if (\in_array((int)$christmasDay->format('w'), [0, 6], true)) { + if (\in_array((int) $christmasDay->format('w'), [0, 6], true)) { $date = clone $christmasDay; - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); $this->addHoliday(new SubstituteHoliday( $christmasDay, [], @@ -288,9 +296,9 @@ protected function calculateChristmasHolidays(string $type = null): void )); } - if (\in_array((int)$secondChristmasDay->format('w'), [0, 6], true)) { + if (\in_array((int) $secondChristmasDay->format('w'), [0, 6], true)) { $date = clone $secondChristmasDay; - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); $this->addHoliday(new SubstituteHoliday( $secondChristmasDay, [], @@ -300,4 +308,123 @@ protected function calculateChristmasHolidays(string $type = null): void )); } } + + /** + * New Year's Day is a public holiday in the United Kingdom on January 1 each year. It marks + * the start of the New Year in the Gregorian calendar. For many people have a quiet day on + * January 1, which marks the end of the Christmas break before they return to work. + * + * If New Years Day falls on a Saturday or Sunday, it is observed the next Monday (January 2nd or 3rd) + * Before 1871 it was not an observed or statutory holiday, after 1871 only an observed holiday. + * Since 1974 (by Royal Proclamation) it was established as a bank holiday. + * + * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom + * @see https://www.timeanddate.com/holidays/uk/new-year-day + * @see https://bank-holidays.uk/history-of-bank-holidays/ + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateNewYearsDay(): void + { + // Before 1871 it was not an observed or statutory holiday + if ($this->year < 1871) { + return; + } + + $type = Holiday::TYPE_BANK; + if ($this->year < 1974) { + $type = Holiday::TYPE_OBSERVANCE; + } + + $newYearsDay = new \DateTime("{$this->year}-01-01", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + + // If New Years Day falls on a Saturday or Sunday, it is observed the next Monday (January 2nd or 3rd) + if (\in_array((int) $newYearsDay->format('w'), [0, 6], true)) { + $newYearsDay->modify('next monday'); + } + + $this->addHoliday(new Holiday('newYearsDay', [], $newYearsDay, $this->locale, $type)); + } + + /** + * The Summer Bank holiday, also known as the Late Summer bank holiday, is a time for people in the United Kingdom + * to have a day off work or school. It falls on the last Monday of August replacing the first Monday in August + * (formerly commonly known as "August Bank Holiday"). + * + * Many organizations, businesses and schools are closed. Stores may be open or closed, according to local custom. + * Public transport systems often run to a holiday timetable. + * + * @see https://www.timeanddate.com/holidays/uk/summer-bank-holiday + * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateSummerBankHoliday(): void + { + if ($this->year < 1871) { + return; + } + + if ($this->year < 1965) { + $this->addHoliday(new Holiday( + 'summerBankHoliday', + ['en' => 'August Bank Holiday'], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + + return; + } + + // Statutory bank holiday from 1971, following a trial period from 1965 to 1970. + // During the trial period, the definition was different than today, causing exceptions + // in 1968 and 1969. + if (1968 === $this->year || 1969 === $this->year) { + $this->addHoliday(new Holiday( + 'summerBankHoliday', + ['en' => 'Summer Bank Holiday'], + new \DateTime("first monday of september {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + + return; + } + + $this->addHoliday(new Holiday( + 'summerBankHoliday', + ['en' => 'Summer Bank Holiday'], + new \DateTime("last monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + } + + /** + * Mothering Sunday is a day honouring mothers and mother churches, celebrated in the United Kingdom, Ireland on the + * fourth Sunday in Lent since the Middle Ages. On Mothering Sunday, Christians have historically visited their + * mother church—the church in which they received the sacrament of baptism. + * + * @see https://en.wikipedia.org/wiki/Mothering_Sunday + * + * @throws \Exception + */ + protected function calculateMotheringSunday(): void + { + $date = $this->calculateEaster($this->year, $this->timezone); + $date->sub(new \DateInterval('P3W')); + + $this->addHoliday(new Holiday( + 'motheringSunday', + ['en' => 'Mothering Sunday'], + $date, + $this->locale, + Holiday::TYPE_OTHER + )); + } } diff --git a/src/Yasumi/Provider/UnitedKingdom/England.php b/src/Yasumi/Provider/UnitedKingdom/England.php index 70c91b8e3..5d193c0e0 100644 --- a/src/Yasumi/Provider/UnitedKingdom/England.php +++ b/src/Yasumi/Provider/UnitedKingdom/England.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\UnitedKingdom; +use Yasumi\Holiday; use Yasumi\Provider\UnitedKingdom; /** @@ -21,13 +27,23 @@ * (50,301 sq mi), and has a population of 5,619,400. London, England's capital, is also the capital of * and the largest city in the United Kingdom. * - * @link https://en.wikipedia.org/wiki/England + * @see https://en.wikipedia.org/wiki/England */ class England extends UnitedKingdom { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GB-ENG'; + + /** + * Initialize holidays for England (United Kingdom).. + */ + public function initialize(): void + { + parent::initialize(); + + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); + } } diff --git a/src/Yasumi/Provider/UnitedKingdom/NorthernIreland.php b/src/Yasumi/Provider/UnitedKingdom/NorthernIreland.php index 28fb7af6d..08f44b35e 100644 --- a/src/Yasumi/Provider/UnitedKingdom/NorthernIreland.php +++ b/src/Yasumi/Provider/UnitedKingdom/NorthernIreland.php @@ -1,22 +1,25 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\UnitedKingdom; use Yasumi\SubstituteHoliday; @@ -27,12 +30,12 @@ * (5,460 sq mi), and has a population of 1,885,400. Belfast, Northern Ireland's capital and largest city, * is the 12th largest city in the United Kingdom. * - * @link https://en.wikipedia.org/wiki/Northern_Ireland + * @see https://en.wikipedia.org/wiki/Northern_Ireland */ class NorthernIreland extends UnitedKingdom { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GB-NIR'; @@ -40,7 +43,6 @@ class NorthernIreland extends UnitedKingdom /** * Initialize holidays for Northern Ireland (United Kingdom). * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -49,10 +51,18 @@ public function initialize(): void { parent::initialize(); + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); $this->calculateStPatricksDay(); $this->calculateBattleOfTheBoyne(); } + public function getSources(): array + { + return [ + 'https://nextbankholidays.co.uk/guides/battle-of-the-boyne/', + ]; + } + /** * St. Patrick's Day. * @@ -62,15 +72,13 @@ public function initialize(): void * of Ireland, Northern Ireland, the Canadian province of Newfoundland and Labrador, and the British Overseas * Territory of Montserrat. * - * @link https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day + * @see https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateStPatricksDay(): void + protected function calculateStPatricksDay(): void { if ($this->year < 1971) { return; @@ -78,8 +86,8 @@ private function calculateStPatricksDay(): void $holiday = new Holiday( 'stPatricksDay', - ['en' => 'St. Patrick\'s Day'], - new DateTime($this->year . '-3-17', new DateTimeZone($this->timezone)), + ['en' => 'St. Patrick’s Day'], + new \DateTime("{$this->year}-3-17", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK ); @@ -87,7 +95,7 @@ private function calculateStPatricksDay(): void $this->addHoliday($holiday); // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); @@ -108,15 +116,14 @@ private function calculateStPatricksDay(): void * and victory of Protestant King William of Orange over Catholic king James II at the Battle of the * Boyne (1690), which began the Protestant Ascendancy in Ireland. * - * @link https://en.wikipedia.org/wiki/The_Twelfth + * @see https://en.wikipedia.org/wiki/The_Twelfth + * @see https://nextbankholidays.co.uk/guides/battle-of-the-boyne/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateBattleOfTheBoyne(): void + protected function calculateBattleOfTheBoyne(): void { if ($this->year < 1926) { return; @@ -125,7 +132,7 @@ private function calculateBattleOfTheBoyne(): void $holiday = new Holiday( 'battleOfTheBoyne', ['en' => 'Battle of the Boyne'], - new DateTime($this->year . '-7-12', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-7-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK ); @@ -133,7 +140,7 @@ private function calculateBattleOfTheBoyne(): void $this->addHoliday($holiday); // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); diff --git a/src/Yasumi/Provider/UnitedKingdom/Scotland.php b/src/Yasumi/Provider/UnitedKingdom/Scotland.php index 91782564f..dae3e6fcc 100644 --- a/src/Yasumi/Provider/UnitedKingdom/Scotland.php +++ b/src/Yasumi/Provider/UnitedKingdom/Scotland.php @@ -1,23 +1,25 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\UnitedKingdom; -use DateInterval; -use DateTime; -use DateTimeZone; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; +use Yasumi\Provider\DateTimeZoneFactory; use Yasumi\Provider\UnitedKingdom; use Yasumi\SubstituteHoliday; @@ -33,23 +35,18 @@ * holidays are not recognised as statutory public holidays in Scotland, as most public holidays are * determined by local authorities across Scotland. * - * @link https://en.wikipedia.org/wiki/Scotland + * @see https://en.wikipedia.org/wiki/Scotland */ class Scotland extends UnitedKingdom { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GB-SCT'; /** - * Initialize holidays for the United Kingdom. - * - * @throws InvalidDateException - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception + * Initialize holidays for Scotland (United Kingdom).. */ public function initialize(): void { @@ -67,6 +64,39 @@ public function initialize(): void $this->calculateChristmasHolidays(Holiday::TYPE_BANK); } + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_and_bank_holidays_in_Scotland', + 'https://bank-holidays.uk/history-of-bank-holidays/', + ]; + } + + /** + * The Summer Bank holiday, also known as the Late Summer bank holiday, is a time for people in the United Kingdom + * to have a day off work or school. In Scotland it falls on the first Monday of August. + * + * @see https://www.timeanddate.com/holidays/uk/summer-bank-holiday + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + protected function calculateSummerBankHoliday(): void + { + if ($this->year < 1871) { + return; + } + + $this->addHoliday(new Holiday( + 'summerBankHoliday', + ['en' => 'August Bank Holiday'], + new \DateTime("first monday of august {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_BANK + )); + } + /** * New Year's Day is a public holiday in the United Kingdom on January 1 each year. It marks * the start of the New Year in the Gregorian calendar. For many people have a quiet day on @@ -75,10 +105,10 @@ public function initialize(): void * In Scotland, January 2 is also a bank holiday. If January 2 falls on a Saturday, the following Monday is a bank holiday. * If New Years Day falls on a Saturday, the following Monday and Tuesday are bank holidays. * - * @link https://en.wikipedia.org/wiki/Public_holidays_in_Scotland - * @link https://www.timeanddate.com/holidays/uk/new-year-day + * @see https://www.timeanddate.com/holidays/uk/new-year-day + * @see https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom + * @see https://bank-holidays.uk/history-of-bank-holidays/ * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception @@ -90,17 +120,16 @@ protected function calculateNewYearsHolidays(): void return; } - if ($this->year <= 1974) { + $type = Holiday::TYPE_BANK; + if ($this->year < 1974) { $type = Holiday::TYPE_OBSERVANCE; - } else { - $type = Holiday::TYPE_BANK; } $newYearsDay = $this->newYearsDay($this->year, $this->timezone, $this->locale, $type); $secondNewYearsDay = new Holiday( 'secondNewYearsDay', [], - new DateTime("$this->year-1-2", new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-1-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, $type ); @@ -108,9 +137,9 @@ protected function calculateNewYearsHolidays(): void $this->addHoliday($newYearsDay); $this->addHoliday($secondNewYearsDay); - if (\in_array((int)$newYearsDay->format('w'), [0, 6], true)) { + if (\in_array((int) $newYearsDay->format('w'), [0, 6], true)) { $date = clone $newYearsDay; - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); $this->addHoliday(new SubstituteHoliday( $newYearsDay, [], @@ -120,9 +149,9 @@ protected function calculateNewYearsHolidays(): void )); } - if (\in_array((int)$secondNewYearsDay->format('w'), [0, 6], true)) { + if (\in_array((int) $secondNewYearsDay->format('w'), [0, 6], true)) { $date = clone $secondNewYearsDay; - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); $this->addHoliday(new SubstituteHoliday( $secondNewYearsDay, [], @@ -133,47 +162,18 @@ protected function calculateNewYearsHolidays(): void } } - /** - * The Summer Bank holiday, also known as the Late Summer bank holiday, is a time for people in the United Kingdom - * to have a day off work or school. In Scotland it falls on the first Monday of August. - * - * @link https://www.timeanddate.com/holidays/uk/summer-bank-holiday - * @link https://en.wikipedia.org/wiki/Public_holidays_in_Scotland - * - * @throws InvalidDateException - * @throws \InvalidArgumentException - * @throws UnknownLocaleException - * @throws \Exception - */ - protected function calculateSummerBankHoliday(): void - { - if ($this->year < 1871) { - return; - } - - $this->addHoliday(new Holiday( - 'summerBankHoliday', - ['en' => 'August Bank Holiday'], - new DateTime("first monday of august $this->year", new DateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_BANK - )); - } - /** * St. Andrew's Day. * * Saint Andrew's Day is Scotland's national day, celebrated on 30 November. * - * @link https://en.wikipedia.org/wiki/Saint_Andrew%27s_Day + * @see https://en.wikipedia.org/wiki/Saint_Andrew%27s_Day * - * @throws InvalidDateException * @throws \InvalidArgumentException * @throws UnknownLocaleException * @throws \Exception - * @throws \Exception */ - private function calculateStAndrewsDay(): void + protected function calculateStAndrewsDay(): void { if ($this->year < 2007) { return; @@ -181,7 +181,7 @@ private function calculateStAndrewsDay(): void $holiday = new Holiday( 'stAndrewsDay', [], - new DateTime($this->year . '-11-30', new DateTimeZone($this->timezone)), + new \DateTime("{$this->year}-11-30", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_BANK ); @@ -189,7 +189,7 @@ private function calculateStAndrewsDay(): void $this->addHoliday($holiday); // Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday - if (\in_array((int)$holiday->format('w'), [0, 6], true)) { + if (\in_array((int) $holiday->format('w'), [0, 6], true)) { $date = clone $holiday; $date->modify('next monday'); diff --git a/src/Yasumi/Provider/UnitedKingdom/Wales.php b/src/Yasumi/Provider/UnitedKingdom/Wales.php index 7d7783477..e82482813 100644 --- a/src/Yasumi/Provider/UnitedKingdom/Wales.php +++ b/src/Yasumi/Provider/UnitedKingdom/Wales.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\Provider\UnitedKingdom; +use Yasumi\Holiday; use Yasumi\Provider\UnitedKingdom; /** @@ -21,13 +27,30 @@ * (8,023 sq mi), and has a population of 3,125,000. Cardiff, Wales's capital and largest city, is the * eleventh largest city in the United Kingdom. * - * @link https://en.wikipedia.org/wiki/Wales + * @see https://en.wikipedia.org/wiki/Wales */ class Wales extends UnitedKingdom { /** - * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective * country or sub-region. */ public const ID = 'GB-WLS'; + + /** + * Initialize holidays for Wales (United Kingdom). + */ + public function initialize(): void + { + parent::initialize(); + + $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); + } + + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Holidays_in_Wales', + ]; + } } diff --git a/src/Yasumi/Provider/Venezuela.php b/src/Yasumi/Provider/Venezuela.php new file mode 100644 index 000000000..0d5c2f644 --- /dev/null +++ b/src/Yasumi/Provider/Venezuela.php @@ -0,0 +1,288 @@ + + */ + +namespace Yasumi\Provider; + +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Holiday; + +/** + * Provider for all holidays in Venezuela. + * + * @see https://en.wikipedia.org/wiki/Public_holidays_in_Venezuela + */ +class Venezuela extends AbstractProvider +{ + use CommonHolidays; + use ChristianHolidays; + + /** + * The year when Venezuela declared independence from Spain. + */ + public const DECLARATION_OF_INDEPENDENCE_YEAR = 1811; + + /** + * Code to identify this Holiday Provider. Typically, this is the ISO3166 code corresponding to the respective + * country or sub-region. + */ + public const ID = 'VE'; + + /** + * Initialize holidays for Venezuela. + * + * @throws \InvalidArgumentException + * @throws UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + $this->timezone = 'America/Caracas'; + + // Add common holidays + $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + + // Add Christian holidays + $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->maundyThursday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + + // Calculate country-specific holidays + $this->calculateCarnaval(); + $this->calculateDeclarationOfIndependence(); + $this->calculateBattleOfCarabobo(); + $this->calculateIndependenceDay(); + $this->calculateSimonBolivarBirthday(); + $this->calculateDayOfIndigenousResistance(); + $this->calculateChristmasEve(); + $this->calculateNewYearsEve(); + } + + /** + * Returns a list of sources for holiday calculations. + * + * @return string[] The source URLs + */ + public function getSources(): array + { + return [ + 'https://en.wikipedia.org/wiki/Public_holidays_in_Venezuela', + 'https://www.timeanddate.com/holidays/venezuela/', + 'https://www.officeholidays.com/countries/venezuela', + ]; + } + + /** + * Carnaval (Carnival). + * + * Carnival is celebrated on Monday and Tuesday before Ash Wednesday. + * It is one of the most important celebrations in Venezuela. + * + * @throws \Exception + */ + protected function calculateCarnaval(): void + { + if ($this->year >= 1700) { + $easter = $this->calculateEaster($this->year, $this->timezone); + + $days = [ + 'carnavalMonday' => [ + 'interval' => 'P48D', + 'name_es' => 'Lunes de Carnaval', + 'name_en' => 'Carnival Monday', + ], + 'carnavalTuesday' => [ + 'interval' => 'P47D', + 'name_es' => 'Martes de Carnaval', + 'name_en' => 'Carnival Tuesday', + ], + ]; + + foreach ($days as $name => $day) { + $date = (clone $easter)->sub(new \DateInterval($day['interval'])); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, $name)); + } + + $this->addHoliday(new Holiday( + $name, + [ + 'es' => $day['name_es'], + 'en' => $day['name_en'], + ], + $date, + $this->locale + )); + } + } + } + + /** + * Declaration of Independence. + * + * On April 19, 1810, Venezuela began its independence movement by establishing a junta + * that deposed the Spanish colonial authorities. This date marks the beginning of + * Venezuelan independence. + * + * @see https://en.wikipedia.org/wiki/Venezuelan_Declaration_of_Independence + */ + protected function calculateDeclarationOfIndependence(): void + { + if ($this->year >= 1810) { + $this->addHoliday(new Holiday( + 'declarationOfIndependence', + [ + 'es' => 'Declaración de la Independencia', + 'en' => 'Declaration of Independence', + ], + new \DateTime("{$this->year}-04-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Battle of Carabobo. + * + * The Battle of Carabobo was fought on June 24, 1821. It was the decisive battle + * in the Venezuelan War of Independence that established the independence of Venezuela. + * + * @see https://en.wikipedia.org/wiki/Battle_of_Carabobo + */ + protected function calculateBattleOfCarabobo(): void + { + if ($this->year >= 1821) { + $this->addHoliday(new Holiday( + 'battleOfCarabobo', + [ + 'es' => 'Batalla de Carabobo', + 'en' => 'Battle of Carabobo', + ], + new \DateTime("{$this->year}-06-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Independence Day. + * + * Venezuelan Independence Day is celebrated on July 5th, marking the day when + * the Congress of Venezuela declared independence from Spain in 1811. + * + * @see https://en.wikipedia.org/wiki/Venezuelan_Independence + */ + protected function calculateIndependenceDay(): void + { + if ($this->year >= self::DECLARATION_OF_INDEPENDENCE_YEAR) { + $this->addHoliday(new Holiday( + 'independenceDay', + [ + 'es' => 'Día de la Independencia', + 'en' => 'Independence Day', + ], + new \DateTime("{$this->year}-07-05", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Simon Bolivar's Birthday. + * + * Simon Bolivar was born on July 24, 1783 in Caracas. He is considered the + * liberator of Venezuela, Colombia, Ecuador, Peru, and Bolivia. + * + * @see https://en.wikipedia.org/wiki/Simon_Bolivar + */ + protected function calculateSimonBolivarBirthday(): void + { + if ($this->year >= 1783) { + $this->addHoliday(new Holiday( + 'simonBolivarBirthday', + [ + 'es' => 'Natalicio del Libertador', + 'en' => "Simon Bolivar\u{2019}s Birthday", + ], + new \DateTime("{$this->year}-07-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Day of Indigenous Resistance. + * + * Formerly known as "Columbus Day" or "Day of the Race" (Día de la Raza), this holiday + * was renamed in 2002 to Day of Indigenous Resistance (Día de la Resistencia Indígena) + * to honor the indigenous peoples who resisted European colonization. + * + * @see https://en.wikipedia.org/wiki/Day_of_Indigenous_Resistance + */ + protected function calculateDayOfIndigenousResistance(): void + { + if ($this->year >= 1921) { + $this->addHoliday(new Holiday( + 'dayOfIndigenousResistance', + [ + 'es' => 'Día de la Resistencia Indígena', + 'en' => 'Day of Indigenous Resistance', + ], + new \DateTime("{$this->year}-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + } + + /** + * Christmas Eve. + * + * Christmas Eve (Nochebuena) is celebrated on December 24th and is an + * important family celebration in Venezuela. + */ + protected function calculateChristmasEve(): void + { + $this->addHoliday(new Holiday( + 'christmasEve', + [ + 'es' => 'Nochebuena', + 'en' => 'Christmas Eve', + ], + new \DateTime("{$this->year}-12-24", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } + + /** + * New Year's Eve. + * + * New Year's Eve (Nochevieja) is celebrated on December 31st. + */ + protected function calculateNewYearsEve(): void + { + $this->addHoliday(new Holiday( + 'newYearsEve', + [ + 'es' => 'Nochevieja', + 'en' => "New Year\u{2019}s Eve", + ], + new \DateTime("{$this->year}-12-31", DateTimeZoneFactory::getDateTimeZone($this->timezone)), + $this->locale + )); + } +} diff --git a/src/Yasumi/ProviderInterface.php b/src/Yasumi/ProviderInterface.php old mode 100755 new mode 100644 index 9c52175f3..60c0d4737 --- a/src/Yasumi/ProviderInterface.php +++ b/src/Yasumi/ProviderInterface.php @@ -1,17 +1,26 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; +use Yasumi\Exception\UnknownLocaleException; +use Yasumi\Filters\BetweenFilter; +use Yasumi\Filters\OnFilter; + /** * Interface ProviderInterface - Holiday provider interface. * @@ -19,10 +28,204 @@ * * @see AbstractProvider */ -interface ProviderInterface +interface ProviderInterface extends \Countable { /** - * Initialize country holidays. + * Returns a list of sources (i.e. references to websites, books, scientific papers, etc.) that are + * used for determining the calculation logic of the providers' holidays. + * + * @return array a list of external sources (empty when no sources are defined) + */ + public function getSources(): array; + + /** + * Returns the current year set for this Holiday calendar. + * + * @return int the year set for this Holiday calendar + */ + public function getYear(): int; + + /** + * Determines whether a date represents a working day or not. + * + * A working day is defined as a day that is not a holiday nor falls in the weekend. The index of the weekdays of + * the defined date is used for establishing this (0 = Sunday, 1 = Monday, etc.) + * + * @param \DateTimeInterface $date any date object that implements the DateTimeInterface (e.g. Yasumi\Holiday, + * \DateTime) + * + * @return bool true if date represents a working day, otherwise false + */ + public function isWorkingDay(\DateTimeInterface $date): bool; + + /** + * Retrieves the holiday object for the given holiday. + * + * @param string $key the name of the holiday + * + * @return Holiday|null a Holiday instance for the given holiday + * + * @throws \InvalidArgumentException when the given name is blank or empty + */ + public function getHoliday(string $key): ?Holiday; + + /** + * Gets all the holidays defined by this holiday provider (for the given year). + * + * @return Holiday[] list of all holidays defined for the given year + */ + public function getHolidays(): array; + + /** + * Determines whether a date represents a holiday or not. + * + * @param \DateTimeInterface $date any date object that implements the DateTimeInterface (e.g. Yasumi\Holiday, + * \DateTime) + * + * @return bool true if date represents a holiday, otherwise false + */ + public function isHoliday(\DateTimeInterface $date): bool; + + /** + * Get an iterator for the holidays. + * + * @return \ArrayIterator iterator for the holidays of this calendar + */ + public function getIterator(): \ArrayIterator; + + /** + * Adds a holiday to the holidays providers (i.e. country/state) list of holidays. + * + * @param Holiday $holiday holiday instance (representing a holiday) to be added to the internal list + * of holidays of this country + */ + public function addHoliday(Holiday $holiday): void; + + /** + * Removes a holiday from the holidays providers (i.e. country/state) list of holidays. + * + * This function can be helpful in cases where an existing holiday provider class can be extended but some holidays + * are not part of the original (extended) provider. + * + * @param string $key holiday key + */ + public function removeHoliday(string $key): void; + + /** + * Determines whether a date represents a weekend day or not. + * + * @param \DateTimeInterface $date any date object that implements the DateTimeInterface (e.g. Yasumi\Holiday, + * \DateTime) + * + * @return bool true if date represents a weekend day, otherwise false + */ + public function isWeekendDay(\DateTimeInterface $date): bool; + + /** + * On what date is the given holiday? + * + * @param string $key holiday key + * + * @return string the date of the requested holiday + * + * @throws \InvalidArgumentException when the given name is blank or empty + */ + public function whenIs(string $key): string; + + /** + * On what day of the week is the given holiday? + * + * This function returns the index number for the day of the week on which the given holiday falls. + * The index number is an integer starting with 0 being Sunday, 1 = Monday, etc. + * + * @param string $key key of the holiday + * + * @return int the index of the weekdays of the requested holiday (0 = Sunday, 1 = Monday, etc.) + * + * @throws \InvalidArgumentException when the given name is blank or empty + */ + public function whatWeekDayIs(string $key): int; + + /** + * Gets all the holiday names defined by this holiday provider (for the given year). + * + * @return array list of all holiday names defined for the given year + */ + public function getHolidayNames(): array; + + /** + * Retrieves the next date (year) the given holiday is going to take place. + * + * @param string $key key of the holiday for which the next occurrence need to be retrieved + * + * @return Holiday|null a Holiday instance for the given holiday + * + * @throws UnknownLocaleException + * @throws \RuntimeException + * @throws \InvalidArgumentException + * + * @covers AbstractProvider::anotherTime + */ + public function next(string $key): ?Holiday; + + /** + * Retrieves the previous date (year) the given holiday took place. + * + * @param string $key key of the holiday for which the previous occurrence need to be retrieved + * + * @return Holiday|null a Holiday instance for the given holiday + * + * @throws UnknownLocaleException + * @throws \RuntimeException + * @throws \InvalidArgumentException + * + * @covers AbstractProvider::anotherTime + */ + public function previous(string $key): ?Holiday; + + /** + * Retrieves a list of all holidays between the given start and end date. + * + * Yasumi only calculates holidays for a single year, so a start date or end date beyond the given year will only + * return holidays for the given year. For example, holidays calculated for the year 2016, will only return 2016 + * holidays if the provided period is for example 01/01/2012 - 31/12/2017. + * + * Please take care to use the appropriate timezone for the start and end date parameters. In case you use + * different + * timezone for these parameters versus the instantiated Holiday Provider, the outcome might be unexpected (but + * correct). + * + * @param \DateTimeInterface $startDate Start date of the time frame to check against + * @param \DateTimeInterface $endDate End date of the time frame to check against + * @param ?bool $equals indicate whether the start and end dates should be included in the + * comparison + * + * @throws \InvalidArgumentException an InvalidArgumentException is thrown if the start date is set after the end + * date + */ + public function between( + \DateTimeInterface $startDate, + \DateTimeInterface $endDate, + ?bool $equals = null, + ): BetweenFilter; + + /** + * Retrieves a list of all holidays that happen on the given date. + * + * Yasumi only calculates holidays for a single year, so a date outside the given year will not appear to + * contain any holidays. + * + * Please take care to use the appropriate timezone for the date parameters. If there is a different timezone used + * for these parameters versus the instantiated Holiday Provider, the outcome might be unexpected (but correct). + * + * @param \DateTimeInterface $date date to check for holidays on + */ + public function on(\DateTimeInterface $date): OnFilter; + + /** + * Gets all the holiday dates defined by this holiday provider (for the given year). + * + * @return array list of all holiday dates defined for the given year */ - public function initialize(); + public function getHolidayDates(): array; } diff --git a/src/Yasumi/SubstituteHoliday.php b/src/Yasumi/SubstituteHoliday.php old mode 100755 new mode 100644 index 1b2559dc5..fbdc08c99 --- a/src/Yasumi/SubstituteHoliday.php +++ b/src/Yasumi/SubstituteHoliday.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; -use Yasumi\Exception\InvalidDateException; +use Yasumi\Exception\MissingTranslationException; use Yasumi\Exception\UnknownLocaleException; /** @@ -21,37 +26,37 @@ * A substitute holiday is a holiday given in lieu of another holiday, if that day falls in a weekend or * overlaps with other holidays, so that people do not "lose" a day off in these years. * - * @link https://en.wikipedia.org/wiki/Substitute_holiday + * @see https://en.wikipedia.org/wiki/Substitute_holiday */ class SubstituteHoliday extends Holiday { /** - * @var Holiday + * @deprecated public access to this property is deprecated in favor of getSubstitutedHoliday() + * @see getSubstitutedHoliday() */ - public $substitutedHoliday; + public Holiday $substitutedHoliday; /** - * @var array list of translations of the "{0} observed" pattern + * @var array list of translations of the "{0} observed" pattern */ - public $substituteHolidayTranslations; + public array $substituteHolidayTranslations; /** * Creates a new SubstituteHoliday. * * If a holiday date needs to be defined for a specific timezone, make sure that the date instance - * (DateTimeInterface) has the correct timezone set. Otherwise the default system timezone is used. + * (DateTimeInterface) has the correct timezone set. Otherwise, the default system timezone is used. * - * @param Holiday $substitutedHoliday The holiday being substituted - * @param array $names An array containing the name/description of this holiday - * in various languages. Overrides global translations - * @param \DateTimeInterface $date A DateTimeInterface instance representing the date of the holiday - * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to - * be displayed in. (Default 'en_US') - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, - * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default - * an official holiday is considered. + * @param Holiday $substitutedHoliday The holiday being substituted + * @param array $names An array containing the name/description of this holiday + * in various languages. Overrides global translations + * @param \DateTimeInterface $date A DateTimeInterface instance representing the date of the holiday + * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to + * be displayed in. (Default 'en_US') + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, + * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default, + * an official holiday is considered. * - * @throws InvalidDateException * @throws UnknownLocaleException * @throws \InvalidArgumentException * @throws \Exception @@ -61,37 +66,58 @@ public function __construct( array $names, \DateTimeInterface $date, string $displayLocale = self::DEFAULT_LOCALE, - string $type = self::TYPE_OFFICIAL + string $type = self::TYPE_OFFICIAL, ) { $this->substitutedHoliday = $substitutedHoliday; - $shortName = 'substituteHoliday:' . $substitutedHoliday->shortName; + $key = 'substituteHoliday:' . $substitutedHoliday->getKey(); if ($date == $substitutedHoliday) { throw new \InvalidArgumentException('Date must differ from the substituted holiday'); } // Construct instance - parent::__construct($shortName, $names, $date, $displayLocale, $type); + parent::__construct($key, $names, $date, $displayLocale, $type); + } + + /** + * Returns the holiday being substituted. + * + * @return Holiday the holiday being substituted + */ + public function getSubstitutedHoliday(): Holiday + { + return $this->substitutedHoliday; } /** - * Returns the name of this holiday. + * Returns the localized name of this holiday. + * + * The provided locales are searched for a translation. The first locale containing a translation will be used. + * + * If no locale is provided, proceed as if an array containing the display locale, Holiday::DEFAULT_LOCALE ('en_US'), and + * Holiday::LOCALE_KEY (the holiday key) was provided. * - * The name of this holiday is returned translated in the given locale. If for the given locale no translation is - * defined, the name in the default locale ('en_US') is returned. In case there is no translation at all, the short - * internal name is returned. + * @param array $locales The locales to search for translations + * + * @throws MissingTranslationException + * + * @see Holiday::DEFAULT_LOCALE + * @see Holiday::LOCALE_KEY */ - public function getName(): string + public function getName(?array $locales = null): string { $name = parent::getName(); - if ($name === $this->shortName) { - $pattern = $this->substituteHolidayTranslations[$this->displayLocale] - ?? $this->substituteHolidayTranslations[self::DEFAULT_LOCALE] - ?? $this->shortName; + if ($name !== $this->getKey()) { + return $name; + } - $name = \str_replace('{0}', $this->substitutedHoliday->getName(), $pattern); + foreach ($this->getLocales($locales) as $localeList) { + $pattern = $this->substituteHolidayTranslations[$localeList] ?? null; + if ($pattern) { + return str_replace('{0}', $this->substitutedHoliday->getName(), $pattern); + } } return $name; @@ -102,7 +128,7 @@ public function getName(): string * * @param TranslationsInterface $globalTranslations global translations */ - public function mergeGlobalTranslations(TranslationsInterface $globalTranslations) + public function mergeGlobalTranslations(TranslationsInterface $globalTranslations): void { $this->substituteHolidayTranslations = $globalTranslations->getTranslations('substituteHoliday'); diff --git a/src/Yasumi/Translations.php b/src/Yasumi/Translations.php index ec4abe1d5..5fa3df77c 100644 --- a/src/Yasumi/Translations.php +++ b/src/Yasumi/Translations.php @@ -1,45 +1,38 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; -use DirectoryIterator; -use InvalidArgumentException; use Yasumi\Exception\UnknownLocaleException; -/** - * Class Translations. - */ class Translations implements TranslationsInterface { /** - * @var array translations array: ['' => ['' => 'translation', ...], ... ] + * @var array> translations array: ['' => ['' => 'translation', ...], ... ] */ - public $translations = []; - - /** - * @var array list of all defined locales - */ - private $availableLocales; + public array $translations = []; /** * Constructor. * - * @param array $availableLocales list of all defined locales + * @param array $availableLocales list of all defined locales */ - public function __construct(array $availableLocales) + public function __construct(private readonly array $availableLocales) { - $this->availableLocales = $availableLocales; } /** @@ -48,19 +41,23 @@ public function __construct(array $availableLocales) * @param string $directoryPath directory path for translation files * * @throws UnknownLocaleException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function loadTranslations(string $directoryPath): void { - if (!\file_exists($directoryPath)) { - throw new InvalidArgumentException('Directory with translations not found'); + if (! file_exists($directoryPath)) { + throw new \InvalidArgumentException('Directory with translations not found'); } - $directoryPath = \rtrim($directoryPath, '/\\') . DIRECTORY_SEPARATOR; + $directoryPath = rtrim($directoryPath, '/\\') . \DIRECTORY_SEPARATOR; $extension = 'php'; - foreach (new DirectoryIterator($directoryPath) as $file) { - if ($file->isDot() || $file->isDir()) { + foreach (new \DirectoryIterator($directoryPath) as $file) { + if ($file->isDot()) { + continue; + } + + if ($file->isDir()) { continue; } @@ -69,90 +66,65 @@ public function loadTranslations(string $directoryPath): void } $filename = $file->getFilename(); - $shortName = $file->getBasename('.' . $extension); + $key = $file->getBasename('.' . $extension); $translations = require $directoryPath . $filename; if (\is_array($translations)) { - foreach (\array_keys($translations) as $locale) { - $this->isValidLocale($locale); // Validate the given locale + foreach (array_keys($translations) as $locale) { + $this->checkLocale((string) $locale); } - $this->translations[$shortName] = $translations; + $this->translations[$key] = $translations; } } } - /** - * Checks whether the given locale is a valid/available locale. - * - * @param string $locale locale the locale to be validated - * - * @return true upon success, otherwise an UnknownLocaleException is thrown - * @throws UnknownLocaleException An UnknownLocaleException is thrown if the given locale is not - * valid/available. - * - */ - protected function isValidLocale(string $locale): bool - { - if (!\in_array($locale, $this->availableLocales, true)) { - throw new UnknownLocaleException(\sprintf('Locale "%s" is not a valid locale.', $locale)); - } - - return true; - } - /** * Adds translation for holiday in specific locale. * - * @param string $shortName holiday short name - * @param string $locale locale + * @param string $key holiday key + * @param string $locale locale * @param string $translation translation * * @throws UnknownLocaleException */ - public function addTranslation(string $shortName, string $locale, string $translation): void + public function addTranslation(string $key, string $locale, string $translation): void { - $this->isValidLocale($locale); // Validate the given locale - - if (!\array_key_exists($shortName, $this->translations)) { - $this->translations[$shortName] = []; - } + $this->checkLocale($locale); - $this->translations[$shortName][$locale] = $translation; + $this->translations[$key][$locale] = $translation; } /** * Returns translation for holiday in specific locale. * - * @param string $shortName holiday short name + * @param string $key holiday key * @param string $locale locale * * @return string|null translated holiday name */ - public function getTranslation(string $shortName, string $locale): ?string + public function getTranslation(string $key, string $locale): ?string { - if (!\array_key_exists($shortName, $this->translations) - || !\array_key_exists($locale, $this->translations[$shortName])) { - return null; - } - - return $this->translations[$shortName][$locale]; + return $this->translations[$key][$locale] ?? null; } /** * Returns all available translations for holiday. * - * @param string $shortName holiday short name + * @param string $key holiday key * - * @return array holiday name translations ['' => '', ...] + * @return array holiday name translations ['' => '', ...] */ - public function getTranslations(string $shortName): array + public function getTranslations(string $key): array { - if (!\array_key_exists($shortName, $this->translations)) { - return []; - } + return $this->translations[$key] ?? []; + } - return $this->translations[$shortName]; + private function checkLocale(string $locale): void + { + if (! \in_array($locale, $this->availableLocales, true)) { + throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $locale)); + } } } diff --git a/src/Yasumi/TranslationsInterface.php b/src/Yasumi/TranslationsInterface.php index 94545cc3b..2dd55a6fc 100644 --- a/src/Yasumi/TranslationsInterface.php +++ b/src/Yasumi/TranslationsInterface.php @@ -1,38 +1,40 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; -/** - * Interface TranslationsInterface. - */ interface TranslationsInterface { /** * Returns translation for holiday in specific locale. * - * @param string $shortName holiday short name + * @param string $key holiday key * @param string $locale locale * * @return string|null translated holiday name */ - public function getTranslation(string $shortName, string $locale): ?string; + public function getTranslation(string $key, string $locale): ?string; /** * Returns all available translations for holiday. * - * @param string $shortName holiday short name + * @param string $key holiday key * - * @return array holiday name translations ['' => '', ...] + * @return array holiday name translations ['' => '', ...] */ - public function getTranslations(string $shortName): array; + public function getTranslations(string $key): array; } diff --git a/src/Yasumi/Yasumi.php b/src/Yasumi/Yasumi.php old mode 100755 new mode 100644 index e9280365a..25ad800be --- a/src/Yasumi/Yasumi.php +++ b/src/Yasumi/Yasumi.php @@ -1,24 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi; -use FilesystemIterator; -use InvalidArgumentException; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; -use ReflectionClass; -use RuntimeException; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\InvalidYearException; use Yasumi\Exception\ProviderNotFoundException; use Yasumi\Exception\UnknownLocaleException; @@ -29,29 +27,26 @@ */ class Yasumi { - /** - * Default locale. - */ public const DEFAULT_LOCALE = 'en_US'; - /** - * @var array list of all defined locales - */ - private static $locales = []; + public const YEAR_LOWER_BOUND = 1000; + + public const YEAR_UPPER_BOUND = 9999; /** - * Global translations. - * - * @var Translations + * @var array list of all defined locales */ - private static $globalTranslations; + private static array $locales = []; + + /** Global translations */ + private static ?Translations $globalTranslations = null; /** - * Provider class to be ignored (Abstract, trait, other) + * Provider class to be ignored (Abstract, trait, other). * - * @var array + * @var array */ - private static $ignoredProvider = [ + private static array $ignoredProvider = [ 'AbstractProvider.php', 'CommonHolidays.php', 'ChristianHolidays.php', @@ -64,40 +59,38 @@ class Yasumi * by this Holiday Provider. The workingDays parameter can be used how far ahead (in days) the next working day * must be searched for. * - * @param string $class Holiday Provider name - * @param \DateTimeInterface $startDate Start date, defaults to today - * @param int $workingDays Number of days to look ahead for the (first) next working day - * - * @return \DateTimeInterface + * @param string $class Holiday Provider name + * @param \DateTimeInterface $startDate Start date, defaults to today + * @param int $workingDays Number of days to look ahead for the (first) next working day * - * @throws \ReflectionException * @throws UnknownLocaleException - * @throws RuntimeException - * @throws InvalidArgumentException + * @throws \RuntimeException + * @throws \InvalidArgumentException * @throws \Exception - * @throws InvalidDateException * * @TODO we should accept a timezone so we can accept int/string for $startDate - * */ public static function nextWorkingDay( string $class, \DateTimeInterface $startDate, - int $workingDays = 1 + int $workingDays = 1, ): \DateTimeInterface { - - // Setup start date, if its an instance of \DateTime, clone to prevent modification to original - $date = $startDate instanceof \DateTime ? clone $startDate : $startDate; - - $provider = false; + $date = $startDate instanceof \DateTime ? \DateTimeImmutable::createFromMutable($startDate) : $startDate; + $provider = null; while ($workingDays > 0) { $date = $date->add(new \DateInterval('P1D')); - if (!$provider || $provider->getYear() !== \getdate()['year']) { - $provider = self::create($class, (int)$date->format('Y')); + + if (! $date instanceof \DateTimeImmutable) { + throw new \RuntimeException('Unable to perform date interval addition'); + } + + if (! $provider instanceof ProviderInterface || $provider->getYear() !== (int) $date->format('Y')) { + $provider = self::create($class, (int) $date->format('Y')); } + if ($provider->isWorkingDay($date)) { - $workingDays--; + --$workingDays; } } @@ -111,60 +104,65 @@ public static function nextWorkingDay( * already with Yasumi, or your own provider by giving the name of your class in the first parameter. Your provider * class needs to implement the 'ProviderInterface' class. * - * @param string $class holiday provider name - * @param int $year year for which the country provider needs to be created. Year needs to be a valid integer - * between 1000 and 9999. + * @param string $class holiday provider name + * @param int $year year for which the country provider needs to be created. Year needs to be a valid integer + * between the defined lower and upper bounds. * @param string $locale The locale to use. If empty we'll use the default locale (en_US) * - * @return AbstractProvider An instance of class $class is created and returned + * @return ProviderInterface An instance of class $class is created and returned * - * @throws RuntimeException If no such holiday provider is found - * @throws InvalidYearException if the year parameter is not between 1000 and 9999 + * @throws \RuntimeException If no such holiday provider is found + * @throws InvalidYearException if the year parameter is not between the defined lower and upper bounds * @throws UnknownLocaleException if the locale parameter is invalid * @throws ProviderNotFoundException if the holiday provider for the given country does not exist - * @throws \ReflectionException */ - public static function create(string $class, int $year = 0, string $locale = self::DEFAULT_LOCALE): ProviderInterface + public static function create(string $class, int $year = self::YEAR_LOWER_BOUND, string $locale = self::DEFAULT_LOCALE): ProviderInterface { // Find and return holiday provider instance - $providerClass = \sprintf('Yasumi\Provider\%s', \str_replace('/', '\\', $class)); + $providerClass = sprintf('Yasumi\Provider\%s', str_replace('/', '\\', $class)); - if (\class_exists($class) && (new ReflectionClass($class))->implementsInterface(ProviderInterface::class)) { + if (class_exists($class) && (new \ReflectionClass($class))->implementsInterface(ProviderInterface::class)) { $providerClass = $class; } - if ('AbstractProvider' === $class || !\class_exists($providerClass)) { - throw new ProviderNotFoundException(\sprintf('Unable to find holiday provider "%s".', $class)); + if ('AbstractProvider' === $class || ! class_exists($providerClass)) { + throw new ProviderNotFoundException(sprintf('Unable to find holiday provider "%s".', $class)); } // Assert year input - if ($year < 1000 || $year > 9999) { - throw new InvalidYearException(\sprintf('Year needs to be between 1000 and 9999 (%d given).', $year)); + if ($year < self::YEAR_LOWER_BOUND || $year > self::YEAR_UPPER_BOUND) { + throw new InvalidYearException(sprintf('Year needs to be between %d and %d (%d given).', self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND, $year)); } // Load internal locales variable - if (empty(self::$locales)) { + if ([] === self::$locales) { self::$locales = self::getAvailableLocales(); } // Load internal translations variable - if (null === self::$globalTranslations) { + if (! self::$globalTranslations instanceof Translations) { self::$globalTranslations = new Translations(self::$locales); self::$globalTranslations->loadTranslations(__DIR__ . '/data/translations'); } // Assert locale input - if (!\in_array($locale, self::$locales, true)) { - throw new UnknownLocaleException(\sprintf('Locale "%s" is not a valid locale.', $locale)); + if (! \in_array($locale, self::$locales, true)) { + throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $locale)); + } + + $instance = new $providerClass($year, $locale, self::$globalTranslations); + + if (! $instance instanceof ProviderInterface) { + throw new ProviderNotFoundException(sprintf('Holiday provider "%s" does not implement ProviderInterface.', $class)); } - return new $providerClass($year, $locale, self::$globalTranslations); + return $instance; } /** * Returns a list of available locales. * - * @return array list of available locales + * @return array list of available locales */ public static function getAvailableLocales(): array { @@ -178,40 +176,37 @@ public static function getAvailableLocales(): array * already with Yasumi, or your own provider by giving the 'const ID', corresponding to the ISO3166-2 Code, set in * your class in the first parameter. Your provider class needs to implement the 'ProviderInterface' class. * - * @param string $iso3166_2 ISO3166-2 Coded region, holiday provider will be searched for - * @param int $year year for which the country provider needs to be created. Year needs to be a valid - * integer between 1000 and 9999. - * @param string $locale The locale to use. If empty we'll use the default locale (en_US) + * @param string $isoCode ISO3166-2 Coded region, holiday provider will be searched for + * @param int $year year for which the country provider needs to be created. Year needs to be a valid + * integer between the defined lower and upper bounds. + * @param string $locale The locale to use. If empty we'll use the default locale (en_US) * - * @return AbstractProvider An instance of class $class is created and returned + * @return ProviderInterface An instance of class $class is created and returned * - * @throws RuntimeException If no such holiday provider is found - * @throws InvalidArgumentException if the year parameter is not between 1000 and 9999 + * @throws \RuntimeException If no such holiday provider is found + * @throws \InvalidArgumentException if the year parameter is not between the defined lower and upper bounds * @throws UnknownLocaleException if the locale parameter is invalid * @throws ProviderNotFoundException if the holiday provider for the given ISO3166-2 code does not exist * @throws \ReflectionException */ public static function createByISO3166_2( - string $iso3166_2, - int $year = 0, - string $locale = self::DEFAULT_LOCALE - ): AbstractProvider { + string $isoCode, + int $year = self::YEAR_LOWER_BOUND, + string $locale = self::DEFAULT_LOCALE, + ): ProviderInterface { $availableProviders = self::getProviders(); - if (false === isset($availableProviders[$iso3166_2])) { - throw new ProviderNotFoundException(\sprintf( - 'Unable to find holiday provider by ISO3166-2 "%s".', - $iso3166_2 - )); + if (! isset($availableProviders[$isoCode])) { + throw new ProviderNotFoundException(sprintf('Unable to find holiday provider by ISO3166-2 "%s".', $isoCode)); } - return self::create($availableProviders[$iso3166_2], $year, $locale); + return self::create($availableProviders[$isoCode], $year, $locale); } /** * Returns a list of available holiday providers. * - * @return array list of available holiday providers + * @return array list of available holiday providers * * @throws \ReflectionException */ @@ -219,34 +214,55 @@ public static function getProviders(): array { // Basic static cache static $providers; - if (!empty($providers)) { + if (null !== $providers && [] !== $providers) { return $providers; } $providers = []; - $filesIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( - __DIR__ . DIRECTORY_SEPARATOR . 'Provider', - FilesystemIterator::SKIP_DOTS - ), RecursiveIteratorIterator::SELF_FIRST); + $filesIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( + __DIR__ . \DIRECTORY_SEPARATOR . 'Provider', + \FilesystemIterator::SKIP_DOTS + ), \RecursiveIteratorIterator::SELF_FIRST); + /** @var \SplFileInfo $file */ foreach ($filesIterator as $file) { - if ($file->isDir() || 'php' !== $file->getExtension() || \in_array( + if ($file->isDir()) { + continue; + } + + if ('php' !== $file->getExtension()) { + continue; + } + + if (\in_array( $file->getBasename('.php'), self::$ignoredProvider, true )) { continue; } + $quotedDs = preg_quote(\DIRECTORY_SEPARATOR, ''); + $provider = preg_replace("#^.+{$quotedDs}Provider{$quotedDs}(.+)\\.php$#", '$1', $file->getPathName()); - $quotedDs = \preg_quote(DIRECTORY_SEPARATOR, ''); - $provider = \preg_replace("#^.+{$quotedDs}Provider{$quotedDs}(.+)\\.php$#", '$1', $file->getPathName()); + if (! is_string($provider)) { + continue; + } - $class = new ReflectionClass(\sprintf('Yasumi\Provider\%s', \str_replace('/', '\\', $provider))); + /** @var class-string $providerClass */ + $providerClass = sprintf('Yasumi\Provider\%s', str_replace('/', '\\', $provider)); + $class = new \ReflectionClass($providerClass); $key = 'ID'; - if ($class->isSubclassOf(AbstractProvider::class) && $class->hasConstant($key)) { - $providers[\strtoupper($class->getConstant($key))] = $provider; + + if (! $class->isSubclassOf(AbstractProvider::class)) { + continue; } + + if (! $class->hasConstant($key)) { + continue; + } + + $providers[strtoupper((string) $class->getConstant($key))] = $provider; } return $providers; @@ -259,39 +275,38 @@ public static function getProviders(): array * by this Holiday Provider. The workingDays parameter can be used how far back (in days) the previous working day * must be searched for. * - * @param string $class Holiday Provider name - * @param \DateTimeInterface $startDate Start date, defaults to today - * @param int $workingDays Number of days to look back for the (first) previous working day + * @param string $class Holiday Provider name + * @param \DateTimeInterface $startDate Start date, defaults to today + * @param int $workingDays Number of days to look back for the (first) previous working day * - * @return \DateTimeInterface - * - * @throws \ReflectionException * @throws UnknownLocaleException - * @throws RuntimeException - * @throws InvalidArgumentException + * @throws \RuntimeException + * @throws \InvalidArgumentException * @throws \Exception - * @throws InvalidDateException * * @TODO we should accept a timezone so we can accept int/string for $startDate */ public static function prevWorkingDay( string $class, \DateTimeInterface $startDate, - int $workingDays = 1 + int $workingDays = 1, ): \DateTimeInterface { - - // Setup start date, if its an instance of \DateTime, clone to prevent modification to original - $date = $startDate instanceof \DateTime ? clone $startDate : $startDate; - - $provider = false; + $date = $startDate instanceof \DateTime ? \DateTimeImmutable::createFromMutable($startDate) : $startDate; + $provider = null; while ($workingDays > 0) { $date = $date->sub(new \DateInterval('P1D')); - if (!$provider || $provider->getYear() !== \getdate()['year']) { - $provider = self::create($class, (int)$date->format('Y')); + + if (! $date instanceof \DateTimeImmutable) { + throw new \RuntimeException('Unable to perform date interval subtraction'); } + + if (! $provider instanceof ProviderInterface || $provider->getYear() !== (int) $date->format('Y')) { + $provider = self::create($class, (int) $date->format('Y')); + } + if ($provider->isWorkingDay($date)) { - $workingDays--; + --$workingDays; } } diff --git a/src/Yasumi/data/locales.php b/src/Yasumi/data/locales.php index e4cd6102d..ba164460f 100644 --- a/src/Yasumi/data/locales.php +++ b/src/Yasumi/data/locales.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // List of possible locales. This list is used in case the 'intl' extension is not loaded/available. diff --git a/src/Yasumi/data/translations/allSaintsDay.php b/src/Yasumi/data/translations/allSaintsDay.php old mode 100755 new mode 100644 index b7e2f2cc7..087210f83 --- a/src/Yasumi/data/translations/allSaintsDay.php +++ b/src/Yasumi/data/translations/allSaintsDay.php @@ -1,24 +1,30 @@ - + * @author Sacha Telgenhof */ // Translations for All Saints' Day return [ + 'ca' => 'Dia de Tots Sants', 'de' => 'Allerheiligen', 'el' => 'Άγιοι Πάντες', - 'en' => 'All Saints\' Day', + 'en' => 'All Saints’ Day', 'es' => 'Día de todos los Santos', 'fi' => 'Pyhäinpäivä', - 'fr_BE' => 'La Toussaint', 'fr' => 'Toussaint', + 'fr_BE' => 'La Toussaint', 'hr' => 'Dan svih svetih', 'hu' => 'Mindenszentek', 'it' => 'Festa di Tutti i Santi', diff --git a/src/Yasumi/data/translations/allSaintsEve.php b/src/Yasumi/data/translations/allSaintsEve.php old mode 100755 new mode 100644 index 27a222c7e..5d47346e2 --- a/src/Yasumi/data/translations/allSaintsEve.php +++ b/src/Yasumi/data/translations/allSaintsEve.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for All Saints' Eve return [ - 'da' => 'Allehelgensaften', - 'en' => 'All Saints\' Eve', + 'da' => 'allehelgensaften', + 'en' => 'All Saints’ Eve', 'sv' => 'alla helgons afton', ]; diff --git a/src/Yasumi/data/translations/allSoulsDay.php b/src/Yasumi/data/translations/allSoulsDay.php new file mode 100644 index 000000000..6a75bc829 --- /dev/null +++ b/src/Yasumi/data/translations/allSoulsDay.php @@ -0,0 +1,23 @@ + + */ + +// Translations for All Souls' Day +return [ + 'en' => 'All Souls’ Day', + 'lt' => 'Vėlinės', + 'pt' => 'Dia de Finados', +]; diff --git a/src/Yasumi/data/translations/annunciation.php b/src/Yasumi/data/translations/annunciation.php index 1a8f148b0..fdcf2ba67 100644 --- a/src/Yasumi/data/translations/annunciation.php +++ b/src/Yasumi/data/translations/annunciation.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Annunciation diff --git a/src/Yasumi/data/translations/anzacDay.php b/src/Yasumi/data/translations/anzacDay.php index 632b1bec9..e2fa9928c 100644 --- a/src/Yasumi/data/translations/anzacDay.php +++ b/src/Yasumi/data/translations/anzacDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for ANZAC Day diff --git a/src/Yasumi/data/translations/armisticeDay.php b/src/Yasumi/data/translations/armisticeDay.php index f9cb906b4..b74650311 100644 --- a/src/Yasumi/data/translations/armisticeDay.php +++ b/src/Yasumi/data/translations/armisticeDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Armistice Day diff --git a/src/Yasumi/data/translations/ascensionDay.php b/src/Yasumi/data/translations/ascensionDay.php index 8e2f97906..1c231f71c 100644 --- a/src/Yasumi/data/translations/ascensionDay.php +++ b/src/Yasumi/data/translations/ascensionDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Ascension Day @@ -22,5 +27,6 @@ 'it' => 'Ascensione', 'nb' => 'Kristi himmelfartsdag', 'nl' => 'Hemelvaart', + 'sk' => 'Nanebovstúpenie Pána', 'sv' => 'Kristi himmelsfärdsdag', ]; diff --git a/src/Yasumi/data/translations/ashWednesday.php b/src/Yasumi/data/translations/ashWednesday.php index 7f15e9ee5..2bac3574b 100644 --- a/src/Yasumi/data/translations/ashWednesday.php +++ b/src/Yasumi/data/translations/ashWednesday.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Ash Wednesday @@ -19,4 +24,5 @@ 'it' => 'Mercoledi delle Ceneri', 'nl' => 'Aswoensdag', 'pt' => 'Quarta-feira de Cinzas', + 'sk' => 'Popolcová streda', ]; diff --git a/src/Yasumi/data/translations/assumptionOfMary.php b/src/Yasumi/data/translations/assumptionOfMary.php old mode 100755 new mode 100644 index 2659f2bf2..15b9451bf --- a/src/Yasumi/data/translations/assumptionOfMary.php +++ b/src/Yasumi/data/translations/assumptionOfMary.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Assumption of Mary return [ + 'ca' => 'l’Assumpció', 'de' => 'Mariä Himmelfahrt', 'el' => 'Κοίμηση της Θεοτόκου', 'en' => 'Assumption of Mary', @@ -26,4 +32,5 @@ 'pt' => 'Assunção de Nossa Senhora', 'ro' => 'Adormirea Maicii Domnului', 'sk' => 'Nanebovzatie Panny Márie', + 'sl' => 'Marijino vnebovzetje', ]; diff --git a/src/Yasumi/data/translations/australiaDay.php b/src/Yasumi/data/translations/australiaDay.php index a07d969b1..f9f9c73a5 100644 --- a/src/Yasumi/data/translations/australiaDay.php +++ b/src/Yasumi/data/translations/australiaDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Australia Day diff --git a/src/Yasumi/data/translations/canadaDay.php b/src/Yasumi/data/translations/canadaDay.php new file mode 100644 index 000000000..4719af44b --- /dev/null +++ b/src/Yasumi/data/translations/canadaDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Canada Day +return [ + 'en' => 'Canada Day', + 'fr' => 'Fête du Canada', +]; diff --git a/src/Yasumi/data/translations/carnationRevolutionDay.php b/src/Yasumi/data/translations/carnationRevolutionDay.php index b223b2d9c..95ae93fae 100644 --- a/src/Yasumi/data/translations/carnationRevolutionDay.php +++ b/src/Yasumi/data/translations/carnationRevolutionDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Freedom Day diff --git a/src/Yasumi/data/translations/christmasDay.php b/src/Yasumi/data/translations/christmasDay.php old mode 100755 new mode 100644 index 04332e431..16d0ab39a --- a/src/Yasumi/data/translations/christmasDay.php +++ b/src/Yasumi/data/translations/christmasDay.php @@ -1,21 +1,28 @@ - + * @author Sacha Telgenhof */ // Translations for Christmas return [ + 'bg' => 'Рождество Христово', 'bs_Latn' => 'Božić', + 'ca' => 'Nadal', 'cs' => '1. svátek vánoční', 'cy' => 'Nadolig', - 'da' => 'Juledag', + 'da' => 'juledag', 'de' => '1. Weihnachtsfeiertag', 'de_AT' => 'Christtag', 'de_CH' => 'Weihnachtstag', @@ -32,14 +39,15 @@ 'ko' => '기독탄신일', 'lt' => 'Šv. Kalėdos', 'lv' => 'Ziemassvētki', - 'nb' => 'Første juledag', - 'nl' => 'Eerste kerstdag', + 'nb' => 'første juledag', + 'nl' => 'eerste kerstdag', 'nl_BE' => 'Kerstmis', 'pl' => 'pierwszy dzień Bożego Narodzenia', 'pt' => 'Natal', 'ro' => 'Crăciunul', 'ru' => 'Рождество', 'sk' => 'Prvý sviatok vianočný', + 'sl' => 'Božič', 'sv' => 'juldagen', 'uk' => 'Різдво', ]; diff --git a/src/Yasumi/data/translations/christmasEve.php b/src/Yasumi/data/translations/christmasEve.php old mode 100755 new mode 100644 index 9315fcd27..df662b8e2 --- a/src/Yasumi/data/translations/christmasEve.php +++ b/src/Yasumi/data/translations/christmasEve.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for Christmas Eve return [ + 'bg' => 'Бъдни вечер', 'cs' => 'Štědrý den', 'cy' => 'Noswyl Nadolig', - 'da' => 'Juleaften', + 'da' => 'juleaften', 'de' => 'Heiliger Abend', 'en' => 'Christmas Eve', 'et' => 'Jõululaupäev', @@ -23,6 +29,7 @@ 'ko' => '크리스마스 이브', 'lt' => 'Šv. Kūčios', 'lv' => 'Ziemassvētku vakars', + 'pl' => 'Wigilia Bożego Narodzenia', 'pt' => 'Véspera de Natal', 'ro' => 'Ajunul Crãciunului', 'sk' => 'Štedrý deň', diff --git a/src/Yasumi/data/translations/civicHoliday.php b/src/Yasumi/data/translations/civicHoliday.php new file mode 100644 index 000000000..0e3193f57 --- /dev/null +++ b/src/Yasumi/data/translations/civicHoliday.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Civic Holiday +return [ + 'en' => 'Civic Holiday', + 'fr' => 'Premier lundi d’août', +]; diff --git a/src/Yasumi/data/translations/corpusChristi.php b/src/Yasumi/data/translations/corpusChristi.php index 4506cea6d..8743b113b 100644 --- a/src/Yasumi/data/translations/corpusChristi.php +++ b/src/Yasumi/data/translations/corpusChristi.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Corpus Christi @@ -20,4 +25,5 @@ 'pl' => 'Boże Ciało', 'pt' => 'Corpus Christi', 'pt_PT' => 'Corpo de Deus', + 'sk' => 'Božie Telo', ]; diff --git a/src/Yasumi/data/translations/dayAfterNewYearsDay.php b/src/Yasumi/data/translations/dayAfterNewYearsDay.php index 53c0692dd..ab9206af9 100644 --- a/src/Yasumi/data/translations/dayAfterNewYearsDay.php +++ b/src/Yasumi/data/translations/dayAfterNewYearsDay.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Day after New Year's Day return [ - 'en' => 'Day after New Year\'s Day', + 'en' => 'Day after New Year’s Day', 'ko' => '새해 연휴', 'ro' => 'A doua zi după Anul Nou', ]; diff --git a/src/Yasumi/data/translations/dayOfLiberation.php b/src/Yasumi/data/translations/dayOfLiberation.php new file mode 100644 index 000000000..bea5ccb96 --- /dev/null +++ b/src/Yasumi/data/translations/dayOfLiberation.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Day of Liberation +return [ + 'de' => 'Tag der Befreiung', + 'en' => 'Day of Liberation', +]; diff --git a/src/Yasumi/data/translations/dayOfReformation.php b/src/Yasumi/data/translations/dayOfReformation.php old mode 100755 new mode 100644 index acbac8543..40b704ac7 --- a/src/Yasumi/data/translations/dayOfReformation.php +++ b/src/Yasumi/data/translations/dayOfReformation.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Day of Reformation diff --git a/src/Yasumi/data/translations/discoveryDay.php b/src/Yasumi/data/translations/discoveryDay.php new file mode 100644 index 000000000..1c2699bbf --- /dev/null +++ b/src/Yasumi/data/translations/discoveryDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Discovery Day +return [ + 'en' => 'Discovery Day', + 'fr' => 'Journée découverte', +]; diff --git a/src/Yasumi/data/translations/easter.php b/src/Yasumi/data/translations/easter.php index 4c431f116..c926fd333 100644 --- a/src/Yasumi/data/translations/easter.php +++ b/src/Yasumi/data/translations/easter.php @@ -1,24 +1,31 @@ - + * @author Sacha Telgenhof */ // Translations for Easter Sunday return [ 'bs_Latn' => 'Uskrs', + 'ca' => 'Pasqua', 'cy' => 'Sul y Pasg', - 'da' => 'Påskedag', + 'da' => 'påskedag', 'de' => 'Ostersonntag', 'de_CH' => 'Ostern', 'el' => 'Κυριακή του Πάσχα', 'en' => 'Easter Sunday', + 'es' => 'Pascua de Resurrección', 'et' => 'Ülestõusmispühade 1. püha', 'fi' => 'Pääsiäispäivä', 'fr' => 'Pâques', @@ -26,14 +33,16 @@ 'hr' => 'Uskrs', 'hu' => 'Húsvét', 'it' => 'Pasqua', + 'ka' => 'აღდგომა', 'lt' => 'Velykos', 'lv' => 'Lieldienas', - 'nb' => 'Første påskedag', - 'nl' => 'Eerste paasdag', + 'nb' => 'første påskedag', + 'nl' => 'eerste paasdag', 'pl' => 'Wielkanoc', 'pt' => 'Páscoa', 'ro' => 'Paștele', 'ru' => 'Пасха', + 'sl' => 'Velika noč', 'sv' => 'påskdagen', 'uk' => 'Великдень', ]; diff --git a/src/Yasumi/data/translations/easterMonday.php b/src/Yasumi/data/translations/easterMonday.php index ce6d42379..e13cfc29d 100644 --- a/src/Yasumi/data/translations/easterMonday.php +++ b/src/Yasumi/data/translations/easterMonday.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Easter Monday return [ + 'ca' => 'dilluns de Pasqua', 'cs' => 'Velikonoční pondělí', 'cy' => 'Llun y Pasg', 'da' => '2. påskedag', @@ -24,15 +30,16 @@ 'ga' => 'Luan Cásca', 'hr' => 'Uskršnji ponedjeljak', 'hu' => 'Húsvéthétfő', - 'it' => 'Lunedì dell\'Angelo', + 'it' => 'Lunedì dell’Angelo', 'it_CH' => 'Lunedi di Pasqua', 'lt' => 'Antroji Velykų diena', 'lv' => 'Otrās Lieldienas', - 'nb' => 'Andre påskedag', - 'nl_BE' => 'Paasmaandag', - 'nl' => 'Tweede paasdag', + 'nb' => 'andre påskedag', + 'nl' => 'tweede paasdag', + 'nl_BE' => 'paasmaandag', 'pl' => 'Poniedziałek Wielkanocny', 'ro' => 'A doua zi de Paște', 'sk' => 'Veľkonočný pondelok', + 'sl' => 'Velikonočni ponedeljek', 'sv' => 'annandag påsk', ]; diff --git a/src/Yasumi/data/translations/epiphany.php b/src/Yasumi/data/translations/epiphany.php index 6f882d100..7825d9678 100644 --- a/src/Yasumi/data/translations/epiphany.php +++ b/src/Yasumi/data/translations/epiphany.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for Epiphany return [ + 'ca' => 'Epifania', + 'de' => 'Heilige 3 Könige', 'de_AT' => 'Heilige Drei Könige', 'de_CH' => 'Heilige Drei Könige', - 'de' => 'Heilige 3 Könige', 'el' => 'Θεοφάνεια', 'en' => 'Epiphany', 'es' => 'Día de Reyes', @@ -25,6 +31,7 @@ 'ja' => 'エピファニー', 'nl' => 'Drie Koningen', 'pl' => 'Święto Trzech Króli', + 'ro' => 'Bobotează', 'sk' => 'Zjavenie Pána / Traja králi', 'sv' => 'trettondedag jul', ]; diff --git a/src/Yasumi/data/translations/epiphanyEve.php b/src/Yasumi/data/translations/epiphanyEve.php index 5b24ddaff..90e73a155 100644 --- a/src/Yasumi/data/translations/epiphanyEve.php +++ b/src/Yasumi/data/translations/epiphanyEve.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Epiphany Eve return [ - 'da' => 'Helligtrekongersaften', + 'da' => 'helligtrekongersaften', 'en' => 'Epiphany Eve', 'sv' => 'trettondagsafton', ]; diff --git a/src/Yasumi/data/translations/familyDay.php b/src/Yasumi/data/translations/familyDay.php new file mode 100644 index 000000000..fcc5475b1 --- /dev/null +++ b/src/Yasumi/data/translations/familyDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Family Day +return [ + 'en' => 'Family Day', + 'fr' => 'Fête de la famille', +]; diff --git a/src/Yasumi/data/translations/fathersDay.php b/src/Yasumi/data/translations/fathersDay.php old mode 100755 new mode 100644 index 9d8b68cd8..d8dd30f8a --- a/src/Yasumi/data/translations/fathersDay.php +++ b/src/Yasumi/data/translations/fathersDay.php @@ -1,22 +1,29 @@ - + * @author Sacha Telgenhof */ // Translations for Father's Day return [ + 'da' => 'fars dag', 'de' => 'Vatertag', 'el' => 'Γιορτή του πατέρα', - 'en' => 'Father\'s Day', + 'en' => 'Father’s Day', 'fr' => 'Fête des pères', 'it' => 'Festa del papà', + 'lt' => 'Tėvo dieną', 'nl' => 'Vaderdag', 'pt' => 'Dia do Pai', 'ro' => 'Ziua Tatălui', diff --git a/src/Yasumi/data/translations/goldCupParadeDay.php b/src/Yasumi/data/translations/goldCupParadeDay.php new file mode 100644 index 000000000..3308bed95 --- /dev/null +++ b/src/Yasumi/data/translations/goldCupParadeDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Gold Cup Parade Day +return [ + 'en' => 'Gold Cup Parade Day', + 'fr' => 'Défilé de la Coupe d’or', +]; diff --git a/src/Yasumi/data/translations/goodFriday.php b/src/Yasumi/data/translations/goodFriday.php index 3fc7edb8e..2d6d7fa29 100644 --- a/src/Yasumi/data/translations/goodFriday.php +++ b/src/Yasumi/data/translations/goodFriday.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for Good Friday return [ + 'ca' => 'Divendres Sant', 'cs' => 'Velký pátek', 'cy' => 'Gwener y Groglith', - 'da' => 'Langfredag', + 'da' => 'langfredag', 'de' => 'Karfreitag', 'el' => 'Μεγάλη Παρασκευή', 'en' => 'Good Friday', @@ -27,7 +33,7 @@ 'it' => 'Venerdi Santo', 'ja' => 'グッドフライデー', 'lv' => 'Lielā Piektdiena', - 'nb' => 'Langfredag', + 'nb' => 'langfredag', 'nl' => 'Goede Vrijdag', 'pl' => 'Wielki Piątek', 'pt' => 'Sexta feira santa', diff --git a/src/Yasumi/data/translations/heritageDay.php b/src/Yasumi/data/translations/heritageDay.php new file mode 100644 index 000000000..122d693b7 --- /dev/null +++ b/src/Yasumi/data/translations/heritageDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Heritage Day +return [ + 'en' => 'Heritage Day', + 'fr' => 'Fête du patrimoine', +]; diff --git a/src/Yasumi/data/translations/immaculateConception.php b/src/Yasumi/data/translations/immaculateConception.php index bace8be7f..175222e80 100644 --- a/src/Yasumi/data/translations/immaculateConception.php +++ b/src/Yasumi/data/translations/immaculateConception.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Immaculate Conception return [ + 'ca' => 'Immaculada Concepció', 'de' => 'Mariä Empfängnis', 'el' => 'Ευαγγελισμός της Θεοτόκου', 'en' => 'Immaculate Conception', @@ -19,4 +25,5 @@ 'fr' => 'Immaculée Conception', 'it' => 'Immacolata Concezione', 'pt' => 'Dia da Imaculada Conceição', + 'sk' => 'Nepoškvrnené počatie Panny Márie', ]; diff --git a/src/Yasumi/data/translations/independenceDay.php b/src/Yasumi/data/translations/independenceDay.php new file mode 100644 index 000000000..c16e6f514 --- /dev/null +++ b/src/Yasumi/data/translations/independenceDay.php @@ -0,0 +1,23 @@ + + */ + +// Translations for Independence Day +return [ + 'en' => 'Independence Day', + 'hr' => 'Dan neovisnosti', + 'sl' => 'Dan samostojnosti in enotnosti', +]; diff --git a/src/Yasumi/data/translations/internationalWomensDay.php b/src/Yasumi/data/translations/internationalWomensDay.php old mode 100755 new mode 100644 index a1ea9c00a..48b62f03f --- a/src/Yasumi/data/translations/internationalWomensDay.php +++ b/src/Yasumi/data/translations/internationalWomensDay.php @@ -1,19 +1,25 @@ - + * @author Sacha Telgenhof */ // Translations for International Women's Day return [ 'de' => 'Internationaler Frauentag', - 'en' => 'International Women\'s Day', + 'en' => 'International Women’s Day', + 'ka' => 'ქალთა საერთაშორისო დღე', 'ko' => '국제 여성의 날', 'ru' => 'Международный женский день', 'uk' => 'Міжнародний жіночий день', diff --git a/src/Yasumi/data/translations/internationalWorkersDay.php b/src/Yasumi/data/translations/internationalWorkersDay.php old mode 100755 new mode 100644 index 267337b3e..456807cec --- a/src/Yasumi/data/translations/internationalWorkersDay.php +++ b/src/Yasumi/data/translations/internationalWorkersDay.php @@ -1,25 +1,32 @@ - + * @author Sacha Telgenhof */ // Translations for International Workers' Day return [ + 'bg' => 'Ден на труда и на международната работническа солидарност', 'bs_Latn' => 'Praznik rada', + 'ca' => 'Dia del Treball', 'cs' => 'Svátek práce', - 'da' => 'Første maj', + 'da' => 'første maj', 'de' => 'Tag der Arbeit', 'de_AT' => 'Staatsfeiertag', 'el' => 'Εργατική Πρωτομαγιά', - 'en_US' => 'International Workers\' Day', - 'en_ZA' => 'Workers\' Day', + 'en_US' => 'International Workers’ Day', + 'en_ZA' => 'Workers’ Day', 'es' => 'Día del Trabajador', 'et' => 'Kevadpüha', 'fi' => 'Vappu', @@ -32,7 +39,7 @@ 'ko' => '노동절', 'lt' => 'Tarptautinė darbo diena', 'lv' => 'Darba svētki', - 'nb' => 'Arbeidernes dag', + 'nb' => 'arbeidernes dag', 'nl' => 'Dag van de arbeid', 'pl' => 'Święto Pracy', 'pt' => 'Dia internacional do trabalhador', @@ -40,6 +47,7 @@ 'ro' => 'Ziua internațională a muncii', 'ru' => 'День международной солидарности трудящихся', 'sk' => 'Sviatok práce', - 'sv' => 'Första maj', + 'sl' => 'Praznik dela', + 'sv' => 'första maj', 'uk' => 'День міжнародної солідарності трудящих', ]; diff --git a/src/Yasumi/data/translations/islanderDay.php b/src/Yasumi/data/translations/islanderDay.php new file mode 100644 index 000000000..13eec3fd6 --- /dev/null +++ b/src/Yasumi/data/translations/islanderDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Islander Day +return [ + 'en' => 'Islander Day', + 'fr' => 'Fête des Insulaires', +]; diff --git a/src/Yasumi/data/translations/labourDay.php b/src/Yasumi/data/translations/labourDay.php index 5c7a060df..a93726664 100644 --- a/src/Yasumi/data/translations/labourDay.php +++ b/src/Yasumi/data/translations/labourDay.php @@ -1,20 +1,29 @@ - + * @author Sacha Telgenhof */ // Translations for Labour Day return [ 'en' => 'Labour Day', + 'en_US' => 'Labor Day', + 'fr' => 'Fête du travail', 'ja' => '労働の日', 'ko' => '노동절', 'nl' => 'Dag van de arbeid', 'sk' => 'Sviatok práce', + 'sl' => 'Praznik dela (2. dan)', + 'tr' => 'Emek ve Dayanışma Günü', ]; diff --git a/src/Yasumi/data/translations/louisRielDay.php b/src/Yasumi/data/translations/louisRielDay.php new file mode 100644 index 000000000..c2b6bda11 --- /dev/null +++ b/src/Yasumi/data/translations/louisRielDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Louis Riel Day +return [ + 'en' => 'Louis Riel Day', + 'fr' => 'Journée Louis Riel', +]; diff --git a/src/Yasumi/data/translations/matariki.php b/src/Yasumi/data/translations/matariki.php new file mode 100644 index 000000000..b5c30a934 --- /dev/null +++ b/src/Yasumi/data/translations/matariki.php @@ -0,0 +1,21 @@ + + */ + +// Translations for Matariki +return [ + 'en' => 'Matariki', +]; diff --git a/src/Yasumi/data/translations/maundyThursday.php b/src/Yasumi/data/translations/maundyThursday.php index 4c1f321d4..6531958ed 100644 --- a/src/Yasumi/data/translations/maundyThursday.php +++ b/src/Yasumi/data/translations/maundyThursday.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for Maundy Thursday return [ - 'da' => 'Skærtorsdag', + 'ca' => 'dijous Sant', + 'da' => 'skærtorsdag', 'el' => 'Μεγάλη Πέμπτη', 'en' => 'Maundy Thursday', 'es' => 'Jueves Santo', - 'nb' => 'Skjærtorsdag', + 'nb' => 'skjærtorsdag', ]; diff --git a/src/Yasumi/data/translations/mothersDay.php b/src/Yasumi/data/translations/mothersDay.php old mode 100755 new mode 100644 index 0ee75170c..4e120a0f9 --- a/src/Yasumi/data/translations/mothersDay.php +++ b/src/Yasumi/data/translations/mothersDay.php @@ -1,22 +1,31 @@ - + * @author Sacha Telgenhof */ // Translations for Mother's Day return [ + 'da' => 'mors dag', 'de' => 'Muttertag', 'el' => 'Ημέρα της μητέρας', - 'en' => 'Mother\'s Day', + 'en' => 'Mother’s Day', 'fr' => 'Fête des mères', 'it' => 'Festa della mamma', + 'ka' => 'დედის დღე', + 'lt' => 'Motinos dieną', + 'lv' => 'Mātes dienu', 'nl' => 'Moederdag', 'pt' => 'Dia da Mãe', 'ro' => 'Ziua Mamei', diff --git a/src/Yasumi/data/translations/natalHoliday.php b/src/Yasumi/data/translations/natalHoliday.php new file mode 100644 index 000000000..7c84a287e --- /dev/null +++ b/src/Yasumi/data/translations/natalHoliday.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Natal Holiday +return [ + 'en' => 'Natal Holiday', + 'fr' => 'Jour de la Fondation', +]; diff --git a/src/Yasumi/data/translations/nationalIndigenousPeoplesDay.php b/src/Yasumi/data/translations/nationalIndigenousPeoplesDay.php new file mode 100644 index 000000000..7672e4ded --- /dev/null +++ b/src/Yasumi/data/translations/nationalIndigenousPeoplesDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for National Indigenous Peoples Day +return [ + 'en' => 'National Indigenous Peoples Day', + 'fr' => 'Journée nationale des peuples autochtones', +]; diff --git a/src/Yasumi/data/translations/nationalPatriotsDay.php b/src/Yasumi/data/translations/nationalPatriotsDay.php new file mode 100644 index 000000000..0d7de5e02 --- /dev/null +++ b/src/Yasumi/data/translations/nationalPatriotsDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for National Patriot's Day +return [ + 'en' => 'National Patriot’s Day', + 'fr' => 'Journée nationale des patriotes', +]; diff --git a/src/Yasumi/data/translations/newYearsDay.php b/src/Yasumi/data/translations/newYearsDay.php old mode 100755 new mode 100644 index 5a787ffac..493f58e5c --- a/src/Yasumi/data/translations/newYearsDay.php +++ b/src/Yasumi/data/translations/newYearsDay.php @@ -1,39 +1,47 @@ - + * @author Sacha Telgenhof */ // Translations for New Year's Day return [ 'bs_Latn' => 'Nova godina', + 'bg' => 'Нова година', + 'ca' => 'Cap d’any', 'cs' => 'Nový rok', 'cy' => 'Dydd Calan', - 'da' => 'Nytårsdag', + 'da' => 'nytårsdag', 'de' => 'Neujahr', 'el' => 'Πρωτοχρονιά', - 'en' => 'New Year\'s Day', + 'en' => 'New Year’s Day', 'es' => 'Año Nuevo', 'et' => 'Uusaasta', 'fi' => 'Uudenvuodenpäivä', + 'fr' => 'Jour de l’An', 'fr_BE' => 'Nouvel An', 'fr_CH' => 'Nouvel An', - 'fr' => 'Jour de l\'An', 'ga' => 'Lá Caille', 'hr' => 'Nova godina', 'hu' => 'Újév', 'it' => 'Capodanno', 'ja' => '元日', + 'ka' => 'ახალი წელი', 'ko' => '새해', 'lt' => 'Naujųjų metų diena', 'lv' => 'Jaunais Gads', - 'nb' => 'Første nyttårsdag', + 'nb' => 'første nyttårsdag', 'nl' => 'Nieuwjaar', 'pl' => 'Nowy Rok', 'pt' => 'Ano novo', @@ -41,6 +49,8 @@ 'ro' => 'Anul Nou', 'ru' => 'Новый год', 'sk' => 'Nový rok', + 'sl' => 'Novo leto', 'sv' => 'nyårsdagen', + 'tr' => 'Yılbaşı', 'uk' => 'Новий Рік', ]; diff --git a/src/Yasumi/data/translations/newYearsEve.php b/src/Yasumi/data/translations/newYearsEve.php old mode 100755 new mode 100644 index 995e8dc01..802d78bf3 --- a/src/Yasumi/data/translations/newYearsEve.php +++ b/src/Yasumi/data/translations/newYearsEve.php @@ -1,19 +1,25 @@ - + * @author Sacha Telgenhof */ // Translations for New Year's Eve return [ - 'da' => 'Nytårsaften', - 'en' => 'New Year\'s Eve', + 'da' => 'nytårsaften', + 'de' => 'Silvester', + 'en' => 'New Year’s Eve', 'ko' => '신년전야', 'lv' => 'Vecgada vakars', 'sv' => 'nyårsafton', diff --git a/src/Yasumi/data/translations/novaScotiaHeritageDay.php b/src/Yasumi/data/translations/novaScotiaHeritageDay.php new file mode 100644 index 000000000..1a679f2b2 --- /dev/null +++ b/src/Yasumi/data/translations/novaScotiaHeritageDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Nova Scotia Heritage Day +return [ + 'en' => 'Nova Scotia Heritage Day', + 'fr' => 'Journée du patrimoine de la Nouvelle-Écosse', +]; diff --git a/src/Yasumi/data/translations/orangemensDay.php b/src/Yasumi/data/translations/orangemensDay.php new file mode 100644 index 000000000..de6aef7f5 --- /dev/null +++ b/src/Yasumi/data/translations/orangemensDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Orangemen's Day +return [ + 'en' => 'Orangemen’s Day', + 'fr' => 'Fête des orangistes', +]; diff --git a/src/Yasumi/data/translations/pentecost.php b/src/Yasumi/data/translations/pentecost.php old mode 100755 new mode 100644 index 345feabd1..f5986f2a2 --- a/src/Yasumi/data/translations/pentecost.php +++ b/src/Yasumi/data/translations/pentecost.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Whitsunday return [ - 'da' => 'Pinsedag', + 'da' => 'pinsedag', 'de' => 'Pfingstsonntag', 'de_AT' => 'Pfingsten', 'de_CH' => 'Pfingsten', @@ -24,11 +29,13 @@ 'ga' => 'Domhnach Cincíse', 'hu' => 'Pünkösd', 'it' => 'Pentecoste', - 'nb' => 'Første pinsedag', - 'nl' => 'Eerste pinksterdag', + 'lv' => 'Vasarsvētkus', + 'nb' => 'første pinsedag', + 'nl' => 'eerste pinksterdag', 'pl' => 'Zielone Świątki', 'ro' => 'Rusaliile', 'ru' => 'Троица', - 'sv' => 'Pingstdagen', + 'sl' => 'Binkoštna nedelja', + 'sv' => 'pingstdagen', 'uk' => 'Трійця', ]; diff --git a/src/Yasumi/data/translations/pentecostMonday.php b/src/Yasumi/data/translations/pentecostMonday.php old mode 100755 new mode 100644 index dc592f80f..9816e2d54 --- a/src/Yasumi/data/translations/pentecostMonday.php +++ b/src/Yasumi/data/translations/pentecostMonday.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Whitmonday return [ + 'ca' => 'Dilluns de Pentecosta', 'da' => '2. pinsedag', 'de' => 'Pfingstmontag', 'el' => 'Αγίου Πνεύματος', @@ -20,8 +26,8 @@ 'ga' => 'Luan Cincíse', 'hu' => 'Pünkösdhétfő', 'it' => 'Lunedi di Pentecoste', - 'nb' => 'Andre pinsedag', - 'nl' => 'Tweede pinksterdag', - 'nl_BE' => 'Pinkstermaandag', + 'nb' => 'andre pinsedag', + 'nl' => 'tweede pinksterdag', + 'nl_BE' => 'pinkstermaandag', 'ro' => 'A doua zi de Rusalii', ]; diff --git a/src/Yasumi/data/translations/plebisciteDay.php b/src/Yasumi/data/translations/plebisciteDay.php new file mode 100644 index 000000000..6ea78c0eb --- /dev/null +++ b/src/Yasumi/data/translations/plebisciteDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Plebiscite Day. +return [ + 'de_AT' => 'Tag der Volksabstimmung', + 'en' => 'Plebiscite Day', +]; diff --git a/src/Yasumi/data/translations/portugalDay.php b/src/Yasumi/data/translations/portugalDay.php index 456677086..7fdbb929d 100644 --- a/src/Yasumi/data/translations/portugalDay.php +++ b/src/Yasumi/data/translations/portugalDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Portugal Day diff --git a/src/Yasumi/data/translations/portugueseRepublicDay.php b/src/Yasumi/data/translations/portugueseRepublicDay.php index a05c1ad48..ac1a1e06d 100644 --- a/src/Yasumi/data/translations/portugueseRepublicDay.php +++ b/src/Yasumi/data/translations/portugueseRepublicDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Implantation of the Portuguese Republic diff --git a/src/Yasumi/data/translations/preserenDay.php b/src/Yasumi/data/translations/preserenDay.php new file mode 100644 index 000000000..60180518c --- /dev/null +++ b/src/Yasumi/data/translations/preserenDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Prešeren Day +return [ + 'en' => 'Prešeren Day, Slovenian Cultural Holiday', + 'sl' => 'Prešernov dan, slovenski kulturni praznik', +]; diff --git a/src/Yasumi/data/translations/queensBirthday.php b/src/Yasumi/data/translations/queensBirthday.php new file mode 100644 index 000000000..759e6e159 --- /dev/null +++ b/src/Yasumi/data/translations/queensBirthday.php @@ -0,0 +1,25 @@ + + */ + +// Translations for Queen's Birthday +return [ + 'da' => 'Dronningens fødselsdag', + 'en' => 'Queen’s Birthday', + 'fr' => 'Anniversaire officiel de la reine', + 'pt' => 'Aniversário da Rainha', + 'ru' => 'Официальный день рождения королевы', +]; diff --git a/src/Yasumi/data/translations/reformationDay.php b/src/Yasumi/data/translations/reformationDay.php old mode 100755 new mode 100644 index 1cdfb1e25..5892133b2 --- a/src/Yasumi/data/translations/reformationDay.php +++ b/src/Yasumi/data/translations/reformationDay.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Reformation Day return [ 'de' => 'Reformationstag', 'en' => 'Reformation Day', + 'sl' => 'Dan reformacije', ]; diff --git a/src/Yasumi/data/translations/remembranceDay.php b/src/Yasumi/data/translations/remembranceDay.php new file mode 100644 index 000000000..d6fc7700e --- /dev/null +++ b/src/Yasumi/data/translations/remembranceDay.php @@ -0,0 +1,23 @@ + + */ + +// Translations for Remembrance Day +return [ + 'en' => 'Remembrance Day', + 'fr' => 'Jour du souvenir', + 'sl' => 'Dan spomina na mrtve', +]; diff --git a/src/Yasumi/data/translations/restorationOfIndepence.php b/src/Yasumi/data/translations/restorationOfIndepence.php index 725850a39..cfd2d1ffe 100644 --- a/src/Yasumi/data/translations/restorationOfIndepence.php +++ b/src/Yasumi/data/translations/restorationOfIndepence.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Restoration of Independence diff --git a/src/Yasumi/data/translations/saintJeanBaptisteDay.php b/src/Yasumi/data/translations/saintJeanBaptisteDay.php new file mode 100644 index 000000000..2d8e2fff6 --- /dev/null +++ b/src/Yasumi/data/translations/saintJeanBaptisteDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Saint-Jean Baptiste Day +return [ + 'en' => 'Saint-Jean-Baptiste Day', + 'fr' => 'Fête de la Saint-Jean-Baptiste', +]; diff --git a/src/Yasumi/data/translations/saskatchewanDay.php b/src/Yasumi/data/translations/saskatchewanDay.php new file mode 100644 index 000000000..81d55fbb3 --- /dev/null +++ b/src/Yasumi/data/translations/saskatchewanDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Saskatchewan Day +return [ + 'en' => 'Saskatchewan Day', + 'fr' => 'Jour Saskatchewan', +]; diff --git a/src/Yasumi/data/translations/secondChristmasDay.php b/src/Yasumi/data/translations/secondChristmasDay.php old mode 100755 new mode 100644 index 252abc852..b9423da35 --- a/src/Yasumi/data/translations/secondChristmasDay.php +++ b/src/Yasumi/data/translations/secondChristmasDay.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Second Christmas Day return [ + 'bg' => 'Втори ден на Коледа', 'cs' => '2. svátek vánoční', 'da' => '2. juledag', 'de' => '2. Weihnachtsfeiertag', @@ -22,12 +28,15 @@ 'en_ZA' => 'Day of Goodwill', 'et' => 'Teine Jõulupüha', 'fi' => '2. joulupäivä', + 'fr' => 'Saint-Étienne', + 'fr_CA' => 'Lendemain de Noël', + 'fr_LU' => 'Deuxième jour de Noël', 'hu' => 'Karácsony másnapja', 'ko' => '성탄절 연휴', 'lt' => 'Kalėdos (antra diena)', 'lv' => 'Otrie Ziemassvētki', - 'nb' => 'Andre juledag', - 'nl' => 'Tweede kerstdag', + 'nb' => 'andre juledag', + 'nl' => 'tweede kerstdag', 'pl' => 'drugi dzień Bożego Narodzenia', 'ro' => 'A doua zi de Crăciun', 'sk' => 'Druhý sviatok vianočný', diff --git a/src/Yasumi/data/translations/secondNewYearsDay.php b/src/Yasumi/data/translations/secondNewYearsDay.php old mode 100755 new mode 100644 index 8a0df1847..69fe7de77 --- a/src/Yasumi/data/translations/secondNewYearsDay.php +++ b/src/Yasumi/data/translations/secondNewYearsDay.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for New Year's Day return [ 'da' => '2. nytårsdag', 'en' => '2nd January', + 'sl' => 'Novo leto (2. dan)', ]; diff --git a/src/Yasumi/data/translations/stAndrewsDay.php b/src/Yasumi/data/translations/stAndrewsDay.php index 197f198e4..8667de172 100644 --- a/src/Yasumi/data/translations/stAndrewsDay.php +++ b/src/Yasumi/data/translations/stAndrewsDay.php @@ -1,17 +1,22 @@ - + * @author Sacha Telgenhof */ // Translations for St. Andrew's Day return [ - 'en' => 'St. Andrew\'s Day', + 'en' => 'St. Andrew’s Day', 'ro' => 'Sfântul Andrei', ]; diff --git a/src/Yasumi/data/translations/stDavidsDay.php b/src/Yasumi/data/translations/stDavidsDay.php index 564b88b8f..1a3838a21 100644 --- a/src/Yasumi/data/translations/stDavidsDay.php +++ b/src/Yasumi/data/translations/stDavidsDay.php @@ -1,17 +1,22 @@ - + * @author Sacha Telgenhof */ // Translations for St. David's Day return [ 'cy' => 'Dydd Gŵyl Dewi', - 'en' => 'St. David\'s Day', + 'en' => 'St. David’s Day', ]; diff --git a/src/Yasumi/data/translations/stFloriansDay.php b/src/Yasumi/data/translations/stFloriansDay.php new file mode 100644 index 000000000..bca71caa7 --- /dev/null +++ b/src/Yasumi/data/translations/stFloriansDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Saint Florian's Day. +return [ + 'de_AT' => 'Florian', + 'en' => 'Saint Florian’s Day', +]; diff --git a/src/Yasumi/data/translations/stGeorgesDay.php b/src/Yasumi/data/translations/stGeorgesDay.php index c8ab6e1a4..5787b8f2b 100644 --- a/src/Yasumi/data/translations/stGeorgesDay.php +++ b/src/Yasumi/data/translations/stGeorgesDay.php @@ -1,18 +1,25 @@ - + * @author Sacha Telgenhof */ // Translations for St. George's Day return [ + 'bg' => 'Гергьовден, ден на храбростта и Българската армия', + 'ca' => 'Sant Jordi', 'el' => 'Αγίου Γεωργίου', - 'en' => 'St. George\'s Day', + 'en' => 'St. George’s Day', 'es' => 'San Jorge', ]; diff --git a/src/Yasumi/data/translations/stJohnsDay.php b/src/Yasumi/data/translations/stJohnsDay.php index 50a4e577c..c11086c0c 100644 --- a/src/Yasumi/data/translations/stJohnsDay.php +++ b/src/Yasumi/data/translations/stJohnsDay.php @@ -1,24 +1,31 @@ - + * @author Sacha Telgenhof */ // Translations for St. John's Day return [ - 'da' => 'Sankthansaften', + 'ca' => 'Sant Joan', + 'da' => 'sankthansaften', 'el' => 'Σύναξις Προφήτου Προδρόμου και Βαπτιστού Ιωάννου', - 'en' => 'St. John\'s Day', + 'en' => 'St. John’s Day', 'es' => 'Sant Joan', 'et' => 'Jaanipäev', 'fi' => 'Juhannuspäivä', 'lt' => 'Rasos ir Joninių diena', 'lv' => 'Jāņi', + 'ro' => 'Sfântul Ioan Botezătorul', 'sv' => 'midsommardagen', ]; diff --git a/src/Yasumi/data/translations/stJohnsEve.php b/src/Yasumi/data/translations/stJohnsEve.php index 0027bd417..aeaaf91dd 100644 --- a/src/Yasumi/data/translations/stJohnsEve.php +++ b/src/Yasumi/data/translations/stJohnsEve.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for St. John's Eve return [ - 'da' => 'Sankthansaften', - 'en' => 'St. John\'s Eve', + 'da' => 'sankthansaften', + 'en' => 'St. John’s Eve', 'sv' => 'midsommarafton', ]; diff --git a/src/Yasumi/data/translations/stJosephsDay.php b/src/Yasumi/data/translations/stJosephsDay.php index 61f45db59..3cd8d53ad 100644 --- a/src/Yasumi/data/translations/stJosephsDay.php +++ b/src/Yasumi/data/translations/stJosephsDay.php @@ -1,19 +1,25 @@ - + * @author Sacha Telgenhof */ // Translations for St. Joseph's Day return [ + 'ca' => 'Sant Josep', 'de' => 'Josephstag', - 'en' => 'St. Joseph\'s Day', + 'en' => 'St. Joseph’s Day', 'es' => 'San José', 'fr' => 'Saint-Joseph', 'it' => 'San Giuseppe', diff --git a/src/Yasumi/data/translations/stLeopoldsDay.php b/src/Yasumi/data/translations/stLeopoldsDay.php new file mode 100644 index 000000000..bdf87f569 --- /dev/null +++ b/src/Yasumi/data/translations/stLeopoldsDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Saint Leopold's Day. +return [ + 'de_AT' => 'Leopold', + 'en' => 'Saint Leopold’s Day', +]; diff --git a/src/Yasumi/data/translations/stMartinsDay.php b/src/Yasumi/data/translations/stMartinsDay.php index 384ae2b20..bc1a40e1c 100644 --- a/src/Yasumi/data/translations/stMartinsDay.php +++ b/src/Yasumi/data/translations/stMartinsDay.php @@ -1,17 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for St. Martin's Day return [ - 'en' => 'St. Martin\'s Day', + 'de_AT' => 'Martin', + 'en' => 'St. Martin’s Day', 'nl' => 'Sint Maarten', ]; diff --git a/src/Yasumi/data/translations/stRupertsDay.php b/src/Yasumi/data/translations/stRupertsDay.php new file mode 100644 index 000000000..c4eec8c81 --- /dev/null +++ b/src/Yasumi/data/translations/stRupertsDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Saint Rupert's Day. +return [ + 'de_AT' => 'Rupert', + 'en' => 'Saint Rupert’s Day', +]; diff --git a/src/Yasumi/data/translations/stStephensDay.php b/src/Yasumi/data/translations/stStephensDay.php index 6259a6ed7..29715e633 100644 --- a/src/Yasumi/data/translations/stStephensDay.php +++ b/src/Yasumi/data/translations/stStephensDay.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for St. Stephen's Day return [ + 'ca' => 'Sant Esteve', 'cy' => 'Gŵyl San Steffan', 'de' => 'Stephanstag', - 'en' => 'St. Stephen\'s Day', + 'en' => 'St. Stephen’s Day', 'es' => 'Sant Esteve', 'fr' => 'Saint-Étienne', 'ga' => 'Lá Fhéile Stiofáin', diff --git a/src/Yasumi/data/translations/statehoodDay.php b/src/Yasumi/data/translations/statehoodDay.php new file mode 100644 index 000000000..67733427c --- /dev/null +++ b/src/Yasumi/data/translations/statehoodDay.php @@ -0,0 +1,23 @@ + + */ + +// Translations for Statehood Day +return [ + 'en' => 'Statehood Day', + 'hr' => 'Dan državnosti', + 'sl' => 'Dan državnosti', +]; diff --git a/src/Yasumi/data/translations/substituteHoliday.php b/src/Yasumi/data/translations/substituteHoliday.php old mode 100755 new mode 100644 index a6333cf32..a3b17de3b --- a/src/Yasumi/data/translations/substituteHoliday.php +++ b/src/Yasumi/data/translations/substituteHoliday.php @@ -1,21 +1,26 @@ - + * @author Sacha Telgenhof */ // Translation pattern for substitute holidays. return [ 'da' => '{0} (erstatning)', 'en' => '{0} (substitute day)', - 'en_US' => '{0} observed', 'en_CA' => '{0} observed', + 'en_US' => '{0} observed', 'ja' => '振替休日 ({0})', 'ko' => '대체공휴일', ]; diff --git a/src/Yasumi/data/translations/summerTime.php b/src/Yasumi/data/translations/summerTime.php index 5a6df066c..607766877 100644 --- a/src/Yasumi/data/translations/summerTime.php +++ b/src/Yasumi/data/translations/summerTime.php @@ -1,19 +1,24 @@ - + * @author Sacha Telgenhof */ // Translations for Summertime return [ - 'da' => 'Sommertid starter', + 'da' => 'sommertid starter', 'en' => 'Summertime', 'ko' => '서머타임', - 'nl' => 'Zomertijd', + 'nl' => 'zomertijd', ]; diff --git a/src/Yasumi/data/translations/terryFoxDay.php b/src/Yasumi/data/translations/terryFoxDay.php new file mode 100644 index 000000000..9db98a854 --- /dev/null +++ b/src/Yasumi/data/translations/terryFoxDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Terry Fox Day +return [ + 'en' => 'Terry Fox Day', + 'fr' => 'Journée Terry Fox', +]; diff --git a/src/Yasumi/data/translations/thanksgivingDay.php b/src/Yasumi/data/translations/thanksgivingDay.php new file mode 100644 index 000000000..ce6ef9e43 --- /dev/null +++ b/src/Yasumi/data/translations/thanksgivingDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Thanksgiving +return [ + 'en' => 'Thanksgiving', + 'fr' => 'Action de grâce', +]; diff --git a/src/Yasumi/data/translations/truthAndReconciliationDay.php b/src/Yasumi/data/translations/truthAndReconciliationDay.php new file mode 100644 index 000000000..053112733 --- /dev/null +++ b/src/Yasumi/data/translations/truthAndReconciliationDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Truth And Reconciliation Day +return [ + 'en' => 'National Day For Truth And Reconciliation', + 'fr' => 'la Journée nationale de la vérité et de la réconciliation', +]; diff --git a/src/Yasumi/data/translations/uprisingAgainstOccupation.php b/src/Yasumi/data/translations/uprisingAgainstOccupation.php new file mode 100644 index 000000000..fc0e3dd21 --- /dev/null +++ b/src/Yasumi/data/translations/uprisingAgainstOccupation.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Day of Uprising Against Occupation +return [ + 'en' => 'Day of Uprising Against Occupation', + 'sl' => 'Dan upora proti okupatorju', +]; diff --git a/src/Yasumi/data/translations/valentinesDay.php b/src/Yasumi/data/translations/valentinesDay.php index fbd6db79d..34b297845 100644 --- a/src/Yasumi/data/translations/valentinesDay.php +++ b/src/Yasumi/data/translations/valentinesDay.php @@ -1,20 +1,26 @@ - + * @author Sacha Telgenhof */ // Translations for Valentine's Day return [ + 'ca' => 'Dia de Sant Valentí', 'de' => 'Valentinstag', 'el' => 'Αγίου Βαλεντίνου', - 'en' => 'Valentine\'s Day', + 'en' => 'Valentine’s Day', 'es' => 'San Valentín', 'fr' => 'Saint-Valentin', 'it' => 'San Valentino', diff --git a/src/Yasumi/data/translations/victoriaDay.php b/src/Yasumi/data/translations/victoriaDay.php new file mode 100644 index 000000000..fb0ff8c92 --- /dev/null +++ b/src/Yasumi/data/translations/victoriaDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Victoria Day +return [ + 'en' => 'Victoria Day', + 'fr' => 'Fête de la Reine', +]; diff --git a/src/Yasumi/data/translations/victoryInEuropeDay.php b/src/Yasumi/data/translations/victoryInEuropeDay.php index 6222f5f5a..cb51fac9c 100644 --- a/src/Yasumi/data/translations/victoryInEuropeDay.php +++ b/src/Yasumi/data/translations/victoryInEuropeDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Victory in Europe Day diff --git a/src/Yasumi/data/translations/waitangiDay.php b/src/Yasumi/data/translations/waitangiDay.php index a91cf8c31..9291992fe 100644 --- a/src/Yasumi/data/translations/waitangiDay.php +++ b/src/Yasumi/data/translations/waitangiDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Waitangi Day diff --git a/src/Yasumi/data/translations/walpurgisEve.php b/src/Yasumi/data/translations/walpurgisEve.php old mode 100755 new mode 100644 index 67efc4b2e..e14fda2d8 --- a/src/Yasumi/data/translations/walpurgisEve.php +++ b/src/Yasumi/data/translations/walpurgisEve.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for Walpurgis Night diff --git a/src/Yasumi/data/translations/winterTime.php b/src/Yasumi/data/translations/winterTime.php index 5c702cdc1..1b45be921 100644 --- a/src/Yasumi/data/translations/winterTime.php +++ b/src/Yasumi/data/translations/winterTime.php @@ -1,18 +1,23 @@ - + * @author Sacha Telgenhof */ // Translations for Wintertime return [ - 'da' => 'Sommertid slutter', + 'da' => 'sommertid slutter', 'en' => 'Wintertime', - 'nl' => 'Wintertijd', + 'nl' => 'wintertijd', ]; diff --git a/src/Yasumi/data/translations/worldAnimalDay.php b/src/Yasumi/data/translations/worldAnimalDay.php index 5a4106beb..d2fe562cf 100644 --- a/src/Yasumi/data/translations/worldAnimalDay.php +++ b/src/Yasumi/data/translations/worldAnimalDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ // Translations for World Animal Day diff --git a/src/Yasumi/data/translations/yukonHeritageDay.php b/src/Yasumi/data/translations/yukonHeritageDay.php new file mode 100644 index 000000000..877f80afa --- /dev/null +++ b/src/Yasumi/data/translations/yukonHeritageDay.php @@ -0,0 +1,22 @@ + + */ + +// Translations for Yukon Heritage Day +return [ + 'en' => 'Yukon Heritage Day', + 'fr' => 'Journée du patrimoine du Yukon', +]; diff --git a/tests/Andorra/AllSaintsDayTest.php b/tests/Andorra/AllSaintsDayTest.php new file mode 100644 index 000000000..c287c5456 --- /dev/null +++ b/tests/Andorra/AllSaintsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for All Saints' Day in Andorra. + */ +class AllSaintsDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'allSaintsDay'; + + /** + * Tests All Saints' Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of All Saints' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dia de Tots Sants'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/AndorraBaseTestCase.php b/tests/Andorra/AndorraBaseTestCase.php new file mode 100644 index 000000000..9b34e159d --- /dev/null +++ b/tests/Andorra/AndorraBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Andorra holiday provider. + */ +abstract class AndorraBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Andorra'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Europe/Andorra'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'ca_AD'; +} diff --git a/tests/Andorra/AndorraTest.php b/tests/Andorra/AndorraTest.php new file mode 100644 index 000000000..bb132e0aa --- /dev/null +++ b/tests/Andorra/AndorraTest.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\Provider\Andorra; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Andorra. + */ +class AndorraTest extends AndorraBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Tests if all official holidays in Andorra are defined by the provider class. + * + * @throws \Exception + */ + public function testOfficialHolidays(): void + { + $year = static::generateRandomYear(); + + $holidays = [ + 'newYearsDay', + 'epiphany', + 'carnival', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'pentecostMonday', + 'assumptionOfMary', + 'meritxellDay', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ]; + + if ($year >= Andorra::CONSTITUTION_YEAR) { + $holidays[] = 'constitutionDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Andorra are defined by the provider class. + * + * @throws \Exception + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Andorra are defined by the provider class. + * + * @throws \Exception + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Andorra are defined by the provider class. + * + * @throws \Exception + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Andorra are defined by the provider class. + * + * @throws \Exception + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Andorra/AssumptionOfMaryTest.php b/tests/Andorra/AssumptionOfMaryTest.php new file mode 100644 index 000000000..9f43879f3 --- /dev/null +++ b/tests/Andorra/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Assumption of Mary in Andorra. + */ +class AssumptionOfMaryTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the Assumption of Mary. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests the translated name of the Assumption of Mary. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => "l\u{2019}Assumpció"] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/CarnivalTest.php b/tests/Andorra/CarnivalTest.php new file mode 100644 index 000000000..90d9ed580 --- /dev/null +++ b/tests/Andorra/CarnivalTest.php @@ -0,0 +1,93 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Carnival (Dimarts Gras) in Andorra. + */ +class CarnivalTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'carnival'; + + /** + * Tests Carnival (Shrove Tuesday / Mardi Gras). + * + * Carnival in Andorra falls on Shrove Tuesday, 47 days before Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of test dates used for assertion of Carnival. + * + * @return array list of test dates for Carnival + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return [ + [2020, new \DateTime('2020-2-25', new \DateTimeZone(self::TIMEZONE))], + [2021, new \DateTime('2021-2-16', new \DateTimeZone(self::TIMEZONE))], + [2022, new \DateTime('2022-3-1', new \DateTimeZone(self::TIMEZONE))], + [2023, new \DateTime('2023-2-21', new \DateTimeZone(self::TIMEZONE))], + [2024, new \DateTime('2024-2-13', new \DateTimeZone(self::TIMEZONE))], + [2025, new \DateTime('2025-3-4', new \DateTimeZone(self::TIMEZONE))], + [2026, new \DateTime('2026-2-17', new \DateTimeZone(self::TIMEZONE))], + ]; + } + + /** + * Tests the translated name of Carnival. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dimarts Gras'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/ChristmasDayTest.php b/tests/Andorra/ChristmasDayTest.php new file mode 100644 index 000000000..d21039373 --- /dev/null +++ b/tests/Andorra/ChristmasDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Christmas Day in Andorra. + */ +class ChristmasDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * Tests the translated name of Christmas Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Nadal'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/ConstitutionDayTest.php b/tests/Andorra/ConstitutionDayTest.php new file mode 100644 index 000000000..b7c0570ee --- /dev/null +++ b/tests/Andorra/ConstitutionDayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\Provider\Andorra; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Constitution Day in Andorra. + */ +class ConstitutionDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'constitutionDay'; + + /** + * The year in which Constitution Day was established. + */ + public const ESTABLISHMENT_YEAR = 1993; + + /** + * Tests Constitution Day on or after 1993. + * + * @throws \Exception + */ + public function testConstitutionDayOnAfter1993(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-3-14", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Constitution Day before 1993 (should not exist). + * + * @throws \Exception + */ + public function testConstitutionDayBefore1993(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the translated name of Constitution Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dia de la Constitució'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Andorra/EasterMondayTest.php b/tests/Andorra/EasterMondayTest.php new file mode 100644 index 000000000..dab887148 --- /dev/null +++ b/tests/Andorra/EasterMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter Monday in Andorra. + */ +class EasterMondayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterMonday'; + + /** + * Tests Easter Monday. + * + * @throws \Exception + */ + public function testEasterMonday(): void + { + $year = 2026; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-6", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of Easter Monday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'dilluns de Pasqua'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/EpiphanyTest.php b/tests/Andorra/EpiphanyTest.php new file mode 100644 index 000000000..c69919817 --- /dev/null +++ b/tests/Andorra/EpiphanyTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Epiphany in Andorra. + */ +class EpiphanyTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'epiphany'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 6, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Epifania'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/GoodFridayTest.php b/tests/Andorra/GoodFridayTest.php new file mode 100644 index 000000000..b02658685 --- /dev/null +++ b/tests/Andorra/GoodFridayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Good Friday in Andorra. + */ +class GoodFridayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'goodFriday'; + + /** + * Tests Good Friday. + * + * @throws \Exception + */ + public function testGoodFriday(): void + { + $year = 2026; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-3", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of Good Friday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Divendres Sant'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/ImmaculateConceptionTest.php b/tests/Andorra/ImmaculateConceptionTest.php new file mode 100644 index 000000000..1b5b46bf9 --- /dev/null +++ b/tests/Andorra/ImmaculateConceptionTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Immaculate Conception in Andorra. + */ +class ImmaculateConceptionTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'immaculateConception'; + + /** + * Tests the Immaculate Conception. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of the Immaculate Conception. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Immaculada Concepció'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/InternationalWorkersDayTest.php b/tests/Andorra/InternationalWorkersDayTest.php new file mode 100644 index 000000000..4a00bc66a --- /dev/null +++ b/tests/Andorra/InternationalWorkersDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for International Workers' Day in Andorra. + */ +class InternationalWorkersDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests International Workers' Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of International Workers' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dia del Treball'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/MeritxellDayTest.php b/tests/Andorra/MeritxellDayTest.php new file mode 100644 index 000000000..de1e04d2e --- /dev/null +++ b/tests/Andorra/MeritxellDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Our Lady of Meritxell Day (National Day) in Andorra. + */ +class MeritxellDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'meritxellDay'; + + /** + * Tests Our Lady of Meritxell Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(9, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of Our Lady of Meritxell Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dia de la Mare de Déu de Meritxell'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/NewYearsDayTest.php b/tests/Andorra/NewYearsDayTest.php new file mode 100644 index 000000000..e1265451c --- /dev/null +++ b/tests/Andorra/NewYearsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for New Year's Day in Andorra. + */ +class NewYearsDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Year's Day. + * + * @param int $year the year for which New Year's Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of New Year's Day. + * + * @return array list of test dates for New Year's Day + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of New Year's Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => "Cap d\u{2019}any"] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/PentecostMondayTest.php b/tests/Andorra/PentecostMondayTest.php new file mode 100644 index 000000000..8136e626d --- /dev/null +++ b/tests/Andorra/PentecostMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Pentecost Monday (Whit Monday) in Andorra. + */ +class PentecostMondayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'pentecostMonday'; + + /** + * Tests Pentecost Monday. + * + * @throws \Exception + */ + public function testPentecostMonday(): void + { + $year = 2026; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of Pentecost Monday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dilluns de Pentecosta'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Andorra/StStephensDayTest.php b/tests/Andorra/StStephensDayTest.php new file mode 100644 index 000000000..efe85b385 --- /dev/null +++ b/tests/Andorra/StStephensDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Andorra; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for St. Stephen's Day in Andorra. + */ +class StStephensDayTest extends AndorraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stStephensDay'; + + /** + * Tests St. Stephen's Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 26, self::TIMEZONE); + } + + /** + * Tests the translated name of St. Stephen's Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Sant Esteve'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/ArgentinaBaseTestCase.php b/tests/Argentina/ArgentinaBaseTestCase.php new file mode 100644 index 000000000..bc728e77f --- /dev/null +++ b/tests/Argentina/ArgentinaBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Class ArgentinaBaseTestCase. + */ +abstract class ArgentinaBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Argentina'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Argentina/Buenos_Aires'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'es'; +} diff --git a/tests/Argentina/ArgentinaTest.php b/tests/Argentina/ArgentinaTest.php new file mode 100644 index 000000000..416442c37 --- /dev/null +++ b/tests/Argentina/ArgentinaTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\Provider\Argentina; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Argentina. + */ +class ArgentinaTest extends ArgentinaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1980); + } + + /** + * Tests if all official holidays in Argentina are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'carnavalMonday', + 'carnavalTuesday', + 'goodFriday', + 'internationalWorkersDay', + 'mayRevolution', + 'generalMartinMigueldeGuemesDay', + 'flagDay', + 'generalJoseSanMartinDay', + 'raceDay', + 'immaculateConceptionDay', + 'christmasDay', + ]; + + if ($this->year >= Argentina::PROCLAMATION_OF_INDEPENDENCE_YEAR) { + $holidays[] = 'independenceDay'; + } + + if ($this->year >= 2006) { + $holidays[] = 'remembranceDay'; + } + + if ($this->year >= 2010) { + $holidays[] = 'nationalSovereigntyDay'; + } + + if ($this->year >= 1982) { + $holidays[] = 'malvinasDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Argentina are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([ + 'easter', + ], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** @throws \Exception */ + public function testSources(): void + { + $this->assertSources(self::REGION, 4); + } +} diff --git a/tests/Argentina/CarnavalMondayTest.php b/tests/Argentina/CarnavalMondayTest.php new file mode 100644 index 000000000..a702d8cbd --- /dev/null +++ b/tests/Argentina/CarnavalMondayTest.php @@ -0,0 +1,89 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Carnaval Monday in Argentina. + */ +class CarnavalMondayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'carnavalMonday'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1700; + + /** + * Tests Carnaval Monday on or after 1700. + * + * @throws \Exception + */ + public function testCarnavalMondayAfter1700(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P48D')) + ); + } + + /** + * Tests Carnaval Monday on or before 1700. + * + * @throws \Exception + */ + public function testCarnavalMondayBefore1700(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Lunes de Carnaval']); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/CarnavalTuesdayTest.php b/tests/Argentina/CarnavalTuesdayTest.php new file mode 100644 index 000000000..8506abbfc --- /dev/null +++ b/tests/Argentina/CarnavalTuesdayTest.php @@ -0,0 +1,89 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Carnaval Tuesday in Argentina. + */ +class CarnavalTuesdayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'carnavalTuesday'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1700; + + /** + * Tests Carnaval Tuesday on or after 1700. + * + * @throws \Exception + */ + public function testCarnavalTuesdayAfter1700(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P47D')) + ); + } + + /** + * Tests Carnaval Tuesday on or before 1700. + * + * @throws \Exception + */ + public function testCarnavalTuesdayBefore1700(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Martes de Carnaval']); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/ChristmasDayTest.php b/tests/Argentina/ChristmasDayTest.php new file mode 100644 index 000000000..b3feccbc0 --- /dev/null +++ b/tests/Argentina/ChristmasDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas Day in Argentina. + */ +class ChristmasDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day. + * + * @throws \Exception + */ + public function testChristmasDay(): void + { + $year = 1897; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Navidad'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/EasterTest.php b/tests/Argentina/EasterTest.php new file mode 100644 index 000000000..eebe388e4 --- /dev/null +++ b/tests/Argentina/EasterTest.php @@ -0,0 +1,71 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter in Argentina. + */ +class EasterTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter. + * + * @throws \Exception + */ + public function testEaster(): void + { + $year = 1948; + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, static::computeEaster($year, self::TIMEZONE)); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Pascua de Resurrección'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Argentina/FlagDayTest.php b/tests/Argentina/FlagDayTest.php new file mode 100644 index 000000000..ca951a176 --- /dev/null +++ b/tests/Argentina/FlagDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing General Manuel Belgrano Memorial Day (Flag Day) in Argentina. + */ +class FlagDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'flagDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1938; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Paso a la Inmortalidad del General Manuel Belgrano'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/GeneralJoseSanMartinDayTest.php b/tests/Argentina/GeneralJoseSanMartinDayTest.php new file mode 100644 index 000000000..d7d015098 --- /dev/null +++ b/tests/Argentina/GeneralJoseSanMartinDayTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing General José de San Martín Memorial Day in Argentina. + */ +class GeneralJoseSanMartinDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'generalJoseSanMartinDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1850; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-08-17", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment from Wednesday to Monday. + * + * @throws \Exception + */ + public function testMovableHoliday2022(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2022, + new \DateTime('2022-08-15', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment does not happen from a Saturday. + * + * @throws \Exception + */ + public function testNotMovableHoliday2024(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2024, + new \DateTime('2024-08-17', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Paso a la Inmortalidad del General José de San Martín'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/GeneralMartinMigueldeGuemesDayTest.php b/tests/Argentina/GeneralMartinMigueldeGuemesDayTest.php new file mode 100644 index 000000000..aaa2d7e7f --- /dev/null +++ b/tests/Argentina/GeneralMartinMigueldeGuemesDayTest.php @@ -0,0 +1,131 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing general Martín Miguel de Güemes Day in Argentina. + */ +class GeneralMartinMigueldeGuemesDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'generalMartinMigueldeGuemesDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1821; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-17", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment from Tuesday to Monday. + * + * @throws \Exception + */ + public function testMovableHoliday2025(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2025, + new \DateTime('2025-06-16', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment does not happen if it coincides with an immovable holiday. + * + * @throws \Exception + */ + public function testNotMovableHoliday2022(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2022, + new \DateTime('2022-06-17', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment does not happen from a Saturday. + * + * @throws \Exception + */ + public function testNotMovableHoliday2023(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2023, + new \DateTime('2023-06-17', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Paso a la Inmortalidad del General Martín Miguel de Güemes'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/GoodFridayTest.php b/tests/Argentina/GoodFridayTest.php new file mode 100644 index 000000000..dbd93b12e --- /dev/null +++ b/tests/Argentina/GoodFridayTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Good Friday in Argentina. + */ +class GoodFridayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'goodFriday'; + + /** + * Tests Good Friday. + * + * @throws \Exception + */ + public function testGoodFriday(): void + { + $year = 1997; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P2D')) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Viernes Santo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/ImmaculateConceptionDayTest.php b/tests/Argentina/ImmaculateConceptionDayTest.php new file mode 100644 index 000000000..a81b55476 --- /dev/null +++ b/tests/Argentina/ImmaculateConceptionDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Proclamation of The Republic Day in Argentina. + */ +class ImmaculateConceptionDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'immaculateConceptionDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1900; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-08", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día de la Inmaculada Concepción de María'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/IndependenceDayTest.php b/tests/Argentina/IndependenceDayTest.php new file mode 100644 index 000000000..78ba51f72 --- /dev/null +++ b/tests/Argentina/IndependenceDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Independence Day in Argentina. + */ +class IndependenceDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'independenceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1816; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-09", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día de la Independencia'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/InternationalWorkersDayTest.php b/tests/Argentina/InternationalWorkersDayTest.php new file mode 100644 index 000000000..270385b56 --- /dev/null +++ b/tests/Argentina/InternationalWorkersDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing International Workers' Day in Argentina. + */ +class InternationalWorkersDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests International Workers' Day. + * + * @throws \Exception + */ + public function testInternationalWorkersDay(): void + { + $year = 1927; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Día del Trabajador'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/MalvinasDayTest.php b/tests/Argentina/MalvinasDayTest.php new file mode 100644 index 000000000..eb73bba02 --- /dev/null +++ b/tests/Argentina/MalvinasDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Malvinas Day in the Argentina. + */ +class MalvinasDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'malvinasDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1982; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-02", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of Malvinas Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día del Veterano y de los Caídos en la Guerra de Malvinas'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/MayRevolutionTest.php b/tests/Argentina/MayRevolutionTest.php new file mode 100644 index 000000000..a2a2f9fe2 --- /dev/null +++ b/tests/Argentina/MayRevolutionTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing First National Government in Argentina. + */ +class MayRevolutionTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'mayRevolution'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1810; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of First National Government. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día de la Revolución de Mayo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/NationalSovereigntyDayTest.php b/tests/Argentina/NationalSovereigntyDayTest.php new file mode 100644 index 000000000..40d52230c --- /dev/null +++ b/tests/Argentina/NationalSovereigntyDayTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing National Sovereignty Day in Argentina. + */ +class NationalSovereigntyDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'nationalSovereigntyDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2010; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-11-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment from Thursday to Monday. + * + * @throws \Exception + */ + public function testMovableHoliday2025(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2025, + new \DateTime('2025-11-24', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment does not happen from a Sunday. + * + * @throws \Exception + */ + public function testNotMovableHoliday2022(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2022, + new \DateTime('2022-11-20', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día de la Soberanía Nacional'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/NewYearsDayTest.php b/tests/Argentina/NewYearsDayTest.php new file mode 100644 index 000000000..17f10a9fd --- /dev/null +++ b/tests/Argentina/NewYearsDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Years Day in Argentina. + */ +class NewYearsDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Years Day. + * + * @throws \Exception + */ + public function testNewYearsDay(): void + { + $year = 1997; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Año Nuevo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/RaceDayTest.php b/tests/Argentina/RaceDayTest.php new file mode 100644 index 000000000..a84a465ed --- /dev/null +++ b/tests/Argentina/RaceDayTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Day of Respect for Cultural Diversity in Argentina. + */ +class RaceDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'raceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1492; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-12", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment from Thursday to Monday. + * + * @throws \Exception + */ + public function testMovableHoliday2023(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2023, + new \DateTime('2023-10-16', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the movable holiday adjustment does not happen from a Saturday. + * + * @throws \Exception + */ + public function testNotMovableHoliday2024(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2024, + new \DateTime('2024-10-12', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día del Respeto a la Diversidad Cultural'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Argentina/RemembranceDayTest.php b/tests/Argentina/RemembranceDayTest.php new file mode 100644 index 000000000..f74a96624 --- /dev/null +++ b/tests/Argentina/RemembranceDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Argentina; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing "Day of Remembrance for Truth and Justice" in Argentina. + */ +class RemembranceDayTest extends ArgentinaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'remembranceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2006; + + /** + * Tests Day of Remembrance for Truth and Justice on or after 2006. + * + * @throws \Exception + */ + public function testRemembranceDayAfter2006(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Day of Remembrance for Truth and Justice on or before 2006. + * + * @throws \Exception + */ + public function testRemembranceDayBefore2006(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Día Nacional de la Memoria por la Verdad y la Justicia']); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/ACT/ACTBaseTestCase.php b/tests/Australia/ACT/ACTBaseTestCase.php deleted file mode 100644 index b09b2a4d9..000000000 --- a/tests/Australia/ACT/ACTBaseTestCase.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -use Yasumi\tests\Australia\AustraliaBaseTestCase; -use Yasumi\tests\YasumiBase; - -/** - * Base class for test cases of the ACT holiday provider. - */ -abstract class ACTBaseTestCase extends AustraliaBaseTestCase -{ - use YasumiBase; - - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\ACT'; - - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/ACT'; -} diff --git a/tests/Australia/ACT/ACTTest.php b/tests/Australia/ACT/ACTTest.php deleted file mode 100644 index 5ccde3761..000000000 --- a/tests/Australia/ACT/ACTTest.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -use ReflectionException; -use Yasumi\Holiday; - -/** - * Class for testing holidays in ACT (Australia). - */ -class ACTTest extends ACTBaseTestCase -{ - /** - * @var int year random year number used for all tests in this Test Case - */ - protected $year; - - /** - * Tests if all official holidays in ACT (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testOfficialHolidays(): void - { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'goodFriday', - 'easterMonday', - 'christmasDay', - 'secondChristmasDay', - 'australiaDay', - 'anzacDay', - 'easter', - 'easterSaturday', - 'queensBirthday', - 'labourDay', - 'canberraDay', - 'reconciliationDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(2018, 2100); - } -} diff --git a/tests/Australia/ACT/AnzacDayTest.php b/tests/Australia/ACT/AnzacDayTest.php deleted file mode 100644 index 8f1085c71..000000000 --- a/tests/Australia/ACT/AnzacDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing ANZAC day in ACT (Australia).. - */ -class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest -{ -} diff --git a/tests/Australia/ACT/AustraliaDayTest.php b/tests/Australia/ACT/AustraliaDayTest.php deleted file mode 100644 index b4014cb6a..000000000 --- a/tests/Australia/ACT/AustraliaDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing Australia day in ACT (Australia).. - */ -class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest -{ -} diff --git a/tests/Australia/ACT/BoxingDayTest.php b/tests/Australia/ACT/BoxingDayTest.php deleted file mode 100644 index 23854a973..000000000 --- a/tests/Australia/ACT/BoxingDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing Boxing Day in ACT (Australia).. - */ -class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest -{ -} diff --git a/tests/Australia/ACT/ChristmasDayTest.php b/tests/Australia/ACT/ChristmasDayTest.php deleted file mode 100644 index f612d1c61..000000000 --- a/tests/Australia/ACT/ChristmasDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing Christmas Day in ACT (Australia).. - */ -class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest -{ -} diff --git a/tests/Australia/ACT/EasterMondayTest.php b/tests/Australia/ACT/EasterMondayTest.php deleted file mode 100644 index 37c808ce5..000000000 --- a/tests/Australia/ACT/EasterMondayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing Easter Monday in ACT (Australia).. - */ -class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest -{ -} diff --git a/tests/Australia/ACT/EasterSaturdayTest.php b/tests/Australia/ACT/EasterSaturdayTest.php deleted file mode 100644 index e2c998189..000000000 --- a/tests/Australia/ACT/EasterSaturdayTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Saturday in ACT (Australia).. - */ -class EasterSaturdayTest extends ACTBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easterSaturday'; - - /** - * Tests Easter Saturday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Saturday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/ACT/EasterSundayTest.php b/tests/Australia/ACT/EasterSundayTest.php deleted file mode 100644 index 4e263f370..000000000 --- a/tests/Australia/ACT/EasterSundayTest.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Sunday in ACT (Australia).. - */ -class EasterSundayTest extends ACTBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easter'; - - /** - * Tests Easter Sunday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Sunday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/ACT/GoodFridayTest.php b/tests/Australia/ACT/GoodFridayTest.php deleted file mode 100644 index 5906c4fef..000000000 --- a/tests/Australia/ACT/GoodFridayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing Good Friday in ACT (Australia).. - */ -class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest -{ -} diff --git a/tests/Australia/ACT/LabourDayTest.php b/tests/Australia/ACT/LabourDayTest.php deleted file mode 100644 index 859bae64d..000000000 --- a/tests/Australia/ACT/LabourDayTest.php +++ /dev/null @@ -1,99 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Labour Day in ACT (Australia).. - */ -class LabourDayTest extends ACTBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'labourDay'; - - /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - */ - public function HolidayDataProvider(): array - { - $data = [ - [2010, '2010-10-04'], - [2011, '2011-10-03'], - [2012, '2012-10-01'], - [2013, '2013-10-07'], - [2014, '2014-10-06'], - [2015, '2015-10-05'], - [2016, '2016-10-03'], - [2017, '2017-10-02'], - [2018, '2018-10-01'], - [2019, '2019-10-07'], - [2020, '2020-10-05'], - ]; - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(1990), - [self::LOCALE => 'Labour Day'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/ACT/NewYearsDayTest.php b/tests/Australia/ACT/NewYearsDayTest.php deleted file mode 100644 index 81bc5c291..000000000 --- a/tests/Australia/ACT/NewYearsDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\ACT; - -/** - * Class for testing New Years Day in ACT (Australia).. - */ -class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest -{ -} diff --git a/tests/Australia/AnzacDayTest.php b/tests/Australia/AnzacDayTest.php index 89eedd963..ccda08d7c 100644 --- a/tests/Australia/AnzacDayTest.php +++ b/tests/Australia/AnzacDayTest.php @@ -1,77 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing ANZAC day in Australia. */ -class AnzacDayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class AnzacDayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'anzacDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1921; /** - * Tests ANZAC Day - * - * @dataProvider HolidayDataProvider + * Tests ANZAC Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Tests that ANZAC Day is not present before 1921 - * @throws ReflectionException + * Tests that ANZAC Day is not present before 1921. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday($this->region, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-04-25'], [2011, '2011-04-25'], [2012, '2012-04-25'], @@ -85,34 +83,34 @@ public function HolidayDataProvider(): array [2019, '2019-04-25'], [2020, '2020-04-25'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'ANZAC Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/AustraliaBaseTestCase.php b/tests/Australia/AustraliaBaseTestCase.php index 701363204..cf0011175 100644 --- a/tests/Australia/AustraliaBaseTestCase.php +++ b/tests/Australia/AustraliaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; @@ -22,16 +27,14 @@ abstract class AustraliaBaseTestCase extends TestCase { use YasumiBase; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_AU'; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Melbourne'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Melbourne'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia'; + + public string $timezone = 'Australia/Melbourne'; } diff --git a/tests/Australia/AustraliaDayTest.php b/tests/Australia/AustraliaDayTest.php index 4d1f0f05d..d405aadb7 100644 --- a/tests/Australia/AustraliaDayTest.php +++ b/tests/Australia/AustraliaDayTest.php @@ -1,100 +1,130 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Australia day in Australia. */ -class AustraliaDayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class AustraliaDayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'australiaDay'; /** - * Tests Australia Day + * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday($this->region, self::HOLIDAY, $year, $expected); + } + + /** + * Tests Australia Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param ?string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('SubstituteHolidayDataProvider')] + public function testSubstituteHoliday(int $year, ?string $expected): void { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); + if ($expected) { + $this->assertSubstituteHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } else { + $this->assertNotSubstituteHoliday( + $this->region, + self::HOLIDAY, + $year + ); + } } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(2000), + static::generateRandomYear(2000), [self::LOCALE => 'Australia Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(2000), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(2000), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of test dates + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ - [2010, '2010-01-26'], - [2011, '2011-01-26'], - [2012, '2012-01-26'], + return static::generateRandomDates(1, 26, 'Australia/Melbourne'); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function SubstituteHolidayDataProvider(): array + { + return [ + [2010, null], + [2011, null], + [2012, null], [2013, '2013-01-28'], [2014, '2014-01-27'], - [2015, '2015-01-26'], - [2016, '2016-01-26'], - [2017, '2017-01-26'], - [2018, '2018-01-26'], + [2015, null], + [2016, null], + [2017, null], + [2018, null], [2019, '2019-01-28'], [2020, '2020-01-27'], ]; - - return $data; } } diff --git a/tests/Australia/AustraliaTest.php b/tests/Australia/AustraliaTest.php index 3dbdc168c..d3c74d0da 100644 --- a/tests/Australia/AustraliaTest.php +++ b/tests/Australia/AustraliaTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Australia. */ -class AustraliaTest extends AustraliaBaseTestCase +class AustraliaTest extends AustraliaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1987); + } /** - * Tests if all official holidays in Australia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Australia are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -39,12 +53,17 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Australia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Australia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -52,8 +71,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Australia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Australia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -61,8 +79,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Australia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Australia are defined by the provider class. */ public function testBankHolidays(): void { @@ -70,8 +87,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Australia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Australia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -79,10 +95,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1987); + $this->assertSources($this->region, 1); // TODO: Investigate why not a constant is used for region. } } diff --git a/tests/Australia/AustralianCapitalTerritory/AnzacDayTest.php b/tests/Australia/AustralianCapitalTerritory/AnzacDayTest.php new file mode 100644 index 000000000..952fc1e05 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/AnzacDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing ANZAC day in Australian Capital Territory (Australia).. + */ +class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/AustraliaDayTest.php b/tests/Australia/AustralianCapitalTerritory/AustraliaDayTest.php new file mode 100644 index 000000000..56f6a2e8d --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/AustraliaDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing Australia day in Australian Capital Territory (Australia).. + */ +class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php new file mode 100644 index 000000000..b92905446 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\tests\Australia\AustraliaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Australian Capital Territory holiday provider. + */ +abstract class AustralianCapitalTerritoryBaseTestCase extends AustraliaBaseTestCase +{ + use YasumiBase; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/ACT'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\AustralianCapitalTerritory'; + + public string $timezone = 'Australia/ACT'; +} diff --git a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php new file mode 100644 index 000000000..fd4717c6c --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php @@ -0,0 +1,79 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Australian Capital Territory (Australia). + */ +class AustralianCapitalTerritoryTest extends AustralianCapitalTerritoryBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2018, 2100); + } + + /** + * Tests if all official holidays in Australian Capital Territory (Australia) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $expectedHolidays = [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'secondChristmasDay', + 'australiaDay', + 'anzacDay', + 'easter', + 'easterSaturday', + 'queensBirthday', + 'labourDay', + 'canberraDay', + 'reconciliationDay', + ]; + + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources($this->region, 1); + } +} diff --git a/tests/Australia/AustralianCapitalTerritory/BoxingDayTest.php b/tests/Australia/AustralianCapitalTerritory/BoxingDayTest.php new file mode 100644 index 000000000..e7005bfe8 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/BoxingDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing Boxing Day in Australian Capital Territory (Australia).. + */ +class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest +{ +} diff --git a/tests/Australia/ACT/CanberraDayTest.php b/tests/Australia/AustralianCapitalTerritory/CanberraDayTest.php similarity index 52% rename from tests/Australia/ACT/CanberraDayTest.php rename to tests/Australia/AustralianCapitalTerritory/CanberraDayTest.php index a03efe9cc..ec5dff140 100644 --- a/tests/Australia/ACT/CanberraDayTest.php +++ b/tests/Australia/AustralianCapitalTerritory/CanberraDayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\ACT; +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Canberra Day in ACT (Australia).. + * Class for testing Canberra Day in Australian Capital Territory (Australia).. */ -class CanberraDayTest extends ACTBaseTestCase implements YasumiTestCaseInterface +class CanberraDayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'canberraDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1913; /** - * Tests Canberra Day - * - * @dataProvider HolidayDataProvider + * Tests Canberra Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-03-08'], [2011, '2011-03-14'], [2012, '2012-03-12'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-03-11'], [2020, '2020-03-09'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Canberra Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/AustralianCapitalTerritory/ChristmasDayTest.php b/tests/Australia/AustralianCapitalTerritory/ChristmasDayTest.php new file mode 100644 index 000000000..3882bd3c3 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/ChristmasDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing Christmas Day in Australian Capital Territory (Australia).. + */ +class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/EasterMondayTest.php b/tests/Australia/AustralianCapitalTerritory/EasterMondayTest.php new file mode 100644 index 000000000..cde1421ad --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/EasterMondayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing Easter Monday in Australian Capital Territory (Australia).. + */ +class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/EasterSaturdayTest.php b/tests/Australia/AustralianCapitalTerritory/EasterSaturdayTest.php new file mode 100644 index 000000000..7c132ebcb --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/EasterSaturdayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Saturday in Australian Capital Territory (Australia).. + */ +class EasterSaturdayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterSaturday'; + + /** + * Tests Easter Saturday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Saturday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/AustralianCapitalTerritory/EasterSundayTest.php b/tests/Australia/AustralianCapitalTerritory/EasterSundayTest.php new file mode 100644 index 000000000..4aaa6924d --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/EasterSundayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in Australian Capital Territory (Australia).. + */ +class EasterSundayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/AustralianCapitalTerritory/GoodFridayTest.php b/tests/Australia/AustralianCapitalTerritory/GoodFridayTest.php new file mode 100644 index 000000000..8f30bee86 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/GoodFridayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing Good Friday in Australian Capital Territory (Australia).. + */ +class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/LabourDayTest.php b/tests/Australia/AustralianCapitalTerritory/LabourDayTest.php new file mode 100644 index 000000000..a8abe5d77 --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/LabourDayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Labour Day in Australian Capital Territory (Australia).. + */ +class LabourDayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'labourDay'; + + /** + * Tests Labour Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2010, '2010-10-04'], + [2011, '2011-10-03'], + [2012, '2012-10-01'], + [2013, '2013-10-07'], + [2014, '2014-10-06'], + [2015, '2015-10-05'], + [2016, '2016-10-03'], + [2017, '2017-10-02'], + [2018, '2018-10-01'], + [2019, '2019-10-07'], + [2020, '2020-10-05'], + ]; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(1990), + [self::LOCALE => 'Labour Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/AustralianCapitalTerritory/NationalDayOfMourningTest.php b/tests/Australia/AustralianCapitalTerritory/NationalDayOfMourningTest.php new file mode 100644 index 000000000..2913817cd --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing National Day of Mourning in Australian Capital Territory (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/AustralianCapitalTerritory/NewYearsDayTest.php b/tests/Australia/AustralianCapitalTerritory/NewYearsDayTest.php new file mode 100644 index 000000000..00fd0508c --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/NewYearsDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +/** + * Class for testing New Years Day in Australian Capital Territory (Australia).. + */ +class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest +{ +} diff --git a/tests/Australia/NSW/QueensBirthdayTest.php b/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php similarity index 50% rename from tests/Australia/NSW/QueensBirthdayTest.php rename to tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php index 4d1fd6d4b..b945dcf3f 100644 --- a/tests/Australia/NSW/QueensBirthdayTest.php +++ b/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NSW; +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in NSW (Australia).. + * Class for testing Queen's Birthday in Australian Capital Territory (Australia).. */ -class QueensBirthdayTest extends NSWBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/ACT/ReconciliationDayTest.php b/tests/Australia/AustralianCapitalTerritory/ReconciliationDayTest.php similarity index 53% rename from tests/Australia/ACT/ReconciliationDayTest.php rename to tests/Australia/AustralianCapitalTerritory/ReconciliationDayTest.php index aaba8f4f9..f6273aa9e 100644 --- a/tests/Australia/ACT/ReconciliationDayTest.php +++ b/tests/Australia/AustralianCapitalTerritory/ReconciliationDayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\ACT; +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Reconciliation Day in ACT (Australia).. + * Class for testing Reconciliation Day in Australian Capital Territory (Australia).. */ -class ReconciliationDayTest extends ACTBaseTestCase implements YasumiTestCaseInterface +class ReconciliationDayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'reconciliationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2018; /** - * Tests Reconciliation Day - * - * @dataProvider HolidayDataProvider + * Tests Reconciliation Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2018, '2018-05-28'], [2019, '2019-05-27'], [2020, '2020-06-01'], @@ -77,34 +76,34 @@ public function HolidayDataProvider(): array [2029, '2029-05-28'], [2030, '2030-05-27'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reconciliation Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/BoxingDayTest.php b/tests/Australia/BoxingDayTest.php index 3ab1e7e2c..acad8315d 100644 --- a/tests/Australia/BoxingDayTest.php +++ b/tests/Australia/BoxingDayTest.php @@ -1,54 +1,53 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in Australia. */ -class BoxingDayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; public const HOLIDAY2 = 'secondChristmasHoliday'; /** - * Tests Boxing Day + * Tests Boxing Day. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * @param ?string $expectedExtra the expected date for the additional holiday, or null if no additional holiday * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * @param string $expectedExtra the expected date for the additional holiday, or null if no additional holiday - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected, $expectedExtra) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected, ?string $expectedExtra): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); if (null === $expectedExtra) { $this->assertNotHoliday( @@ -61,19 +60,19 @@ public function testHoliday($year, $expected, $expectedExtra) $this->region, self::HOLIDAY2, $year, - new DateTime($expectedExtra, new DateTimeZone($this->timezone)) + new \DateTime($expectedExtra, new \DateTimeZone($this->timezone)) ); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-12-26', '2010-12-28'], [2011, '2011-12-26', null], [2012, '2012-12-26', null], @@ -86,21 +85,19 @@ public function HolidayDataProvider(): array [2019, '2019-12-26', null], [2020, '2020-12-26', '2020-12-28'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); $this->assertTranslatedHolidayName( @@ -114,11 +111,11 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); $this->assertHolidayType($this->region, self::HOLIDAY2, 2020, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/ChristmasDayTest.php b/tests/Australia/ChristmasDayTest.php index 25e8fa41b..cf18119a6 100644 --- a/tests/Australia/ChristmasDayTest.php +++ b/tests/Australia/ChristmasDayTest.php @@ -1,54 +1,53 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Australia. */ -class ChristmasDayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; public const HOLIDAY2 = 'christmasHoliday'; /** - * Tests Christmas Day + * Tests Christmas Day. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * @param ?string $expectedExtra the expected date for the additional holiday, or null if no additional holiday * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * @param string $expectedExtra the expected date for the additional holiday, or null if no additional holiday - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected, $expectedExtra) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected, ?string $expectedExtra): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); if (null === $expectedExtra) { $this->assertNotHoliday( @@ -61,19 +60,19 @@ public function testHoliday($year, $expected, $expectedExtra) $this->region, self::HOLIDAY2, $year, - new DateTime($expectedExtra, new DateTimeZone($this->timezone)) + new \DateTime($expectedExtra, new \DateTimeZone($this->timezone)) ); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-12-25', '2010-12-27'], [2011, '2011-12-25', '2011-12-27'], [2012, '2012-12-25', null], @@ -86,21 +85,19 @@ public function HolidayDataProvider(): array [2019, '2019-12-25', null], [2020, '2020-12-25', null], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); $this->assertTranslatedHolidayName( @@ -114,11 +111,11 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); $this->assertHolidayType($this->region, self::HOLIDAY2, 2016, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/EasterMondayTest.php b/tests/Australia/EasterMondayTest.php index a1f4e9a13..228bb0299 100644 --- a/tests/Australia/EasterMondayTest.php +++ b/tests/Australia/EasterMondayTest.php @@ -1,92 +1,89 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Monday in Australia. */ -class EasterMondayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; public const HOLIDAY2 = 'easterTuesday'; /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider + * Tests Easter Monday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Tests Easter Tuesday for those years when ANZAC Day clashes with Easter Sunday or Monday + * Tests Easter Tuesday for those years when ANZAC Day clashes with Easter Sunday or Monday. * - * @dataProvider HolidayDataProvider2 - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday2($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider2')] + public function testHoliday2(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY2, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -95,33 +92,31 @@ public function HolidayDataProvider(): array } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider2(): array + public static function HolidayDataProvider2(): array { - $data = [ + return [ [2011, '2011-04-26'], [2038, '2038-04-27'], [2095, '2095-04-26'], [2163, '2163-04-26'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); $this->assertTranslatedHolidayName( @@ -135,11 +130,11 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); $this->assertHolidayType($this->region, self::HOLIDAY2, 2011, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/GoodFridayTest.php b/tests/Australia/GoodFridayTest.php index d2d261ba6..f08e65007 100644 --- a/tests/Australia/GoodFridayTest.php +++ b/tests/Australia/GoodFridayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in Australia. */ -class GoodFridayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'goodFriday'; /** - * Tests Good Friday - * - * @dataProvider HolidayDataProvider + * Tests Good Friday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P2D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P2D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -73,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/NSW/AnzacDayTest.php b/tests/Australia/NSW/AnzacDayTest.php deleted file mode 100644 index 8f8677bbd..000000000 --- a/tests/Australia/NSW/AnzacDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing ANZAC day in NSW (Australia).. - */ -class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest -{ -} diff --git a/tests/Australia/NSW/AustraliaDayTest.php b/tests/Australia/NSW/AustraliaDayTest.php deleted file mode 100644 index 8f77c3300..000000000 --- a/tests/Australia/NSW/AustraliaDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing Australia day in NSW (Australia).. - */ -class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest -{ -} diff --git a/tests/Australia/NSW/BoxingDayTest.php b/tests/Australia/NSW/BoxingDayTest.php deleted file mode 100644 index edf2a9e6b..000000000 --- a/tests/Australia/NSW/BoxingDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing Boxing Day in NSW (Australia).. - */ -class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest -{ -} diff --git a/tests/Australia/NSW/ChristmasDayTest.php b/tests/Australia/NSW/ChristmasDayTest.php deleted file mode 100644 index a8a35aba3..000000000 --- a/tests/Australia/NSW/ChristmasDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing Christmas Day in NSW (Australia).. - */ -class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest -{ -} diff --git a/tests/Australia/NSW/EasterMondayTest.php b/tests/Australia/NSW/EasterMondayTest.php deleted file mode 100644 index f666aef4f..000000000 --- a/tests/Australia/NSW/EasterMondayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing Easter Monday in NSW (Australia).. - */ -class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest -{ -} diff --git a/tests/Australia/NSW/EasterSaturdayTest.php b/tests/Australia/NSW/EasterSaturdayTest.php deleted file mode 100644 index 5af477d88..000000000 --- a/tests/Australia/NSW/EasterSaturdayTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Saturday in NSW (Australia).. - */ -class EasterSaturdayTest extends NSWBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easterSaturday'; - - /** - * Tests Easter Saturday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Saturday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/NSW/EasterSundayTest.php b/tests/Australia/NSW/EasterSundayTest.php deleted file mode 100644 index 5f9bfde47..000000000 --- a/tests/Australia/NSW/EasterSundayTest.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Sunday in NSW (Australia).. - */ -class EasterSundayTest extends NSWBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easter'; - - /** - * Tests Easter Sunday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Sunday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/NSW/GoodFridayTest.php b/tests/Australia/NSW/GoodFridayTest.php deleted file mode 100644 index ed35da765..000000000 --- a/tests/Australia/NSW/GoodFridayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing Good Friday in NSW (Australia).. - */ -class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest -{ -} diff --git a/tests/Australia/NSW/NSWBaseTestCase.php b/tests/Australia/NSW/NSWBaseTestCase.php deleted file mode 100644 index 04dc69795..000000000 --- a/tests/Australia/NSW/NSWBaseTestCase.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -use Yasumi\tests\Australia\AustraliaBaseTestCase; -use Yasumi\tests\YasumiBase; - -/** - * Base class for test cases of the NSW holiday provider. - */ -abstract class NSWBaseTestCase extends AustraliaBaseTestCase -{ - use YasumiBase; - - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\NSW'; - - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/NSW'; -} diff --git a/tests/Australia/NSW/NSWTest.php b/tests/Australia/NSW/NSWTest.php deleted file mode 100644 index d773a970f..000000000 --- a/tests/Australia/NSW/NSWTest.php +++ /dev/null @@ -1,67 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -use ReflectionException; -use Yasumi\Holiday; - -/** - * Class for testing holidays in NSW (Australia). - */ -class NSWTest extends NSWBaseTestCase -{ - /** - * @var int year random year number used for all tests in this Test Case - */ - protected $year; - - /** - * Tests if all official holidays in NSW (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testOfficialHolidays(): void - { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'goodFriday', - 'easterMonday', - 'christmasDay', - 'secondChristmasDay', - 'australiaDay', - 'anzacDay', - 'easter', - 'easterSaturday', - 'queensBirthday', - 'labourDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Tests if all bank holidays in NSW (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testBankHolidays(): void - { - $this->assertDefinedHolidays([ - 'bankHoliday', - ], $this->region, $this->year, Holiday::TYPE_BANK); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1921); - } -} diff --git a/tests/Australia/NSW/NewYearsDayTest.php b/tests/Australia/NSW/NewYearsDayTest.php deleted file mode 100644 index 83c806d6d..000000000 --- a/tests/Australia/NSW/NewYearsDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NSW; - -/** - * Class for testing New Years Day in NSW (Australia).. - */ -class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest -{ -} diff --git a/tests/Australia/NT/AnzacDayTest.php b/tests/Australia/NT/AnzacDayTest.php deleted file mode 100644 index 04265910e..000000000 --- a/tests/Australia/NT/AnzacDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing ANZAC day in NT (Australia).. - */ -class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest -{ -} diff --git a/tests/Australia/NT/AustraliaDayTest.php b/tests/Australia/NT/AustraliaDayTest.php deleted file mode 100644 index 4b20e9f63..000000000 --- a/tests/Australia/NT/AustraliaDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing Australia day in NT (Australia).. - */ -class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest -{ -} diff --git a/tests/Australia/NT/BoxingDayTest.php b/tests/Australia/NT/BoxingDayTest.php deleted file mode 100644 index a5a335303..000000000 --- a/tests/Australia/NT/BoxingDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing Boxing Day in NT (Australia).. - */ -class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest -{ -} diff --git a/tests/Australia/NT/ChristmasDayTest.php b/tests/Australia/NT/ChristmasDayTest.php deleted file mode 100644 index 2d0a22310..000000000 --- a/tests/Australia/NT/ChristmasDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing Christmas Day in NT (Australia).. - */ -class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest -{ -} diff --git a/tests/Australia/NT/EasterMondayTest.php b/tests/Australia/NT/EasterMondayTest.php deleted file mode 100644 index 98e89ec88..000000000 --- a/tests/Australia/NT/EasterMondayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing Easter Monday in NT (Australia).. - */ -class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest -{ -} diff --git a/tests/Australia/NT/EasterSaturdayTest.php b/tests/Australia/NT/EasterSaturdayTest.php deleted file mode 100644 index 3cd542dc2..000000000 --- a/tests/Australia/NT/EasterSaturdayTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Saturday in NT (Australia).. - */ -class EasterSaturdayTest extends NTBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easterSaturday'; - - /** - * Tests Easter Saturday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Saturday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/NT/GoodFridayTest.php b/tests/Australia/NT/GoodFridayTest.php deleted file mode 100644 index 10d9d7844..000000000 --- a/tests/Australia/NT/GoodFridayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing Good Friday in NT (Australia).. - */ -class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest -{ -} diff --git a/tests/Australia/NT/NTBaseTestCase.php b/tests/Australia/NT/NTBaseTestCase.php deleted file mode 100644 index ff371b92b..000000000 --- a/tests/Australia/NT/NTBaseTestCase.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -use Yasumi\tests\Australia\AustraliaBaseTestCase; -use Yasumi\tests\YasumiBase; - -/** - * Base class for test cases of the NT holiday provider. - */ -abstract class NTBaseTestCase extends AustraliaBaseTestCase -{ - use YasumiBase; - - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\NT'; - - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/North'; -} diff --git a/tests/Australia/NT/NTTest.php b/tests/Australia/NT/NTTest.php deleted file mode 100644 index fda09c5a3..000000000 --- a/tests/Australia/NT/NTTest.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -use ReflectionException; -use Yasumi\Holiday; - -/** - * Class for testing holidays in NT (Australia). - */ -class NTTest extends NTBaseTestCase -{ - /** - * @var int year random year number used for all tests in this Test Case - */ - protected $year; - - /** - * Tests if all official holidays in NT (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testOfficialHolidays(): void - { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'goodFriday', - 'easterMonday', - 'christmasDay', - 'secondChristmasDay', - 'australiaDay', - 'anzacDay', - 'easterSaturday', - 'queensBirthday', - 'mayDay', - 'picnicDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1921); - } -} diff --git a/tests/Australia/NT/NewYearsDayTest.php b/tests/Australia/NT/NewYearsDayTest.php deleted file mode 100644 index 04e24cd0b..000000000 --- a/tests/Australia/NT/NewYearsDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\NT; - -/** - * Class for testing New Years Day in NT (Australia).. - */ -class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest -{ -} diff --git a/tests/Australia/NationalDayOfMourningTest.php b/tests/Australia/NationalDayOfMourningTest.php new file mode 100644 index 000000000..90b5045f8 --- /dev/null +++ b/tests/Australia/NationalDayOfMourningTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Australia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing National Day of Mourning in Australia. + */ +class NationalDayOfMourningTest extends AustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'nationalDayOfMourning'; + + /** + * The year in which the holiday was first established. + */ + public const ACTIVE_YEAR = 2022; + + /** + * The date on which the holiday occurred. + */ + public const ACTIVE_DATE = '2022-9-22'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + self::ACTIVE_YEAR, + new \DateTime(self::ACTIVE_DATE, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Tests the holiday defined in this test before the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayBeforeActive(): void + { + $this->assertNotHoliday( + $this->region, + self::HOLIDAY, + static::generateRandomYear(1000, self::ACTIVE_YEAR - 1) + ); + } + + /** + * Tests the holiday defined in this test after the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayAfterActive(): void + { + $this->assertNotHoliday( + $this->region, + self::HOLIDAY, + static::generateRandomYear(self::ACTIVE_YEAR + 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + self::ACTIVE_YEAR, + [self::LOCALE => 'National Day of Mourning'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + $this->region, + self::HOLIDAY, + self::ACTIVE_YEAR, + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Australia/NewSouthWales/AnzacDayTest.php b/tests/Australia/NewSouthWales/AnzacDayTest.php new file mode 100644 index 000000000..cef8c5fed --- /dev/null +++ b/tests/Australia/NewSouthWales/AnzacDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing ANZAC day in New South Wales (Australia).. + */ +class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest +{ +} diff --git a/tests/Australia/NewSouthWales/AustraliaDayTest.php b/tests/Australia/NewSouthWales/AustraliaDayTest.php new file mode 100644 index 000000000..1772c6e72 --- /dev/null +++ b/tests/Australia/NewSouthWales/AustraliaDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing Australia day in New South Wales (Australia).. + */ +class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest +{ +} diff --git a/tests/Australia/NSW/BankHolidayTest.php b/tests/Australia/NewSouthWales/BankHolidayTest.php similarity index 50% rename from tests/Australia/NSW/BankHolidayTest.php rename to tests/Australia/NewSouthWales/BankHolidayTest.php index 0325527c7..0031a2df1 100644 --- a/tests/Australia/NSW/BankHolidayTest.php +++ b/tests/Australia/NewSouthWales/BankHolidayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NSW; +namespace Yasumi\tests\Australia\NewSouthWales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Bank Holiday in NSW (Australia).. + * Class for testing Bank Holiday in New South Wales (Australia).. */ -class BankHolidayTest extends NSWBaseTestCase implements YasumiTestCaseInterface +class BankHolidayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bankHoliday'; /** - * Tests Bank Holiday - * - * @dataProvider HolidayDataProvider + * Tests Bank Holiday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-08-02'], [2011, '2011-08-01'], [2012, '2012-08-06'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-08-05'], [2020, '2020-08-03'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_BANK); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_BANK); } } diff --git a/tests/Australia/NewSouthWales/BoxingDayTest.php b/tests/Australia/NewSouthWales/BoxingDayTest.php new file mode 100644 index 000000000..ed002dfa2 --- /dev/null +++ b/tests/Australia/NewSouthWales/BoxingDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing Boxing Day in New South Wales (Australia).. + */ +class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest +{ +} diff --git a/tests/Australia/NewSouthWales/ChristmasDayTest.php b/tests/Australia/NewSouthWales/ChristmasDayTest.php new file mode 100644 index 000000000..066d5fd91 --- /dev/null +++ b/tests/Australia/NewSouthWales/ChristmasDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing Christmas Day in New South Wales (Australia).. + */ +class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest +{ +} diff --git a/tests/Australia/NewSouthWales/EasterMondayTest.php b/tests/Australia/NewSouthWales/EasterMondayTest.php new file mode 100644 index 000000000..5d86955f9 --- /dev/null +++ b/tests/Australia/NewSouthWales/EasterMondayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing Easter Monday in New South Wales (Australia).. + */ +class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest +{ +} diff --git a/tests/Australia/NewSouthWales/EasterSaturdayTest.php b/tests/Australia/NewSouthWales/EasterSaturdayTest.php new file mode 100644 index 000000000..7eaf9321d --- /dev/null +++ b/tests/Australia/NewSouthWales/EasterSaturdayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Saturday in New South Wales (Australia).. + */ +class EasterSaturdayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterSaturday'; + + /** + * Tests Easter Saturday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Saturday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NewSouthWales/EasterSundayTest.php b/tests/Australia/NewSouthWales/EasterSundayTest.php new file mode 100644 index 000000000..6abf6b4f2 --- /dev/null +++ b/tests/Australia/NewSouthWales/EasterSundayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in New South Wales (Australia).. + */ +class EasterSundayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NewSouthWales/GoodFridayTest.php b/tests/Australia/NewSouthWales/GoodFridayTest.php new file mode 100644 index 000000000..5a5d539ca --- /dev/null +++ b/tests/Australia/NewSouthWales/GoodFridayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing Good Friday in New South Wales (Australia).. + */ +class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest +{ +} diff --git a/tests/Australia/SA/LabourDayTest.php b/tests/Australia/NewSouthWales/LabourDayTest.php similarity index 50% rename from tests/Australia/SA/LabourDayTest.php rename to tests/Australia/NewSouthWales/LabourDayTest.php index f045656c0..2d241e693 100644 --- a/tests/Australia/SA/LabourDayTest.php +++ b/tests/Australia/NewSouthWales/LabourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\SA; +namespace Yasumi\tests\Australia\NewSouthWales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Labour Day in SA (Australia).. + * Class for testing Labour Day in New South Wales (Australia).. */ -class LabourDayTest extends SABaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-04'], [2011, '2011-10-03'], [2012, '2012-10-01'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-07'], [2020, '2020-10-05'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/NewSouthWales/NationalDayOfMourningTest.php b/tests/Australia/NewSouthWales/NationalDayOfMourningTest.php new file mode 100644 index 000000000..c4593154a --- /dev/null +++ b/tests/Australia/NewSouthWales/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing National Day of Mourning in New South Wales (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php b/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php new file mode 100644 index 000000000..a2e8f801a --- /dev/null +++ b/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +use Yasumi\tests\Australia\AustraliaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the New South Wales holiday provider. + */ +abstract class NewSouthWalesBaseTestCase extends AustraliaBaseTestCase +{ + use YasumiBase; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/NSW'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\NewSouthWales'; + + public string $timezone = 'Australia/NSW'; +} diff --git a/tests/Australia/NewSouthWales/NewSouthWalesTest.php b/tests/Australia/NewSouthWales/NewSouthWalesTest.php new file mode 100644 index 000000000..995eec31f --- /dev/null +++ b/tests/Australia/NewSouthWales/NewSouthWalesTest.php @@ -0,0 +1,87 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in New South Wales (Australia). + */ +class NewSouthWalesTest extends NewSouthWalesBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in New South Wales (Australia) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'secondChristmasDay', + 'australiaDay', + 'anzacDay', + 'easter', + 'easterSaturday', + 'queensBirthday', + 'labourDay', + ]; + + if (2022 === $this->year) { + $holidays[] = 'nationalDayOfMourning'; + } + + $this->assertDefinedHolidays($holidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all bank holidays in New South Wales (Australia) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([ + 'bankHoliday', + ], $this->region, $this->year, Holiday::TYPE_BANK); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources($this->region, 1); + } +} diff --git a/tests/Australia/NewSouthWales/NewYearsDayTest.php b/tests/Australia/NewSouthWales/NewYearsDayTest.php new file mode 100644 index 000000000..7ba05529f --- /dev/null +++ b/tests/Australia/NewSouthWales/NewYearsDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +/** + * Class for testing New Years Day in New South Wales (Australia).. + */ +class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest +{ +} diff --git a/tests/Australia/SA/QueensBirthdayTest.php b/tests/Australia/NewSouthWales/QueensBirthdayTest.php similarity index 51% rename from tests/Australia/SA/QueensBirthdayTest.php rename to tests/Australia/NewSouthWales/QueensBirthdayTest.php index 21df3e7a9..a81507681 100644 --- a/tests/Australia/SA/QueensBirthdayTest.php +++ b/tests/Australia/NewSouthWales/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\SA; +namespace Yasumi\tests\Australia\NewSouthWales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in SA (Australia).. + * Class for testing Queen's Birthday in New South Wales (Australia).. */ -class QueensBirthdayTest extends SABaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/NewYearsDayTest.php b/tests/Australia/NewYearsDayTest.php index f4dca22f0..8af3fe44f 100644 --- a/tests/Australia/NewYearsDayTest.php +++ b/tests/Australia/NewYearsDayTest.php @@ -1,54 +1,53 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Australia. */ -class NewYearsDayTest extends AustraliaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends AustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; public const HOLIDAY2 = 'newYearsHoliday'; /** - * Tests New Years Day + * Tests New Years Day. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * @param ?string $expectedExtra the expected date for the additional holiday, or null if no additional holiday * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * @param string $expectedExtra the expected date for the additional holiday, or null if no additional holiday - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected, $expectedExtra) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected, ?string $expectedExtra): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); if (null === $expectedExtra) { $this->assertNotHoliday( @@ -61,19 +60,19 @@ public function testHoliday($year, $expected, $expectedExtra) $this->region, self::HOLIDAY2, $year, - new DateTime($expectedExtra, new DateTimeZone($this->timezone)) + new \DateTime($expectedExtra, new \DateTimeZone($this->timezone)) ); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-01-01', null], [2011, '2011-01-01', '2011-01-03'], [2012, '2012-01-01', '2012-01-02'], @@ -86,39 +85,37 @@ public function HolidayDataProvider(): array [2019, '2019-01-01', null], [2020, '2020-01-01', null], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(), + [self::LOCALE => 'New Year’s Day'] ); $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY2, 2017, - [self::LOCALE => 'New Year\'s Holiday'] + [self::LOCALE => 'New Year’s Holiday'] ); } /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); $this->assertHolidayType($this->region, self::HOLIDAY2, 2017, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/NorthernTerritory/AnzacDayTest.php b/tests/Australia/NorthernTerritory/AnzacDayTest.php new file mode 100644 index 000000000..492c8bde7 --- /dev/null +++ b/tests/Australia/NorthernTerritory/AnzacDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing ANZAC day in Northern Territory (Australia). + */ +class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/AustraliaDayTest.php b/tests/Australia/NorthernTerritory/AustraliaDayTest.php new file mode 100644 index 000000000..5c0438f67 --- /dev/null +++ b/tests/Australia/NorthernTerritory/AustraliaDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing Australia day in Northern Territory (Australia). + */ +class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/BoxingDayTest.php b/tests/Australia/NorthernTerritory/BoxingDayTest.php new file mode 100644 index 000000000..b360d5ccc --- /dev/null +++ b/tests/Australia/NorthernTerritory/BoxingDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing Boxing Day in Northern Territory (Australia). + */ +class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/ChristmasDayTest.php b/tests/Australia/NorthernTerritory/ChristmasDayTest.php new file mode 100644 index 000000000..8267ae589 --- /dev/null +++ b/tests/Australia/NorthernTerritory/ChristmasDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing Christmas Day in Northern Territory (Australia). + */ +class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/EasterMondayTest.php b/tests/Australia/NorthernTerritory/EasterMondayTest.php new file mode 100644 index 000000000..178a32363 --- /dev/null +++ b/tests/Australia/NorthernTerritory/EasterMondayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing Easter Monday in Northern Territory (Australia). + */ +class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/EasterSaturdayTest.php b/tests/Australia/NorthernTerritory/EasterSaturdayTest.php new file mode 100644 index 000000000..8c9b5547a --- /dev/null +++ b/tests/Australia/NorthernTerritory/EasterSaturdayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Saturday in Northern Territory (Australia). + */ +class EasterSaturdayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterSaturday'; + + /** + * Tests Easter Saturday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Saturday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NorthernTerritory/GoodFridayTest.php b/tests/Australia/NorthernTerritory/GoodFridayTest.php new file mode 100644 index 000000000..29020a25e --- /dev/null +++ b/tests/Australia/NorthernTerritory/GoodFridayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing Good Friday in Northern Territory (Australia). + */ +class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest +{ +} diff --git a/tests/Australia/NT/MayDayTest.php b/tests/Australia/NorthernTerritory/MayDayTest.php similarity index 50% rename from tests/Australia/NT/MayDayTest.php rename to tests/Australia/NorthernTerritory/MayDayTest.php index ea37aafc7..fb719510e 100644 --- a/tests/Australia/NT/MayDayTest.php +++ b/tests/Australia/NorthernTerritory/MayDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NT; +namespace Yasumi\tests\Australia\NorthernTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing May Day in NT (Australia).. + * Class for testing May Day in Northern Territory (Australia). */ -class MayDayTest extends NTBaseTestCase implements YasumiTestCaseInterface +class MayDayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDay'; /** - * Tests May Day - * - * @dataProvider HolidayDataProvider + * Tests May Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-05-03'], [2011, '2011-05-02'], [2012, '2012-05-07'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-05-06'], [2020, '2020-05-04'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'May Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/NorthernTerritory/NationalDayOfMourningTest.php b/tests/Australia/NorthernTerritory/NationalDayOfMourningTest.php new file mode 100644 index 000000000..89c05edcd --- /dev/null +++ b/tests/Australia/NorthernTerritory/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing National Day of Mourning in Northern Territory (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/NorthernTerritory/NewYearsDayTest.php b/tests/Australia/NorthernTerritory/NewYearsDayTest.php new file mode 100644 index 000000000..9a8f310e2 --- /dev/null +++ b/tests/Australia/NorthernTerritory/NewYearsDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +/** + * Class for testing New Years Day in Northern Territory (Australia). + */ +class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest +{ +} diff --git a/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php b/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php new file mode 100644 index 000000000..d4be2ce9d --- /dev/null +++ b/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +use Yasumi\tests\Australia\AustraliaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Northern Territory holiday provider. + */ +abstract class NorthernTerritoryBaseTestCase extends AustraliaBaseTestCase +{ + use YasumiBase; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/North'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\NorthernTerritory'; + + public string $timezone = 'Australia/North'; +} diff --git a/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php b/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php new file mode 100644 index 000000000..746a52884 --- /dev/null +++ b/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php @@ -0,0 +1,77 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Northern Territory (Australia). + */ +class NorthernTerritoryTest extends NorthernTerritoryBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Northern Territory (Australia) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $expectedHolidays = [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'secondChristmasDay', + 'australiaDay', + 'anzacDay', + 'easterSaturday', + 'queensBirthday', + 'mayDay', + 'picnicDay', + ]; + + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources($this->region, 1); + } +} diff --git a/tests/Australia/NT/PicnicDayTest.php b/tests/Australia/NorthernTerritory/PicnicDayTest.php similarity index 50% rename from tests/Australia/NT/PicnicDayTest.php rename to tests/Australia/NorthernTerritory/PicnicDayTest.php index 490d33c34..40d76b23f 100644 --- a/tests/Australia/NT/PicnicDayTest.php +++ b/tests/Australia/NorthernTerritory/PicnicDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NT; +namespace Yasumi\tests\Australia\NorthernTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Picnic Day in NT (Australia).. + * Class for testing Picnic Day in Northern Territory (Australia). */ -class PicnicDayTest extends NTBaseTestCase implements YasumiTestCaseInterface +class PicnicDayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'picnicDay'; /** - * Tests Picnic Day - * - * @dataProvider HolidayDataProvider + * Tests Picnic Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-08-02'], [2011, '2011-08-01'], [2012, '2012-08-06'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-08-05'], [2020, '2020-08-03'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Picnic Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/NT/QueensBirthdayTest.php b/tests/Australia/NorthernTerritory/QueensBirthdayTest.php similarity index 51% rename from tests/Australia/NT/QueensBirthdayTest.php rename to tests/Australia/NorthernTerritory/QueensBirthdayTest.php index 936823ad4..c9aa98c09 100644 --- a/tests/Australia/NT/QueensBirthdayTest.php +++ b/tests/Australia/NorthernTerritory/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NT; +namespace Yasumi\tests\Australia\NorthernTerritory; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in NT (Australia).. + * Class for testing Queen's Birthday in Northern Territory (Australia). */ -class QueensBirthdayTest extends NTBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/Queensland/AnzacDayTest.php b/tests/Australia/Queensland/AnzacDayTest.php index 41d96d9b2..b5b69a00c 100644 --- a/tests/Australia/Queensland/AnzacDayTest.php +++ b/tests/Australia/Queensland/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/AustraliaDayTest.php b/tests/Australia/Queensland/AustraliaDayTest.php index dc13ccdd3..4f6bd2359 100644 --- a/tests/Australia/Queensland/AustraliaDayTest.php +++ b/tests/Australia/Queensland/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/BoxingDayTest.php b/tests/Australia/Queensland/BoxingDayTest.php index 3ea80d8fc..3b6cac82f 100644 --- a/tests/Australia/Queensland/BoxingDayTest.php +++ b/tests/Australia/Queensland/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/Brisbane/AnzacDayTest.php b/tests/Australia/Queensland/Brisbane/AnzacDayTest.php index 31726a5be..5b37581e9 100644 --- a/tests/Australia/Queensland/Brisbane/AnzacDayTest.php +++ b/tests/Australia/Queensland/Brisbane/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/AustraliaDayTest.php b/tests/Australia/Queensland/Brisbane/AustraliaDayTest.php index 052c2fbb1..1542677dd 100644 --- a/tests/Australia/Queensland/Brisbane/AustraliaDayTest.php +++ b/tests/Australia/Queensland/Brisbane/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/BoxingDayTest.php b/tests/Australia/Queensland/Brisbane/BoxingDayTest.php index d6c1dccdb..1e2850d3b 100644 --- a/tests/Australia/Queensland/Brisbane/BoxingDayTest.php +++ b/tests/Australia/Queensland/Brisbane/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/BrisbaneBaseTestCase.php b/tests/Australia/Queensland/Brisbane/BrisbaneBaseTestCase.php index 2a5b8f752..aa5faa9bf 100644 --- a/tests/Australia/Queensland/Brisbane/BrisbaneBaseTestCase.php +++ b/tests/Australia/Queensland/Brisbane/BrisbaneBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; @@ -22,13 +27,11 @@ abstract class BrisbaneBaseTestCase extends QueenslandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Queensland\Brisbane'; + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Brisbane'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Queensland\Brisbane'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Brisbane'; + public string $timezone = 'Australia/Brisbane'; } diff --git a/tests/Australia/Queensland/Brisbane/BrisbaneTest.php b/tests/Australia/Queensland/Brisbane/BrisbaneTest.php index 083ca1b29..a5dbea8a1 100644 --- a/tests/Australia/Queensland/Brisbane/BrisbaneTest.php +++ b/tests/Australia/Queensland/Brisbane/BrisbaneTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Queensland (Australia). */ -class BrisbaneTest extends BrisbaneBaseTestCase +class BrisbaneTest extends BrisbaneBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Queensland (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Queensland (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -43,14 +56,19 @@ public function testOfficialHolidays(): void 'queensBirthday', 'labourDay', 'peoplesDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Queensland/Brisbane/ChristmasDayTest.php b/tests/Australia/Queensland/Brisbane/ChristmasDayTest.php index 7574d1be3..f53cf2272 100644 --- a/tests/Australia/Queensland/Brisbane/ChristmasDayTest.php +++ b/tests/Australia/Queensland/Brisbane/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/EasterMondayTest.php b/tests/Australia/Queensland/Brisbane/EasterMondayTest.php index e71419a9e..dea84b0ca 100644 --- a/tests/Australia/Queensland/Brisbane/EasterMondayTest.php +++ b/tests/Australia/Queensland/Brisbane/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/GoodFridayTest.php b/tests/Australia/Queensland/Brisbane/GoodFridayTest.php index a6172126a..159872538 100644 --- a/tests/Australia/Queensland/Brisbane/GoodFridayTest.php +++ b/tests/Australia/Queensland/Brisbane/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/LabourDayTest.php b/tests/Australia/Queensland/Brisbane/LabourDayTest.php index bf12be474..009caaa17 100644 --- a/tests/Australia/Queensland/Brisbane/LabourDayTest.php +++ b/tests/Australia/Queensland/Brisbane/LabourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/NationalDayOfMourningTest.php b/tests/Australia/Queensland/Brisbane/NationalDayOfMourningTest.php new file mode 100644 index 000000000..5c2d12f62 --- /dev/null +++ b/tests/Australia/Queensland/Brisbane/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Queensland\Brisbane; + +/** + * Class for testing National Day of Mourning in Brisbane (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Queensland\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Queensland/Brisbane/NewYearsDayTest.php b/tests/Australia/Queensland/Brisbane/NewYearsDayTest.php index 82cdf6a27..f0c867376 100644 --- a/tests/Australia/Queensland/Brisbane/NewYearsDayTest.php +++ b/tests/Australia/Queensland/Brisbane/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/Brisbane/PeoplesDayTest.php b/tests/Australia/Queensland/Brisbane/PeoplesDayTest.php index fb93510ad..9f05a9bbf 100644 --- a/tests/Australia/Queensland/Brisbane/PeoplesDayTest.php +++ b/tests/Australia/Queensland/Brisbane/PeoplesDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ekka People's Day in Brisbane (Australia).. */ -class PeoplesDayTest extends BrisbaneBaseTestCase implements YasumiTestCaseInterface +class PeoplesDayTest extends BrisbaneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'peoplesDay'; /** - * Tests Ekka People's Day - * - * @dataProvider HolidayDataProvider + * Tests Ekka People's Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-08-11'], [2011, '2011-08-10'], [2012, '2012-08-15'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-08-14'], [2020, '2020-08-12'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), - [self::LOCALE => 'Ekka People\'s Day'] + static::generateRandomYear(1990), + [self::LOCALE => 'Ekka People’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php b/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php index 97bed4c70..cda565a91 100644 --- a/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php +++ b/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland\Brisbane; diff --git a/tests/Australia/Queensland/ChristmasDayTest.php b/tests/Australia/Queensland/ChristmasDayTest.php index 03da82bb6..204498b6f 100644 --- a/tests/Australia/Queensland/ChristmasDayTest.php +++ b/tests/Australia/Queensland/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/EasterMondayTest.php b/tests/Australia/Queensland/EasterMondayTest.php index 6e41907a7..ff8a2fed8 100644 --- a/tests/Australia/Queensland/EasterMondayTest.php +++ b/tests/Australia/Queensland/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/GoodFridayTest.php b/tests/Australia/Queensland/GoodFridayTest.php index e1e9d6d85..90bfd2476 100644 --- a/tests/Australia/Queensland/GoodFridayTest.php +++ b/tests/Australia/Queensland/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/LabourDayTest.php b/tests/Australia/Queensland/LabourDayTest.php index e938513d7..35c73e0b4 100644 --- a/tests/Australia/Queensland/LabourDayTest.php +++ b/tests/Australia/Queensland/LabourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Labour Day in Queensland (Australia).. */ -class LabourDayTest extends QueenslandBaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends QueenslandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-05-03'], [2011, '2011-05-02'], [2012, '2012-05-07'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-05-06'], [2020, '2020-05-04'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Queensland/NationalDayOfMourningTest.php b/tests/Australia/Queensland/NationalDayOfMourningTest.php new file mode 100644 index 000000000..671601e70 --- /dev/null +++ b/tests/Australia/Queensland/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Queensland; + +/** + * Class for testing National Day of Mourning in Queensland (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Queensland/NewYearsDayTest.php b/tests/Australia/Queensland/NewYearsDayTest.php index 425e24456..e3ed9f3b8 100644 --- a/tests/Australia/Queensland/NewYearsDayTest.php +++ b/tests/Australia/Queensland/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; diff --git a/tests/Australia/Queensland/QueensBirthdayTest.php b/tests/Australia/Queensland/QueensBirthdayTest.php index bdb214d9e..8d3f14f67 100644 --- a/tests/Australia/Queensland/QueensBirthdayTest.php +++ b/tests/Australia/Queensland/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Queen's Birthday in Queensland (Australia).. */ -class QueensBirthdayTest extends QueenslandBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends QueenslandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-10-01'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-10-07'], [2020, '2020-10-05'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/Queensland/QueenslandBaseTestCase.php b/tests/Australia/Queensland/QueenslandBaseTestCase.php index 3b00beeac..d27d7965e 100644 --- a/tests/Australia/Queensland/QueenslandBaseTestCase.php +++ b/tests/Australia/Queensland/QueenslandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; @@ -22,13 +27,11 @@ abstract class QueenslandBaseTestCase extends AustraliaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Queensland'; + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Queensland'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Queensland'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Queensland'; + public string $timezone = 'Australia/Queensland'; } diff --git a/tests/Australia/Queensland/QueenslandTest.php b/tests/Australia/Queensland/QueenslandTest.php index 4340c3ab0..d291e2364 100644 --- a/tests/Australia/Queensland/QueenslandTest.php +++ b/tests/Australia/Queensland/QueenslandTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Queensland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Queensland (Australia). */ -class QueenslandTest extends QueenslandBaseTestCase +class QueenslandTest extends QueenslandBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Queensland (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Queensland (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -42,14 +55,19 @@ public function testOfficialHolidays(): void 'anzacDay', 'queensBirthday', 'labourDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/SA/AnzacDayTest.php b/tests/Australia/SA/AnzacDayTest.php deleted file mode 100644 index daaa488bf..000000000 --- a/tests/Australia/SA/AnzacDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -/** - * Class for testing ANZAC day in SA (Australia).. - */ -class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest -{ -} diff --git a/tests/Australia/SA/AustraliaDayTest.php b/tests/Australia/SA/AustraliaDayTest.php deleted file mode 100644 index e9ea088d3..000000000 --- a/tests/Australia/SA/AustraliaDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -/** - * Class for testing Australia day in SA (Australia).. - */ -class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest -{ -} diff --git a/tests/Australia/SA/EasterMondayTest.php b/tests/Australia/SA/EasterMondayTest.php deleted file mode 100644 index fb559a017..000000000 --- a/tests/Australia/SA/EasterMondayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -/** - * Class for testing Easter Monday in SA (Australia).. - */ -class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest -{ -} diff --git a/tests/Australia/SA/EasterSaturdayTest.php b/tests/Australia/SA/EasterSaturdayTest.php deleted file mode 100644 index 3b6f7d7ae..000000000 --- a/tests/Australia/SA/EasterSaturdayTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Saturday in SA (Australia).. - */ -class EasterSaturdayTest extends SABaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easterSaturday'; - - /** - * Tests Easter Saturday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Saturday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/SA/GoodFridayTest.php b/tests/Australia/SA/GoodFridayTest.php deleted file mode 100644 index 22d313262..000000000 --- a/tests/Australia/SA/GoodFridayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -/** - * Class for testing Good Friday in SA (Australia).. - */ -class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest -{ -} diff --git a/tests/Australia/SA/NewYearsDayTest.php b/tests/Australia/SA/NewYearsDayTest.php deleted file mode 100644 index e6b31ea64..000000000 --- a/tests/Australia/SA/NewYearsDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -/** - * Class for testing New Years Day in SA (Australia).. - */ -class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest -{ -} diff --git a/tests/Australia/SA/SABaseTestCase.php b/tests/Australia/SA/SABaseTestCase.php deleted file mode 100644 index 6204c06ef..000000000 --- a/tests/Australia/SA/SABaseTestCase.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -use Yasumi\tests\Australia\AustraliaBaseTestCase; -use Yasumi\tests\YasumiBase; - -/** - * Base class for test cases of the Victoria holiday provider. - */ -abstract class SABaseTestCase extends AustraliaBaseTestCase -{ - use YasumiBase; - - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\SA'; - - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/South'; -} diff --git a/tests/Australia/SA/SATest.php b/tests/Australia/SA/SATest.php deleted file mode 100644 index cf4d3c301..000000000 --- a/tests/Australia/SA/SATest.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\SA; - -use ReflectionException; -use Yasumi\Holiday; - -/** - * Class for testing holidays in SA (Australia). - */ -class SATest extends SABaseTestCase -{ - /** - * @var int year random year number used for all tests in this Test Case - */ - protected $year; - - /** - * Tests if all official holidays in SA (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testOfficialHolidays(): void - { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'goodFriday', - 'easterMonday', - 'christmasDay', - 'proclamationDay', - 'australiaDay', - 'anzacDay', - 'easterSaturday', - 'queensBirthday', - 'labourDay', - 'adelaideCup', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1973); - } -} diff --git a/tests/Australia/SA/AdelaideCupDayTest.php b/tests/Australia/SouthAustralia/AdelaideCupDayTest.php similarity index 58% rename from tests/Australia/SA/AdelaideCupDayTest.php rename to tests/Australia/SouthAustralia/AdelaideCupDayTest.php index 35c5a1ea7..663482aa3 100644 --- a/tests/Australia/SA/AdelaideCupDayTest.php +++ b/tests/Australia/SouthAustralia/AdelaideCupDayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\SA; +namespace Yasumi\tests\Australia\SouthAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Adelaide Cup Day in SA (Australia).. + * Class for testing Adelaide Cup Day in South Australia (Australia).. */ -class AdelaideCupDayTest extends SABaseTestCase implements YasumiTestCaseInterface +class AdelaideCupDayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'adelaideCup'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1973; /** - * Tests Adelaide Cup Day - * - * @dataProvider HolidayDataProvider + * Tests Adelaide Cup Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2000, '2000-05-15'], [2001, '2001-05-21'], [2002, '2002-05-20'], @@ -85,34 +84,34 @@ public function HolidayDataProvider(): array [2019, '2019-03-11'], [2020, '2020-03-09'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Adelaide Cup'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/SouthAustralia/AnzacDayTest.php b/tests/Australia/SouthAustralia/AnzacDayTest.php new file mode 100644 index 000000000..43e814451 --- /dev/null +++ b/tests/Australia/SouthAustralia/AnzacDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing ANZAC day in South Australia (Australia).. + */ +class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest +{ +} diff --git a/tests/Australia/SouthAustralia/AustraliaDayTest.php b/tests/Australia/SouthAustralia/AustraliaDayTest.php new file mode 100644 index 000000000..688c39d6c --- /dev/null +++ b/tests/Australia/SouthAustralia/AustraliaDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing Australia day in South Australia (Australia).. + */ +class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest +{ +} diff --git a/tests/Australia/SA/ChristmasDayTest.php b/tests/Australia/SouthAustralia/ChristmasDayTest.php similarity index 58% rename from tests/Australia/SA/ChristmasDayTest.php rename to tests/Australia/SouthAustralia/ChristmasDayTest.php index d5a5c247c..a103ff68d 100644 --- a/tests/Australia/SA/ChristmasDayTest.php +++ b/tests/Australia/SouthAustralia/ChristmasDayTest.php @@ -1,54 +1,53 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\SA; +namespace Yasumi\tests\Australia\SouthAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in South Australia. */ -class ChristmasDayTest extends SABaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; public const HOLIDAY2 = 'christmasHoliday'; /** - * Tests Christmas Day + * Tests Christmas Day. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * @param ?string $expectedExtra the expected date for the additional holiday, or null if no additional holiday * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * @param string $expectedExtra the expected date for the additional holiday, or null if no additional holiday - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected, $expectedExtra) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected, ?string $expectedExtra): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); if (null === $expectedExtra) { $this->assertNotHoliday( @@ -61,19 +60,19 @@ public function testHoliday($year, $expected, $expectedExtra) $this->region, self::HOLIDAY2, $year, - new DateTime($expectedExtra, new DateTimeZone($this->timezone)) + new \DateTime($expectedExtra, new \DateTimeZone($this->timezone)) ); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-12-25', '2010-12-27'], [2011, '2011-12-25', '2011-12-26'], [2012, '2012-12-25', null], @@ -86,21 +85,19 @@ public function HolidayDataProvider(): array [2019, '2019-12-25', null], [2020, '2020-12-25', null], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); $this->assertTranslatedHolidayName( @@ -114,11 +111,11 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); $this->assertHolidayType($this->region, self::HOLIDAY2, 2016, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/SouthAustralia/EasterMondayTest.php b/tests/Australia/SouthAustralia/EasterMondayTest.php new file mode 100644 index 000000000..e8141a05c --- /dev/null +++ b/tests/Australia/SouthAustralia/EasterMondayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing Easter Monday in South Australia (Australia).. + */ +class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest +{ +} diff --git a/tests/Australia/SouthAustralia/EasterSaturdayTest.php b/tests/Australia/SouthAustralia/EasterSaturdayTest.php new file mode 100644 index 000000000..3e9f934ba --- /dev/null +++ b/tests/Australia/SouthAustralia/EasterSaturdayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Saturday in South Australia (Australia).. + */ +class EasterSaturdayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterSaturday'; + + /** + * Tests Easter Saturday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Saturday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/SouthAustralia/GoodFridayTest.php b/tests/Australia/SouthAustralia/GoodFridayTest.php new file mode 100644 index 000000000..198719baf --- /dev/null +++ b/tests/Australia/SouthAustralia/GoodFridayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing Good Friday in South Australia (Australia).. + */ +class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest +{ +} diff --git a/tests/Australia/NSW/LabourDayTest.php b/tests/Australia/SouthAustralia/LabourDayTest.php similarity index 50% rename from tests/Australia/NSW/LabourDayTest.php rename to tests/Australia/SouthAustralia/LabourDayTest.php index f0ed1e675..eb4207cde 100644 --- a/tests/Australia/NSW/LabourDayTest.php +++ b/tests/Australia/SouthAustralia/LabourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\NSW; +namespace Yasumi\tests\Australia\SouthAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Labour Day in NSW (Australia).. + * Class for testing Labour Day in South Australia (Australia).. */ -class LabourDayTest extends NSWBaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-04'], [2011, '2011-10-03'], [2012, '2012-10-01'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-07'], [2020, '2020-10-05'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/SouthAustralia/NationalDayOfMourningTest.php b/tests/Australia/SouthAustralia/NationalDayOfMourningTest.php new file mode 100644 index 000000000..ddc5d0e30 --- /dev/null +++ b/tests/Australia/SouthAustralia/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing National Day of Mourning in South Australia (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/SouthAustralia/NewYearsDayTest.php b/tests/Australia/SouthAustralia/NewYearsDayTest.php new file mode 100644 index 000000000..b0aa86659 --- /dev/null +++ b/tests/Australia/SouthAustralia/NewYearsDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +/** + * Class for testing New Years Day in South Australia (Australia).. + */ +class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest +{ +} diff --git a/tests/Australia/SA/ProclamationDayTest.php b/tests/Australia/SouthAustralia/ProclamationDayTest.php similarity index 54% rename from tests/Australia/SA/ProclamationDayTest.php rename to tests/Australia/SouthAustralia/ProclamationDayTest.php index 90971bfb5..dddd26513 100644 --- a/tests/Australia/SA/ProclamationDayTest.php +++ b/tests/Australia/SouthAustralia/ProclamationDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\SA; +namespace Yasumi\tests\Australia\SouthAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Proclamation Day in SA (Australia).. + * Class for testing Proclamation Day in South Australia (Australia).. */ -class ProclamationDayTest extends SABaseTestCase implements YasumiTestCaseInterface +class ProclamationDayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'proclamationDay'; /** - * Tests Proclamation Day - * - * @dataProvider HolidayDataProvider + * Tests Proclamation Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-12-28'], [2011, '2011-12-27'], [2012, '2012-12-26'], @@ -70,34 +69,34 @@ public function HolidayDataProvider(): array [2019, '2019-12-26'], [2020, '2020-12-28'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Proclamation Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/ACT/QueensBirthdayTest.php b/tests/Australia/SouthAustralia/QueensBirthdayTest.php similarity index 51% rename from tests/Australia/ACT/QueensBirthdayTest.php rename to tests/Australia/SouthAustralia/QueensBirthdayTest.php index 1fef2369c..f01e518ad 100644 --- a/tests/Australia/ACT/QueensBirthdayTest.php +++ b/tests/Australia/SouthAustralia/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\ACT; +namespace Yasumi\tests\Australia\SouthAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in ACT (Australia).. + * Class for testing Queen's Birthday in South Australia (Australia).. */ -class QueensBirthdayTest extends ACTBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php b/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php new file mode 100644 index 000000000..e81e15457 --- /dev/null +++ b/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +use Yasumi\tests\Australia\AustraliaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Victoria holiday provider. + */ +abstract class SouthAustraliaBaseTestCase extends AustraliaBaseTestCase +{ + use YasumiBase; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/South'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\SouthAustralia'; + + public string $timezone = 'Australia/South'; +} diff --git a/tests/Australia/SouthAustralia/SouthAustraliaTest.php b/tests/Australia/SouthAustralia/SouthAustraliaTest.php new file mode 100644 index 000000000..030ba90bd --- /dev/null +++ b/tests/Australia/SouthAustralia/SouthAustraliaTest.php @@ -0,0 +1,75 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in South Australia (Australia). + */ +class SouthAustraliaTest extends SouthAustraliaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1973); + } + + /** + * Tests if all official holidays in South Australia (Australia) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $expectedHolidays = [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'proclamationDay', + 'australiaDay', + 'anzacDay', + 'easterSaturday', + 'queensBirthday', + 'labourDay', + 'adelaideCup', + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources($this->region, 1); + } +} diff --git a/tests/Australia/Tasmania/AnzacDayTest.php b/tests/Australia/Tasmania/AnzacDayTest.php index 1681139c0..35f6459d5 100644 --- a/tests/Australia/Tasmania/AnzacDayTest.php +++ b/tests/Australia/Tasmania/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/AustraliaDayTest.php b/tests/Australia/Tasmania/AustraliaDayTest.php index 113dadd51..53b7370e8 100644 --- a/tests/Australia/Tasmania/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/BoxingDayTest.php b/tests/Australia/Tasmania/BoxingDayTest.php index aa308b1ee..a739f6f16 100644 --- a/tests/Australia/Tasmania/BoxingDayTest.php +++ b/tests/Australia/Tasmania/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/CentralNorth/AnzacDayTest.php b/tests/Australia/Tasmania/CentralNorth/AnzacDayTest.php index a3da91eed..8083b8c56 100644 --- a/tests/Australia/Tasmania/CentralNorth/AnzacDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/AustraliaDayTest.php b/tests/Australia/Tasmania/CentralNorth/AustraliaDayTest.php index 9b2d7cc61..f1f6be2cd 100644 --- a/tests/Australia/Tasmania/CentralNorth/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/BoxingDayTest.php b/tests/Australia/Tasmania/CentralNorth/BoxingDayTest.php index 6b7d2a9c6..40f6cc55f 100644 --- a/tests/Australia/Tasmania/CentralNorth/BoxingDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/CentralNorthBaseTestCase.php b/tests/Australia/Tasmania/CentralNorth/CentralNorthBaseTestCase.php index 037e03126..baa5cc4ee 100644 --- a/tests/Australia/Tasmania/CentralNorth/CentralNorthBaseTestCase.php +++ b/tests/Australia/Tasmania/CentralNorth/CentralNorthBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; @@ -22,8 +27,6 @@ abstract class CentralNorthBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\CentralNorth'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\CentralNorth'; } diff --git a/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php b/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php index 08a673d62..9c29788ae 100644 --- a/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php +++ b/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in central north Tasmania (Australia). */ -class CentralNorthTest extends CentralNorthBaseTestCase +class CentralNorthTest extends CentralNorthBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } /** - * Tests if all official holidays in central north Tasmania (Australia) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in central north Tasmania (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -43,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'devonportShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/CentralNorth/ChristmasDayTest.php b/tests/Australia/Tasmania/CentralNorth/ChristmasDayTest.php index 106234972..06a37b051 100644 --- a/tests/Australia/Tasmania/CentralNorth/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/DevonportShowTest.php b/tests/Australia/Tasmania/CentralNorth/DevonportShowTest.php index ad560b65f..553fa2dac 100644 --- a/tests/Australia/Tasmania/CentralNorth/DevonportShowTest.php +++ b/tests/Australia/Tasmania/CentralNorth/DevonportShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Devonport Show Day in central north Tasmania (Australia).. */ -class DevonportShowTest extends CentralNorthBaseTestCase implements YasumiTestCaseInterface +class DevonportShowTest extends CentralNorthBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'devonportShow'; /** - * Tests Devonport Show Day - * - * @dataProvider HolidayDataProvider + * Tests Devonport Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-11-26'], [2011, '2011-11-25'], [2012, '2012-11-30'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-11-29'], [2020, '2020-11-27'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Devonport Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/CentralNorth/EasterMondayTest.php b/tests/Australia/Tasmania/CentralNorth/EasterMondayTest.php index f74cf4515..e33832437 100644 --- a/tests/Australia/Tasmania/CentralNorth/EasterMondayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/EightHourDayTest.php b/tests/Australia/Tasmania/CentralNorth/EightHourDayTest.php index becdb550c..1e7fe7e55 100644 --- a/tests/Australia/Tasmania/CentralNorth/EightHourDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/GoodFridayTest.php b/tests/Australia/Tasmania/CentralNorth/GoodFridayTest.php index 7528781fa..3ad01dbbe 100644 --- a/tests/Australia/Tasmania/CentralNorth/GoodFridayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/CentralNorth/NationalDayOfMourningTest.php new file mode 100644 index 000000000..df90f3e32 --- /dev/null +++ b/tests/Australia/Tasmania/CentralNorth/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\CentralNorth; + +/** + * Class for testing National Day of Mourning in central north Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/CentralNorth/NewYearsDayTest.php b/tests/Australia/Tasmania/CentralNorth/NewYearsDayTest.php index 2ce755875..657db80ec 100644 --- a/tests/Australia/Tasmania/CentralNorth/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php b/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php index fa55bc753..11419c8fb 100644 --- a/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/CentralNorth/RecreationDayTest.php b/tests/Australia/Tasmania/CentralNorth/RecreationDayTest.php index 787291aa3..27a9e31d8 100644 --- a/tests/Australia/Tasmania/CentralNorth/RecreationDayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; diff --git a/tests/Australia/Tasmania/ChristmasDayTest.php b/tests/Australia/Tasmania/ChristmasDayTest.php index b66b6cb45..0b5ab3ef7 100644 --- a/tests/Australia/Tasmania/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/EasterMondayTest.php b/tests/Australia/Tasmania/EasterMondayTest.php index 579862cf2..5653a3cb1 100644 --- a/tests/Australia/Tasmania/EasterMondayTest.php +++ b/tests/Australia/Tasmania/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/EightHourDayTest.php b/tests/Australia/Tasmania/EightHourDayTest.php index afc49189b..8e72b5bb9 100644 --- a/tests/Australia/Tasmania/EightHourDayTest.php +++ b/tests/Australia/Tasmania/EightHourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Eight Hour Day in Tasmania (Australia).. */ -class EightHourDayTest extends TasmaniaBaseTestCase implements YasumiTestCaseInterface +class EightHourDayTest extends TasmaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'eightHourDay'; /** - * Tests Eight Hour Day - * - * @dataProvider HolidayDataProvider + * Tests Eight Hour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-03-08'], [2011, '2011-03-14'], [2012, '2012-03-12'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-03-11'], [2020, '2020-03-09'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Eight Hour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/FlindersIsland/AnzacDayTest.php b/tests/Australia/Tasmania/FlindersIsland/AnzacDayTest.php index a3df0b86b..e8e3c7cef 100644 --- a/tests/Australia/Tasmania/FlindersIsland/AnzacDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/AustraliaDayTest.php b/tests/Australia/Tasmania/FlindersIsland/AustraliaDayTest.php index 5f96ed76d..a8f28feb8 100644 --- a/tests/Australia/Tasmania/FlindersIsland/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/BoxingDayTest.php b/tests/Australia/Tasmania/FlindersIsland/BoxingDayTest.php index aa9937db1..af9f142cd 100644 --- a/tests/Australia/Tasmania/FlindersIsland/BoxingDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/ChristmasDayTest.php b/tests/Australia/Tasmania/FlindersIsland/ChristmasDayTest.php index c77049e03..b81fce234 100644 --- a/tests/Australia/Tasmania/FlindersIsland/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/EasterMondayTest.php b/tests/Australia/Tasmania/FlindersIsland/EasterMondayTest.php index d555bf708..784ed8062 100644 --- a/tests/Australia/Tasmania/FlindersIsland/EasterMondayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/EightHourDayTest.php b/tests/Australia/Tasmania/FlindersIsland/EightHourDayTest.php index a8588fd6e..e08a31376 100644 --- a/tests/Australia/Tasmania/FlindersIsland/EightHourDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandBaseTestCase.php b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandBaseTestCase.php index 0335a4bd6..845cd0e04 100644 --- a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandBaseTestCase.php +++ b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; @@ -22,8 +27,6 @@ abstract class FlindersIslandBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\FlindersIsland'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\FlindersIsland'; } diff --git a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandShowTest.php b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandShowTest.php index b63d43e06..fb3809c1c 100644 --- a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandShowTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Flinders Island Show Day in Flinders Island (Australia).. */ -class FlindersIslandShowTest extends FlindersIslandBaseTestCase implements YasumiTestCaseInterface +class FlindersIslandShowTest extends FlindersIslandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'flindersIslandShow'; /** - * Tests Flinders Island Show Day - * - * @dataProvider HolidayDataProvider + * Tests Flinders Island Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-15'], [2011, '2011-10-14'], [2012, '2012-10-19'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-18'], [2020, '2020-10-16'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Flinders Island Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php index 2e560e42e..c62151902 100644 --- a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Flinders Island (Australia). */ -class FlindersIslandTest extends FlindersIslandBaseTestCase +class FlindersIslandTest extends FlindersIslandBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Flinders Island (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Flinders Island (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'flindersIslandShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/FlindersIsland/GoodFridayTest.php b/tests/Australia/Tasmania/FlindersIsland/GoodFridayTest.php index d22df4f64..1e9248515 100644 --- a/tests/Australia/Tasmania/FlindersIsland/GoodFridayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/FlindersIsland/NationalDayOfMourningTest.php new file mode 100644 index 000000000..dd7927c9c --- /dev/null +++ b/tests/Australia/Tasmania/FlindersIsland/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; + +/** + * Class for testing National Day of Mourning in Flinders Island (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/FlindersIsland/NewYearsDayTest.php b/tests/Australia/Tasmania/FlindersIsland/NewYearsDayTest.php index b5d282458..734d1dd9d 100644 --- a/tests/Australia/Tasmania/FlindersIsland/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php b/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php index 93ec3a6cc..4de25bac8 100644 --- a/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/FlindersIsland/RecreationDayTest.php b/tests/Australia/Tasmania/FlindersIsland/RecreationDayTest.php index f68b64690..a28504687 100644 --- a/tests/Australia/Tasmania/FlindersIsland/RecreationDayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; diff --git a/tests/Australia/Tasmania/GoodFridayTest.php b/tests/Australia/Tasmania/GoodFridayTest.php index dba9602bb..81ff5a0da 100644 --- a/tests/Australia/Tasmania/GoodFridayTest.php +++ b/tests/Australia/Tasmania/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/KingIsland/AnzacDayTest.php b/tests/Australia/Tasmania/KingIsland/AnzacDayTest.php index c21fe8f61..e5b4a3a03 100644 --- a/tests/Australia/Tasmania/KingIsland/AnzacDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/AustraliaDayTest.php b/tests/Australia/Tasmania/KingIsland/AustraliaDayTest.php index adbda5000..298ce3016 100644 --- a/tests/Australia/Tasmania/KingIsland/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/BoxingDayTest.php b/tests/Australia/Tasmania/KingIsland/BoxingDayTest.php index 7f3c8b128..9694854f1 100644 --- a/tests/Australia/Tasmania/KingIsland/BoxingDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/ChristmasDayTest.php b/tests/Australia/Tasmania/KingIsland/ChristmasDayTest.php index c9ee8996e..cd5749c50 100644 --- a/tests/Australia/Tasmania/KingIsland/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/EasterMondayTest.php b/tests/Australia/Tasmania/KingIsland/EasterMondayTest.php index cc6643419..1aff146a8 100644 --- a/tests/Australia/Tasmania/KingIsland/EasterMondayTest.php +++ b/tests/Australia/Tasmania/KingIsland/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/EightHourDayTest.php b/tests/Australia/Tasmania/KingIsland/EightHourDayTest.php index 5a9fe0493..3415ca6ab 100644 --- a/tests/Australia/Tasmania/KingIsland/EightHourDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/GoodFridayTest.php b/tests/Australia/Tasmania/KingIsland/GoodFridayTest.php index ecfaf9ce8..1cc951297 100644 --- a/tests/Australia/Tasmania/KingIsland/GoodFridayTest.php +++ b/tests/Australia/Tasmania/KingIsland/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/KingIslandBaseTestCase.php b/tests/Australia/Tasmania/KingIsland/KingIslandBaseTestCase.php index 8d21f8a8a..291221e35 100644 --- a/tests/Australia/Tasmania/KingIsland/KingIslandBaseTestCase.php +++ b/tests/Australia/Tasmania/KingIsland/KingIslandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; @@ -22,8 +27,6 @@ abstract class KingIslandBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\KingIsland'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\KingIsland'; } diff --git a/tests/Australia/Tasmania/KingIsland/KingIslandShowTest.php b/tests/Australia/Tasmania/KingIsland/KingIslandShowTest.php index 7b9451736..324677b87 100644 --- a/tests/Australia/Tasmania/KingIsland/KingIslandShowTest.php +++ b/tests/Australia/Tasmania/KingIsland/KingIslandShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing King Island Show Day in King Island (Australia).. */ -class KingIslandShowTest extends KingIslandBaseTestCase implements YasumiTestCaseInterface +class KingIslandShowTest extends KingIslandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'kingIslandShow'; /** - * Tests King Island Show Day - * - * @dataProvider HolidayDataProvider + * Tests King Island Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-03-02'], [2011, '2011-03-01'], [2012, '2012-03-06'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-03-05'], [2020, '2020-03-03'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'King Island Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/KingIsland/KingIslandTest.php b/tests/Australia/Tasmania/KingIsland/KingIslandTest.php index 45d3ed623..6d3dc16af 100644 --- a/tests/Australia/Tasmania/KingIsland/KingIslandTest.php +++ b/tests/Australia/Tasmania/KingIsland/KingIslandTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Flinders Island (Australia). */ -class KingIslandTest extends KingIslandBaseTestCase +class KingIslandTest extends KingIslandBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in King Island (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in King Island (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'kingIslandShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/KingIsland/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/KingIsland/NationalDayOfMourningTest.php new file mode 100644 index 000000000..37d8f8582 --- /dev/null +++ b/tests/Australia/Tasmania/KingIsland/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\KingIsland; + +/** + * Class for testing National Day of Mourning in King Island (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/KingIsland/NewYearsDayTest.php b/tests/Australia/Tasmania/KingIsland/NewYearsDayTest.php index 19f9f1989..4c1c53e7d 100644 --- a/tests/Australia/Tasmania/KingIsland/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php b/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php index aafd650dc..f994c01c3 100644 --- a/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/KingIsland/RecreationDayTest.php b/tests/Australia/Tasmania/KingIsland/RecreationDayTest.php index ff52738c6..63b5c3c72 100644 --- a/tests/Australia/Tasmania/KingIsland/RecreationDayTest.php +++ b/tests/Australia/Tasmania/KingIsland/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\KingIsland; diff --git a/tests/Australia/Tasmania/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/NationalDayOfMourningTest.php new file mode 100644 index 000000000..a13dd05ff --- /dev/null +++ b/tests/Australia/Tasmania/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania; + +/** + * Class for testing National Day of Mourning in Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/NewYearsDayTest.php b/tests/Australia/Tasmania/NewYearsDayTest.php index a238d49fd..f1e682a57 100644 --- a/tests/Australia/Tasmania/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; diff --git a/tests/Australia/Tasmania/Northeast/AnzacDayTest.php b/tests/Australia/Tasmania/Northeast/AnzacDayTest.php index 1ecb444a2..fe3b1a8e7 100644 --- a/tests/Australia/Tasmania/Northeast/AnzacDayTest.php +++ b/tests/Australia/Tasmania/Northeast/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/AustraliaDayTest.php b/tests/Australia/Tasmania/Northeast/AustraliaDayTest.php index 8f99b211c..471d86a8f 100644 --- a/tests/Australia/Tasmania/Northeast/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/Northeast/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/BoxingDayTest.php b/tests/Australia/Tasmania/Northeast/BoxingDayTest.php index 59466c61b..44c2ffd21 100644 --- a/tests/Australia/Tasmania/Northeast/BoxingDayTest.php +++ b/tests/Australia/Tasmania/Northeast/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/ChristmasDayTest.php b/tests/Australia/Tasmania/Northeast/ChristmasDayTest.php index bf8c51599..6da331d42 100644 --- a/tests/Australia/Tasmania/Northeast/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/Northeast/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/EasterMondayTest.php b/tests/Australia/Tasmania/Northeast/EasterMondayTest.php index 5a85a7e2c..49deb0675 100644 --- a/tests/Australia/Tasmania/Northeast/EasterMondayTest.php +++ b/tests/Australia/Tasmania/Northeast/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/EightHourDayTest.php b/tests/Australia/Tasmania/Northeast/EightHourDayTest.php index 2ef2cf289..41edca77d 100644 --- a/tests/Australia/Tasmania/Northeast/EightHourDayTest.php +++ b/tests/Australia/Tasmania/Northeast/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/GoodFridayTest.php b/tests/Australia/Tasmania/Northeast/GoodFridayTest.php index 07f08cdda..740f5036f 100644 --- a/tests/Australia/Tasmania/Northeast/GoodFridayTest.php +++ b/tests/Australia/Tasmania/Northeast/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/LauncestonShowTest.php b/tests/Australia/Tasmania/Northeast/LauncestonShowTest.php index 59514437d..5a4314960 100644 --- a/tests/Australia/Tasmania/Northeast/LauncestonShowTest.php +++ b/tests/Australia/Tasmania/Northeast/LauncestonShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Launceston Show Day in northeastern Tasmania (Australia).. */ -class LauncestonShowTest extends NortheastBaseTestCase implements YasumiTestCaseInterface +class LauncestonShowTest extends NortheastBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'launcestonShow'; /** - * Tests Launceston Show Day - * - * @dataProvider HolidayDataProvider + * Tests Launceston Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-07'], [2011, '2011-10-06'], [2012, '2012-10-11'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-10'], [2020, '2020-10-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Royal Launceston Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/Northeast/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/Northeast/NationalDayOfMourningTest.php new file mode 100644 index 000000000..0a45edf55 --- /dev/null +++ b/tests/Australia/Tasmania/Northeast/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\Northeast; + +/** + * Class for testing National Day of Mourning in northeastern Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/Northeast/NewYearsDayTest.php b/tests/Australia/Tasmania/Northeast/NewYearsDayTest.php index c16110a7f..0fad972a1 100644 --- a/tests/Australia/Tasmania/Northeast/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/Northeast/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/NortheastBaseTestCase.php b/tests/Australia/Tasmania/Northeast/NortheastBaseTestCase.php index 85e0c40e1..cc8b76f9f 100644 --- a/tests/Australia/Tasmania/Northeast/NortheastBaseTestCase.php +++ b/tests/Australia/Tasmania/Northeast/NortheastBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; @@ -22,8 +27,6 @@ abstract class NortheastBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\Northeast'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\Northeast'; } diff --git a/tests/Australia/Tasmania/Northeast/NortheastTest.php b/tests/Australia/Tasmania/Northeast/NortheastTest.php index ab36b2f94..218199f4c 100644 --- a/tests/Australia/Tasmania/Northeast/NortheastTest.php +++ b/tests/Australia/Tasmania/Northeast/NortheastTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in northeastern Tasmania (Australia). */ -class NortheastTest extends NortheastBaseTestCase +class NortheastTest extends NortheastBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in northeastern Tasmania (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in northeastern Tasmania (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'launcestonShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php index 5b4049a67..026aec886 100644 --- a/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northeast/RecreationDayTest.php b/tests/Australia/Tasmania/Northeast/RecreationDayTest.php index 4a4108750..bf6654fb3 100644 --- a/tests/Australia/Tasmania/Northeast/RecreationDayTest.php +++ b/tests/Australia/Tasmania/Northeast/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northeast; diff --git a/tests/Australia/Tasmania/Northwest/AnzacDayTest.php b/tests/Australia/Tasmania/Northwest/AnzacDayTest.php index 1d7ef99e3..71fed688a 100644 --- a/tests/Australia/Tasmania/Northwest/AnzacDayTest.php +++ b/tests/Australia/Tasmania/Northwest/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/AustraliaDayTest.php b/tests/Australia/Tasmania/Northwest/AustraliaDayTest.php index 32383adfd..1f14ff387 100644 --- a/tests/Australia/Tasmania/Northwest/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/Northwest/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/BoxingDayTest.php b/tests/Australia/Tasmania/Northwest/BoxingDayTest.php index 5d834b66c..f69bd4995 100644 --- a/tests/Australia/Tasmania/Northwest/BoxingDayTest.php +++ b/tests/Australia/Tasmania/Northwest/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/BurnieShowTest.php b/tests/Australia/Tasmania/Northwest/BurnieShowTest.php index 2c9d4ac89..824ea622b 100644 --- a/tests/Australia/Tasmania/Northwest/BurnieShowTest.php +++ b/tests/Australia/Tasmania/Northwest/BurnieShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Burnie Show Day in northwestern Tasmania (Australia).. */ -class BurnieShowTest extends NorthwestBaseTestCase implements YasumiTestCaseInterface +class BurnieShowTest extends NorthwestBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'burnieShow'; /** - * Tests Burnie Show Day - * - * @dataProvider HolidayDataProvider + * Tests Burnie Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-01'], [2011, '2011-09-30'], [2012, '2012-10-05'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-04'], [2020, '2020-10-02'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Burnie Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/Northwest/ChristmasDayTest.php b/tests/Australia/Tasmania/Northwest/ChristmasDayTest.php index 1926a8563..d1cd8175a 100644 --- a/tests/Australia/Tasmania/Northwest/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/Northwest/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/AGFESTTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/AGFESTTest.php index 4eaa837da..d863fd7d0 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/AGFESTTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/AGFESTTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing AGFEST in northwestern Tasmania (Australia).. */ -class AGFESTTest extends CircularHeadBaseTestCase implements YasumiTestCaseInterface +class AGFESTTest extends CircularHeadBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'agfest'; /** - * Tests AGFEST - * - * @dataProvider HolidayDataProvider + * Tests AGFEST. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-05-07'], [2011, '2011-05-06'], [2012, '2012-05-04'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-05-03'], [2020, '2020-05-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'AGFEST'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/AnzacDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/AnzacDayTest.php index fcd450c1b..c2733179a 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/AnzacDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/AustraliaDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/AustraliaDayTest.php index 7ad6bef07..b291801c3 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/BoxingDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/BoxingDayTest.php index 71a3bc88d..355c21f5d 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/BoxingDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/BurnieShowTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/BurnieShowTest.php index b071e75a2..3141d3041 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/BurnieShowTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/BurnieShowTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/ChristmasDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/ChristmasDayTest.php index ef5dfcc9d..28b85dcad 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadBaseTestCase.php b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadBaseTestCase.php index 4923c4d59..f4ff269bc 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadBaseTestCase.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; @@ -22,8 +27,6 @@ abstract class CircularHeadBaseTestCase extends NorthwestBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\Northwest\CircularHead'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\Northwest\CircularHead'; } diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php index 3fd9a9507..62eabdf0a 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; -use ReflectionException; use Yasumi\Holiday; /** @@ -20,19 +24,27 @@ */ class CircularHeadTest extends CircularHeadBaseTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } /** - * Tests if all official holidays in Circular Head (Australia) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Circular Head (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -45,14 +57,10 @@ public function testOfficialHolidays(): void 'recreationDay', 'burnieShow', 'agfest', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1921); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/EasterMondayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/EasterMondayTest.php index d1770daf6..69af4485a 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/EasterMondayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/EightHourDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/EightHourDayTest.php index 8e386ebd9..bf1c41281 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/EightHourDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/GoodFridayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/GoodFridayTest.php index 5af760142..e5649f962 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/GoodFridayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/NationalDayOfMourningTest.php new file mode 100644 index 000000000..4e681fbca --- /dev/null +++ b/tests/Australia/Tasmania/Northwest/CircularHead/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; + +/** + * Class for testing National Day of Mourning in Circular Head (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\Northwest\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/NewYearsDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/NewYearsDayTest.php index b3758aad3..2d2560a5f 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php index 0b7a28250..d0ed1e5c4 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/RecreationDayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/RecreationDayTest.php index 8f2a36772..022531456 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/RecreationDayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; diff --git a/tests/Australia/Tasmania/Northwest/EasterMondayTest.php b/tests/Australia/Tasmania/Northwest/EasterMondayTest.php index 0853f28f3..f87bf5c15 100644 --- a/tests/Australia/Tasmania/Northwest/EasterMondayTest.php +++ b/tests/Australia/Tasmania/Northwest/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/EightHourDayTest.php b/tests/Australia/Tasmania/Northwest/EightHourDayTest.php index ce618ce7a..448da964d 100644 --- a/tests/Australia/Tasmania/Northwest/EightHourDayTest.php +++ b/tests/Australia/Tasmania/Northwest/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/GoodFridayTest.php b/tests/Australia/Tasmania/Northwest/GoodFridayTest.php index 7c79bbfe4..7abf3ff72 100644 --- a/tests/Australia/Tasmania/Northwest/GoodFridayTest.php +++ b/tests/Australia/Tasmania/Northwest/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/Northwest/NationalDayOfMourningTest.php new file mode 100644 index 000000000..0f80223b5 --- /dev/null +++ b/tests/Australia/Tasmania/Northwest/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\Northwest; + +/** + * Class for testing National Day of Mourning in northwestern Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/Northwest/NewYearsDayTest.php b/tests/Australia/Tasmania/Northwest/NewYearsDayTest.php index 27be2d3fe..47f4854f9 100644 --- a/tests/Australia/Tasmania/Northwest/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/Northwest/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/NorthwestBaseTestCase.php b/tests/Australia/Tasmania/Northwest/NorthwestBaseTestCase.php index 96d971d21..d89482492 100644 --- a/tests/Australia/Tasmania/Northwest/NorthwestBaseTestCase.php +++ b/tests/Australia/Tasmania/Northwest/NorthwestBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; @@ -22,8 +27,6 @@ abstract class NorthwestBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\Northwest'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\Northwest'; } diff --git a/tests/Australia/Tasmania/Northwest/NorthwestTest.php b/tests/Australia/Tasmania/Northwest/NorthwestTest.php index f702cd78d..fb1de0c14 100644 --- a/tests/Australia/Tasmania/Northwest/NorthwestTest.php +++ b/tests/Australia/Tasmania/Northwest/NorthwestTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in northwestern Tasmania (Australia). */ -class NorthwestTest extends NorthwestBaseTestCase +class NorthwestTest extends NorthwestBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in northwestern Tasmania (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in northwestern Tasmania (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'burnieShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php index 702718b3b..89fe4db23 100644 --- a/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/Northwest/RecreationDayTest.php b/tests/Australia/Tasmania/Northwest/RecreationDayTest.php index d4cd1c7dc..d06d0361c 100644 --- a/tests/Australia/Tasmania/Northwest/RecreationDayTest.php +++ b/tests/Australia/Tasmania/Northwest/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\Northwest; diff --git a/tests/Australia/Tasmania/QueensBirthdayTest.php b/tests/Australia/Tasmania/QueensBirthdayTest.php index 7a8443fbe..255009155 100644 --- a/tests/Australia/Tasmania/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Queen's Birthday in Tasmania (Australia).. */ -class QueensBirthdayTest extends TasmaniaBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends TasmaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/Tasmania/RecreationDayTest.php b/tests/Australia/Tasmania/RecreationDayTest.php index 5ef1b6912..ab7a7b203 100644 --- a/tests/Australia/Tasmania/RecreationDayTest.php +++ b/tests/Australia/Tasmania/RecreationDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Recreation Day in Tasmania (Australia).. */ -class RecreationDayTest extends TasmaniaBaseTestCase implements YasumiTestCaseInterface +class RecreationDayTest extends TasmaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'recreationDay'; /** - * Tests Recreation Day - * - * @dataProvider HolidayDataProvider + * Tests Recreation Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-11-01'], [2011, '2011-11-07'], [2012, '2012-11-05'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-11-04'], [2020, '2020-11-02'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Recreation Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/South/AnzacDayTest.php b/tests/Australia/Tasmania/South/AnzacDayTest.php index 3dd8d924b..7580f1022 100644 --- a/tests/Australia/Tasmania/South/AnzacDayTest.php +++ b/tests/Australia/Tasmania/South/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/AustraliaDayTest.php b/tests/Australia/Tasmania/South/AustraliaDayTest.php index af099518c..907d7ed8d 100644 --- a/tests/Australia/Tasmania/South/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/South/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/BoxingDayTest.php b/tests/Australia/Tasmania/South/BoxingDayTest.php index 04eda195a..a4178c826 100644 --- a/tests/Australia/Tasmania/South/BoxingDayTest.php +++ b/tests/Australia/Tasmania/South/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/ChristmasDayTest.php b/tests/Australia/Tasmania/South/ChristmasDayTest.php index 5f1361c00..4b70beea9 100644 --- a/tests/Australia/Tasmania/South/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/South/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/EasterMondayTest.php b/tests/Australia/Tasmania/South/EasterMondayTest.php index 79bb65638..37e9f473b 100644 --- a/tests/Australia/Tasmania/South/EasterMondayTest.php +++ b/tests/Australia/Tasmania/South/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/EightHourDayTest.php b/tests/Australia/Tasmania/South/EightHourDayTest.php index a5c63f78a..a578d31ae 100644 --- a/tests/Australia/Tasmania/South/EightHourDayTest.php +++ b/tests/Australia/Tasmania/South/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/GoodFridayTest.php b/tests/Australia/Tasmania/South/GoodFridayTest.php index 5223bafec..665d5c476 100644 --- a/tests/Australia/Tasmania/South/GoodFridayTest.php +++ b/tests/Australia/Tasmania/South/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/HobartShowTest.php b/tests/Australia/Tasmania/South/HobartShowTest.php index a7b35c5a2..78fca84e5 100644 --- a/tests/Australia/Tasmania/South/HobartShowTest.php +++ b/tests/Australia/Tasmania/South/HobartShowTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Royal Hobart Show Day in southern Tasmania (Australia).. */ -class HobartShowTest extends SouthBaseTestCase implements YasumiTestCaseInterface +class HobartShowTest extends SouthBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'hobartShow'; /** - * Tests Royal Hobart Show Day - * - * @dataProvider HolidayDataProvider + * Tests Royal Hobart Show Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-10-21'], [2011, '2011-10-20'], [2012, '2012-10-25'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-10-24'], [2020, '2020-10-22'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Royal Hobart Show'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/South/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/South/NationalDayOfMourningTest.php new file mode 100644 index 000000000..e63ab8c2a --- /dev/null +++ b/tests/Australia/Tasmania/South/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\South; + +/** + * Class for testing National Day of Mourning in southern Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/South/NewYearsDayTest.php b/tests/Australia/Tasmania/South/NewYearsDayTest.php index 308ea2153..79f6d33f4 100644 --- a/tests/Australia/Tasmania/South/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/South/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/QueensBirthdayTest.php b/tests/Australia/Tasmania/South/QueensBirthdayTest.php index 7123c3b17..93e51a1b9 100644 --- a/tests/Australia/Tasmania/South/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/South/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/RecreationDayTest.php b/tests/Australia/Tasmania/South/RecreationDayTest.php index 54cc28fac..92cd07d82 100644 --- a/tests/Australia/Tasmania/South/RecreationDayTest.php +++ b/tests/Australia/Tasmania/South/RecreationDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; diff --git a/tests/Australia/Tasmania/South/SouthBaseTestCase.php b/tests/Australia/Tasmania/South/SouthBaseTestCase.php index dcc949990..c21a73ad6 100644 --- a/tests/Australia/Tasmania/South/SouthBaseTestCase.php +++ b/tests/Australia/Tasmania/South/SouthBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; @@ -22,8 +27,6 @@ abstract class SouthBaseTestCase extends TasmaniaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\South'; + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\South'; } diff --git a/tests/Australia/Tasmania/South/SouthTest.php b/tests/Australia/Tasmania/South/SouthTest.php index f3dce3271..67c2b1fc0 100644 --- a/tests/Australia/Tasmania/South/SouthTest.php +++ b/tests/Australia/Tasmania/South/SouthTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in southern Tasmania (Australia). */ -class SouthTest extends SouthBaseTestCase +class SouthTest extends SouthBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in northwestern Tasmania (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in northwestern Tasmania (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +57,19 @@ public function testOfficialHolidays(): void 'eightHourDay', 'recreationDay', 'hobartShow', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Tasmania/South/Southeast/AnzacDayTest.php b/tests/Australia/Tasmania/South/Southeast/AnzacDayTest.php index 47980d195..0e6c23323 100644 --- a/tests/Australia/Tasmania/South/Southeast/AnzacDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/AustraliaDayTest.php b/tests/Australia/Tasmania/South/Southeast/AustraliaDayTest.php index faa0f28a9..bad72f888 100644 --- a/tests/Australia/Tasmania/South/Southeast/AustraliaDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/BoxingDayTest.php b/tests/Australia/Tasmania/South/Southeast/BoxingDayTest.php index 1b40f5fdb..48e133153 100644 --- a/tests/Australia/Tasmania/South/Southeast/BoxingDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/ChristmasDayTest.php b/tests/Australia/Tasmania/South/Southeast/ChristmasDayTest.php index 126b8ba89..206a7ce32 100644 --- a/tests/Australia/Tasmania/South/Southeast/ChristmasDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/EasterMondayTest.php b/tests/Australia/Tasmania/South/Southeast/EasterMondayTest.php index 189e94099..daa0c4ed5 100644 --- a/tests/Australia/Tasmania/South/Southeast/EasterMondayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/EightHourDayTest.php b/tests/Australia/Tasmania/South/Southeast/EightHourDayTest.php index ebf9f1783..d196e2890 100644 --- a/tests/Australia/Tasmania/South/Southeast/EightHourDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/EightHourDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/GoodFridayTest.php b/tests/Australia/Tasmania/South/Southeast/GoodFridayTest.php index 07e33e1f1..eaf0d5dc7 100644 --- a/tests/Australia/Tasmania/South/Southeast/GoodFridayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/HobartRegattaTest.php b/tests/Australia/Tasmania/South/Southeast/HobartRegattaTest.php index 3431403d1..1c3f960ad 100644 --- a/tests/Australia/Tasmania/South/Southeast/HobartRegattaTest.php +++ b/tests/Australia/Tasmania/South/Southeast/HobartRegattaTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Burnie Show Day in northwestern Tasmania (Australia).. */ -class HobartRegattaTest extends SoutheastBaseTestCase implements YasumiTestCaseInterface +class HobartRegattaTest extends SoutheastBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'hobartRegatta'; /** - * Tests Royal Hobart Regatta - * - * @dataProvider HolidayDataProvider + * Tests Royal Hobart Regatta. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-02-08'], [2011, '2011-02-14'], [2012, '2012-02-13'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-02-11'], [2020, '2020-02-10'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Royal Hobart Regatta'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/South/Southeast/HobartShowTest.php b/tests/Australia/Tasmania/South/Southeast/HobartShowTest.php index 12ff38604..113759b1e 100644 --- a/tests/Australia/Tasmania/South/Southeast/HobartShowTest.php +++ b/tests/Australia/Tasmania/South/Southeast/HobartShowTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/NationalDayOfMourningTest.php b/tests/Australia/Tasmania/South/Southeast/NationalDayOfMourningTest.php new file mode 100644 index 000000000..6150ec657 --- /dev/null +++ b/tests/Australia/Tasmania/South/Southeast/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Tasmania\South\Southeast; + +/** + * Class for testing National Day of Mourning in southeastern Tasmania (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\Tasmania\South\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Tasmania/South/Southeast/NewYearsDayTest.php b/tests/Australia/Tasmania/South/Southeast/NewYearsDayTest.php index 6194e82c7..c546b4ca0 100644 --- a/tests/Australia/Tasmania/South/Southeast/NewYearsDayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php b/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php index 004eb6101..32d2ae81d 100644 --- a/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; diff --git a/tests/Australia/Tasmania/South/Southeast/SoutheastBaseTestCase.php b/tests/Australia/Tasmania/South/Southeast/SoutheastBaseTestCase.php index 71acd04fb..f70499b76 100644 --- a/tests/Australia/Tasmania/South/Southeast/SoutheastBaseTestCase.php +++ b/tests/Australia/Tasmania/South/Southeast/SoutheastBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; @@ -22,13 +27,11 @@ abstract class SoutheastBaseTestCase extends SouthBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania\South\Southeast'; + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Hobart'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania\South\Southeast'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Hobart'; + public string $timezone = 'Australia/Hobart'; } diff --git a/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php b/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php index 9ac91057a..8d4f0f59b 100644 --- a/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php +++ b/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; -use ReflectionException; use Yasumi\Holiday; /** @@ -20,19 +24,27 @@ */ class SoutheastTest extends SoutheastBaseTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } /** - * Tests if all official holidays in Circular Head (Australia) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Circular Head (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -44,14 +56,10 @@ public function testOfficialHolidays(): void 'eightHourDay', 'hobartShow', 'hobartRegatta', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1921); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Tasmania/TasmaniaBaseTestCase.php b/tests/Australia/Tasmania/TasmaniaBaseTestCase.php index 5185a3732..6bd6d3e77 100644 --- a/tests/Australia/Tasmania/TasmaniaBaseTestCase.php +++ b/tests/Australia/Tasmania/TasmaniaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; @@ -22,13 +27,11 @@ abstract class TasmaniaBaseTestCase extends AustraliaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Tasmania'; + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Tasmania'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Tasmania'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Tasmania'; + public string $timezone = 'Australia/Tasmania'; } diff --git a/tests/Australia/Tasmania/TasmaniaTest.php b/tests/Australia/Tasmania/TasmaniaTest.php index 38639bc89..9f4347e08 100644 --- a/tests/Australia/Tasmania/TasmaniaTest.php +++ b/tests/Australia/Tasmania/TasmaniaTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Tasmania; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Tasmania (Australia). */ -class TasmaniaTest extends TasmaniaBaseTestCase +class TasmaniaTest extends TasmaniaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } /** - * Tests if all official holidays in Tasmania (Australia) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Tasmania (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -42,14 +56,19 @@ public function testOfficialHolidays(): void 'queensBirthday', 'eightHourDay', 'recreationDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1921); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/Victoria/AFLGrandFinalFridayTest.php b/tests/Australia/Victoria/AFLGrandFinalFridayTest.php index 303ce70aa..2b10ce91d 100644 --- a/tests/Australia/Victoria/AFLGrandFinalFridayTest.php +++ b/tests/Australia/Victoria/AFLGrandFinalFridayTest.php @@ -1,110 +1,109 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing AFL Grand Final Friday in Victoria (Australia).. */ -class AFLGrandFinalFridayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class AFLGrandFinalFridayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'aflGrandFinalFriday'; public const ESTABLISHMENT_YEAR = 2015; - public const LAST_KNOWN_YEAR = 2018; + public const LAST_KNOWN_YEAR = 2020; /** - * Tests AFL Grand Final Friday - * - * @dataProvider HolidayDataProvider + * Tests AFL Grand Final Friday. * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::LAST_KNOWN_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LAST_KNOWN_YEAR), [self::LOCALE => 'AFL Grand Final Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::LAST_KNOWN_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LAST_KNOWN_YEAR), Holiday::TYPE_OFFICIAL ); } /** - * Tests that Holiday is not present before establishment year - * @throws ReflectionException + * Tests that Holiday is not present before establishment year. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday($this->region, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2015, '2015-10-02'], [2016, '2016-09-30'], [2017, '2017-09-29'], [2018, '2018-09-28'], + [2019, '2019-09-27'], + [2020, '2020-09-25'], ]; - - return $data; } } diff --git a/tests/Australia/Victoria/AnzacDayTest.php b/tests/Australia/Victoria/AnzacDayTest.php index 1d8cbf568..a749bc3aa 100644 --- a/tests/Australia/Victoria/AnzacDayTest.php +++ b/tests/Australia/Victoria/AnzacDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/AustraliaDayTest.php b/tests/Australia/Victoria/AustraliaDayTest.php index 5baf1207b..7bafb6d18 100644 --- a/tests/Australia/Victoria/AustraliaDayTest.php +++ b/tests/Australia/Victoria/AustraliaDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/BoxingDayTest.php b/tests/Australia/Victoria/BoxingDayTest.php index d2880a018..f3d7e06dc 100644 --- a/tests/Australia/Victoria/BoxingDayTest.php +++ b/tests/Australia/Victoria/BoxingDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/ChristmasDayTest.php b/tests/Australia/Victoria/ChristmasDayTest.php index d508699d5..76207dd63 100644 --- a/tests/Australia/Victoria/ChristmasDayTest.php +++ b/tests/Australia/Victoria/ChristmasDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/EasterMondayTest.php b/tests/Australia/Victoria/EasterMondayTest.php index b45c9d682..afd4336a6 100644 --- a/tests/Australia/Victoria/EasterMondayTest.php +++ b/tests/Australia/Victoria/EasterMondayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/EasterSaturdayTest.php b/tests/Australia/Victoria/EasterSaturdayTest.php index f074c1960..75452f8b0 100644 --- a/tests/Australia/Victoria/EasterSaturdayTest.php +++ b/tests/Australia/Victoria/EasterSaturdayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Saturday in Victoria (Australia).. */ -class EasterSaturdayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class EasterSaturdayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterSaturday'; /** - * Tests Easter Saturday - * - * @dataProvider HolidayDataProvider + * Tests Easter Saturday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); - $date->sub(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,24 +73,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Saturday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Victoria/EasterSundayTest.php b/tests/Australia/Victoria/EasterSundayTest.php index cba538d36..cee3a2da3 100644 --- a/tests/Australia/Victoria/EasterSundayTest.php +++ b/tests/Australia/Victoria/EasterSundayTest.php @@ -1,68 +1,68 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Sunday in Victoria (Australia).. */ -class EasterSundayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class EasterSundayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easter'; /** - * Tests Easter Sunday - * - * @dataProvider HolidayDataProvider + * Tests Easter Sunday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, $this->timezone); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); $data[] = [$year, $date->format('Y-m-d')]; } @@ -72,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Sunday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Victoria/GoodFridayTest.php b/tests/Australia/Victoria/GoodFridayTest.php index daf7b1f62..bd869c112 100644 --- a/tests/Australia/Victoria/GoodFridayTest.php +++ b/tests/Australia/Victoria/GoodFridayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/LabourDayTest.php b/tests/Australia/Victoria/LabourDayTest.php index 0cff91fc7..9a3cb59ef 100644 --- a/tests/Australia/Victoria/LabourDayTest.php +++ b/tests/Australia/Victoria/LabourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Labour Day in Victoria (Australia).. */ -class LabourDayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-03-08'], [2011, '2011-03-14'], [2012, '2012-03-12'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-03-11'], [2020, '2020-03-09'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/Victoria/MelbourneCupDayTest.php b/tests/Australia/Victoria/MelbourneCupDayTest.php index cfdedd5ee..00457ef09 100644 --- a/tests/Australia/Victoria/MelbourneCupDayTest.php +++ b/tests/Australia/Victoria/MelbourneCupDayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Melbourne cup Day in Victoria (Australia).. */ -class MelbourneCupDayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class MelbourneCupDayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'melbourneCup'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1877; /** - * Tests Melbourne Cup Day - * - * @dataProvider HolidayDataProvider + * Tests Melbourne Cup Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-11-02'], [2011, '2011-11-01'], [2012, '2012-11-06'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-11-05'], [2020, '2020-11-03'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Melbourne Cup'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/Victoria/NationalDayOfMourningTest.php b/tests/Australia/Victoria/NationalDayOfMourningTest.php new file mode 100644 index 000000000..2906157a7 --- /dev/null +++ b/tests/Australia/Victoria/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\Victoria; + +/** + * Class for testing National Day of Mourning in Victoria (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/Victoria/NewYearsDayTest.php b/tests/Australia/Victoria/NewYearsDayTest.php index d1c433a19..dfde1b037 100644 --- a/tests/Australia/Victoria/NewYearsDayTest.php +++ b/tests/Australia/Victoria/NewYearsDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; diff --git a/tests/Australia/Victoria/QueensBirthdayTest.php b/tests/Australia/Victoria/QueensBirthdayTest.php index edabf8864..b8a7cd95d 100644 --- a/tests/Australia/Victoria/QueensBirthdayTest.php +++ b/tests/Australia/Victoria/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Queen's Birthday in Victoria (Australia).. */ -class QueensBirthdayTest extends VictoriaBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends VictoriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-06-14'], [2011, '2011-06-13'], [2012, '2012-06-11'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-06-10'], [2020, '2020-06-08'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/Victoria/VictoriaBaseTestCase.php b/tests/Australia/Victoria/VictoriaBaseTestCase.php index 4ff848eaa..06796c0e4 100644 --- a/tests/Australia/Victoria/VictoriaBaseTestCase.php +++ b/tests/Australia/Victoria/VictoriaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; @@ -22,13 +27,11 @@ abstract class VictoriaBaseTestCase extends AustraliaBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\Victoria'; + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/Victoria'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\Victoria'; - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/Victoria'; + public string $timezone = 'Australia/Victoria'; } diff --git a/tests/Australia/Victoria/VictoriaTest.php b/tests/Australia/Victoria/VictoriaTest.php index 8794c7f71..d3558e5fd 100644 --- a/tests/Australia/Victoria/VictoriaTest.php +++ b/tests/Australia/Victoria/VictoriaTest.php @@ -1,38 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Australia\Victoria; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Victoria (Australia). */ -class VictoriaTest extends VictoriaBaseTestCase +class VictoriaTest extends VictoriaBaseTestCase implements ProviderTestCase { - /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Victoria (Australia) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2015, 2018); + } + + /** + * Tests if all official holidays in Victoria (Australia) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $expectedHolidays = [ 'newYearsDay', 'goodFriday', 'easterMonday', @@ -46,14 +59,19 @@ public function testOfficialHolidays(): void 'labourDay', 'aflGrandFinalFriday', 'melbourneCup', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2015, 2018); + $this->assertSources($this->region, 1); } } diff --git a/tests/Australia/WA/AnzacDayTest.php b/tests/Australia/WA/AnzacDayTest.php deleted file mode 100644 index 6af012b98..000000000 --- a/tests/Australia/WA/AnzacDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing ANZAC day in WA (Australia).. - */ -class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest -{ -} diff --git a/tests/Australia/WA/AustraliaDayTest.php b/tests/Australia/WA/AustraliaDayTest.php deleted file mode 100644 index 00ea1bc65..000000000 --- a/tests/Australia/WA/AustraliaDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing Australia day in WA (Australia).. - */ -class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest -{ -} diff --git a/tests/Australia/WA/BoxingDayTest.php b/tests/Australia/WA/BoxingDayTest.php deleted file mode 100644 index a3a1f2e54..000000000 --- a/tests/Australia/WA/BoxingDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing Boxing Day in WA (Australia).. - */ -class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest -{ -} diff --git a/tests/Australia/WA/ChristmasDayTest.php b/tests/Australia/WA/ChristmasDayTest.php deleted file mode 100644 index c78aaa867..000000000 --- a/tests/Australia/WA/ChristmasDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing Christmas Day in WA (Australia).. - */ -class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest -{ -} diff --git a/tests/Australia/WA/EasterMondayTest.php b/tests/Australia/WA/EasterMondayTest.php deleted file mode 100644 index f2cfb9b7d..000000000 --- a/tests/Australia/WA/EasterMondayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing Easter Monday in WA (Australia).. - */ -class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest -{ -} diff --git a/tests/Australia/WA/GoodFridayTest.php b/tests/Australia/WA/GoodFridayTest.php deleted file mode 100644 index f76730a51..000000000 --- a/tests/Australia/WA/GoodFridayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing Good Friday in WA (Australia).. - */ -class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest -{ -} diff --git a/tests/Australia/WA/NewYearsDayTest.php b/tests/Australia/WA/NewYearsDayTest.php deleted file mode 100644 index 78a255901..000000000 --- a/tests/Australia/WA/NewYearsDayTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -/** - * Class for testing New Years Day in WA (Australia).. - */ -class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest -{ -} diff --git a/tests/Australia/WA/WABaseTestCase.php b/tests/Australia/WA/WABaseTestCase.php deleted file mode 100644 index 0db77c9ce..000000000 --- a/tests/Australia/WA/WABaseTestCase.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -use Yasumi\tests\Australia\AustraliaBaseTestCase; -use Yasumi\tests\YasumiBase; - -/** - * Base class for test cases of the Queensland holiday provider. - */ -abstract class WABaseTestCase extends AustraliaBaseTestCase -{ - use YasumiBase; - - /** - * Name of the region (e.g. country / state) to be tested - */ - public $region = 'Australia\WA'; - - /** - * Timezone in which this provider has holidays defined - */ - public $timezone = 'Australia/West'; -} diff --git a/tests/Australia/WA/WATest.php b/tests/Australia/WA/WATest.php deleted file mode 100644 index 56b5a941b..000000000 --- a/tests/Australia/WA/WATest.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -use ReflectionException; -use Yasumi\Holiday; - -/** - * Class for testing holidays in WA (Australia). - */ -class WATest extends WABaseTestCase -{ - - /** - * @var int year random year number used for all tests in this Test Case - */ - protected $year; - - /** - * Tests if all official holidays in WA (Australia) are defined by the provider class - * @throws ReflectionException - */ - public function testOfficialHolidays(): void - { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'goodFriday', - 'easterMonday', - 'christmasDay', - 'secondChristmasDay', - 'australiaDay', - 'anzacDay', - 'queensBirthday', - 'labourDay', - 'westernAustraliaDay', - ], $this->region, $this->year, Holiday::TYPE_OFFICIAL); - } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = $this->generateRandomYear(1921); - } -} diff --git a/tests/Australia/WA/WesternAustraliaDayTest.php b/tests/Australia/WA/WesternAustraliaDayTest.php deleted file mode 100644 index 406767267..000000000 --- a/tests/Australia/WA/WesternAustraliaDayTest.php +++ /dev/null @@ -1,99 +0,0 @@ - - */ - -namespace Yasumi\tests\Australia\WA; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Western Australia Day in WA (Australia).. - */ -class WesternAustraliaDayTest extends WABaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'westernAustraliaDay'; - - /** - * Tests Western Australia Day - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - $this->region, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone($this->timezone)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - */ - public function HolidayDataProvider(): array - { - $data = [ - [2010, '2010-06-07'], - [2011, '2011-06-06'], - [2012, '2012-06-04'], - [2013, '2013-06-03'], - [2014, '2014-06-02'], - [2015, '2015-06-01'], - [2016, '2016-06-06'], - [2017, '2017-06-05'], - [2018, '2018-06-04'], - [2019, '2019-06-03'], - [2020, '2020-06-01'], - ]; - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - $this->region, - self::HOLIDAY, - $this->generateRandomYear(1990), - [self::LOCALE => 'Western Australia Day'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Australia/WesternAustralia/AnzacDayTest.php b/tests/Australia/WesternAustralia/AnzacDayTest.php new file mode 100644 index 000000000..de47d2392 --- /dev/null +++ b/tests/Australia/WesternAustralia/AnzacDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing ANZAC day in Western Australia (Australia).. + */ +class AnzacDayTest extends \Yasumi\tests\Australia\AnzacDayTest +{ +} diff --git a/tests/Australia/WesternAustralia/AustraliaDayTest.php b/tests/Australia/WesternAustralia/AustraliaDayTest.php new file mode 100644 index 000000000..b431f6e96 --- /dev/null +++ b/tests/Australia/WesternAustralia/AustraliaDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing Australia day in Western Australia (Australia).. + */ +class AustraliaDayTest extends \Yasumi\tests\Australia\AustraliaDayTest +{ +} diff --git a/tests/Australia/WesternAustralia/BoxingDayTest.php b/tests/Australia/WesternAustralia/BoxingDayTest.php new file mode 100644 index 000000000..b52f81476 --- /dev/null +++ b/tests/Australia/WesternAustralia/BoxingDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing Boxing Day in Western Australia (Australia).. + */ +class BoxingDayTest extends \Yasumi\tests\Australia\BoxingDayTest +{ +} diff --git a/tests/Australia/WesternAustralia/ChristmasDayTest.php b/tests/Australia/WesternAustralia/ChristmasDayTest.php new file mode 100644 index 000000000..0f657f6e0 --- /dev/null +++ b/tests/Australia/WesternAustralia/ChristmasDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing Christmas Day in Western Australia (Australia).. + */ +class ChristmasDayTest extends \Yasumi\tests\Australia\ChristmasDayTest +{ +} diff --git a/tests/Australia/WesternAustralia/EasterMondayTest.php b/tests/Australia/WesternAustralia/EasterMondayTest.php new file mode 100644 index 000000000..edaa473ca --- /dev/null +++ b/tests/Australia/WesternAustralia/EasterMondayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing Easter Monday in Western Australia (Australia).. + */ +class EasterMondayTest extends \Yasumi\tests\Australia\EasterMondayTest +{ +} diff --git a/tests/Australia/WesternAustralia/GoodFridayTest.php b/tests/Australia/WesternAustralia/GoodFridayTest.php new file mode 100644 index 000000000..ade1cdd6c --- /dev/null +++ b/tests/Australia/WesternAustralia/GoodFridayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing Good Friday in Western Australia (Australia).. + */ +class GoodFridayTest extends \Yasumi\tests\Australia\GoodFridayTest +{ +} diff --git a/tests/Australia/WA/LabourDayTest.php b/tests/Australia/WesternAustralia/LabourDayTest.php similarity index 50% rename from tests/Australia/WA/LabourDayTest.php rename to tests/Australia/WesternAustralia/LabourDayTest.php index 6f866e73a..d21949277 100644 --- a/tests/Australia/WA/LabourDayTest.php +++ b/tests/Australia/WesternAustralia/LabourDayTest.php @@ -1,63 +1,62 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\WA; +namespace Yasumi\tests\Australia\WesternAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Labour Day in WA (Australia).. + * Class for testing Labour Day in Western Australia (Australia).. */ -class LabourDayTest extends WABaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-03-01'], [2011, '2011-03-07'], [2012, '2012-03-05'], @@ -70,30 +69,30 @@ public function HolidayDataProvider(): array [2019, '2019-03-04'], [2020, '2020-03-02'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(1990), + static::generateRandomYear(1990), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType($this->region, self::HOLIDAY, $this->generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Australia/WesternAustralia/NationalDayOfMourningTest.php b/tests/Australia/WesternAustralia/NationalDayOfMourningTest.php new file mode 100644 index 000000000..838d0073e --- /dev/null +++ b/tests/Australia/WesternAustralia/NationalDayOfMourningTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing National Day of Mourning in Western Australia (Australia).. + */ +class NationalDayOfMourningTest extends \Yasumi\tests\Australia\NationalDayOfMourningTest +{ +} diff --git a/tests/Australia/WesternAustralia/NewYearsDayTest.php b/tests/Australia/WesternAustralia/NewYearsDayTest.php new file mode 100644 index 000000000..0e1cbdbc5 --- /dev/null +++ b/tests/Australia/WesternAustralia/NewYearsDayTest.php @@ -0,0 +1,25 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +/** + * Class for testing New Years Day in Western Australia (Australia).. + */ +class NewYearsDayTest extends \Yasumi\tests\Australia\NewYearsDayTest +{ +} diff --git a/tests/Australia/WA/QueensBirthdayTest.php b/tests/Australia/WesternAustralia/QueensBirthdayTest.php similarity index 51% rename from tests/Australia/WA/QueensBirthdayTest.php rename to tests/Australia/WesternAustralia/QueensBirthdayTest.php index 69c4d1c3d..0ea4590c5 100644 --- a/tests/Australia/WA/QueensBirthdayTest.php +++ b/tests/Australia/WesternAustralia/QueensBirthdayTest.php @@ -1,68 +1,67 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests\Australia\WA; +namespace Yasumi\tests\Australia\WesternAustralia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in WA (Australia).. + * Class for testing Queen's Birthday in Western Australia (Australia).. */ -class QueensBirthdayTest extends WABaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queen's Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( $this->region, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone($this->timezone)) + new \DateTime($expected, new \DateTimeZone($this->timezone)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - $data = [ + return [ [2010, '2010-09-27'], [2011, '2011-10-28'], [2012, '2012-10-01'], @@ -75,34 +74,34 @@ public function HolidayDataProvider(): array [2019, '2019-09-30'], [2020, '2020-09-28'], ]; - - return $data; } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queen\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( $this->region, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2100), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php b/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php new file mode 100644 index 000000000..e57df32e4 --- /dev/null +++ b/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +use Yasumi\tests\Australia\AustraliaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Queensland holiday provider. + */ +abstract class WesternAustraliaBaseTestCase extends AustraliaBaseTestCase +{ + use YasumiBase; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Australia/West'; + + /** Name of the region (e.g. country / state) to be tested. */ + public string $region = 'Australia\WesternAustralia'; + + public string $timezone = 'Australia/West'; +} diff --git a/tests/Australia/WesternAustralia/WesternAustraliaDayTest.php b/tests/Australia/WesternAustralia/WesternAustraliaDayTest.php new file mode 100644 index 000000000..663034d55 --- /dev/null +++ b/tests/Australia/WesternAustralia/WesternAustraliaDayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Western Australia Day in Western Australia (Australia).. + */ +class WesternAustraliaDayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'westernAustraliaDay'; + + /** + * Tests Western Australia Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2010, '2010-06-07'], + [2011, '2011-06-06'], + [2012, '2012-06-04'], + [2013, '2013-06-03'], + [2014, '2014-06-02'], + [2015, '2015-06-01'], + [2016, '2016-06-06'], + [2017, '2017-06-05'], + [2018, '2018-06-04'], + [2019, '2019-06-03'], + [2020, '2020-06-01'], + ]; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(1990), + [self::LOCALE => 'Western Australia Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(1990), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/WesternAustralia/WesternAustraliaTest.php b/tests/Australia/WesternAustralia/WesternAustraliaTest.php new file mode 100644 index 000000000..408b5e2ae --- /dev/null +++ b/tests/Australia/WesternAustralia/WesternAustraliaTest.php @@ -0,0 +1,74 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Western Australia (Australia). + */ +class WesternAustraliaTest extends WesternAustraliaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Western Australia (Australia) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $expectedHolidays = [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'christmasDay', + 'secondChristmasDay', + 'australiaDay', + 'anzacDay', + 'queensBirthday', + 'labourDay', + 'westernAustraliaDay', + ]; + if (2022 === $this->year) { + $expectedHolidays[] = 'nationalDayOfMourning'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources($this->region, 1); + } +} diff --git a/tests/Austria/AllSaintsDayTest.php b/tests/Austria/AllSaintsDayTest.php index aec20f856..31efa3729 100644 --- a/tests/Austria/AllSaintsDayTest.php +++ b/tests/Austria/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Austria. */ -class AllSaintsDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/AscensionDayTest.php b/tests/Austria/AscensionDayTest.php index b84e6cdab..671846291 100644 --- a/tests/Austria/AscensionDayTest.php +++ b/tests/Austria/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Austria. */ -class AscensionDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1754; $this->assertHoliday( self::REGION, 'ascensionDay', $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christi Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/AssumptionOfMaryTest.php b/tests/Austria/AssumptionOfMaryTest.php index 2412ba2a7..e8eb50664 100644 --- a/tests/Austria/AssumptionOfMaryTest.php +++ b/tests/Austria/AssumptionOfMaryTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Austria. */ -class AssumptionOfMaryTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/AustriaBaseTestCase.php b/tests/Austria/AustriaBaseTestCase.php index 53c3ddf37..0c5a80a9c 100644 --- a/tests/Austria/AustriaBaseTestCase.php +++ b/tests/Austria/AustriaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; @@ -22,18 +27,17 @@ abstract class AustriaBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Austria'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Vienna'; + /** Locale that is considered common for this provider. */ + public const LOCALE = 'de_AT'; + /** - * Locale that is considered common for this provider + * Number of iterations to be used for the various unit tests of this provider. */ - public const LOCALE = 'de_AT'; + public const TEST_ITERATIONS = 50; } diff --git a/tests/Austria/AustriaTest.php b/tests/Austria/AustriaTest.php index 25dd8b6d6..5b25263ab 100644 --- a/tests/Austria/AustriaTest.php +++ b/tests/Austria/AustriaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Austria. */ -class AustriaTest extends AustriaBaseTestCase +class AustriaTest extends AustriaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1955); + } /** - * Tests if all official holidays in Austria are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Austria are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -49,8 +63,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Austria are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Austria are defined by the provider class. */ public function testObservedHolidays(): void { @@ -58,8 +71,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Austria are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Austria are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +79,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Austria are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Austria are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +87,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Austria are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Austria are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +95,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1955); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Austria/Burgenland/BurgenlandBaseTestCase.php b/tests/Austria/Burgenland/BurgenlandBaseTestCase.php new file mode 100644 index 000000000..f17ea431d --- /dev/null +++ b/tests/Austria/Burgenland/BurgenlandBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Burgenland; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Burgenland (Austria) holiday provider. + */ +abstract class BurgenlandBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Burgenland'; +} diff --git a/tests/Austria/Burgenland/BurgenlandTest.php b/tests/Austria/Burgenland/BurgenlandTest.php new file mode 100644 index 000000000..7e7a12e69 --- /dev/null +++ b/tests/Austria/Burgenland/BurgenlandTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Austria\Burgenland; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Burgenland (Austria). + */ +class BurgenlandTest extends BurgenlandBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Burgenland (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + 'stMartinsDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Burgenland (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Burgenland (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Burgenland (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Burgenland (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Burgenland/stMartinsDayTest.php b/tests/Austria/Burgenland/stMartinsDayTest.php new file mode 100644 index 000000000..c93b483a0 --- /dev/null +++ b/tests/Austria/Burgenland/stMartinsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Burgenland; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing st Martins Day in the Netherlands. + */ +class stMartinsDayTest extends BurgenlandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stMartinsDay'; + + /** + * Tests Saint Martins Day. + * + * @param int $year the year for which Saint Martins Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('stMartinsDayDataProvider')] + public function teststMartinsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Saint Martins Day. + * + * @return array list of test dates for Saint Martins Day + * + * @throws \Exception + */ + public static function stMartinsDayDataProvider(): array + { + return static::generateRandomDates(11, 11, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Martin'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Carinthia/CarinthiaBaseTestCase.php b/tests/Austria/Carinthia/CarinthiaBaseTestCase.php new file mode 100644 index 000000000..689ca1af8 --- /dev/null +++ b/tests/Austria/Carinthia/CarinthiaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Carinthia; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Carinthia (Austria) holiday provider. + */ +abstract class CarinthiaBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Carinthia'; +} diff --git a/tests/Austria/Carinthia/CarinthiaTest.php b/tests/Austria/Carinthia/CarinthiaTest.php new file mode 100644 index 000000000..693485608 --- /dev/null +++ b/tests/Austria/Carinthia/CarinthiaTest.php @@ -0,0 +1,115 @@ + + */ + +namespace Yasumi\tests\Austria\Carinthia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Carinthia (Austria). + */ +class CarinthiaTest extends CarinthiaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Carinthia (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + 'stJosephsDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + if (1920 <= $this->year) { + $holidays[] = 'plebisciteDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Carinthia (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Carinthia (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Carinthia (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Carinthia (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Carinthia/PlebisciteDayTest.php b/tests/Austria/Carinthia/PlebisciteDayTest.php new file mode 100644 index 000000000..07fa083c2 --- /dev/null +++ b/tests/Austria/Carinthia/PlebisciteDayTest.php @@ -0,0 +1,107 @@ + + */ + +namespace Yasumi\tests\Austria\Carinthia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Plebiscite Day in Carinthia (Austria). + */ +class PlebisciteDayTest extends CarinthiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'plebisciteDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1920; + + /** + * Tests Plebiscite Day. + * + * @param int $year the year for which Plebiscite Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('PlebisciteDayDataProvider')] + public function testPlebisciteDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Plebiscite Day. + * + * @return array list of test dates for Plebiscite Day + * + * @throws \Exception + */ + public static function PlebisciteDayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-10", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Tag der Volksabstimmung'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Carinthia/StJosephsDayTest.php b/tests/Austria/Carinthia/StJosephsDayTest.php new file mode 100644 index 000000000..23c02299a --- /dev/null +++ b/tests/Austria/Carinthia/StJosephsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Carinthia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing St. Joseph's Day in Carinthia (Austria). + */ +class StJosephsDayTest extends CarinthiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stJosephsDay'; + + /** + * Tests St. Joseph's Day. + * + * @param int $year the year for which St. Joseph's Day needs to be tested. + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephsDayDataProvider')] + public function testStJosephsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of St. Joseph's Day. + * + * @return array list of test dates for St. Joseph's Day. + * + * @throws \Exception + */ + public static function StJosephsDayDataProvider(): array + { + return static::generateRandomDates(3, 19, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Josephstag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/ChristmasTest.php b/tests/Austria/ChristmasTest.php index 5813ed158..203bbb3c6 100644 --- a/tests/Austria/ChristmasTest.php +++ b/tests/Austria/ChristmasTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Austria. */ -class ChristmasTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christtag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/CorpusChristiTest.php b/tests/Austria/CorpusChristiTest.php index 218a25cc9..953dbd30d 100644 --- a/tests/Austria/CorpusChristiTest.php +++ b/tests/Austria/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Austria. */ -class CorpusChristiTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends AustriaBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/EasterMondayTest.php b/tests/Austria/EasterMondayTest.php index df31b6923..32b09bafe 100644 --- a/tests/Austria/EasterMondayTest.php +++ b/tests/Austria/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Austria. */ -class EasterMondayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/EasterTest.php b/tests/Austria/EasterTest.php index 66851b3a2..8aeb0be14 100644 --- a/tests/Austria/EasterTest.php +++ b/tests/Austria/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Austria. */ -class EasterTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2009; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostersonntag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/EpiphanyTest.php b/tests/Austria/EpiphanyTest.php index 1afe89a81..0483510a1 100644 --- a/tests/Austria/EpiphanyTest.php +++ b/tests/Austria/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Austria. */ -class EpiphanyTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige Drei Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/ImmaculateConceptionTest.php b/tests/Austria/ImmaculateConceptionTest.php index 51197cbc2..26b25228f 100644 --- a/tests/Austria/ImmaculateConceptionTest.php +++ b/tests/Austria/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Austria. */ -class ImmaculateConceptionTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/InternationalWorkersDayTest.php b/tests/Austria/InternationalWorkersDayTest.php index 8e7dab7a9..151a2dcd3 100644 --- a/tests/Austria/InternationalWorkersDayTest.php +++ b/tests/Austria/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Austria. */ -class InternationalWorkersDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Staatsfeiertag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/LowerAustria/LowerAustriaBaseTestCase.php b/tests/Austria/LowerAustria/LowerAustriaBaseTestCase.php new file mode 100644 index 000000000..a341901e7 --- /dev/null +++ b/tests/Austria/LowerAustria/LowerAustriaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\LowerAustria; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Lower Austria (Austria) holiday provider. + */ +abstract class LowerAustriaBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/LowerAustria'; +} diff --git a/tests/Austria/LowerAustria/LowerAustriaTest.php b/tests/Austria/LowerAustria/LowerAustriaTest.php new file mode 100644 index 000000000..24c6eee58 --- /dev/null +++ b/tests/Austria/LowerAustria/LowerAustriaTest.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\tests\Austria\LowerAustria; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Lower Austria (Austria). + */ +class LowerAustriaTest extends LowerAustriaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Lower Austria (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + if (1136 <= $this->year) { + $holidays[] = 'stLeopoldsDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Lower Austria (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Lower Austria (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Lower Austria (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Lower Austria (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/LowerAustria/StLeopoldsDayTest.php b/tests/Austria/LowerAustria/StLeopoldsDayTest.php new file mode 100644 index 000000000..65b720857 --- /dev/null +++ b/tests/Austria/LowerAustria/StLeopoldsDayTest.php @@ -0,0 +1,107 @@ + + */ + +namespace Yasumi\tests\Austria\LowerAustria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Saint Leopold's Day in Lower Austria (Austria). + */ +class StLeopoldsDayTest extends LowerAustriaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stLeopoldsDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1136; + + /** + * Tests Saint Leopold's Day. + * + * @param int $year the year for which Saint Leopold's Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StLeopoldsDayDataProvider')] + public function testStLeopoldsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Saint Leopold's Day. + * + * @return array list of test dates for Saint Leopold's Day + * + * @throws \Exception + */ + public static function StLeopoldsDayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-11-15", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Leopold'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/NationalDayTest.php b/tests/Austria/NationalDayTest.php index c7d35d1c5..dc64bc687 100644 --- a/tests/Austria/NationalDayTest.php +++ b/tests/Austria/NationalDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for National Day in Austria. */ -class NationalDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class NationalDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1955; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-26", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-26", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Nationalfeiertag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Austria/NewYearsDayTest.php b/tests/Austria/NewYearsDayTest.php index 833956a82..c24d02504 100644 --- a/tests/Austria/NewYearsDayTest.php +++ b/tests/Austria/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Austria. */ -class NewYearsDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/PentecostMondayTest.php b/tests/Austria/PentecostMondayTest.php index 6180080a6..5d18c864d 100644 --- a/tests/Austria/PentecostMondayTest.php +++ b/tests/Austria/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Austria. */ -class PentecostMondayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/PentecostTest.php b/tests/Austria/PentecostTest.php index b3124fe41..940097071 100644 --- a/tests/Austria/PentecostTest.php +++ b/tests/Austria/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Austria. */ -class PentecostTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1344; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingsten'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Austria/Salzburg/SalzburgBaseTestCase.php b/tests/Austria/Salzburg/SalzburgBaseTestCase.php new file mode 100644 index 000000000..b4fa9c4c2 --- /dev/null +++ b/tests/Austria/Salzburg/SalzburgBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Salzburg; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Salzburg (Austria) holiday provider. + */ +abstract class SalzburgBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Salzburg'; +} diff --git a/tests/Austria/Salzburg/SalzburgTest.php b/tests/Austria/Salzburg/SalzburgTest.php new file mode 100644 index 000000000..d9e6e56f2 --- /dev/null +++ b/tests/Austria/Salzburg/SalzburgTest.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\tests\Austria\Salzburg; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Salzburg (Austria). + */ +class SalzburgTest extends SalzburgBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Salzburg (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + if (710 <= $this->year) { + $holidays[] = 'stRupertsDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Salzburg (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Salzburg (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Salzburg (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Salzburg (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Salzburg/StRupertsDayTest.php b/tests/Austria/Salzburg/StRupertsDayTest.php new file mode 100644 index 000000000..75574239e --- /dev/null +++ b/tests/Austria/Salzburg/StRupertsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Salzburg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Saint Rupert's Day in Salzburg (Austria). + */ +class StRupertsDayTest extends SalzburgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stRupertsDay'; + + /** + * Tests Saint Rupert's Day. + * + * @param int $year the year for which Saint Rupert's Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StRupertsDayDataProvider')] + public function testStRupertsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Saint Rupert's Day. + * + * @return array list of test dates for Saint Rupert's Day + * + * @throws \Exception + */ + public static function StRupertsDayDataProvider(): array + { + return static::generateRandomDates(9, 24, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Rupert'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/SecondChristmasDayTest.php b/tests/Austria/SecondChristmasDayTest.php index 7ae928f8e..43c30ed87 100644 --- a/tests/Austria/SecondChristmasDayTest.php +++ b/tests/Austria/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Austria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Austria. */ -class SecondChristmasDayTest extends AustriaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends AustriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stefanitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Austria/Styria/StJosephsDayTest.php b/tests/Austria/Styria/StJosephsDayTest.php new file mode 100644 index 000000000..7d70cca41 --- /dev/null +++ b/tests/Austria/Styria/StJosephsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Styria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing St. Joseph's Day in Styria (Austria). + */ +class StJosephsDayTest extends StyriaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stJosephsDay'; + + /** + * Tests St. Joseph's Day. + * + * @param int $year the year for which St. Joseph's Day needs to be tested. + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephsDayDataProvider')] + public function testStJosephsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of St. Joseph's Day. + * + * @return array list of test dates for St. Joseph's Day. + * + * @throws \Exception + */ + public static function StJosephsDayDataProvider(): array + { + return static::generateRandomDates(3, 19, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Josephstag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Styria/StyriaBaseTestCase.php b/tests/Austria/Styria/StyriaBaseTestCase.php new file mode 100644 index 000000000..6147108db --- /dev/null +++ b/tests/Austria/Styria/StyriaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Styria; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Styria (Austria) holiday provider. + */ +abstract class StyriaBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Styria'; +} diff --git a/tests/Austria/Styria/StyriaTest.php b/tests/Austria/Styria/StyriaTest.php new file mode 100644 index 000000000..4dc14925e --- /dev/null +++ b/tests/Austria/Styria/StyriaTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Austria\Styria; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Styria (Austria). + */ +class StyriaTest extends StyriaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Styria (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + 'stJosephsDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Styria (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Styria (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Styria (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Styria (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Tyrol/StJosephsDayTest.php b/tests/Austria/Tyrol/StJosephsDayTest.php new file mode 100644 index 000000000..c16a3cc75 --- /dev/null +++ b/tests/Austria/Tyrol/StJosephsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Tyrol; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing St. Joseph's Day in Tyrol (Austria). + */ +class StJosephsDayTest extends TyrolBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stJosephsDay'; + + /** + * Tests St. Joseph's Day. + * + * @param int $year the year for which St. Joseph's Day needs to be tested. + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephsDayDataProvider')] + public function testStJosephsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of St. Joseph's Day. + * + * @return array list of test dates for St. Joseph's Day. + * + * @throws \Exception + */ + public static function StJosephsDayDataProvider(): array + { + return static::generateRandomDates(3, 19, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Josephstag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Tyrol/TyrolBaseTestCase.php b/tests/Austria/Tyrol/TyrolBaseTestCase.php new file mode 100644 index 000000000..891bc407a --- /dev/null +++ b/tests/Austria/Tyrol/TyrolBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Tyrol; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Tyrol (Austria) holiday provider. + */ +abstract class TyrolBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Tyrol'; +} diff --git a/tests/Austria/Tyrol/TyrolTest.php b/tests/Austria/Tyrol/TyrolTest.php new file mode 100644 index 000000000..db4d8818f --- /dev/null +++ b/tests/Austria/Tyrol/TyrolTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Austria\Tyrol; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Tyrol (Austria). + */ +class TyrolTest extends TyrolBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Tyrol (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + 'stJosephsDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Tyrol (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Tyrol (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Tyrol (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Tyrol (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/UpperAustria/StFloriansDayTest.php b/tests/Austria/UpperAustria/StFloriansDayTest.php new file mode 100644 index 000000000..3ff4b5177 --- /dev/null +++ b/tests/Austria/UpperAustria/StFloriansDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\UpperAustria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Saint Florian's Day in Upper Austria (Austria). + */ +class StFloriansDayTest extends UpperAustriaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stFloriansDay'; + + /** + * Tests Saint Florian's Day. + * + * @param int $year the year for which Saint Florian's Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StFloriansDayDataProvider')] + public function testStFloriansDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Saint Florian's Day. + * + * @return array list of test dates for Saint Florian's Day + * + * @throws \Exception + */ + public static function StFloriansDayDataProvider(): array + { + return static::generateRandomDates(5, 4, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Florian'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/UpperAustria/UpperAustriaBaseTestCase.php b/tests/Austria/UpperAustria/UpperAustriaBaseTestCase.php new file mode 100644 index 000000000..3f3beb99a --- /dev/null +++ b/tests/Austria/UpperAustria/UpperAustriaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\UpperAustria; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Upper Austria (Austria) holiday provider. + */ +abstract class UpperAustriaBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/UpperAustria'; +} diff --git a/tests/Austria/UpperAustria/UpperAustriaTest.php b/tests/Austria/UpperAustria/UpperAustriaTest.php new file mode 100644 index 000000000..36888f03e --- /dev/null +++ b/tests/Austria/UpperAustria/UpperAustriaTest.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\tests\Austria\UpperAustria; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Upper Austria (Austria). + */ +class UpperAustriaTest extends UpperAustriaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Upper Austria (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + if (304 <= $this->year) { + $holidays[] = 'stFloriansDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Upper Austria (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Upper Austria (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Upper Austria (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Upper Austria (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Vienna/StLeopoldsDayTest.php b/tests/Austria/Vienna/StLeopoldsDayTest.php new file mode 100644 index 000000000..842a38842 --- /dev/null +++ b/tests/Austria/Vienna/StLeopoldsDayTest.php @@ -0,0 +1,107 @@ + + */ + +namespace Yasumi\tests\Austria\Vienna; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Saint Leopold's Day in Lower Austria (Austria). + */ +class StLeopoldsDayTest extends ViennaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stLeopoldsDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1136; + + /** + * Tests Saint Leopold's Day. + * + * @param int $year the year for which Saint Leopold's Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StLeopoldsDayDataProvider')] + public function testStLeopoldsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Saint Leopold's Day. + * + * @return array list of test dates for Saint Leopold's Day + * + * @throws \Exception + */ + public static function StLeopoldsDayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-11-15", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Leopold'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Vienna/ViennaBaseTestCase.php b/tests/Austria/Vienna/ViennaBaseTestCase.php new file mode 100644 index 000000000..b1ad9c2e4 --- /dev/null +++ b/tests/Austria/Vienna/ViennaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Vienna; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Vienna (Austria) holiday provider. + */ +abstract class ViennaBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Vienna'; +} diff --git a/tests/Austria/Vienna/ViennaTest.php b/tests/Austria/Vienna/ViennaTest.php new file mode 100644 index 000000000..2c5e8bf35 --- /dev/null +++ b/tests/Austria/Vienna/ViennaTest.php @@ -0,0 +1,114 @@ + + */ + +namespace Yasumi\tests\Austria\Vienna; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Vienna (Austria). + */ +class ViennaTest extends ViennaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Vienna (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + if (1136 <= $this->year) { + $holidays[] = 'stLeopoldsDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Vienna (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Vienna (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Vienna (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Vienna (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Austria/Vorarlberg/StJosephsDayTest.php b/tests/Austria/Vorarlberg/StJosephsDayTest.php new file mode 100644 index 000000000..850e6a464 --- /dev/null +++ b/tests/Austria/Vorarlberg/StJosephsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Austria\Vorarlberg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing St. Joseph's Day in Vorarlberg (Austria). + */ +class StJosephsDayTest extends VorarlbergBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stJosephsDay'; + + /** + * Tests St. Joseph's Day. + * + * @param int $year the year for which St. Joseph's Day needs to be tested. + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephsDayDataProvider')] + public function testStJosephsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of St. Joseph's Day. + * + * @return array list of test dates for St. Joseph's Day. + * + * @throws \Exception + */ + public static function StJosephsDayDataProvider(): array + { + return static::generateRandomDates(3, 19, self::TIMEZONE); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Josephstag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Austria/Vorarlberg/VorarlbergBaseTestCase.php b/tests/Austria/Vorarlberg/VorarlbergBaseTestCase.php new file mode 100644 index 000000000..617a8c524 --- /dev/null +++ b/tests/Austria/Vorarlberg/VorarlbergBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Austria\Vorarlberg; + +use Yasumi\tests\Austria\AustriaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Vorarlberg (Austria) holiday provider. + */ +abstract class VorarlbergBaseTestCase extends AustriaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Austria/Vorarlberg'; +} diff --git a/tests/Austria/Vorarlberg/VorarlbergTest.php b/tests/Austria/Vorarlberg/VorarlbergTest.php new file mode 100644 index 000000000..282073b10 --- /dev/null +++ b/tests/Austria/Vorarlberg/VorarlbergTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Austria\Vorarlberg; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Vorarlberg (Austria). + */ +class VorarlbergTest extends VorarlbergBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1135); + } + + /** + * Tests if all official holidays in Vorarlberg (Austria) are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'ascensionDay', + 'assumptionOfMary', + 'corpusChristi', + 'easter', + 'easterMonday', + 'epiphany', + 'allSaintsDay', + 'internationalWorkersDay', + 'newYearsDay', + 'pentecostMonday', + 'christmasDay', + 'secondChristmasDay', + 'stJosephsDay', + ]; + + if (1955 <= $this->year) { + $holidays[] = 'nationalDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Vorarlberg (Austria) are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays(['pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Vorarlberg (Austria) are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Vorarlberg (Austria) are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Vorarlberg (Austria) are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Base/HolidayBetweenFilterTest.php b/tests/Base/HolidayBetweenFilterTest.php index 4b0766877..cb2df9c72 100644 --- a/tests/Base/HolidayBetweenFilterTest.php +++ b/tests/Base/HolidayBetweenFilterTest.php @@ -1,152 +1,127 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use DateTime; -use DateTimeImmutable; -use DateTimeZone; -use Exception; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; -use ReflectionException; use Yasumi\tests\YasumiBase; use Yasumi\Yasumi; -/** - * Class HolidayBetweenFilterTest. - * - * Contains tests for testing the BetweenFilter class - */ class HolidayBetweenFilterTest extends TestCase { use YasumiBase; - /** - * Tests the basic usage of the BetweenFilter. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRange(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); $between = $holidays->between( - new DateTime('03/25/2016', new DateTimeZone($timezone)), - new DateTime('07/25/2016', new DateTimeZone($timezone)) + new \DateTime('03/25/2016', new \DateTimeZone($timezone)), + new \DateTime('07/25/2016', new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); - - $this->assertArrayHasKey('goodFriday', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('summerTime', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('kingsDay', $betweenHolidays); - $this->assertArrayHasKey('internationalWorkersDay', $betweenHolidays); - $this->assertArrayHasKey('commemorationDay', $betweenHolidays); - $this->assertArrayHasKey('ascensionDay', $betweenHolidays); - $this->assertArrayHasKey('liberationDay', $betweenHolidays); - $this->assertArrayHasKey('mothersDay', $betweenHolidays); - $this->assertArrayHasKey('pentecost', $betweenHolidays); - $this->assertArrayHasKey('pentecostMonday', $betweenHolidays); - $this->assertArrayHasKey('fathersDay', $betweenHolidays); - - $this->assertArrayNotHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayNotHasKey('epiphany', $betweenHolidays); - $this->assertArrayNotHasKey('carnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondCarnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('thirdCarnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('ashWednesday', $betweenHolidays); - $this->assertArrayNotHasKey('valentinesDay', $betweenHolidays); - $this->assertArrayNotHasKey('princesDay', $betweenHolidays); - $this->assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); - $this->assertArrayNotHasKey('winterTime', $betweenHolidays); - $this->assertArrayNotHasKey('halloween', $betweenHolidays); - $this->assertArrayNotHasKey('stMartinsDay', $betweenHolidays); - $this->assertArrayNotHasKey('stNicholasDay', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); - - $this->assertCount(13, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(13, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + $betweenHolidays = iterator_to_array($between); + + self::assertArrayHasKey('goodFriday', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('kingsDay', $betweenHolidays); + self::assertArrayHasKey('internationalWorkersDay', $betweenHolidays); + self::assertArrayHasKey('commemorationDay', $betweenHolidays); + self::assertArrayHasKey('ascensionDay', $betweenHolidays); + self::assertArrayHasKey('liberationDay', $betweenHolidays); + self::assertArrayHasKey('mothersDay', $betweenHolidays); + self::assertArrayHasKey('pentecost', $betweenHolidays); + self::assertArrayHasKey('pentecostMonday', $betweenHolidays); + self::assertArrayHasKey('fathersDay', $betweenHolidays); + + self::assertArrayNotHasKey('newYearsDay', $betweenHolidays); + self::assertArrayNotHasKey('epiphany', $betweenHolidays); + self::assertArrayNotHasKey('carnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('secondCarnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('thirdCarnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('ashWednesday', $betweenHolidays); + self::assertArrayNotHasKey('valentinesDay', $betweenHolidays); + self::assertArrayNotHasKey('princesDay', $betweenHolidays); + self::assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); + self::assertArrayNotHasKey('halloween', $betweenHolidays); + self::assertArrayNotHasKey('stMartinsDay', $betweenHolidays); + self::assertArrayNotHasKey('stNicholasDay', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); + + self::assertCount(12, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(12, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } - /** - * Tests the basic usage of the BetweenFilter using DateTimeImmutable objects. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRangeWithDateTimeImmutable(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); $between = $holidays->between( - new DateTimeImmutable('03/25/2016', new DateTimeZone($timezone)), - new DateTimeImmutable('07/25/2016', new DateTimeZone($timezone)) + new \DateTimeImmutable('03/25/2016', new \DateTimeZone($timezone)), + new \DateTimeImmutable('07/25/2016', new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); - - $this->assertArrayHasKey('goodFriday', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('summerTime', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('kingsDay', $betweenHolidays); - $this->assertArrayHasKey('internationalWorkersDay', $betweenHolidays); - $this->assertArrayHasKey('commemorationDay', $betweenHolidays); - $this->assertArrayHasKey('ascensionDay', $betweenHolidays); - $this->assertArrayHasKey('liberationDay', $betweenHolidays); - $this->assertArrayHasKey('mothersDay', $betweenHolidays); - $this->assertArrayHasKey('pentecost', $betweenHolidays); - $this->assertArrayHasKey('pentecostMonday', $betweenHolidays); - $this->assertArrayHasKey('fathersDay', $betweenHolidays); - - $this->assertArrayNotHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayNotHasKey('epiphany', $betweenHolidays); - $this->assertArrayNotHasKey('carnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondCarnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('thirdCarnivalDay', $betweenHolidays); - $this->assertArrayNotHasKey('ashWednesday', $betweenHolidays); - $this->assertArrayNotHasKey('valentinesDay', $betweenHolidays); - $this->assertArrayNotHasKey('princesDay', $betweenHolidays); - $this->assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); - $this->assertArrayNotHasKey('winterTime', $betweenHolidays); - $this->assertArrayNotHasKey('halloween', $betweenHolidays); - $this->assertArrayNotHasKey('stMartinsDay', $betweenHolidays); - $this->assertArrayNotHasKey('stNicholasDay', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); - - $this->assertCount(13, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(13, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + $betweenHolidays = iterator_to_array($between); + + self::assertArrayHasKey('goodFriday', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('kingsDay', $betweenHolidays); + self::assertArrayHasKey('internationalWorkersDay', $betweenHolidays); + self::assertArrayHasKey('commemorationDay', $betweenHolidays); + self::assertArrayHasKey('ascensionDay', $betweenHolidays); + self::assertArrayHasKey('liberationDay', $betweenHolidays); + self::assertArrayHasKey('mothersDay', $betweenHolidays); + self::assertArrayHasKey('pentecost', $betweenHolidays); + self::assertArrayHasKey('pentecostMonday', $betweenHolidays); + self::assertArrayHasKey('fathersDay', $betweenHolidays); + + self::assertArrayNotHasKey('newYearsDay', $betweenHolidays); + self::assertArrayNotHasKey('epiphany', $betweenHolidays); + self::assertArrayNotHasKey('carnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('secondCarnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('thirdCarnivalDay', $betweenHolidays); + self::assertArrayNotHasKey('ashWednesday', $betweenHolidays); + self::assertArrayNotHasKey('valentinesDay', $betweenHolidays); + self::assertArrayNotHasKey('princesDay', $betweenHolidays); + self::assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); + self::assertArrayNotHasKey('halloween', $betweenHolidays); + self::assertArrayNotHasKey('stMartinsDay', $betweenHolidays); + self::assertArrayNotHasKey('stNicholasDay', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); + + self::assertCount(12, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(12, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } - /** - * Tests that BetweenFilter considers the date and ignores timezones and time of day. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRangeDifferentTimezone(): void { $holidays = Yasumi::create('Netherlands', 2016); @@ -155,81 +130,69 @@ public function testHolidaysBetweenDateRangeDifferentTimezone(): void foreach ($timezones as $timezone) { $between = $holidays->between( - new DateTime('01/01/2016', new DateTimeZone($timezone)), - new DateTime('01/01/2016', new DateTimeZone($timezone)) + new \DateTime('01/01/2016', new \DateTimeZone($timezone)), + new \DateTime('01/01/2016', new \DateTimeZone($timezone)) ); - $this->assertCount(1, $between); + self::assertCount(1, $between); $between = $holidays->between( - new DateTime('01/01/2016 23:59:59', new DateTimeZone($timezone)), - new DateTime('01/01/2016 23:59:59', new DateTimeZone($timezone)) + new \DateTime('01/01/2016 23:59:59', new \DateTimeZone($timezone)), + new \DateTime('01/01/2016 23:59:59', new \DateTimeZone($timezone)) ); - $this->assertCount(1, $between); + self::assertCount(1, $between); } } - /** - * Tests the BetweenFilter with date range where start and end date are exclusive of the comparison. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRangeExclusiveStartEndDate(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); $between = $holidays->between( - new DateTime('01/01/2016', new DateTimeZone($timezone)), - new DateTime('07/25/2016', new DateTimeZone($timezone)), + new \DateTime('01/01/2016', new \DateTimeZone($timezone)), + new \DateTime('07/25/2016', new \DateTimeZone($timezone)), false ); - $betweenHolidays = \iterator_to_array($between); - - $this->assertArrayHasKey('epiphany', $betweenHolidays); - $this->assertArrayHasKey('carnivalDay', $betweenHolidays); - $this->assertArrayHasKey('secondCarnivalDay', $betweenHolidays); - $this->assertArrayHasKey('thirdCarnivalDay', $betweenHolidays); - $this->assertArrayHasKey('ashWednesday', $betweenHolidays); - $this->assertArrayHasKey('valentinesDay', $betweenHolidays); - $this->assertArrayHasKey('goodFriday', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('summerTime', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('kingsDay', $betweenHolidays); - $this->assertArrayHasKey('internationalWorkersDay', $betweenHolidays); - $this->assertArrayHasKey('commemorationDay', $betweenHolidays); - $this->assertArrayHasKey('ascensionDay', $betweenHolidays); - $this->assertArrayHasKey('liberationDay', $betweenHolidays); - $this->assertArrayHasKey('mothersDay', $betweenHolidays); - $this->assertArrayHasKey('pentecost', $betweenHolidays); - $this->assertArrayHasKey('pentecostMonday', $betweenHolidays); - $this->assertArrayHasKey('fathersDay', $betweenHolidays); - - $this->assertArrayNotHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayNotHasKey('princesDay', $betweenHolidays); - $this->assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); - $this->assertArrayNotHasKey('winterTime', $betweenHolidays); - $this->assertArrayNotHasKey('halloween', $betweenHolidays); - $this->assertArrayNotHasKey('stMartinsDay', $betweenHolidays); - $this->assertArrayNotHasKey('stNicholasDay', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); - - $this->assertCount(19, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(19, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + $betweenHolidays = iterator_to_array($between); + + self::assertArrayHasKey('epiphany', $betweenHolidays); + self::assertArrayHasKey('carnivalDay', $betweenHolidays); + self::assertArrayHasKey('secondCarnivalDay', $betweenHolidays); + self::assertArrayHasKey('thirdCarnivalDay', $betweenHolidays); + self::assertArrayHasKey('ashWednesday', $betweenHolidays); + self::assertArrayHasKey('valentinesDay', $betweenHolidays); + self::assertArrayHasKey('goodFriday', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('kingsDay', $betweenHolidays); + self::assertArrayHasKey('internationalWorkersDay', $betweenHolidays); + self::assertArrayHasKey('commemorationDay', $betweenHolidays); + self::assertArrayHasKey('ascensionDay', $betweenHolidays); + self::assertArrayHasKey('liberationDay', $betweenHolidays); + self::assertArrayHasKey('mothersDay', $betweenHolidays); + self::assertArrayHasKey('pentecost', $betweenHolidays); + self::assertArrayHasKey('pentecostMonday', $betweenHolidays); + self::assertArrayHasKey('fathersDay', $betweenHolidays); + + self::assertArrayNotHasKey('newYearsDay', $betweenHolidays); + self::assertArrayNotHasKey('princesDay', $betweenHolidays); + self::assertArrayNotHasKey('worldAnimalDay', $betweenHolidays); + self::assertArrayNotHasKey('halloween', $betweenHolidays); + self::assertArrayNotHasKey('stMartinsDay', $betweenHolidays); + self::assertArrayNotHasKey('stNicholasDay', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); + + self::assertCount(18, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(18, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } - /** - * Tests the BetweenFilter where the start date lies before the year of the Holiday Provider instance. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRangeWithStartBeforeInstanceYear(): void { $year = 2015; @@ -237,39 +200,34 @@ public function testHolidaysBetweenDateRangeWithStartBeforeInstanceYear(): void $holidays = Yasumi::create('Norway', $year); $between = $holidays->between( - new DateTime('03/25/2011', new DateTimeZone($timezone)), - new DateTime('05/17/' . $year, new DateTimeZone($timezone)) + new \DateTime('03/25/2011', new \DateTimeZone($timezone)), + new \DateTime('05/17/' . $year, new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); - $this->assertArrayHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayHasKey('maundyThursday', $betweenHolidays); - $this->assertArrayHasKey('goodFriday', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('internationalWorkersDay', $betweenHolidays); - $this->assertArrayHasKey('ascensionDay', $betweenHolidays); - $this->assertArrayHasKey('constitutionDay', $betweenHolidays); + self::assertArrayHasKey('newYearsDay', $betweenHolidays); + self::assertArrayHasKey('maundyThursday', $betweenHolidays); + self::assertArrayHasKey('goodFriday', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('internationalWorkersDay', $betweenHolidays); + self::assertArrayHasKey('ascensionDay', $betweenHolidays); + self::assertArrayHasKey('constitutionDay', $betweenHolidays); - $this->assertArrayNotHasKey('pentecost', $betweenHolidays); - $this->assertArrayNotHasKey('pentecostMonday', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); + self::assertArrayNotHasKey('pentecost', $betweenHolidays); + self::assertArrayNotHasKey('pentecostMonday', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('secondChristmasDay', $betweenHolidays); - $this->assertCount(8, $between); - $this->assertNotCount(\count($holidays), $between); + self::assertCount(8, $between); + self::assertNotCount(\count($holidays), $between); - $this->assertEquals(8, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + self::assertEquals(8, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } - /** - * Tests the BetweenFilter where the end date lies beyond the year of the Holiday Provider instance. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testHolidaysBetweenDateRangeWithEndAfterInstanceYear(): void { $year = 2000; @@ -277,50 +235,45 @@ public function testHolidaysBetweenDateRangeWithEndAfterInstanceYear(): void $holidays = Yasumi::create('Italy', $year); $between = $holidays->between( - new DateTime('03/25/' . $year, new DateTimeZone($timezone)), - new DateTime('09/21/2021', new DateTimeZone($timezone)) + new \DateTime('03/25/' . $year, new \DateTimeZone($timezone)), + new \DateTime('09/21/2021', new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); - $this->assertArrayNotHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayNotHasKey('epiphany', $betweenHolidays); + self::assertArrayNotHasKey('newYearsDay', $betweenHolidays); + self::assertArrayNotHasKey('epiphany', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('liberationDay', $betweenHolidays); - $this->assertArrayHasKey('internationalWorkersDay', $betweenHolidays); - $this->assertArrayHasKey('republicDay', $betweenHolidays); - $this->assertArrayHasKey('assumptionOfMary', $betweenHolidays); - $this->assertArrayHasKey('allSaintsDay', $betweenHolidays); - $this->assertArrayHasKey('immaculateConception', $betweenHolidays); - $this->assertArrayHasKey('christmasDay', $betweenHolidays); - $this->assertArrayHasKey('stStephensDay', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('liberationDay', $betweenHolidays); + self::assertArrayHasKey('internationalWorkersDay', $betweenHolidays); + self::assertArrayHasKey('republicDay', $betweenHolidays); + self::assertArrayHasKey('assumptionOfMary', $betweenHolidays); + self::assertArrayHasKey('allSaintsDay', $betweenHolidays); + self::assertArrayHasKey('immaculateConception', $betweenHolidays); + self::assertArrayHasKey('christmasDay', $betweenHolidays); + self::assertArrayHasKey('stStephensDay', $betweenHolidays); - $this->assertCount(10, $between); - $this->assertNotCount(\count($holidays), $between); + self::assertCount(10, $between); + self::assertNotCount(\count($holidays), $between); - $this->assertEquals(10, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + self::assertEquals(10, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } - /** - * Tests that an InvalidArgumentException is thrown in case an invalid holiday provider is given. - * - * @throws Exception - * @throws ReflectionException - */ + /** @throws \Exception */ public function testWrongDates(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $year = 2017; $timezone = 'America/New_York'; $holidays = Yasumi::create('USA', $year); $holidays->between( - new DateTime('12/31/' . $year, new DateTimeZone($timezone)), - new DateTime('01/01/' . $year, new DateTimeZone($timezone)) + new \DateTime('12/31/' . $year, new \DateTimeZone($timezone)), + new \DateTime('01/01/' . $year, new \DateTimeZone($timezone)) ); } @@ -329,8 +282,7 @@ public function testWrongDates(): void * * This test covers the scenario that the requested date range covers all know holidays. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testCountBetweenWithSubstitutes(): void { @@ -340,29 +292,29 @@ public function testCountBetweenWithSubstitutes(): void $holidays = Yasumi::create('Ireland', $year); $between = $holidays->between( - new DateTime('01/01/' . $year, new DateTimeZone($timezone)), - new DateTime('12/31/' . $year, new DateTimeZone($timezone)) + new \DateTime('01/01/' . $year, new \DateTimeZone($timezone)), + new \DateTime('12/31/' . $year, new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); // Assert array definitions - $this->assertArrayHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayHasKey('stPatricksDay', $betweenHolidays); - $this->assertArrayHasKey('easter', $betweenHolidays); - $this->assertArrayHasKey('easterMonday', $betweenHolidays); - $this->assertArrayHasKey('mayDay', $betweenHolidays); - $this->assertArrayHasKey('juneHoliday', $betweenHolidays); - $this->assertArrayHasKey('augustHoliday', $betweenHolidays); - $this->assertArrayHasKey('octoberHoliday', $betweenHolidays); - $this->assertArrayHasKey('christmasDay', $betweenHolidays); - $this->assertArrayHasKey('stStephensDay', $betweenHolidays); - $this->assertArrayHasKey('pentecost', $betweenHolidays); - $this->assertArrayHasKey('goodFriday', $betweenHolidays); - $this->assertArrayNotHasKey('pentecostMonday', $betweenHolidays); - - $this->assertCount(12, $between); - $this->assertEquals(12, $between->count()); + self::assertArrayHasKey('newYearsDay', $betweenHolidays); + self::assertArrayHasKey('stPatricksDay', $betweenHolidays); + self::assertArrayHasKey('easter', $betweenHolidays); + self::assertArrayHasKey('easterMonday', $betweenHolidays); + self::assertArrayHasKey('mayDay', $betweenHolidays); + self::assertArrayHasKey('juneHoliday', $betweenHolidays); + self::assertArrayHasKey('augustHoliday', $betweenHolidays); + self::assertArrayHasKey('octoberHoliday', $betweenHolidays); + self::assertArrayHasKey('christmasDay', $betweenHolidays); + self::assertArrayHasKey('stStephensDay', $betweenHolidays); + self::assertArrayHasKey('pentecost', $betweenHolidays); + self::assertArrayHasKey('goodFriday', $betweenHolidays); + self::assertArrayNotHasKey('pentecostMonday', $betweenHolidays); + + self::assertCount(12, $between); + self::assertEquals(12, $between->count()); } /** @@ -370,8 +322,7 @@ public function testCountBetweenWithSubstitutes(): void * * This test covers the scenario that the requested date range excludes a substituted holiday. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testCountBetweenExcludingSubstituteHoliday(): void { @@ -381,32 +332,32 @@ public function testCountBetweenExcludingSubstituteHoliday(): void $holidays = Yasumi::create('Ireland', $year); $between = $holidays->between( - new DateTime('01/01/' . $year, new DateTimeZone($timezone)), - new DateTime('03/20/' . $year, new DateTimeZone($timezone)) + new \DateTime('01/01/' . $year, new \DateTimeZone($timezone)), + new \DateTime('03/20/' . $year, new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); // Assert array definitions - $this->assertArrayHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayHasKey('stPatricksDay', $betweenHolidays); - $this->assertArrayNotHasKey('mayDay', $betweenHolidays); - $this->assertArrayNotHasKey('juneHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('augustHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('octoberHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('stStephensDay', $betweenHolidays); - $this->assertArrayNotHasKey('pentecost', $betweenHolidays); - $this->assertArrayNotHasKey('goodFriday', $betweenHolidays); - $this->assertArrayNotHasKey('easter', $betweenHolidays); - $this->assertArrayNotHasKey('easterMonday', $betweenHolidays); - $this->assertArrayNotHasKey('pentecostMonday', $betweenHolidays); - - $this->assertCount(2, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(2, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + self::assertArrayHasKey('newYearsDay', $betweenHolidays); + self::assertArrayHasKey('stPatricksDay', $betweenHolidays); + self::assertArrayNotHasKey('mayDay', $betweenHolidays); + self::assertArrayNotHasKey('juneHoliday', $betweenHolidays); + self::assertArrayNotHasKey('augustHoliday', $betweenHolidays); + self::assertArrayNotHasKey('octoberHoliday', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('stStephensDay', $betweenHolidays); + self::assertArrayNotHasKey('pentecost', $betweenHolidays); + self::assertArrayNotHasKey('goodFriday', $betweenHolidays); + self::assertArrayNotHasKey('easter', $betweenHolidays); + self::assertArrayNotHasKey('easterMonday', $betweenHolidays); + self::assertArrayNotHasKey('pentecostMonday', $betweenHolidays); + + self::assertCount(2, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(2, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } /** @@ -415,8 +366,7 @@ public function testCountBetweenExcludingSubstituteHoliday(): void * This test covers the scenario that the requested date range excludes a substituted holiday, but includes * the original substituted holiday. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testCountBetweenExcludingSubstituteHolidayIncludingOriginalHoliday(): void { @@ -426,33 +376,33 @@ public function testCountBetweenExcludingSubstituteHolidayIncludingOriginalHolid $holidays = Yasumi::create('Ireland', $year); $between = $holidays->between( - new DateTime('01/01/' . $year, new DateTimeZone($timezone)), - new DateTime('03/18/' . $year, new DateTimeZone($timezone)) + new \DateTime('01/01/' . $year, new \DateTimeZone($timezone)), + new \DateTime('03/18/' . $year, new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); // Assert array definitions - $this->assertArrayHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayHasKey('stPatricksDay', $betweenHolidays); - $this->assertArrayNotHasKey('easterMonday', $betweenHolidays); - $this->assertArrayNotHasKey('mayDay', $betweenHolidays); - $this->assertArrayNotHasKey('juneHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('augustHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('octoberHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('stStephensDay', $betweenHolidays); - $this->assertArrayNotHasKey('pentecost', $betweenHolidays); - $this->assertArrayNotHasKey('goodFriday', $betweenHolidays); - $this->assertArrayNotHasKey('easter', $betweenHolidays); - $this->assertArrayNotHasKey('easterMonday', $betweenHolidays); - $this->assertArrayNotHasKey('pentecostMonday', $betweenHolidays); - - $this->assertCount(2, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(2, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + self::assertArrayHasKey('newYearsDay', $betweenHolidays); + self::assertArrayHasKey('stPatricksDay', $betweenHolidays); + self::assertArrayNotHasKey('easterMonday', $betweenHolidays); + self::assertArrayNotHasKey('mayDay', $betweenHolidays); + self::assertArrayNotHasKey('juneHoliday', $betweenHolidays); + self::assertArrayNotHasKey('augustHoliday', $betweenHolidays); + self::assertArrayNotHasKey('octoberHoliday', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('stStephensDay', $betweenHolidays); + self::assertArrayNotHasKey('pentecost', $betweenHolidays); + self::assertArrayNotHasKey('goodFriday', $betweenHolidays); + self::assertArrayNotHasKey('easter', $betweenHolidays); + self::assertArrayNotHasKey('easterMonday', $betweenHolidays); + self::assertArrayNotHasKey('pentecostMonday', $betweenHolidays); + + self::assertCount(2, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(2, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } /** @@ -461,8 +411,7 @@ public function testCountBetweenExcludingSubstituteHolidayIncludingOriginalHolid * This test covers the scenario that the requested date range excludes a substituted holiday and also * the original substituted holiday. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testCountBetweenExcludingSubstituteHolidayAndOriginalHoliday(): void { @@ -472,31 +421,31 @@ public function testCountBetweenExcludingSubstituteHolidayAndOriginalHoliday(): $holidays = Yasumi::create('Ireland', $year); $between = $holidays->between( - new DateTime('01/01/' . $year, new DateTimeZone($timezone)), - new DateTime('03/16/' . $year, new DateTimeZone($timezone)) + new \DateTime('01/01/' . $year, new \DateTimeZone($timezone)), + new \DateTime('03/16/' . $year, new \DateTimeZone($timezone)) ); - $betweenHolidays = \iterator_to_array($between); + $betweenHolidays = iterator_to_array($between); // Assert array definitions - $this->assertArrayHasKey('newYearsDay', $betweenHolidays); - $this->assertArrayNotHasKey('stPatricksDay', $betweenHolidays); - $this->assertArrayNotHasKey('mayDay', $betweenHolidays); - $this->assertArrayNotHasKey('juneHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('augustHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('octoberHoliday', $betweenHolidays); - $this->assertArrayNotHasKey('christmasDay', $betweenHolidays); - $this->assertArrayNotHasKey('stStephensDay', $betweenHolidays); - $this->assertArrayNotHasKey('pentecost', $betweenHolidays); - $this->assertArrayNotHasKey('goodFriday', $betweenHolidays); - $this->assertArrayNotHasKey('easter', $betweenHolidays); - $this->assertArrayNotHasKey('easterMonday', $betweenHolidays); - $this->assertArrayNotHasKey('pentecostMonday', $betweenHolidays); - - $this->assertCount(1, $between); - $this->assertNotCount(\count($holidays), $between); - - $this->assertEquals(1, $between->count()); - $this->assertNotEquals(\count($holidays), $between->count()); + self::assertArrayHasKey('newYearsDay', $betweenHolidays); + self::assertArrayNotHasKey('stPatricksDay', $betweenHolidays); + self::assertArrayNotHasKey('mayDay', $betweenHolidays); + self::assertArrayNotHasKey('juneHoliday', $betweenHolidays); + self::assertArrayNotHasKey('augustHoliday', $betweenHolidays); + self::assertArrayNotHasKey('octoberHoliday', $betweenHolidays); + self::assertArrayNotHasKey('christmasDay', $betweenHolidays); + self::assertArrayNotHasKey('stStephensDay', $betweenHolidays); + self::assertArrayNotHasKey('pentecost', $betweenHolidays); + self::assertArrayNotHasKey('goodFriday', $betweenHolidays); + self::assertArrayNotHasKey('easter', $betweenHolidays); + self::assertArrayNotHasKey('easterMonday', $betweenHolidays); + self::assertArrayNotHasKey('pentecostMonday', $betweenHolidays); + + self::assertCount(1, $between); + self::assertNotCount(\count($holidays), $between); + + self::assertEquals(1, $between->count()); + self::assertNotEquals(\count($holidays), $between->count()); } } diff --git a/tests/Base/HolidayFiltersTest.php b/tests/Base/HolidayFiltersTest.php index 22da23fc9..9199d4230 100644 --- a/tests/Base/HolidayFiltersTest.php +++ b/tests/Base/HolidayFiltersTest.php @@ -1,19 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; use PHPUnit\Framework\TestCase; -use ReflectionException; use Yasumi\Filters\BankHolidaysFilter; use Yasumi\Filters\ObservedHolidaysFilter; use Yasumi\Filters\OfficialHolidaysFilter; @@ -22,210 +26,179 @@ use Yasumi\tests\YasumiBase; use Yasumi\Yasumi; -/** - * Class HolidayFiltersTest. - * - * Contains tests for testing the filter classes - */ class HolidayFiltersTest extends TestCase { use YasumiBase; - /** - * Tests the Official Holidays filter - * @throws ReflectionException - */ public function testOfficialHolidaysFilter(): void { // There are 11 official holidays in Ireland in the year 2018, with 1 substituted holiday. $holidays = Yasumi::create('Ireland', 2018); $filteredHolidays = new OfficialHolidaysFilter($holidays->getIterator()); - $filteredHolidaysArray = \iterator_to_array($filteredHolidays); + $filteredHolidaysArray = iterator_to_array($filteredHolidays); // Assert array definitions - $this->assertArrayHasKey('newYearsDay', $filteredHolidaysArray); - $this->assertArrayHasKey('stPatricksDay', $filteredHolidaysArray); - $this->assertArrayHasKey('easter', $filteredHolidaysArray); - $this->assertArrayHasKey('easterMonday', $filteredHolidaysArray); - $this->assertArrayHasKey('mayDay', $filteredHolidaysArray); - $this->assertArrayHasKey('juneHoliday', $filteredHolidaysArray); - $this->assertArrayHasKey('augustHoliday', $filteredHolidaysArray); - $this->assertArrayHasKey('octoberHoliday', $filteredHolidaysArray); - $this->assertArrayHasKey('christmasDay', $filteredHolidaysArray); - $this->assertArrayHasKey('stStephensDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecost', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayHasKey('newYearsDay', $filteredHolidaysArray); + self::assertArrayHasKey('stPatricksDay', $filteredHolidaysArray); + self::assertArrayHasKey('easterMonday', $filteredHolidaysArray); + self::assertArrayHasKey('mayDay', $filteredHolidaysArray); + self::assertArrayHasKey('juneHoliday', $filteredHolidaysArray); + self::assertArrayHasKey('augustHoliday', $filteredHolidaysArray); + self::assertArrayHasKey('octoberHoliday', $filteredHolidaysArray); + self::assertArrayHasKey('christmasDay', $filteredHolidaysArray); + self::assertArrayHasKey('stStephensDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayNotHasKey('easter', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecost', $filteredHolidaysArray); // Assert number of results returned - $this->assertCount(10, $filteredHolidays); - $this->assertNotCount(\count($holidays), $filteredHolidays); - $this->assertEquals(10, $filteredHolidays->count()); - $this->assertNotEquals(\count($holidays), $filteredHolidays->count()); + self::assertCount(9, $filteredHolidays); + self::assertNotCount(\count($holidays), $filteredHolidays); + self::assertEquals(9, $filteredHolidays->count()); + self::assertNotEquals(\count($holidays), $filteredHolidays->count()); } - /** - * Tests the Observed Holidays filter - * @throws ReflectionException - */ public function testObservedHolidaysFilter(): void { // There are 2 observed holidays in Ireland in the year 2018. $holidays = Yasumi::create('Ireland', 2018); $filteredHolidays = new ObservedHolidaysFilter($holidays->getIterator()); - $filteredHolidaysArray = \iterator_to_array($filteredHolidays); + $filteredHolidaysArray = iterator_to_array($filteredHolidays); // Assert array definitions - $this->assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stPatricksDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easter', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('mayDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('juneHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('augustHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('octoberHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stStephensDay', $filteredHolidaysArray); - $this->assertArrayHasKey('pentecost', $filteredHolidaysArray); - $this->assertArrayHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stPatricksDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('mayDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('juneHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('augustHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('octoberHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stStephensDay', $filteredHolidaysArray); + self::assertArrayHasKey('easter', $filteredHolidaysArray); + self::assertArrayHasKey('pentecost', $filteredHolidaysArray); + self::assertArrayHasKey('goodFriday', $filteredHolidaysArray); // Assert number of results returned - $this->assertCount(2, $filteredHolidays); - $this->assertNotCount(\count($holidays), $filteredHolidays); - $this->assertEquals(2, $filteredHolidays->count()); - $this->assertNotEquals(\count($holidays), $filteredHolidays->count()); + self::assertCount(3, $filteredHolidays); + self::assertNotCount(\count($holidays), $filteredHolidays); + self::assertEquals(3, $filteredHolidays->count()); + self::assertNotEquals(\count($holidays), $filteredHolidays->count()); } - /** - * Tests Bank Holidays - * @throws ReflectionException - */ public function testBankHolidaysFilter(): void { // There are no bank holidays in Ireland in the year 2018. $holidays = Yasumi::create('Ireland', 2018); $filteredHolidays = new BankHolidaysFilter($holidays->getIterator()); - $filteredHolidaysArray = \iterator_to_array($filteredHolidays); + $filteredHolidaysArray = iterator_to_array($filteredHolidays); // Assert array definitions - $this->assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stPatricksDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easter', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('mayDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('juneHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('augustHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('octoberHoliday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stStephensDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecost', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stPatricksDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('easter', $filteredHolidaysArray); + self::assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('mayDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('juneHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('augustHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('octoberHoliday', $filteredHolidaysArray); + self::assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stStephensDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecost', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); // Assert number of results returned - $this->assertCount(0, $filteredHolidays); - $this->assertNotCount(\count($holidays), $filteredHolidays); - $this->assertEquals(0, $filteredHolidays->count()); - $this->assertNotEquals(\count($holidays), $filteredHolidays->count()); + self::assertCount(0, $filteredHolidays); + self::assertNotCount(\count($holidays), $filteredHolidays); + self::assertEquals(0, $filteredHolidays->count()); + self::assertNotEquals(\count($holidays), $filteredHolidays->count()); } - /** - * Tests Seasonal Holidays - * @throws ReflectionException - */ public function testSeasonalHolidaysFilter(): void { $holidays = Yasumi::create('Netherlands', 2017); $filteredHolidays = new SeasonalHolidaysFilter($holidays->getIterator()); - $filteredHolidaysArray = \iterator_to_array($filteredHolidays); + $filteredHolidaysArray = iterator_to_array($filteredHolidays); // Assert array definitions - $this->assertArrayHasKey('summerTime', $filteredHolidaysArray); - $this->assertArrayHasKey('winterTime', $filteredHolidaysArray); - $this->assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easter', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('kingsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('ascensionDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecost', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('secondChristmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stMartinsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('ashWednesday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('commemorationDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('liberationDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('halloween', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stNicholasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('carnivalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('secondCarnivalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('thirdCarnivalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('internationalWorkersDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('valentinesDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('worldAnimalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('fathersDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('mothersDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('epiphany', $filteredHolidaysArray); - $this->assertArrayNotHasKey('princesDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('easter', $filteredHolidaysArray); + self::assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('kingsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('ascensionDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecost', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('secondChristmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stMartinsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayNotHasKey('ashWednesday', $filteredHolidaysArray); + self::assertArrayNotHasKey('commemorationDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('liberationDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('halloween', $filteredHolidaysArray); + self::assertArrayNotHasKey('stNicholasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('carnivalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('secondCarnivalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('thirdCarnivalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('internationalWorkersDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('valentinesDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('worldAnimalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('fathersDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('mothersDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('epiphany', $filteredHolidaysArray); + self::assertArrayNotHasKey('princesDay', $filteredHolidaysArray); // Assert number of results returned - $this->assertCount(2, $filteredHolidays); - $this->assertNotCount(\count($holidays), $filteredHolidays); - $this->assertEquals(2, $filteredHolidays->count()); - $this->assertNotEquals(\count($holidays), $filteredHolidays->count()); + self::assertCount(0, $filteredHolidays); + self::assertNotCount(\count($holidays), $filteredHolidays); + self::assertEquals(0, $filteredHolidays->count()); + self::assertNotEquals(\count($holidays), $filteredHolidays->count()); } - /** - * Tests other type of Holidays - * @throws ReflectionException - */ public function testOtherHolidaysFilter(): void { $holidays = Yasumi::create('Netherlands', 2017); $filteredHolidays = new OtherHolidaysFilter($holidays->getIterator()); - $filteredHolidaysArray = \iterator_to_array($filteredHolidays); + $filteredHolidaysArray = iterator_to_array($filteredHolidays); // Assert array definitions - $this->assertArrayHasKey('internationalWorkersDay', $filteredHolidaysArray); - $this->assertArrayHasKey('valentinesDay', $filteredHolidaysArray); - $this->assertArrayHasKey('worldAnimalDay', $filteredHolidaysArray); - $this->assertArrayHasKey('fathersDay', $filteredHolidaysArray); - $this->assertArrayHasKey('mothersDay', $filteredHolidaysArray); - $this->assertArrayHasKey('epiphany', $filteredHolidaysArray); - $this->assertArrayHasKey('princesDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('summerTime', $filteredHolidaysArray); - $this->assertArrayNotHasKey('winterTime', $filteredHolidaysArray); - $this->assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easter', $filteredHolidaysArray); - $this->assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('kingsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('ascensionDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecost', $filteredHolidaysArray); - $this->assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('secondChristmasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stMartinsDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('ashWednesday', $filteredHolidaysArray); - $this->assertArrayNotHasKey('commemorationDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('liberationDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('halloween', $filteredHolidaysArray); - $this->assertArrayNotHasKey('stNicholasDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('carnivalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('secondCarnivalDay', $filteredHolidaysArray); - $this->assertArrayNotHasKey('thirdCarnivalDay', $filteredHolidaysArray); + self::assertArrayHasKey('internationalWorkersDay', $filteredHolidaysArray); + self::assertArrayHasKey('valentinesDay', $filteredHolidaysArray); + self::assertArrayHasKey('worldAnimalDay', $filteredHolidaysArray); + self::assertArrayHasKey('fathersDay', $filteredHolidaysArray); + self::assertArrayHasKey('mothersDay', $filteredHolidaysArray); + self::assertArrayHasKey('epiphany', $filteredHolidaysArray); + self::assertArrayHasKey('princesDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('newYearsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('easter', $filteredHolidaysArray); + self::assertArrayNotHasKey('easterMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('kingsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('ascensionDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecost', $filteredHolidaysArray); + self::assertArrayNotHasKey('pentecostMonday', $filteredHolidaysArray); + self::assertArrayNotHasKey('christmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('secondChristmasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('stMartinsDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('goodFriday', $filteredHolidaysArray); + self::assertArrayNotHasKey('ashWednesday', $filteredHolidaysArray); + self::assertArrayNotHasKey('commemorationDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('liberationDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('halloween', $filteredHolidaysArray); + self::assertArrayNotHasKey('stNicholasDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('carnivalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('secondCarnivalDay', $filteredHolidaysArray); + self::assertArrayNotHasKey('thirdCarnivalDay', $filteredHolidaysArray); // Assert number of results returned - $this->assertCount(7, $filteredHolidays); - $this->assertNotCount(\count($holidays), $filteredHolidays); - $this->assertEquals(7, $filteredHolidays->count()); - $this->assertNotEquals(\count($holidays), $filteredHolidays->count()); + self::assertCount(7, $filteredHolidays); + self::assertNotCount(\count($holidays), $filteredHolidays); + self::assertEquals(7, $filteredHolidays->count()); + self::assertNotEquals(\count($holidays), $filteredHolidays->count()); } } diff --git a/tests/Base/HolidayOnFilterTest.php b/tests/Base/HolidayOnFilterTest.php index b895041bd..bebd43ee5 100644 --- a/tests/Base/HolidayOnFilterTest.php +++ b/tests/Base/HolidayOnFilterTest.php @@ -1,49 +1,39 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use DateTime; -use DateTimeZone; -use Exception; use PHPUnit\Framework\TestCase; -use ReflectionException; use Yasumi\tests\YasumiBase; use Yasumi\Yasumi; -/** - * Class HolidayOnFilterTest. - * - * Contains tests for testing the OnFilter class - */ class HolidayOnFilterTest extends TestCase { use YasumiBase; - /** - * Tests the basic usage of the OnFilter. - * - * @throws ReflectionException - * @throws Exception - */ + /** @throws \Exception */ public function testHolidaysOnDate(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); $holidayDates = [ - 'goodFriday' => new DateTime('03/25/2016', new DateTimeZone($timezone)), - 'easter' => new DateTime('03/27/2016', new DateTimeZone($timezone)), - 'summerTime' => new DateTime('03/27/2016', new DateTimeZone($timezone)), + 'goodFriday' => new \DateTime('03/25/2016', new \DateTimeZone($timezone)), + 'easter' => new \DateTime('03/27/2016', new \DateTimeZone($timezone)), ]; foreach ($holidayDates as $name => $date) { @@ -51,23 +41,19 @@ public function testHolidaysOnDate(): void $date ); - $this->assertArrayHasKey($name, \iterator_to_array($holidaysOnDate)); + self::assertArrayHasKey($name, iterator_to_array($holidaysOnDate)); } } - /** - * @throws ReflectionException - * @throws Exception - */ + /** @throws \Exception */ public function testHolidaysNotOnDate(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); $holidayWrongDates = [ - 'goodFriday' => new DateTime('04/25/2016', new DateTimeZone($timezone)), - 'easter' => new DateTime('03/22/2016', new DateTimeZone($timezone)), - 'summerTime' => new DateTime('12/27/2016', new DateTimeZone($timezone)), + 'goodFriday' => new \DateTime('04/25/2016', new \DateTimeZone($timezone)), + 'easter' => new \DateTime('03/22/2016', new \DateTimeZone($timezone)), ]; foreach ($holidayWrongDates as $name => $date) { @@ -75,29 +61,22 @@ public function testHolidaysNotOnDate(): void $date ); - $this->assertArrayNotHasKey($name, \iterator_to_array($holidaysOnDate)); + self::assertArrayNotHasKey($name, iterator_to_array($holidaysOnDate), sprintf('`%s` should not exist for `%s`', $name, $date->format('Y-m-d'))); } } - /** - * @throws ReflectionException - * @throws Exception - */ + /** @throws \Exception */ public function testCorrectNumberOfHolidaysOnDate(): void { $timezone = 'Europe/Amsterdam'; $holidays = Yasumi::create('Netherlands', 2016); // No holidays - $holidaysOnDate = $holidays->on(new DateTime('11/19/2016', new DateTimeZone($timezone))); - $this->assertEquals(0, $holidaysOnDate->count()); + $holidaysOnDate = $holidays->on(new \DateTime('11/19/2016', new \DateTimeZone($timezone))); + self::assertEquals(0, $holidaysOnDate->count()); // One holiday - $holidaysOnDate = $holidays->on(new DateTime('12/25/2016', new DateTimeZone($timezone))); - $this->assertEquals(1, $holidaysOnDate->count()); - - // Multiple holidays - $holidaysOnDate = $holidays->on(new DateTime('03/27/2016', new DateTimeZone($timezone))); - $this->assertGreaterThan(1, $holidaysOnDate->count()); + $holidaysOnDate = $holidays->on(new \DateTime('12/25/2016', new \DateTimeZone($timezone))); + self::assertEquals(1, $holidaysOnDate->count()); } } diff --git a/tests/Base/HolidayTest.php b/tests/Base/HolidayTest.php index 4a1972051..57ae5e395 100644 --- a/tests/Base/HolidayTest.php +++ b/tests/Base/HolidayTest.php @@ -1,218 +1,212 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use DateTime; -use DateTimeImmutable; -use Exception; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use Yasumi\Exception\MissingTranslationException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; use Yasumi\tests\YasumiBase; use Yasumi\TranslationsInterface; -/** - * Class HolidayTest. - * - * Contains tests for testing the Holiday class - */ class HolidayTest extends TestCase { use YasumiBase; - /** - * Tests that an InvalidArgumentException is thrown in case an blank short name is given. - * - * @throws Exception - */ - public function testHolidayBlankNameInvalidArgumentException(): void + /** @throws \Exception */ + public function testHolidayBlankKeyInvalidArgumentException(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); - new Holiday('', [], new DateTime()); + new Holiday('', [], new \DateTime()); } - /** - * Tests that an Yasumi\Exception\UnknownLocaleException is thrown in case an invalid locale is given. - * - * @throws Exception - */ + /** @throws \Exception */ public function testCreateHolidayUnknownLocaleException(): void { $this->expectException(UnknownLocaleException::class); - new Holiday('testHoliday', [], new DateTime(), 'wx-YZ'); + new Holiday('testHoliday', [], new \DateTime(), 'wx-YZ'); } - /** - * Tests that a Yasumi holiday instance can be serialized to a JSON object. - * @throws Exception - */ + /** @throws \Exception */ public function testHolidayIsJsonSerializable(): void { - $holiday = new Holiday('testHoliday', [], new DateTime(), 'en_US'); - $json = \json_encode($holiday); - $instance = \json_decode($json, true); + $holiday = new Holiday('testHoliday', [], new \DateTime(), 'en_US'); + $json = json_encode($holiday, JSON_THROW_ON_ERROR); + $instance = json_decode($json, true, 512, JSON_THROW_ON_ERROR); - $this->assertIsArray($instance); - $this->assertNotNull($instance); - $this->assertArrayHasKey('shortName', $instance); + self::assertArrayHasKey('shortName', $instance); } - /** - * Tests that a Yasumi holiday instance can be created using an object that implements the DateTimeInterface (e.g. - * DateTime or DateTimeImmutable) - * @throws Exception - */ + /** @throws \Exception */ public function testHolidayWithDateTimeInterface(): void { // Assert with DateTime instance - $holiday = new Holiday('testHoliday', [], new DateTime(), 'en_US'); - $this->assertNotNull($holiday); - $this->assertInstanceOf(Holiday::class, $holiday); + $holiday = new Holiday('testHoliday', [], new \DateTime(), 'en_US'); + self::assertInstanceOf(Holiday::class, $holiday, 'No holiday instance for date with DateTime instance'); // Assert with DateTimeImmutable instance - $holiday = new Holiday('testHoliday', [], new DateTimeImmutable(), 'en_US'); - $this->assertNotNull($holiday); - $this->assertInstanceOf(Holiday::class, $holiday); + $holiday = new Holiday('testHoliday', [], new \DateTimeImmutable(), 'en_US'); + self::assertInstanceOf(Holiday::class, $holiday, 'No holiday instance for date with DateTimeImmutable instance'); } - /** - * Tests the getName function of the Holiday object with no translations for the name given. - * @throws Exception - */ - public function testHolidayGetNameWithNoTranslations(): void + /** @throws \Exception */ + public function testHolidayGetLocales(): void { - $name = 'testHoliday'; - $holiday = new Holiday($name, [], new DateTime(), 'en_US'); + $holiday = new Holiday('testHoliday', [], new \DateTime(), 'ca_ES_VALENCIA'); + $method = new \ReflectionMethod(Holiday::class, 'getLocales'); - $this->assertIsString($holiday->getName()); - $this->assertEquals($name, $holiday->getName()); + self::assertEquals(['ca_ES_VALENCIA', 'ca_ES', 'ca', 'en_US', 'en', Holiday::LOCALE_KEY], $method->invoke($holiday, null)); + self::assertEquals(['de_DE', 'de', 'es_ES', 'es'], $method->invoke($holiday, ['de_DE', 'es_ES'])); + self::assertEquals(['de_DE', 'de', Holiday::LOCALE_KEY], $method->invoke($holiday, ['de_DE', Holiday::LOCALE_KEY])); } - /** - * Tests the getName function of the Holiday object with only a parent translation for the name given. - * @throws Exception - */ - public function testHolidayGetNameWithParentLocaleTranslation(): void + /** @throws \Exception */ + public function testHolidayGetNameWithoutArgument(): void { - $name = 'testHoliday'; - $translation = 'My Holiday'; - $holiday = new Holiday($name, ['de' => $translation], new DateTime(), 'de_DE'); + // 'en_US' fallback + $translations = [ + 'de' => 'Holiday DE', + 'de_AT' => 'Holiday DE-AT', + 'en' => 'Holiday EN', + 'en_US' => 'Holiday EN-US', + ]; - $this->assertIsString($holiday->getName()); - $this->assertEquals($translation, $holiday->getName()); - } + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de_AT'); + self::assertEquals('Holiday DE-AT', $holiday->getName()); - /** - * Tests the getName function of the Holiday object with only a default translation for the name given. - * @throws Exception - */ - public function testHolidayGetNameWithOnlyDefaultTranslation(): void - { - $name = 'testHoliday'; - $translation = 'My Holiday'; - $locale = 'en_US'; - $holiday = new Holiday($name, [$locale => $translation], new DateTime(), $locale); + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de'); + self::assertEquals('Holiday DE', $holiday->getName()); + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de_DE'); + self::assertEquals('Holiday DE', $holiday->getName()); + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'ja'); + self::assertEquals('Holiday EN-US', $holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($translation, $holiday->getName()); + // 'en' fallback + $translations = [ + 'de' => 'Holiday DE', + 'en' => 'Holiday EN', + ]; + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de_DE'); + self::assertEquals('Holiday DE', $holiday->getName()); + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'ja'); + self::assertEquals('Holiday EN', $holiday->getName()); + + // No 'en' or 'en_US' fallback + $translations = [ + 'de' => 'Holiday DE', + ]; + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de_DE'); + self::assertEquals('Holiday DE', $holiday->getName()); + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'ja'); + self::assertEquals('testHoliday', $holiday->getName()); } - /** - * Tests the getName function of the Holiday object with only a default translation for the name given. - * - * @throws Exception - */ - public function testHolidayGetNameWithOneNonDefaultTranslation(): void + /** @throws \Exception */ + public function testHolidayGetNameWithArgument(): void { - $name = 'testHoliday'; - $translation = 'My Holiday'; - $holiday = new Holiday($name, ['en_US' => $translation], new DateTime(), 'nl_NL'); - - $this->assertNotNull($holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($translation, $holiday->getName()); + $translations = [ + 'de' => 'Holiday DE', + 'de_AT' => 'Holiday DE-AT', + 'nl' => 'Holiday NL', + 'it_IT' => 'Holiday IT-IT', + 'en_US' => 'Holiday EN-US', + ]; + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'de_DE'); + + self::assertEquals('Holiday DE', $holiday->getName(['de'])); + self::assertEquals('Holiday DE', $holiday->getName(['ja', 'de', 'nl', 'it_IT'])); + self::assertEquals('Holiday DE', $holiday->getName(['de_DE'])); + self::assertEquals('Holiday DE', $holiday->getName(['de_DE_berlin'])); + self::assertEquals('Holiday DE', $holiday->getName(['de_DE_berlin', 'nl', 'it_IT'])); + self::assertEquals('Holiday DE-AT', $holiday->getName(['de_AT'])); + self::assertEquals('Holiday DE-AT', $holiday->getName(['de_AT_vienna'])); + self::assertEquals('Holiday NL', $holiday->getName(['nl'])); + self::assertEquals('Holiday NL', $holiday->getName(['nl_NL'])); + self::assertEquals('Holiday IT-IT', $holiday->getName(['it_IT'])); + self::assertEquals('Holiday IT-IT', $holiday->getName(['it_IT', Holiday::LOCALE_KEY])); + self::assertEquals('testHoliday', $holiday->getName([Holiday::LOCALE_KEY])); + + $holiday = new Holiday('testHoliday', $translations, new \DateTime(), 'ja'); + self::assertEquals('Holiday EN-US', $holiday->getName()); + + $this->expectException(MissingTranslationException::class); + $holiday->getName(['it']); } - /** - * Tests the getName function of the Holiday object with global translations and no custom translation. - * @throws Exception - */ + /** @throws \Exception */ public function testHolidayGetNameWithGlobalTranslations(): void { - /** @var TranslationsInterface|PHPUnit_Framework_MockObject_MockObject $translationsStub */ $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); $translations = [ - 'en_US' => 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'pl_PL' => 'Nowy Rok', ]; - $translationsStub->expects($this->once())->method('getTranslations')->with($this->equalTo('newYearsDay'))->willReturn($translations); + $translationsStub->expects(self::once())->method('getTranslations')->with(self::equalTo('newYearsDay'))->willReturn($translations); $locale = 'pl_PL'; - $holiday = new Holiday('newYearsDay', [], new DateTime('2015-01-01'), $locale); + $holiday = new Holiday('newYearsDay', [], new \DateTime('2015-01-01'), $locale); $holiday->mergeGlobalTranslations($translationsStub); - $this->assertNotNull($holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($translations[$locale], $holiday->getName()); + self::assertEquals($translations[$locale], $holiday->getName()); } - /** - * Tests the getName function of the Holiday object with global translations and no custom translation. - * @throws Exception - */ + /** @throws \Exception */ public function testHolidayGetNameWithGlobalParentLocaleTranslations(): void { - /** @var TranslationsInterface|PHPUnit_Framework_MockObject_MockObject $translationsStub */ $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); $translations = [ - 'en_US' => 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'pl' => 'Nowy Rok', ]; - $translationsStub->expects($this->once())->method('getTranslations')->with($this->equalTo('newYearsDay'))->willReturn($translations); + $translationsStub->expects(self::once())->method('getTranslations')->with(self::equalTo('newYearsDay'))->willReturn($translations); $locale = 'pl_PL'; - $holiday = new Holiday('newYearsDay', [], new DateTime('2015-01-01'), $locale); + $holiday = new Holiday('newYearsDay', [], new \DateTime('2015-01-01'), $locale); $holiday->mergeGlobalTranslations($translationsStub); - $this->assertNotNull($holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($translations['pl'], $holiday->getName()); + self::assertEquals($translations['pl'], $holiday->getName()); } - /** - * Tests the getName function of the Holiday object with global translations and a new custom translation. - * @throws Exception - */ + /** @throws \Exception */ public function testHolidayGetNameWithGlobalAndCustomTranslations(): void { - /** @var TranslationsInterface|PHPUnit_Framework_MockObject_MockObject $translationsStub */ $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); $translations = [ - 'en_US' => 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'pl_PL' => 'Nowy Rok', ]; - $translationsStub->expects($this->once())->method('getTranslations')->with($this->equalTo('newYearsDay'))->willReturn($translations); + $translationsStub->expects(self::once())->method('getTranslations')->with(self::equalTo('newYearsDay'))->willReturn($translations); $customLocale = 'nl_NL'; $customTranslation = 'Nieuwjaar'; @@ -220,31 +214,25 @@ public function testHolidayGetNameWithGlobalAndCustomTranslations(): void $holiday = new Holiday( 'newYearsDay', [$customLocale => $customTranslation], - new DateTime('2015-01-01'), + new \DateTime('2015-01-01'), $customLocale ); $holiday->mergeGlobalTranslations($translationsStub); - $this->assertNotNull($holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($customTranslation, $holiday->getName()); + self::assertEquals($customTranslation, $holiday->getName()); } - /** - * Tests the getName function of the Holiday object with global translations and an overriding custom translation. - * @throws Exception - */ - public function testHolidayGetNameWithOverridenGlobalTranslations(): void + /** @throws \Exception */ + public function testHolidayGetNameWithOverriddenGlobalTranslations(): void { - /** @var TranslationsInterface|PHPUnit_Framework_MockObject_MockObject $translationsStub */ $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); $translations = [ - 'en_US' => 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'pl_PL' => 'Nowy Rok', ]; - $translationsStub->expects($this->once())->method('getTranslations')->with($this->equalTo('newYearsDay'))->willReturn($translations); + $translationsStub->expects(self::once())->method('getTranslations')->with(self::equalTo('newYearsDay'))->willReturn($translations); $customLocale = 'pl_PL'; $customTranslation = 'Bardzo Nowy Rok'; @@ -252,13 +240,11 @@ public function testHolidayGetNameWithOverridenGlobalTranslations(): void $holiday = new Holiday( 'newYearsDay', [$customLocale => $customTranslation], - new DateTime('2014-01-01'), + new \DateTime('2014-01-01'), $customLocale ); $holiday->mergeGlobalTranslations($translationsStub); - $this->assertNotNull($holiday->getName()); - $this->assertIsString($holiday->getName()); - $this->assertEquals($customTranslation, $holiday->getName()); + self::assertEquals($customTranslation, $holiday->getName()); } } diff --git a/tests/Base/SubstituteHolidayTest.php b/tests/Base/SubstituteHolidayTest.php index 9937835d3..39ebd0be4 100644 --- a/tests/Base/SubstituteHolidayTest.php +++ b/tests/Base/SubstituteHolidayTest.php @@ -1,19 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use DateTime; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; @@ -21,174 +24,227 @@ use Yasumi\tests\YasumiBase; use Yasumi\TranslationsInterface; -/** - * Class SubstituteHolidayTest. - * - * Contains tests for testing the SubstituteHoliday class - */ class SubstituteHolidayTest extends TestCase { use YasumiBase; - /** - * Tests that an UnknownLocaleException is thrown in case an invalid locale is given. - * - * @throws \Exception - */ + /** @throws \Exception */ public function testCreateSubstituteHolidayUnknownLocaleException(): void { - $holiday = new Holiday('testHoliday', [], new DateTime()); + $holiday = new Holiday('testHoliday', [], new \DateTime()); $this->expectException(UnknownLocaleException::class); - new SubstituteHoliday($holiday, [], new DateTime(), 'wx-YZ'); + new SubstituteHoliday($holiday, [], new \DateTime(), 'wx-YZ'); } /** * Tests that an InvalidArgumentException is thrown in case the substitute is on the same date as the substituted. + * * @throws \Exception */ public function testCreateSubstituteHolidaySameDate(): void { - $holiday = new Holiday('testHoliday', [], new DateTime('2019-01-01')); + $holiday = new Holiday('testHoliday', [], new \DateTime('2019-01-01')); - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); - new SubstituteHoliday($holiday, [], new DateTime('2019-01-01')); + new SubstituteHoliday($holiday, [], new \DateTime('2019-01-01')); } - /** - * Tests the constructor. - * - * @throws \Exception - */ + /** @throws \Exception */ public function testConstructor(): void { - $holiday = new Holiday('testHoliday', [], new DateTime('2019-01-01'), 'en_US', Holiday::TYPE_BANK); - $substitute = new SubstituteHoliday($holiday, [], new DateTime('2019-01-02'), 'en_US', Holiday::TYPE_SEASON); + $holiday = new Holiday('testHoliday', [], new \DateTime('2019-01-01'), 'en_US', Holiday::TYPE_BANK); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), 'en_US', Holiday::TYPE_SEASON); - $this->assertSame($holiday, $substitute->substitutedHoliday); - $this->assertEquals('substituteHoliday:testHoliday', $substitute->shortName); - $this->assertEquals(Holiday::TYPE_SEASON, $substitute->getType()); - $this->assertEquals(new DateTime('2019-01-02'), $substitute); + self::assertSame($holiday, $substitute->getSubstitutedHoliday()); + self::assertEquals('substituteHoliday:testHoliday', $substitute->getKey()); + self::assertEquals(Holiday::TYPE_SEASON, $substitute->getType()); + $this->assertDateTime(new \DateTime('2019-01-02'), $substitute); } - /** - * Tests that a Yasumi holiday instance can be serialized to a JSON object. - * @throws \Exception - */ + /** @throws \Exception */ public function testSubstituteHolidayIsJsonSerializable(): void { - $holiday = new Holiday('testHoliday', [], new DateTime('2019-01-01'), 'en_US'); - $substitute = new SubstituteHoliday($holiday, [], new DateTime('2019-01-02'), 'en_US'); - $json = \json_encode($substitute); - $instance = \json_decode($json, true); - - $this->assertIsArray($instance); - $this->assertNotNull($instance); - $this->assertArrayHasKey('shortName', $instance); - $this->assertArrayHasKey('substitutedHoliday', $instance); + $holiday = new Holiday('testHoliday', [], new \DateTime('2019-01-01'), 'en_US'); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), 'en_US'); + $json = json_encode($substitute, JSON_THROW_ON_ERROR); + $instance = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + + self::assertArrayHasKey('shortName', $instance); + self::assertArrayHasKey('substitutedHoliday', $instance); } - /** - * Tests that a Yasumi holiday instance can be created using an object that implements the DateTimeInterface (e.g. - * DateTime or DateTimeImmutable) - * @throws \Exception - */ + /** @throws \Exception */ public function testSubstituteHolidayWithDateTimeInterface(): void { // Assert with DateTime instance - $holiday = new Holiday('testHoliday', [], new DateTime('2019-01-01'), 'en_US'); - $substitute = new SubstituteHoliday($holiday, [], new DateTime('2019-01-02'), 'en_US'); - $this->assertNotNull($holiday); - $this->assertInstanceOf(SubstituteHoliday::class, $substitute); + $holiday = new Holiday('testHoliday', [], new \DateTime('2019-01-01'), 'en_US'); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), 'en_US'); + self::assertInstanceOf(SubstituteHoliday::class, $substitute, 'No substitute holiday instance on 2019-01-02'); // Assert with DateTimeImmutable instance $substitute = new SubstituteHoliday($holiday, [], new \DateTimeImmutable(), 'en_US'); - $this->assertNotNull($holiday); - $this->assertInstanceOf(SubstituteHoliday::class, $substitute); + self::assertInstanceOf(SubstituteHoliday::class, $substitute, 'No substitute holiday with DateTimeImmutable date'); } - /** - * Tests the getName function of the SubstituteHoliday object with no translations for the name given. - * @throws \Exception - */ + /** @throws \Exception */ public function testSubstituteHolidayGetNameWithNoTranslations(): void { $name = 'testHoliday'; - $holiday = new Holiday($name, [], new DateTime('2019-01-01')); - $substitute = new SubstituteHoliday($holiday, [], new DateTime('2019-01-02'), 'en_US'); + $holiday = new Holiday($name, [], new \DateTime('2019-01-01')); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), 'en_US'); - $this->assertIsString($substitute->getName()); - $this->assertEquals('substituteHoliday:' . $name, $substitute->getName()); + self::assertIsString($substitute->getName()); + self::assertEquals('substituteHoliday:' . $name, $substitute->getName()); } - /** - * Tests the getName function of the SubstituteHoliday object when it has a custom translation. - * @throws \Exception - */ + /** @throws \Exception */ public function testSubstituteHolidayGetNameWithCustomSubstituteTranslation(): void { - $name = 'testHoliday'; + $name = 'testHoliday'; $translation = 'My Holiday'; - $locale = 'en_US'; - $holiday = new Holiday($name, [$locale => 'foo'], new DateTime('2019-01-01'), $locale); - $substitute = new SubstituteHoliday($holiday, [$locale => $translation], new DateTime('2019-01-02'), $locale); + $locale = 'en_US'; + $holiday = new Holiday($name, [$locale => 'foo'], new \DateTime('2019-01-01'), $locale); + $substitute = new SubstituteHoliday($holiday, [$locale => $translation], new \DateTime('2019-01-02'), $locale); $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); - $translationsStub->expects($this->at(0))->method('getTranslations')->with($this->equalTo('substituteHoliday'))->willReturn([$locale => 'foo']); - $translationsStub->expects($this->at(1))->method('getTranslations')->with($this->equalTo('substituteHoliday:testHoliday'))->willReturn([$locale => 'foo']); - $translationsStub->expects($this->at(2))->method('getTranslations')->with($this->equalTo('testHoliday'))->willReturn([$locale => 'foo']); + $matcher = self::exactly(3); + $translationsStub + ->expects($matcher) + ->method('getTranslations')->willReturnCallback(function (...$parameters) use ($matcher, $locale) { + if (1 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday', $parameters[0]); + + return [$locale => 'foo']; + } + if (2 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday:testHoliday', $parameters[0]); + + return [$locale => 'foo']; + } + if (3 === $matcher->numberOfInvocations()) { + self::assertSame('testHoliday', $parameters[0]); + + return ['en' => 'foo']; + } + }); $substitute->mergeGlobalTranslations($translationsStub); - $this->assertIsString($substitute->getName()); - $this->assertEquals($translation, $substitute->getName()); + self::assertIsString($substitute->getName()); + self::assertEquals($translation, $substitute->getName()); } - /** - * Tests the getName function of the SubstituteHoliday object when it has a global translation. - * @throws \Exception - */ + /** @throws \Exception */ + public function testSubstituteHolidayGetNameWithPatternFallback(): void + { + $name = 'testHoliday'; + $translation = 'My Holiday'; + $locale = 'en_US'; + $holiday = new Holiday($name, [], new \DateTime('2019-01-01'), $locale); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), $locale); + + $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); + $matcher = self::exactly(3); + $translationsStub + ->expects($matcher) + ->method('getTranslations')->willReturnCallback(function (...$parameters) use ($matcher, $locale, $translation) { + if (1 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday', $parameters[0]); + + return ['en' => '{0} obs']; + } + if (2 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday:testHoliday', $parameters[0]); + + return []; + } + if (3 === $matcher->numberOfInvocations()) { + self::assertSame('testHoliday', $parameters[0]); + + return [$locale => $translation]; + } + }); + + $substitute->mergeGlobalTranslations($translationsStub); + + self::assertIsString($substitute->getName()); + self::assertEquals('My Holiday obs', $substitute->getName()); + } + + /** @throws \Exception */ public function testSubstituteHolidayGetNameWithGlobalSubstituteTranslation(): void { - $name = 'testHoliday'; + $name = 'testHoliday'; $translation = 'My Substitute'; - $locale = 'en_US'; - $holiday = new Holiday($name, [$locale => 'foo'], new DateTime('2019-01-01'), $locale); - $substitute = new SubstituteHoliday($holiday, [$locale => $translation], new DateTime('2019-01-02'), $locale); + $locale = 'en_US'; + $holiday = new Holiday($name, [$locale => 'foo'], new \DateTime('2019-01-01'), $locale); + $substitute = new SubstituteHoliday($holiday, [$locale => $translation], new \DateTime('2019-01-02'), $locale); $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); - $translationsStub->expects($this->at(0))->method('getTranslations')->with($this->equalTo('substituteHoliday'))->willReturn([$locale => '{0} observed']); - $translationsStub->expects($this->at(1))->method('getTranslations')->with($this->equalTo('substituteHoliday:testHoliday'))->willReturn([$locale => $translation]); - $translationsStub->expects($this->at(2))->method('getTranslations')->with($this->equalTo('testHoliday'))->willReturn([$locale => 'foo']); + $matcher = self::exactly(3); + $translationsStub + ->expects($matcher) + ->method('getTranslations')->willReturnCallback(function (...$parameters) use ($matcher, $locale, $translation) { + if (1 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday', $parameters[0]); + + return [$locale => '{0} observed']; + } + if (2 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday:testHoliday', $parameters[0]); + + return [$locale => $translation]; + } + if (3 === $matcher->numberOfInvocations()) { + self::assertSame('testHoliday', $parameters[0]); + + return [$locale => 'foo']; + } + }); $substitute->mergeGlobalTranslations($translationsStub); - $this->assertIsString($substitute->getName()); - $this->assertEquals($translation, $substitute->getName()); + self::assertIsString($substitute->getName()); + self::assertEquals($translation, $substitute->getName()); } - /** - * Tests the getName function of the SubstituteHoliday object when only the substituted holiday has a translation. - * @throws \Exception - */ + /** @throws \Exception */ public function testSubstituteHolidayGetNameWithSubstitutedTranslation(): void { - $name = 'testHoliday'; + $name = 'testHoliday'; $translation = 'My Holiday'; - $locale = 'en_US'; - $holiday = new Holiday($name, [$locale => $translation], new DateTime('2019-01-01'), $locale); - $substitute = new SubstituteHoliday($holiday, [], new DateTime('2019-01-02'), $locale); + $locale = 'en_US'; + $holiday = new Holiday($name, [$locale => $translation], new \DateTime('2019-01-01'), $locale); + $substitute = new SubstituteHoliday($holiday, [], new \DateTime('2019-01-02'), $locale); $translationsStub = $this->getMockBuilder(TranslationsInterface::class)->getMock(); - $translationsStub->expects($this->at(0))->method('getTranslations')->with($this->equalTo('substituteHoliday'))->willReturn([$locale => '{0} observed']); - $translationsStub->expects($this->at(1))->method('getTranslations')->with($this->equalTo('substituteHoliday:testHoliday'))->willReturn([]); - $translationsStub->expects($this->at(2))->method('getTranslations')->with($this->equalTo('testHoliday'))->willReturn([$locale => $translation]); + $matcher = self::exactly(3); + $translationsStub + ->expects($matcher) + ->method('getTranslations')->willReturnCallback(function (...$parameters) use ($matcher, $locale, $translation) { + if (1 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday', $parameters[0]); + + return [$locale => '{0} observed']; + } + if (2 === $matcher->numberOfInvocations()) { + self::assertSame('substituteHoliday:testHoliday', $parameters[0]); + + return []; + } + if (3 === $matcher->numberOfInvocations()) { + self::assertSame('testHoliday', $parameters[0]); + + return [$locale => $translation]; + } + }); $substitute->mergeGlobalTranslations($translationsStub); - $this->assertIsString($substitute->getName()); - $this->assertEquals('My Holiday observed', $substitute->getName()); + self::assertIsString($substitute->getName()); + self::assertEquals('My Holiday observed', $substitute->getName()); } } diff --git a/tests/Base/TranslationsTest.php b/tests/Base/TranslationsTest.php index 77c983ea1..e45c46cfd 100644 --- a/tests/Base/TranslationsTest.php +++ b/tests/Base/TranslationsTest.php @@ -1,28 +1,27 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use InvalidArgumentException; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Translations; -/** - * Class TranslationsTest. - * - * Contains tests for testing the Translations class - */ class TranslationsTest extends TestCase { public const LOCALES = [ @@ -31,88 +30,58 @@ class TranslationsTest extends TestCase 'pl_PL', ]; - /** - * Tests adding single translation. - */ public function testAddTranslation(): void { $translations = new Translations(self::LOCALES); $locale = 'en_US'; - $shortName = 'newYearsDay'; - $translation = 'New Year\'s Day'; - - $this->assertNull($translations->getTranslation($shortName, $locale)); - $this->assertEmpty($translations->getTranslations($shortName)); + $key = 'newYearsDay'; + $translation = 'New Year’s Day'; - $translations->addTranslation($shortName, $locale, $translation); + self::assertNull($translations->getTranslation($key, $locale)); + self::assertEmpty($translations->getTranslations($key)); - $this->assertNotNull($translations->getTranslations($shortName)); - $this->assertNotEmpty($translations->getTranslations($shortName)); - $this->assertEquals([$locale => $translation], $translations->getTranslations($shortName)); + $translations->addTranslation($key, $locale, $translation); - $this->assertNotNull($translations->getTranslation($shortName, $locale)); - $this->assertIsString($translations->getTranslation($shortName, $locale)); - $this->assertEquals($translation, $translations->getTranslation($shortName, $locale)); + self::assertEquals([$locale => $translation], $translations->getTranslations($key)); + self::assertEquals($translation, $translations->getTranslation($key, $locale)); } - /** - * Tests adding multiple translations. - */ public function testAddMultipleTranslations(): void { $translations = new Translations(self::LOCALES); $firstLocale = 'en_US'; - $firstShortName = 'newYearsDay'; - $firstTranslation = 'New Year\'s Day'; - - $translations->addTranslation($firstShortName, $firstLocale, $firstTranslation); + $firstIdentifier = 'newYearsDay'; + $firstTranslation = 'New Year’s Day'; - $this->assertNotNull($translations->getTranslations($firstShortName)); - $this->assertNotEmpty($translations->getTranslations($firstShortName)); - $this->assertEquals([$firstLocale => $firstTranslation], $translations->getTranslations($firstShortName)); + $translations->addTranslation($firstIdentifier, $firstLocale, $firstTranslation); - $this->assertNotNull($translations->getTranslation($firstShortName, $firstLocale)); - $this->assertIsString($translations->getTranslation($firstShortName, $firstLocale)); - $this->assertEquals($firstTranslation, $translations->getTranslation($firstShortName, $firstLocale)); + self::assertEquals([$firstLocale => $firstTranslation], $translations->getTranslations($firstIdentifier)); + self::assertEquals($firstTranslation, $translations->getTranslation($firstIdentifier, $firstLocale)); $secondLocale = 'nl_NL'; - $secondShortName = 'easter'; + $secondIdentifier = 'easter'; $secondTranslation = 'Eerste paasdag'; - $translations->addTranslation($secondShortName, $secondLocale, $secondTranslation); + $translations->addTranslation($secondIdentifier, $secondLocale, $secondTranslation); - $this->assertNotNull($translations->getTranslations($secondShortName)); - $this->assertNotEmpty($translations->getTranslations($secondShortName)); - $this->assertEquals([$secondLocale => $secondTranslation], $translations->getTranslations($secondShortName)); - - $this->assertNotNull($translations->getTranslation($secondShortName, $secondLocale)); - $this->assertIsString($translations->getTranslation($secondShortName, $secondLocale)); - $this->assertEquals($secondTranslation, $translations->getTranslation($secondShortName, $secondLocale)); + self::assertEquals([$secondLocale => $secondTranslation], $translations->getTranslations($secondIdentifier)); + self::assertEquals($secondTranslation, $translations->getTranslation($secondIdentifier, $secondLocale)); $thirdLocale = 'en_US'; - $thirdShortName = 'easter'; + $thirdIdentifier = 'easter'; $thirdTranslation = 'Easter Sunday'; - $translations->addTranslation($thirdShortName, $thirdLocale, $thirdTranslation); + $translations->addTranslation($thirdIdentifier, $thirdLocale, $thirdTranslation); - $this->assertNotNull($translations->getTranslations($thirdShortName)); - $this->assertNotEmpty($translations->getTranslations($thirdShortName)); - $this->assertEquals( + self::assertEquals( [$thirdLocale => $thirdTranslation, $secondLocale => $secondTranslation], - $translations->getTranslations($thirdShortName) + $translations->getTranslations($thirdIdentifier) ); - - $this->assertNotNull($translations->getTranslation($thirdShortName, $thirdLocale)); - $this->assertIsString($translations->getTranslation($thirdShortName, $thirdLocale)); - $this->assertEquals($thirdTranslation, $translations->getTranslation($thirdShortName, $thirdLocale)); + self::assertEquals($thirdTranslation, $translations->getTranslation($thirdIdentifier, $thirdLocale)); } - /** - * Tests that an UnknownLocaleException is thrown when adding translation for unknown locale. - * - */ public function testAddTranslationUnknownLocaleException(): void { $this->expectException(UnknownLocaleException::class); @@ -120,132 +89,109 @@ public function testAddTranslationUnknownLocaleException(): void $translations = new Translations(self::LOCALES); $unknownLocale = 'en_XY'; - $shortName = 'newYearsDay'; - $translation = 'New Year\'s Day'; + $key = 'newYearsDay'; + $translation = 'New Year’s Day'; - $translations->addTranslation($shortName, $unknownLocale, $translation); + $translations->addTranslation($key, $unknownLocale, $translation); } - /** - * Tests that no translation is returned for an unknown holiday. - */ public function testNoTranslationForUnknownHoliday(): void { $translations = new Translations(self::LOCALES); $locale = 'en_US'; - $shortName = 'newYearsDay'; - $translation = 'New Year\'s Day'; + $key = 'newYearsDay'; + $translation = 'New Year’s Day'; - $unknownShortName = 'unknownHoliday'; + $unknownIdentifier = 'unknownHoliday'; - $translations->addTranslation($shortName, $locale, $translation); + $translations->addTranslation($key, $locale, $translation); - $this->assertNull($translations->getTranslation($unknownShortName, $locale)); - $this->assertEmpty($translations->getTranslations($unknownShortName)); + self::assertNull($translations->getTranslation($unknownIdentifier, $locale)); + self::assertEmpty($translations->getTranslations($unknownIdentifier)); } - /** - * Tests that no translation is returned for not translated locale. - */ public function testNoTranslationForNotTranslatedLocale(): void { $translations = new Translations(self::LOCALES); $locale = 'en_US'; - $shortName = 'newYearsDay'; - $translation = 'New Year\'s Day'; + $key = 'newYearsDay'; + $translation = 'New Year’s Day'; $unknownLocale = 'pl_PL'; - $translations->addTranslation($shortName, $locale, $translation); + $translations->addTranslation($key, $locale, $translation); - $this->assertNull($translations->getTranslation($shortName, $unknownLocale)); + self::assertNull($translations->getTranslation($key, $unknownLocale)); } - /** - * Tests loading one translation file from directory. - */ public function testLoadingTranslationsFromDirectory(): void { - $shortName = 'newYearsDay'; + $key = 'newYearsDay'; $fileContents = <<<'FILE' 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'nl_NL' => 'Nieuwjaar', 'pl_PL' => 'Nowy Rok', ]; FILE; - vfsStream::setup('root', null, ['lang' => [$shortName . '.php' => $fileContents]]); + vfsStream::setup('root', null, ['lang' => [$key . '.php' => $fileContents]]); $translations = new Translations(self::LOCALES); $translations->loadTranslations(vfsStream::url('root/lang')); $locale = 'en_US'; - $translation = 'New Year\'s Day'; + $translation = 'New Year’s Day'; - $this->assertNotNull($translations->getTranslations($shortName)); - $this->assertNotEmpty($translations->getTranslations($shortName)); - $this->assertIsString($translations->getTranslation($shortName, $locale)); - $this->assertEquals($translation, $translations->getTranslation($shortName, $locale)); + self::assertEquals($translation, $translations->getTranslation($key, $locale)); } - /** - * Tests that translation is not loaded from file with invalid extension. - */ public function testNotLoadingTranslationsFromFileWithInvalidExtension(): void { - $shortName = 'newYearsDay'; + $key = 'newYearsDay'; $fileContents = <<<'FILE' 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'nl_NL' => 'Nieuwjaar', 'pl_PL' => 'Nowy Rok', ]; FILE; - vfsStream::setup('root', null, ['lang' => [$shortName . '.translation' => $fileContents]]); + vfsStream::setup('root', null, ['lang' => [$key . '.translation' => $fileContents]]); $translations = new Translations(self::LOCALES); $translations->loadTranslations(vfsStream::url('root/lang')); - $this->assertNotNull($translations->getTranslations($shortName)); - $this->assertEmpty($translations->getTranslations($shortName)); + self::assertNotNull($translations->getTranslations($key)); + self::assertEmpty($translations->getTranslations($key)); } - /** - * Tests that an UnknownLocaleException is thrown when loading translation with unknown locale(s). - * - */ public function testLoadingTranslationsFromDirectoryWithUnknownLocaleException(): void { $this->expectException(UnknownLocaleException::class); - $shortName = 'newYearsDay'; + $key = 'newYearsDay'; $fileContents = <<<'FILE' 'New Year\'s Day', + 'en_XY' => 'New Year’s Day', 'nl_NL' => 'Nieuwjaar', ]; FILE; - vfsStream::setup('root', null, ['lang' => [$shortName . '.php' => $fileContents]]); + vfsStream::setup('root', null, ['lang' => [$key . '.php' => $fileContents]]); $translations = new Translations(self::LOCALES); $translations->loadTranslations(vfsStream::url('root/lang')); } - /** - * Tests that an InvalidArgumentException is thrown when loading translation from inexistent directory. - * - */ public function testLoadingTranslationsFromInexistentDirectory(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); vfsStream::setup(); @@ -253,22 +199,19 @@ public function testLoadingTranslationsFromInexistentDirectory(): void $translations->loadTranslations(vfsStream::url('root/lang')); } - /** - * Tests loading more than one translation file from directory. - */ public function testLoadingMultipleTranslationsFromDirectory(): void { - $firstShortName = 'newYearsDay'; + $firstIdentifier = 'newYearsDay'; $firstFileContents = <<<'FILE' 'New Year\'s Day', + 'en_US' => 'New Year’s Day', 'nl_NL' => 'Nieuwjaar', 'pl_PL' => 'Nowy Rok', ]; FILE; - $secondShortName = 'easter'; + $secondIdentifier = 'easter'; $secondFileContents = <<<'FILE' [ - $firstShortName . '.php' => $firstFileContents, - $secondShortName . '.php' => $secondFileContents, + $firstIdentifier . '.php' => $firstFileContents, + $secondIdentifier . '.php' => $secondFileContents, ], ]); @@ -289,19 +232,13 @@ public function testLoadingMultipleTranslationsFromDirectory(): void $translations->loadTranslations(vfsStream::url('root/lang')); $locale = 'en_US'; - $translation = 'New Year\'s Day'; + $translation = 'New Year’s Day'; - $this->assertNotNull($translations->getTranslations($firstShortName)); - $this->assertNotEmpty($translations->getTranslations($firstShortName)); - $this->assertIsString($translations->getTranslation($firstShortName, $locale)); - $this->assertEquals($translation, $translations->getTranslation($firstShortName, $locale)); + self::assertEquals($translation, $translations->getTranslation($firstIdentifier, $locale)); $locale = 'nl_NL'; $translation = 'Eerste Paasdag'; - $this->assertNotNull($translations->getTranslations($secondShortName)); - $this->assertNotEmpty($translations->getTranslations($secondShortName)); - $this->assertIsString($translations->getTranslation($secondShortName, $locale)); - $this->assertEquals($translation, $translations->getTranslation($secondShortName, $locale)); + self::assertEquals($translation, $translations->getTranslation($secondIdentifier, $locale)); } } diff --git a/tests/Base/TypographyTest.php b/tests/Base/TypographyTest.php new file mode 100644 index 000000000..a233b3f20 --- /dev/null +++ b/tests/Base/TypographyTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Base; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; +use Yasumi\Yasumi; + +/** + * Class TypographyTest. + * + * Verifies that translations uses typographic apostrophe (’) and quotation marks (“ ”) + * rather than their typewriter versions (' and "). + * + * @see https://en.wikipedia.org/wiki/Apostrophe + * @see https://en.wikipedia.org/wiki/Quotation_mark + */ +class TypographyTest extends TestCase +{ + use YasumiBase; + + /** + * @param string $name The localized holiday name + * @param string $class The provider + * @param string $key The holiday key + * @param string $locale The locale + */ + #[\PHPUnit\Framework\Attributes\DataProvider('translationProvider')] + public function testTranslations(string $name, string $class, string $key, string $locale): void + { + self::assertStringNotContainsString("'", $name, 'Translation contains typewriter apostrophe'); + self::assertStringNotContainsString('"', $name, 'Translation contains typewriter quote'); + } + + /** + * Provides test data for testProvider(). + * + * @return array list of test translations + * + * @throws \ReflectionException + * @throws \Exception + */ + public static function translationProvider(): array + { + $classes = Yasumi::getProviders(); + + $tests = []; + + foreach ($classes as $class) { + $provider = Yasumi::create($class, static::generateRandomYear()); + + foreach ($provider->getHolidays() as $holiday) { + foreach ($holiday->translations as $locale => $name) { + $tests[$name] = [$name, $class, $holiday->getKey(), $locale]; + } + } + } + + return array_values($tests); + } +} diff --git a/tests/Base/WeekendTest.php b/tests/Base/WeekendTest.php new file mode 100644 index 000000000..5acadfd24 --- /dev/null +++ b/tests/Base/WeekendTest.php @@ -0,0 +1,110 @@ + + */ + +namespace Yasumi\tests\Base; + +use PHPUnit\Framework\TestCase; +use Yasumi\Yasumi; + +/** + * Class containing various tests pertaining to the determination of a date + * being a weekend (i.e. non-working day) or not. + */ +class WeekendTest extends TestCase +{ + private const HOLIDAY_PROVIDER = 'Belgium'; + + /** + * Tests that the isWeekendDay function correctly assesses that the given date falls into the + * weekend. + * + * Note: this test uses Belgium as a representative country for the global, common weekend definition. + * Tests for countries that deviate from the global definition will be added as soon as their respective + * Holiday Provider is created. + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderWeekendDays')] + public function testWeekendDay(\DateTimeImmutable $date): void + { + $yasumiProvider = Yasumi::create(self::HOLIDAY_PROVIDER, (int) $date->format('Y')); + $isWeekendDay = $yasumiProvider->isWeekendDay($date); + + self::assertTrue($isWeekendDay); + } + + /** + * @return array list of test dates that are considered a weekend date + * + * @throws \Exception + */ + public static function dataProviderWeekendDays(): array + { + return [ + [ + new \DateTimeImmutable('2020-04-19'), + ], + [ + new \DateTimeImmutable('2019-12-29'), + ], + [ + new \DateTimeImmutable('2019-12-28'), + ], + [ + new \DateTimeImmutable('2018-06-16'), + ], + ]; + } + + /** + * Tests that the isWeekendDay function correctly assesses that the given date does not + * fall into the weekend. + * + * Note: this test uses Belgium as a representative country for the global, common weekend definition. + * Tests for countries that deviate from the global definition will be added as soon as their respective + * Holiday Provider is created. + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderNonWeekendDays')] + public function testNonWeekendDay(\DateTimeImmutable $date): void + { + $yasumiProvider = Yasumi::create(self::HOLIDAY_PROVIDER, (int) $date->format('Y')); + $isWeekendDay = $yasumiProvider->isWeekendDay($date); + + self::assertFalse($isWeekendDay); + } + + /** + * @return array list of test dates that are considered not a weekend date + * + * @throws \Exception + */ + public static function dataProviderNonWeekendDays(): array + { + return [ + [ + new \DateTimeImmutable('2020-04-20'), + ], + [ + new \DateTimeImmutable('2019-12-30'), + ], + [ + new \DateTimeImmutable('2019-12-27'), + ], + [ + new \DateTimeImmutable('2018-06-15'), + ], + ]; + } +} diff --git a/tests/Base/YasumiExternalProvider.php b/tests/Base/YasumiExternalProvider.php index 2dccb5642..ebdb4f243 100644 --- a/tests/Base/YasumiExternalProvider.php +++ b/tests/Base/YasumiExternalProvider.php @@ -1,31 +1,33 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use Yasumi\ProviderInterface; +use Yasumi\Provider\AbstractProvider; -/** - * Class YasumiExternalProvider. - * - * Class for testing the use of an external holiday provider class. - */ -class YasumiExternalProvider implements ProviderInterface +class YasumiExternalProvider extends AbstractProvider { - /** - * Initialize country holidays. - */ public function initialize(): void { // We don't actually have to do anything here. } + + public function getSources(): array + { + return []; + } } diff --git a/tests/Base/YasumiTest.php b/tests/Base/YasumiTest.php index f65159114..f39b35231 100644 --- a/tests/Base/YasumiTest.php +++ b/tests/Base/YasumiTest.php @@ -1,59 +1,38 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Base; -use ArrayIterator; -use DateTime; -use DateTimeImmutable; -use Exception; -use Faker\Factory; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; -use ReflectionException; -use stdClass; -use TypeError; use Yasumi\Exception\InvalidYearException; use Yasumi\Exception\ProviderNotFoundException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; -use Yasumi\Provider\AbstractProvider; use Yasumi\tests\YasumiBase; use Yasumi\Yasumi; -/** - * Class YasumiTest. - * - * Contains tests for testing the Holiday class - */ class YasumiTest extends TestCase { use YasumiBase; - /** - * The lower year limit supported by Yasumi - */ public const YEAR_LOWER_BOUND = 1000; - /** - * The upper year limit supported by Yasumi - */ public const YEAR_UPPER_BOUND = 9999; - /** - * Tests that an InvalidArgumentException is thrown in case an invalid year is given. - * - * @throws ReflectionException - */ public function testCreateWithInvalidYear(): void { $this->expectException(InvalidYearException::class); @@ -61,11 +40,6 @@ public function testCreateWithInvalidYear(): void Yasumi::create('Japan', 10100); } - /** - * Tests that an InvalidArgumentException is thrown in case an invalid holiday provider is given. - * - * @throws ReflectionException - */ public function testCreateWithInvalidProvider(): void { $this->expectException(ProviderNotFoundException::class); @@ -73,283 +47,207 @@ public function testCreateWithInvalidProvider(): void Yasumi::create('Mars'); } - /** - * Tests that an InvalidArgumentException is thrown in case we try to load a Trait as provider. - * - * @throws ReflectionException - */ public function testCreateWithInvalidProviderBecauseItsATrait(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); Yasumi::create('CommonHolidays'); } - /** - * Tests that an InvalidArgumentException is thrown in case we try to load the AbstractProvider as provider. - * - * @throws ReflectionException - */ public function testCreateWithAbstractClassProvider(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); Yasumi::create('AbstractProvider'); } - /** - * Tests that Yasumi allows external classes that extend the ProviderInterface. - * @throws ReflectionException - */ + public function testCreateWithClassNotImplementingProviderInterface(): void + { + $this->expectException(ProviderNotFoundException::class); + + $class = new class {}; + Yasumi::create($class::class, self::YEAR_LOWER_BOUND); + } + public function testCreateWithAbstractExtension(): void { $class = YasumiExternalProvider::class; $instance = Yasumi::create( $class, - Factory::create()->numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND) + self::numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND) ); - $this->assertInstanceOf($class, $instance); + self::assertInstanceOf(YasumiExternalProvider::class, $instance, 'No holiday instance for external holiday provider'); } - /** - * Tests that an Yasumi\Exception\UnknownLocaleException is thrown in case an invalid locale is given. - * - * @throws ReflectionException - */ public function testCreateWithInvalidLocale(): void { $this->expectException(UnknownLocaleException::class); Yasumi::create( 'Japan', - Factory::create()->numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND), + self::numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND), 'wx_YZ' ); } - /** - * Tests that the getIterator function returns an ArrayIterator object - * @throws ReflectionException - */ - public function testGetIterator(): void - { - $holidays = Yasumi::create( - 'Japan', - Factory::create()->numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND) - ); - - $this->assertInstanceOf(ArrayIterator::class, $holidays->getIterator()); - } - - /** - * Tests that the count function returns an integer and a correct count for the test holiday provider - * @throws ReflectionException - */ public function testCount(): void { // There are 16 holidays in Japan in the year 2015, with 1 substituted holiday. $holidays = Yasumi::create('Japan', 2015); - $this->assertIsInt($holidays->count()); - $this->assertEquals(16, $holidays->count()); - $this->assertNotEquals(17, $holidays->count()); + self::assertIsInt($holidays->count()); + self::assertEquals(16, $holidays->count()); + self::assertNotEquals(17, $holidays->count()); } - /** - * Tests that the getType function returns a string for the test holiday provider - * @throws ReflectionException - */ public function testGetType(): void { - $holidays = Yasumi::create('Japan', Factory::create()->numberBetween(1949, self::YEAR_UPPER_BOUND)); + $holidays = Yasumi::create('Japan', self::numberBetween(1949, self::YEAR_UPPER_BOUND)); $holiday = $holidays->getHoliday('newYearsDay'); - $this->assertIsString($holiday->getType()); + self::assertIsString($holiday->getType()); } - /** - * Tests that the getYear function returns an integer for the test holiday provider - * @throws ReflectionException - */ public function testGetYear(): void { - $year = Factory::create()->numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND); + $year = self::numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND); $holidays = Yasumi::create('Netherlands', $year); - $this->assertIsInt($holidays->getYear()); - $this->assertEquals($year, $holidays->getYear()); + self::assertIsInt($holidays->getYear()); + self::assertEquals($year, $holidays->getYear()); } /** - * Tests that the next function returns the next upcoming date (i.e. next year) for the given holiday + * Tests that the next function returns the next upcoming date (i.e. next year) for the given holiday. * - * @throws ReflectionException + * @throws \Exception */ public function testNext(): void { $country = 'Japan'; $name = 'childrensDay'; - $year = Factory::create()->numberBetween(1949, self::YEAR_UPPER_BOUND - 1); + $year = self::numberBetween(1949, self::YEAR_UPPER_BOUND - 1); $holidays = Yasumi::create($country, $year); $this->assertHoliday($country, $name, $year + 1, $holidays->next($name)); } - /** - * Tests the next function that an InvalidArgumentException is thrown in case a blank name is given. - * - * @throws ReflectionException - */ - public function testNextWithBlankName(): void + public function testNextWithBlankKey(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $holidays = Yasumi::create( 'Netherlands', - Factory::create()->numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND - 1) + self::numberBetween(self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND - 1) ); - $holidays->next(null); + $holidays->next(''); } /** - * Tests the previous function returns the previous date (i.e. previous year) for the given holiday + * Tests the previous function returns the previous date (i.e. previous year) for the given holiday. * - * @throws ReflectionException + * @throws \Exception */ public function testPrevious(): void { $country = 'Netherlands'; $name = 'liberationDay'; - $year_lower_limit = 1949; - $year = Factory::create()->numberBetween($year_lower_limit, self::YEAR_UPPER_BOUND); + $year_lower_limit = 1950; + $year = self::numberBetween($year_lower_limit, self::YEAR_UPPER_BOUND); $holidays = Yasumi::create($country, $year); $this->assertHoliday( $country, $name, - (($year > $year_lower_limit) ? $year - 1 : $year_lower_limit), + ($year > $year_lower_limit) ? $year - 1 : $year_lower_limit, $holidays->previous($name) ); } - /** - * Tests the previous function that an InvalidArgumentException is thrown in case a blank name is given. - * - * @throws ReflectionException - */ - public function testPreviousWithBlankName(): void + public function testPreviousWithBlankKey(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $holidays = Yasumi::create( 'Netherlands', - Factory::create()->numberBetween(self::YEAR_LOWER_BOUND + 1, self::YEAR_UPPER_BOUND) + self::numberBetween(self::YEAR_LOWER_BOUND + 1, self::YEAR_UPPER_BOUND) ); - $holidays->previous(null); + $holidays->previous(''); } - /** - * Tests that the getHolidayNames function returns an array and a correct count for the test holiday provider - * @throws ReflectionException - */ public function testGetHolidayNames(): void { $holidays = Yasumi::create('Japan', 2015); $holidayNames = $holidays->getHolidayNames(); - $this->assertIsArray($holidayNames); - $this->assertCount(17, $holidayNames); - $this->assertContains('newYearsDay', $holidayNames); + self::assertIsArray($holidayNames); + self::assertCount(17, $holidayNames); + self::assertContains('newYearsDay', $holidayNames); } - /** - * Tests that the WhenIs function returns a string representation of the date the given holiday occurs. - * @throws ReflectionException - */ public function testWhenIs(): void { $holidays = Yasumi::create('Japan', 2010); $when = $holidays->whenIs('autumnalEquinoxDay'); - $this->assertIsString($when); - $this->assertEquals('2010-09-23', $when); + self::assertIsString($when); + self::assertEquals('2010-09-23', $when); } - /** - * Tests that the WhenIs function throws an InvalidArgumentException when a blank name is given. - * - * @throws ReflectionException - */ - public function testWhenIsWithBlankName(): void + public function testWhenIsWithBlankKey(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $holidays = Yasumi::create('Japan', 2010); - $holidays->whenIs(null); + $holidays->whenIs(''); } - /** - * Tests that an InvalidArgumentException is thrown in case a blank name is given for the getHoliday function. - * - * @throws ReflectionException - */ - public function testGetHolidayWithBlankName(): void + public function testGetHolidayWithBlankKey(): void { - $this->expectException(InvalidArgumentException::class); - $holidays = Yasumi::create('Netherlands', 1999); - $holidays->getHoliday(null); + self::assertNull($holidays->getHoliday('')); } - /** - * Tests that the whatWeekDayIs function returns an integer representation of the day of the week the given holiday - * is occurring. - * @throws ReflectionException - */ public function testWhatWeekDayIs(): void { $holidays = Yasumi::create('Netherlands', 2110); $weekDay = $holidays->whatWeekDayIs('stMartinsDay'); - $this->assertIsInt($weekDay); - $this->assertEquals(2, $weekDay); + self::assertIsInt($weekDay); + self::assertEquals(2, $weekDay); } - /** - * Tests that the whatWeekDayIs function throws an InvalidArgumentException when a blank name is given. - * - * @throws ReflectionException - */ - public function testWhatWeekDayIsWithBlankName(): void + public function testWhatWeekDayIsWithBlankKey(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $holidays = Yasumi::create('Netherlands', 2388); - $holidays->whatWeekDayIs(null); + $holidays->whatWeekDayIs(''); } /** * Tests that the getProviders function returns an array containing all available holiday providers. - * @throws ReflectionException + * + * @throws \ReflectionException */ public function testGetProviders(): void { $providers = Yasumi::getProviders(); - $this->assertNotEmpty($providers); - $this->assertIsArray($providers); - $this->assertContains('Netherlands', $providers); - $this->assertEquals('USA', $providers['US']); - $this->assertNotContains('AbstractProvider', $providers); + self::assertNotEmpty($providers); + self::assertIsArray($providers); + self::assertContains('Netherlands', $providers); + self::assertEquals('USA', $providers['US']); + self::assertNotContains('AbstractProvider', $providers); } /** * Tests that the getProviders function (static call) returns the same data when called again. * - * @throws ReflectionException + * @throws \ReflectionException */ public function testGetProvidersStaticCall(): void { @@ -357,23 +255,24 @@ public function testGetProvidersStaticCall(): void $providers = Yasumi::getProviders(); $initial_providers = $providers; - $this->assertNotEmpty($providers); - $this->assertIsArray($providers); - $this->assertContains($provider, $providers); + self::assertNotEmpty($providers); + self::assertIsArray($providers); + self::assertContains($provider, $providers); $providers = Yasumi::getProviders(); - $this->assertNotEmpty($providers); - $this->assertIsArray($providers); - $this->assertContains($provider, $providers); - $this->assertEquals($initial_providers, $providers); + self::assertNotEmpty($providers); + self::assertIsArray($providers); + self::assertContains($provider, $providers); + self::assertEquals($initial_providers, $providers); } /** * Tests that the isHoliday function returns a boolean true for a date that is defined as a holiday. - * @throws Exception - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * + * Note that this function does *NOT* determine whether a date is a working or non-working day. It + * only asserts that it is a date calculated by the Holiday Provider. + * + * @throws \Exception */ public function testIsHoliday(): void { @@ -382,24 +281,19 @@ public function testIsHoliday(): void $date = $year . '-08-15'; // Assertion using a DateTime instance - $isHoliday = Yasumi::create($provider, $year)->isHoliday(new DateTime($date)); - $this->assertIsBool($isHoliday); - $this->assertTrue($isHoliday); + self::assertTrue(Yasumi::create($provider, $year)->isHoliday(new \DateTime($date)), sprintf('Date `%s` not recognised as holiday', $date)); // Assertion using a DateTimeImmutable instance - $isHoliday = Yasumi::create($provider, $year)->isHoliday(new DateTimeImmutable($date)); - $this->assertIsBool($isHoliday); - $this->assertTrue($isHoliday); - - unset($isHoliday); + self::assertTrue(Yasumi::create($provider, $year)->isHoliday(new \DateTimeImmutable($date)), sprintf('Immutable Date `%s` not recognised as holiday', $date)); } /** * Tests that the isHoliday function returns a boolean false for a date that is not defined as a holiday. - * @throws Exception - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * + * Note that this function does *NOT* determine whether a date is a working or non-working day. It + * only asserts that it is a date calculated by the Holiday Provider. + * + * @throws \Exception */ public function testIsNotHoliday(): void { @@ -408,43 +302,23 @@ public function testIsNotHoliday(): void $date = $year . '-06-10'; // Assertion using a DateTime instance - $isHoliday = Yasumi::create($provider, $year)->isHoliday(new DateTime($date)); - $this->assertIsBool($isHoliday); - $this->assertFalse($isHoliday); + $isHoliday = Yasumi::create($provider, $year)->isHoliday(new \DateTime($date)); + self::assertFalse($isHoliday); // Assertion using a DateTimeImmutable instance - $isHoliday = Yasumi::create($provider, $year)->isHoliday(new DateTimeImmutable($date)); - $this->assertIsBool($isHoliday); - $this->assertFalse($isHoliday); + $isHoliday = Yasumi::create($provider, $year)->isHoliday(new \DateTimeImmutable($date)); + self::assertFalse($isHoliday); unset($isHoliday); } - /** - * Tests that the isHoliday function throws a TypeError when the given argument is not an instance that - * implements the DateTimeInterface (e.g. DateTime or DateTimeImmutable) - * @throws ReflectionException - */ - public function testIsHolidayException(): void - { - $this->expectException(TypeError::class); - - /** @noinspection PhpParamsInspection */ - Yasumi::create('Spain', Factory::create()->numberBetween( - self::YEAR_LOWER_BOUND, - self::YEAR_UPPER_BOUND - ))->isHoliday(new stdClass()); - } - /** * Tests that the isWorkingDay function returns a boolean true for a date that is defined as a holiday or falls in * the weekend. * * @TODO Add additional unit tests for those holiday providers that differ from the global definition - * @throws Exception - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ public function testIsWorkingDay(): void { @@ -453,14 +327,12 @@ public function testIsWorkingDay(): void $date = $year . '-06-02'; // Assertion using a DateTime instance - $isWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new DateTime($date)); - $this->assertIsBool($isWorkingDay); - $this->assertTrue($isWorkingDay); + $isWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new \DateTime($date)); + self::assertTrue($isWorkingDay); // Assertion using a DateTimeImmutable instance - $isWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new DateTimeImmutable($date)); - $this->assertIsBool($isWorkingDay); - $this->assertTrue($isWorkingDay); + $isWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new \DateTimeImmutable($date)); + self::assertTrue($isWorkingDay); unset($isWorkingDay); } @@ -470,10 +342,8 @@ public function testIsWorkingDay(): void * the weekend. * * @TODO Add additional unit tests for those holiday providers that differ from the global definition - * @throws Exception - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ public function testIsNotWorkingDay(): void { @@ -482,61 +352,36 @@ public function testIsNotWorkingDay(): void $date = $year . '-01-11'; // Assertion using a DateTime instance - $isNotWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new DateTime($date)); - $this->assertIsBool($isNotWorkingDay); - $this->assertFalse($isNotWorkingDay); + $isNotWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new \DateTime($date)); + self::assertFalse($isNotWorkingDay); // Assertion using a DateTimeImmutable instance - $isNotWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new DateTimeImmutable($date)); - $this->assertIsBool($isNotWorkingDay); - $this->assertFalse($isNotWorkingDay); + $isNotWorkingDay = Yasumi::create($provider, $year)->isWorkingDay(new \DateTimeImmutable($date)); + self::assertFalse($isNotWorkingDay); unset($isNotWorkingDay); } - /** - * Tests that the isWorkingDay function throws a TypeError when the given argument is not an instance - * that implements the DateTimeInterface (e.g. DateTime or DateTimeImmutable) - * - * @TODO Add additional unit tests for those holiday providers that differ from the global definition - * @throws ReflectionException - */ - public function testIsWorkingDayException(): void - { - $this->expectException(TypeError::class); - - /** @noinspection PhpParamsInspection */ - Yasumi::create('SouthAfrica', Factory::create()->numberBetween( - self::YEAR_LOWER_BOUND, - self::YEAR_UPPER_BOUND - ))->isWorkingDay(new stdClass()); - } - - /** - * Tests that holidays successfully can be removed from the list of holidays of a provider - * - * @throws ReflectionException - */ public function testRemoveHoliday(): void { $provider = Yasumi::create('Ireland', 2018); $holidays = $provider->getHolidays(); // Assert initial list of holidays - $this->assertCount(13, $holidays); - $this->assertArrayHasKey('newYearsDay', $holidays); - $this->assertArrayHasKey('stPatricksDay', $holidays); - $this->assertArrayHasKey('substituteHoliday:stPatricksDay', $holidays); - $this->assertArrayHasKey('goodFriday', $holidays); - $this->assertArrayHasKey('easter', $holidays); - $this->assertArrayHasKey('easterMonday', $holidays); - $this->assertArrayHasKey('mayDay', $holidays); - $this->assertArrayHasKey('pentecost', $holidays); - $this->assertArrayHasKey('juneHoliday', $holidays); - $this->assertArrayHasKey('augustHoliday', $holidays); - $this->assertArrayHasKey('octoberHoliday', $holidays); - $this->assertArrayHasKey('christmasDay', $holidays); - $this->assertArrayHasKey('stStephensDay', $holidays); + self::assertCount(13, $holidays); + self::assertArrayHasKey('newYearsDay', $holidays); + self::assertArrayHasKey('stPatricksDay', $holidays); + self::assertArrayHasKey('substituteHoliday:stPatricksDay', $holidays); + self::assertArrayHasKey('goodFriday', $holidays); + self::assertArrayHasKey('easter', $holidays); + self::assertArrayHasKey('easterMonday', $holidays); + self::assertArrayHasKey('mayDay', $holidays); + self::assertArrayHasKey('pentecost', $holidays); + self::assertArrayHasKey('juneHoliday', $holidays); + self::assertArrayHasKey('augustHoliday', $holidays); + self::assertArrayHasKey('octoberHoliday', $holidays); + self::assertArrayHasKey('christmasDay', $holidays); + self::assertArrayHasKey('stStephensDay', $holidays); $provider->removeHoliday('juneHoliday'); $provider->removeHoliday('augustHoliday'); @@ -545,31 +390,39 @@ public function testRemoveHoliday(): void $holidaysAfterRemoval = $provider->getHolidays(); // Assert list of holidays after removal of some holidays - $this->assertCount(10, $holidaysAfterRemoval); - $this->assertArrayHasKey('newYearsDay', $holidaysAfterRemoval); - $this->assertArrayHasKey('stPatricksDay', $holidaysAfterRemoval); - $this->assertArrayHasKey('substituteHoliday:stPatricksDay', $holidaysAfterRemoval); - $this->assertArrayHasKey('goodFriday', $holidaysAfterRemoval); - $this->assertArrayHasKey('easter', $holidaysAfterRemoval); - $this->assertArrayHasKey('easterMonday', $holidaysAfterRemoval); - $this->assertArrayHasKey('mayDay', $holidaysAfterRemoval); - $this->assertArrayHasKey('pentecost', $holidaysAfterRemoval); - $this->assertArrayHasKey('christmasDay', $holidaysAfterRemoval); - $this->assertArrayHasKey('stStephensDay', $holidaysAfterRemoval); - $this->assertArrayNotHasKey('juneHoliday', $holidaysAfterRemoval); - $this->assertArrayNotHasKey('augustHoliday', $holidaysAfterRemoval); - $this->assertArrayNotHasKey('octoberHoliday', $holidaysAfterRemoval); + self::assertCount(10, $holidaysAfterRemoval); + self::assertArrayHasKey('newYearsDay', $holidaysAfterRemoval); + self::assertArrayHasKey('stPatricksDay', $holidaysAfterRemoval); + self::assertArrayHasKey('substituteHoliday:stPatricksDay', $holidaysAfterRemoval); + self::assertArrayHasKey('goodFriday', $holidaysAfterRemoval); + self::assertArrayHasKey('easter', $holidaysAfterRemoval); + self::assertArrayHasKey('easterMonday', $holidaysAfterRemoval); + self::assertArrayHasKey('mayDay', $holidaysAfterRemoval); + self::assertArrayHasKey('pentecost', $holidaysAfterRemoval); + self::assertArrayHasKey('christmasDay', $holidaysAfterRemoval); + self::assertArrayHasKey('stStephensDay', $holidaysAfterRemoval); + self::assertArrayNotHasKey('juneHoliday', $holidaysAfterRemoval); + self::assertArrayNotHasKey('augustHoliday', $holidaysAfterRemoval); + self::assertArrayNotHasKey('octoberHoliday', $holidaysAfterRemoval); + } + + public function testRemoveHolidayWithBlankKey(): void + { + $this->expectException(\InvalidArgumentException::class); + + $holidays = Yasumi::create('Netherlands', 1999); + $holidays->removeHoliday(''); } /** * Tests that a holiday provider instance can be created by using the ISO3166-2 - * country/region code. (Using the Yasumi::createByISO3166_2 method) + * country/region code. (Using the Yasumi::createByISO3166_2 method). * - * @throws ReflectionException + * @throws \ReflectionException */ - public function testCreateByISO3166_2(): void + public function testCreateByISO31662(): void { - $year = Factory::create()->numberBetween( + $year = self::numberBetween( self::YEAR_LOWER_BOUND, self::YEAR_UPPER_BOUND ); @@ -579,17 +432,16 @@ public function testCreateByISO3166_2(): void $year ); - $this->assertInstanceOf(AbstractProvider::class, $provider); - $this->assertEquals($year, $provider->getYear()); + self::assertEquals($year, $provider->getYear()); } /** * Tests that a ProviderNotFoundException is thrown when providing a invalid * ISO3166-2 code when using the Yasumi::createByISO3166_2 method. * - * @throws ReflectionException + * @throws \ReflectionException */ - public function testCreateByISO3166_2WithInvalidCode(): void + public function testCreateByISO31662WithInvalidCode(): void { $this->expectException(ProviderNotFoundException::class); @@ -600,30 +452,30 @@ public function testCreateByISO3166_2WithInvalidCode(): void * Tests that a holiday can be added to a provider. In addition, it * tests that the same holiday instance isn't added twice. * - * @throws ReflectionException - * @throws Exception + * @throws \ReflectionException + * @throws \Exception */ public function testAddExistingHoliday(): void { $provider = Yasumi::createByISO3166_2('NL', 2019); $holidayName = 'testHoliday'; - $holiday = new Holiday($holidayName, [], new DateTime()); + $holiday = new Holiday($holidayName, [], new \DateTime()); $originalHolidays = $provider->getHolidayNames(); // Add a new holiday $provider->addHoliday($holiday); $newHolidays = $provider->getHolidayNames(); - $this->assertContains($holidayName, $provider->getHolidayNames()); - $this->assertNotSameSize($originalHolidays, $newHolidays); - $this->assertNotEquals($newHolidays, $originalHolidays); + self::assertContains($holidayName, $provider->getHolidayNames()); + self::assertNotSameSize($originalHolidays, $newHolidays); + self::assertNotEquals($newHolidays, $originalHolidays); // Add same holiday again $provider->addHoliday($holiday); - $this->assertContains($holidayName, $provider->getHolidayNames()); - $this->assertSameSize($newHolidays, $provider->getHolidayNames()); - $this->assertNotSameSize($originalHolidays, $provider->getHolidayNames()); - $this->assertEquals($newHolidays, $provider->getHolidayNames()); - $this->assertNotEquals($originalHolidays, $provider->getHolidayNames()); + self::assertContains($holidayName, $provider->getHolidayNames()); + self::assertSameSize($newHolidays, $provider->getHolidayNames()); + self::assertNotSameSize($originalHolidays, $provider->getHolidayNames()); + self::assertEquals($newHolidays, $provider->getHolidayNames()); + self::assertNotEquals($originalHolidays, $provider->getHolidayNames()); } } diff --git a/tests/Base/YasumiWorkdayTest.php b/tests/Base/YasumiWorkdayTest.php index acb84fe20..90bd91ec8 100644 --- a/tests/Base/YasumiWorkdayTest.php +++ b/tests/Base/YasumiWorkdayTest.php @@ -1,39 +1,33 @@ - + * @author Sacha Telgenhof */ -namespace Yasumi\tests; +namespace Yasumi\tests\Base; -use DateTime; -use DateTimeImmutable; -use DateTimeZone; -use Exception; use PHPUnit\Framework\TestCase; -use ReflectionException; use Yasumi\Yasumi; -/** - * Class YasumiWorkdayTest. - * - * Class for testing the workday functions. - */ class YasumiWorkdayTest extends TestCase { public const FORMAT_DATE = 'Y-m-d'; /** - * Tests that the nextWorkingDay function returns an object that implements the DateTimeInterface (e.g. DateTime) + * Tests that the nextWorkingDay function returns an object that implements the DateTimeInterface (e.g. DateTime). * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testNextWorkingDay(): void { @@ -44,25 +38,24 @@ public function testNextWorkingDay(): void $expectedDate = '2016-07-05'; // Assertion using a DateTime instance - $startDate = new DateTime($date, new DateTimeZone($timezone)); - $result = Yasumi::nextWorkingDay($provider, $startDate); + $startDate = new \DateTime($date, new \DateTimeZone($timezone)); + $nextWorkingDay = Yasumi::nextWorkingDay($provider, $startDate); - $this->assertInstanceOf(DateTime::class, $result); - $this->assertEquals($expectedDate, $result->format(self::FORMAT_DATE)); + self::assertInstanceOf(\DateTimeImmutable::class, $nextWorkingDay, sprintf('No holiday instance for the next working day of `%s`', $date)); + self::assertEquals($expectedDate, $nextWorkingDay->format(self::FORMAT_DATE)); // Assertion using a DateTimeImmutable instance - $startDate = new DateTimeImmutable($date, new DateTimeZone($timezone)); - $result = Yasumi::nextWorkingDay($provider, $startDate); + $startDate = new \DateTimeImmutable($date, new \DateTimeZone($timezone)); + $nextWorkingDay = Yasumi::nextWorkingDay($provider, $startDate); - $this->assertInstanceOf(DateTimeImmutable::class, $result); - $this->assertEquals($expectedDate, $result->format(self::FORMAT_DATE)); + self::assertInstanceOf(\DateTimeImmutable::class, $nextWorkingDay, sprintf('No holiday instance for the next working day of `%s`', $date)); + self::assertEquals($expectedDate, $nextWorkingDay->format(self::FORMAT_DATE)); } /** - * Tests that the prevWorkingDay function returns an object that implements the DateTimeInterface (e.g. DateTime) + * Tests that the prevWorkingDay function returns an object that implements the DateTimeInterface (e.g. DateTime). * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testPreviousWorkingDay(): void { @@ -73,31 +66,30 @@ public function testPreviousWorkingDay(): void $expectedDate = '2016-07-01'; // Assertion using a DateTime instance - $startDate = new DateTime($date, new DateTimeZone($timezone)); - $result = Yasumi::prevWorkingDay($provider, $startDate); + $startDate = new \DateTime($date, new \DateTimeZone($timezone)); + $previousWorkingDay = Yasumi::prevWorkingDay($provider, $startDate); - $this->assertInstanceOf(DateTime::class, $result); - $this->assertEquals($expectedDate, $result->format(self::FORMAT_DATE)); + self::assertInstanceOf(\DateTimeImmutable::class, $previousWorkingDay, sprintf('No holiday instance for the previous working day of `%s`', $date)); + self::assertEquals($expectedDate, $previousWorkingDay->format(self::FORMAT_DATE)); // Assertion using a DateTimeImmutable instance - $startDate = new DateTimeImmutable($date, new DateTimeZone($timezone)); - $result = Yasumi::prevWorkingDay($provider, $startDate); + $startDate = new \DateTimeImmutable($date, new \DateTimeZone($timezone)); + $previousWorkingDay = Yasumi::prevWorkingDay($provider, $startDate); - $this->assertInstanceOf(DateTimeImmutable::class, $result); - $this->assertEquals($expectedDate, $result->format(self::FORMAT_DATE)); + self::assertInstanceOf(\DateTimeImmutable::class, $previousWorkingDay, sprintf('No holiday instance for the previous working day of `%s`', $date)); + self::assertEquals($expectedDate, $previousWorkingDay->format(self::FORMAT_DATE)); } /** * Tests that the prevWorkingDay and nextWorkingDay functions returns an object that implements the - * DateTimeInterface (e.g. DateTime) when an interval is chosen that passes the year boundary (i.e. beyond 12/31) + * DateTimeInterface (e.g. DateTime) when an interval is chosen that passes the year boundary (i.e. beyond 12/31). * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ public function testYearBoundary(): void { /** - * Use Case (USA): + * Use Case (USA):. * * 20 working days between 20th Dec and 20th Jan * 2015-12-20 is a Sunday @@ -113,7 +105,6 @@ public function testYearBoundary(): void * * @see https://www.timeanddate.com/calendar/?year=2016&country=1 */ - $provider = 'USA'; $timezone = 'America/New_York'; $interval = 20; @@ -122,24 +113,93 @@ public function testYearBoundary(): void $expectedPrevious = '2015-12-18'; // Assertion using a DateTime instance - $startDate = new DateTime($start, new DateTimeZone($timezone)); - $result = Yasumi::nextWorkingDay($provider, $startDate, $interval); + $startDate = new \DateTime($start, new \DateTimeZone($timezone)); + $nextWorkingDay = Yasumi::nextWorkingDay($provider, $startDate, $interval); - $this->assertEquals($expectedNext, $result->format(self::FORMAT_DATE)); - - $startDate = new DateTime($expectedNext, new DateTimeZone($timezone)); - $result = Yasumi::prevWorkingDay($provider, $startDate, $interval); - $this->assertEquals($expectedPrevious, $result->format(self::FORMAT_DATE)); + self::assertEquals($expectedNext, $nextWorkingDay->format(self::FORMAT_DATE)); + $startDate = new \DateTime($expectedNext, new \DateTimeZone($timezone)); + $previousWorkingDay = Yasumi::prevWorkingDay($provider, $startDate, $interval); + self::assertEquals($expectedPrevious, $previousWorkingDay->format(self::FORMAT_DATE)); // Assertion using a DateTimeImmutable instance - $startDate = new DateTimeImmutable($start, new DateTimeZone($timezone)); - $result = Yasumi::nextWorkingDay($provider, $startDate, $interval); + $startDate = new \DateTimeImmutable($start, new \DateTimeZone($timezone)); + $nextWorkingDay = Yasumi::nextWorkingDay($provider, $startDate, $interval); + + self::assertEquals($expectedNext, $nextWorkingDay->format(self::FORMAT_DATE)); + + $startDate = new \DateTimeImmutable($expectedNext, new \DateTimeZone($timezone)); + $previousWorkingDay = Yasumi::prevWorkingDay($provider, $startDate, $interval); + self::assertEquals($expectedPrevious, $previousWorkingDay->format(self::FORMAT_DATE)); + } + + /** + * Tests when the next working day happens to be in the next year. + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderWorkDayNextYear')] + public function testWorkDayIsNextYear(string $start, int $workdays, string $expectedNext): void + { + $provider = 'USA'; + $timezone = 'America/New_York'; + $startDate = new \DateTime($start, new \DateTimeZone($timezone)); + $nextWorkingDay = Yasumi::nextWorkingDay($provider, $startDate, $workdays); - $this->assertEquals($expectedNext, $result->format(self::FORMAT_DATE)); + self::assertEquals($expectedNext, $nextWorkingDay->format(self::FORMAT_DATE)); + } + + /** + * @return array list of test dates that are considered working days the next year + */ + public static function dataProviderWorkDayNextYear(): array + { + return [ + [ + '2019-12-30', + 2, + '2020-01-02', + ], + [ + '2018-12-28', + 2, + '2019-01-02', + ], + ]; + } + + /** + * Tests when the previous working day happens to be in the previous year. + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderWorkDayPreviousYear')] + public function testWorkDayIsPreviousYear(string $start, int $workdays, string $expectedNext): void + { + $provider = 'USA'; + $timezone = 'America/New_York'; + $startDate = new \DateTime($start, new \DateTimeZone($timezone)); + $previousWorkingDay = Yasumi::prevWorkingDay($provider, $startDate, $workdays); - $startDate = new DateTimeImmutable($expectedNext, new DateTimeZone($timezone)); - $result = Yasumi::prevWorkingDay($provider, $startDate, $interval); - $this->assertEquals($expectedPrevious, $result->format(self::FORMAT_DATE)); + self::assertEquals($expectedNext, $previousWorkingDay->format(self::FORMAT_DATE)); + } + + /** + * @return array list of test dates that are considered working days the previous year + */ + public static function dataProviderWorkDayPreviousYear(): array + { + return [ + [ + '2020-01-02', + 2, + '2019-12-30', + ], + [ + '2019-01-02', + 2, + '2018-12-28', + ], + ]; } } diff --git a/tests/Belgium/AllSaintsDayTest.php b/tests/Belgium/AllSaintsDayTest.php index f4734046d..bf6fc119b 100644 --- a/tests/Belgium/AllSaintsDayTest.php +++ b/tests/Belgium/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Belgium. */ -class AllSaintsDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * TThe name of the holiday to be tested + * TThe name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/ArmisticeDayTest.php b/tests/Belgium/ArmisticeDayTest.php index 87fc3b762..301506fcd 100644 --- a/tests/Belgium/ArmisticeDayTest.php +++ b/tests/Belgium/ArmisticeDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Armistice Day in Belgium. */ -class ArmisticeDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class ArmisticeDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'armisticeDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 11, self::TIMEZONE); + return static::generateRandomDates(11, 11, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Wapenstilstand'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/AscensionDayTest.php b/tests/Belgium/AscensionDayTest.php index fc0cd53ff..6e6fa0354 100644 --- a/tests/Belgium/AscensionDayTest.php +++ b/tests/Belgium/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Belgium. */ -class AscensionDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1818; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Hemelvaart'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/AssumptionOfMaryTest.php b/tests/Belgium/AssumptionOfMaryTest.php index be7fa4267..7cb6538a1 100644 --- a/tests/Belgium/AssumptionOfMaryTest.php +++ b/tests/Belgium/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Belgium. */ -class AssumptionOfMaryTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Onze Lieve Vrouw hemelvaart'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/BelgiumBaseTestCase.php b/tests/Belgium/BelgiumBaseTestCase.php index 1adf3e6c0..b80fe1eec 100644 --- a/tests/Belgium/BelgiumBaseTestCase.php +++ b/tests/Belgium/BelgiumBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; @@ -23,17 +28,13 @@ abstract class BelgiumBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Belgium'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Brussels'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'nl_BE'; } diff --git a/tests/Belgium/BelgiumTest.php b/tests/Belgium/BelgiumTest.php index cc02d7e04..259e032f7 100644 --- a/tests/Belgium/BelgiumTest.php +++ b/tests/Belgium/BelgiumTest.php @@ -1,18 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use ReflectionException; use Yasumi\Holiday; /** @@ -23,11 +27,20 @@ class BelgiumTest extends BelgiumBaseTestCase /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Belgium are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Belgium are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -48,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Belgium are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Belgium are defined by the provider class. */ public function testObservedHolidays(): void { @@ -57,8 +69,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Belgium are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Belgium are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -66,8 +77,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Belgium are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Belgium are defined by the provider class. */ public function testBankHolidays(): void { @@ -75,8 +85,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Belgium are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Belgium are defined by the provider class. */ public function testOtherHolidays(): void { @@ -84,10 +93,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Belgium/ChristmasTest.php b/tests/Belgium/ChristmasTest.php index d02079544..97f653b9d 100644 --- a/tests/Belgium/ChristmasTest.php +++ b/tests/Belgium/ChristmasTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Belgium. */ -class ChristmasTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kerstmis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/EasterMondayTest.php b/tests/Belgium/EasterMondayTest.php index f39b18c7f..073e5ff7d 100644 --- a/tests/Belgium/EasterMondayTest.php +++ b/tests/Belgium/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in the Belgium. */ -class EasterMondayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Paasmaandag'] + static::generateRandomYear(), + [self::LOCALE => 'paasmaandag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/EasterTest.php b/tests/Belgium/EasterTest.php index 88d8506ff..fc14e1f5f 100644 --- a/tests/Belgium/EasterTest.php +++ b/tests/Belgium/EasterTest.php @@ -1,70 +1,80 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter in Belgium. */ -class EasterTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easter'; /** * Tests Easter. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEaster() + public function testEaster(): void { $year = 2010; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-4", new \DateTimeZone(self::TIMEZONE)) + ); + $year = 2025; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-20", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Eerste paasdag'] + static::generateRandomYear(), + [self::LOCALE => 'eerste paasdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/InternationalWorkersDayTest.php b/tests/Belgium/InternationalWorkersDayTest.php index f93e82b87..6eedf9c31 100644 --- a/tests/Belgium/InternationalWorkersDayTest.php +++ b/tests/Belgium/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Belgium. */ -class InternationalWorkersDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dag van de arbeid'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/NationalDayTest.php b/tests/Belgium/NationalDayTest.php index 8ddc79cbe..b8dd5583a 100644 --- a/tests/Belgium/NationalDayTest.php +++ b/tests/Belgium/NationalDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Belgium. */ -class NationalDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class NationalDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(7, 21, self::TIMEZONE); + return static::generateRandomDates(7, 21, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Nationale feestdag'] + static::generateRandomYear(), + [self::LOCALE => 'nationale feestdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/NewYearsDayTest.php b/tests/Belgium/NewYearsDayTest.php index a560b81cf..addb79aef 100644 --- a/tests/Belgium/NewYearsDayTest.php +++ b/tests/Belgium/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Belgium. */ -class NewYearsDayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nieuwjaar'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/PentecostTest.php b/tests/Belgium/PentecostTest.php index c994be531..5bbd7bef6 100644 --- a/tests/Belgium/PentecostTest.php +++ b/tests/Belgium/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost in Belgium. */ -class PentecostTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecost'; /** * Tests Pentecost. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2025; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Eerste pinksterdag'] + static::generateRandomYear(), + [self::LOCALE => 'eerste pinksterdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Belgium/pentecostMondayTest.php b/tests/Belgium/pentecostMondayTest.php index 6f4c0b99f..75eb16a64 100644 --- a/tests/Belgium/pentecostMondayTest.php +++ b/tests/Belgium/pentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Belgium; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Belgium. */ -class pentecostMondayTest extends BelgiumBaseTestCase implements YasumiTestCaseInterface +class pentecostMondayTest extends BelgiumBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, 'pentecostMonday', $year, - new DateTime("$year-6-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Pinkstermaandag'] + static::generateRandomYear(), + [self::LOCALE => 'pinkstermaandag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/BosniaBaseTestCase.php b/tests/Bosnia/BosniaBaseTestCase.php index 8fa09d2cf..f44b8ac77 100644 --- a/tests/Bosnia/BosniaBaseTestCase.php +++ b/tests/Bosnia/BosniaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; @@ -25,17 +30,13 @@ abstract class BosniaBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Bosnia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Sarajevo'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'bs_Latn_BA'; } diff --git a/tests/Bosnia/BosniaTest.php b/tests/Bosnia/BosniaTest.php index cf2452911..361e19c00 100644 --- a/tests/Bosnia/BosniaTest.php +++ b/tests/Bosnia/BosniaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Bosnia. */ -class BosniaTest extends BosniaBaseTestCase +class BosniaTest extends BosniaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1992); + } /** - * Tests if all official holidays in Bosnia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Bosnia are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -46,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Bosnia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Bosnia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -55,8 +68,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Bosnia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Bosnia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -64,8 +76,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Bosnia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Bosnia are defined by the provider class. */ public function testBankHolidays(): void { @@ -73,8 +84,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Bosnia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Bosnia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -82,10 +92,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1992); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Bosnia/ChristmasDayTest.php b/tests/Bosnia/ChristmasDayTest.php index a63b4ba2b..c5fb8241b 100644 --- a/tests/Bosnia/ChristmasDayTest.php +++ b/tests/Bosnia/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Bosnia. */ -class ChristmasDayTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Božić'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/DayAfterNewYearsDay.php b/tests/Bosnia/DayAfterNewYearsDay.php index 72e811953..b1a580e3a 100644 --- a/tests/Bosnia/DayAfterNewYearsDay.php +++ b/tests/Bosnia/DayAfterNewYearsDay.php @@ -1,79 +1,86 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Day after New Years Day in Bosnia. */ -class DayAfterNewYearsDay extends BosniaBaseTestCase implements YasumiTestCaseInterface +class DayAfterNewYearsDay extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'dayAfterNewYearsDay'; + public function __construct() + { + parent::__construct(static::class); + } + /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 2, self::TIMEZONE); + return static::generateRandomDates(1, 2, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nova godina - drugi dan'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/EasterTest.php b/tests/Bosnia/EasterTest.php index d5c18f270..1c3defa82 100644 --- a/tests/Bosnia/EasterTest.php +++ b/tests/Bosnia/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Bosnia. */ -class EasterTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1677; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uskrs'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/IndependenceDayTest.php b/tests/Bosnia/IndependenceDayTest.php index afc67962c..a03425c81 100644 --- a/tests/Bosnia/IndependenceDayTest.php +++ b/tests/Bosnia/IndependenceDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Independence Day in Bosnia. */ -class IndependenceDayTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1992; /** * Tests Independence Day on or after 1992. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayOnAfter1992() + public function testIndependenceDayOnAfter1992(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Independence Day before 1992. - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayBefore1992() + public function testIndependenceDayBefore1992(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Independence Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Dan Nezavisnosti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Bosnia/InternationalWorkersDayTest.php b/tests/Bosnia/InternationalWorkersDayTest.php index 715cabf87..b48bca6bd 100644 --- a/tests/Bosnia/InternationalWorkersDayTest.php +++ b/tests/Bosnia/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Bosnia. */ -class InternationalWorkersDayTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Praznik rada'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Bosnia/NewYearsDayTest.php b/tests/Bosnia/NewYearsDayTest.php index 5eaf67619..a113dab7b 100644 --- a/tests/Bosnia/NewYearsDayTest.php +++ b/tests/Bosnia/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Bosnia. */ -class NewYearsDayTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nova godina'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/OrthodoxChristmasDay.php b/tests/Bosnia/OrthodoxChristmasDay.php index 2ac7a5c68..224b08ba5 100644 --- a/tests/Bosnia/OrthodoxChristmasDay.php +++ b/tests/Bosnia/OrthodoxChristmasDay.php @@ -1,76 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Orthodox Christmas Day in Bosnia. */ -class OrthodoxChristmasDay extends BosniaBaseTestCase implements YasumiTestCaseInterface +class OrthodoxChristmasDay extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'orthodoxChristmasDay'; - - /** - * @return array - * @throws Exception - */ - public function holidayDataProvider(): array + public function __construct() { - return $this->generateRandomDates(1, 7, self::TIMEZONE); + parent::__construct(static::class); } /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected + * @return array list of test dates for the holiday defined in this test * - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday($year, DateTime $expected) + public static function holidayDataProvider(): array + { + return static::generateRandomDates(1, 7, self::TIMEZONE); + } + + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pravoslavni Božić'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bosnia/SecondLabourDay.php b/tests/Bosnia/SecondLabourDay.php index 26a91b376..92f94366c 100644 --- a/tests/Bosnia/SecondLabourDay.php +++ b/tests/Bosnia/SecondLabourDay.php @@ -1,79 +1,86 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for the Second International Workers' Day (i.e. Labour Day) in Bosnia. */ -class SecondLabourDay extends BosniaBaseTestCase implements YasumiTestCaseInterface +class SecondLabourDay extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondLabourDay'; + public function __construct() + { + parent::__construct(static::class); + } + /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Praznik rada - drugi dan'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 2, self::TIMEZONE); + return static::generateRandomDates(5, 2, self::TIMEZONE); } } diff --git a/tests/Bosnia/StatehoodDayTest.php b/tests/Bosnia/StatehoodDayTest.php index 1105d5668..60c9228b3 100644 --- a/tests/Bosnia/StatehoodDayTest.php +++ b/tests/Bosnia/StatehoodDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Bosnia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Statehood Day in Bosnia. */ -class StatehoodDayTest extends BosniaBaseTestCase implements YasumiTestCaseInterface +class StatehoodDayTest extends BosniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'statehoodDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1943; /** * Tests Statehood Day on or after 1943. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testStatehoodDayOnAfter1943() + public function testStatehoodDayOnAfter1943(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Statehood Day before 1943. - * @throws ReflectionException + * + * @throws \Exception */ - public function testStatehoodDayBefore1943() + public function testStatehoodDayBefore1943(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Statehood Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Dan državnosti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Brazil/AllSoulsDayTest.php b/tests/Brazil/AllSoulsDayTest.php index 604154954..8e3fb4025 100644 --- a/tests/Brazil/AllSoulsDayTest.php +++ b/tests/Brazil/AllSoulsDayTest.php @@ -1,82 +1,86 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Dia dos Finados in Brazil. */ -class AllSoulsDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class AllSoulsDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSoulsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1300; /** * Tests Dia dos Finados on or after 1300. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDosFinadosAfter1300() + public function testDiaDosFinadosAfter1300(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-02", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-02", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Dia dos Finados on or before 1300. - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDosFinadosBefore1300() + public function testDiaDosFinadosBefore1300(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Dia de Finados']); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/AshWednesdayTest.php b/tests/Brazil/AshWednesdayTest.php index 57029fdb1..13f18f583 100644 --- a/tests/Brazil/AshWednesdayTest.php +++ b/tests/Brazil/AshWednesdayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ash Wednesday in the Brazil. */ -class AshWednesdayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class AshWednesdayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ashWednesday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1999; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ash Wednesday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Quarta-feira de Cinzas'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/BlackConsciousnessDayTest.php b/tests/Brazil/BlackConsciousnessDayTest.php new file mode 100644 index 000000000..1f9c4c62c --- /dev/null +++ b/tests/Brazil/BlackConsciousnessDayTest.php @@ -0,0 +1,110 @@ + + */ + +namespace Yasumi\tests\Brazil; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Black Consciousness Day in Brazil. + */ +class BlackConsciousnessDayTest extends BrazilBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'blackConsciousnessDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2011; + + /** + * The year in which the holiday celebration date has changed. + */ + public const OFFICIAL_YEAR = 2024; + + /** + * Tests Black Consciousness Day. + * + * @throws \Exception + */ + public function testBlackConsciousnessDay(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::OFFICIAL_YEAR - 1); + $expectedDate = "{$year}-11-20"; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expectedDate, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Black Consciousness Day before 2011. + * + * @throws \Exception + */ + public function testBlackConsciousnessDayBefore2011(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Black Consciousness Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dia Nacional de Zumbi e da Consciência Negra'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::OFFICIAL_YEAR - 1), + Holiday::TYPE_OBSERVANCE + ); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::OFFICIAL_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Brazil/BrazilBaseTestCase.php b/tests/Brazil/BrazilBaseTestCase.php index 06852ab21..7b1057474 100644 --- a/tests/Brazil/BrazilBaseTestCase.php +++ b/tests/Brazil/BrazilBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; @@ -23,17 +28,13 @@ abstract class BrazilBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Brazil'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'America/Fortaleza'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'pt_BR'; } diff --git a/tests/Brazil/BrazilTest.php b/tests/Brazil/BrazilTest.php index d30d362b2..b83479ace 100644 --- a/tests/Brazil/BrazilTest.php +++ b/tests/Brazil/BrazilTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Brazil. */ -class BrazilTest extends BrazilBaseTestCase +class BrazilTest extends BrazilBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1980); + } /** - * Tests if all official holidays in Brazil are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Brazil are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -44,8 +58,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Brazil are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Brazil are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Brazil are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Brazil are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Brazil are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Brazil are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Brazil are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Brazil are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1980); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Brazil/CarnavalMondayTest.php b/tests/Brazil/CarnavalMondayTest.php index 5dac0d750..4a07ebe4b 100644 --- a/tests/Brazil/CarnavalMondayTest.php +++ b/tests/Brazil/CarnavalMondayTest.php @@ -1,85 +1,89 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Carnaval Monday in Brazil. */ -class CarnavalMondayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class CarnavalMondayTest extends BrazilBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'carnavalMonday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1700; /** * Tests Carnaval Monday on or after 1700. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCarnavalMondayAfter1700() + public function testCarnavalMondayAfter1700(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P48D')) + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P48D')) ); } /** * Tests Carnaval Monday on or before 1700. - * @throws ReflectionException + * + * @throws \Exception */ - public function testCarnavalMondayBefore1700() + public function testCarnavalMondayBefore1700(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Segunda-feira de Carnaval']); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/CarnavalTuesdayTest.php b/tests/Brazil/CarnavalTuesdayTest.php index e5780182a..96a5479cc 100644 --- a/tests/Brazil/CarnavalTuesdayTest.php +++ b/tests/Brazil/CarnavalTuesdayTest.php @@ -1,85 +1,89 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Carnaval Tuesday in Brazil. */ -class CarnavalTuesdayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class CarnavalTuesdayTest extends BrazilBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'carnavalTuesday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1700; /** * Tests Carnaval Tuesday on or after 1700. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCarnavalTuesdayAfter1700() + public function testCarnavalTuesdayAfter1700(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P47D')) + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P47D')) ); } /** * Tests Carnaval Tuesday on or before 1700. - * @throws ReflectionException + * + * @throws \Exception */ - public function testCarnavalTuesdayBefore1700() + public function testCarnavalTuesdayBefore1700(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Terça-feira de Carnaval']); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/ChristmasDayTest.php b/tests/Brazil/ChristmasDayTest.php index a8ccd0ec4..02dbb0bb1 100644 --- a/tests/Brazil/ChristmasDayTest.php +++ b/tests/Brazil/ChristmasDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Brazil. */ -class ChristmasDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testChristmasDay() + public function testChristmasDay(): void { $year = 1897; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Natal'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/CorpusChristiTest.php b/tests/Brazil/CorpusChristiTest.php index ae4524b67..7ab7fe654 100644 --- a/tests/Brazil/CorpusChristiTest.php +++ b/tests/Brazil/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Brazil. */ -class CorpusChristiTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends BrazilBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Corpus Christi'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/EasterTest.php b/tests/Brazil/EasterTest.php index 9701b43fd..f95506240 100644 --- a/tests/Brazil/EasterTest.php +++ b/tests/Brazil/EasterTest.php @@ -1,66 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter in Brazil. */ -class EasterTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends BrazilBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easter'; /** * Tests Easter. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEaster() + public function testEaster(): void { $year = 1948; - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $this->calculateEaster($year, self::TIMEZONE)); + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, static::computeEaster($year, self::TIMEZONE)); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Páscoa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/GoodFridayTest.php b/tests/Brazil/GoodFridayTest.php index cb4c299b4..41b203205 100644 --- a/tests/Brazil/GoodFridayTest.php +++ b/tests/Brazil/GoodFridayTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in Brazil. */ -class GoodFridayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends BrazilBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'goodFriday'; /** * Tests Good Friday. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testGoodFriday() + public function testGoodFriday(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P2D')) + static::computeEaster($year, self::TIMEZONE)->sub(new \DateInterval('P2D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sexta feira santa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Brazil/IndependenceDayTest.php b/tests/Brazil/IndependenceDayTest.php index 26d081923..66ecc9ab8 100644 --- a/tests/Brazil/IndependenceDayTest.php +++ b/tests/Brazil/IndependenceDayTest.php @@ -1,72 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Independence Day in Brazil. */ -class IndependenceDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1822; /** * Tests Dia da independência do Brasil on or after 1822. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDaIndependenciaDoBrasilAfter1822() + public function testDiaDaIndependenciaDoBrasilAfter1822(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-09-07", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-09-07", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Dia da independência do Brasil on or before 1822. - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDaIndependenciaDoBrasilBefore1822() + public function testDiaDaIndependenciaDoBrasilBefore1822(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -77,11 +80,12 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/InternationalWorkersDayTest.php b/tests/Brazil/InternationalWorkersDayTest.php index 946634fe1..92d30a2c1 100644 --- a/tests/Brazil/InternationalWorkersDayTest.php +++ b/tests/Brazil/InternationalWorkersDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing International Workers' Day in Brazil. */ -class InternationalWorkersDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testInternationalWorkersDay() + public function testInternationalWorkersDay(): void { $year = 1927; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dia internacional do trabalhador'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/NewYearsDayTest.php b/tests/Brazil/NewYearsDayTest.php index 41d25e000..5c4cf30bf 100644 --- a/tests/Brazil/NewYearsDayTest.php +++ b/tests/Brazil/NewYearsDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Brazil. */ -class NewYearsDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNewYearsDay() + public function testNewYearsDay(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ano novo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/OurLadyOfAparecidaDayTest.php b/tests/Brazil/OurLadyOfAparecidaDayTest.php index 8c58c0cfb..5db5b47ea 100644 --- a/tests/Brazil/OurLadyOfAparecidaDayTest.php +++ b/tests/Brazil/OurLadyOfAparecidaDayTest.php @@ -1,72 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Our Lady Aparecida Day in Brazil. */ -class OurLadyOfAparecidaDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class OurLadyOfAparecidaDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ourLadyOfAparecidaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1980; /** * Tests Nossa Senhora Aparecida on or after 1980. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNossaSenhoraAparecidaAfter1980() + public function testNossaSenhoraAparecidaAfter1980(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Nossa Senhora Aparecida on or before 1980. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNossaSenhoraAparecidaBefore1980() + public function testNossaSenhoraAparecidaBefore1980(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -77,11 +80,12 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/ProclamationOfRepublicDayTest.php b/tests/Brazil/ProclamationOfRepublicDayTest.php index 91e4b7fa5..4c7a94471 100644 --- a/tests/Brazil/ProclamationOfRepublicDayTest.php +++ b/tests/Brazil/ProclamationOfRepublicDayTest.php @@ -1,72 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Proclamation of The Republic Day in Brazil. */ -class ProclamationOfRepublicDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class ProclamationOfRepublicDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'proclamationOfRepublicDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1889; /** * Tests Proclamação da República on or after 1889. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testProclamacaoDaRepublicaAfter1889() + public function testProclamacaoDaRepublicaAfter1889(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Proclamação da República on or before 1889. - * @throws ReflectionException + * + * @throws \Exception */ - public function testProclamacaoDaRepublicaBefore1889() + public function testProclamacaoDaRepublicaBefore1889(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -77,11 +80,12 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Brazil/TiradentesDayTest.php b/tests/Brazil/TiradentesDayTest.php index c4510095b..d74bc8540 100644 --- a/tests/Brazil/TiradentesDayTest.php +++ b/tests/Brazil/TiradentesDayTest.php @@ -1,82 +1,86 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Brazil; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Tiradentes' Day in Brazil. */ -class TiradentesDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface +class TiradentesDayTest extends BrazilBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'tiradentesDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1792; /** * Tests Dia de Tiradentes on or after 1792. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDeTiradentesAfter1792() + public function testDiaDeTiradentesAfter1792(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-04-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-04-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Dia de Tiradentes on or before 1792. - * @throws ReflectionException + * + * @throws \Exception */ - public function testDiaDeTiradentesBefore1792() + public function testDiaDeTiradentesBefore1792(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Dia de Tiradentes']); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Bulgaria/BulgariaBaseTestCase.php b/tests/Bulgaria/BulgariaBaseTestCase.php new file mode 100644 index 000000000..a6526d417 --- /dev/null +++ b/tests/Bulgaria/BulgariaBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +abstract class BulgariaBaseTestCase extends TestCase +{ + use YasumiBase; + + public const REGION = 'Bulgaria'; + + public const TIMEZONE = 'Europe/Sofia'; + + public const LOCALE = 'bg_BG'; +} diff --git a/tests/Bulgaria/BulgariaTest.php b/tests/Bulgaria/BulgariaTest.php new file mode 100644 index 000000000..83a18d207 --- /dev/null +++ b/tests/Bulgaria/BulgariaTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +class BulgariaTest extends BulgariaBaseTestCase implements ProviderTestCase +{ + protected int $year; + + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } + + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'internationalWorkersDay', + 'stGeorgesDay', + 'christmasDay', + 'christmasEve', + 'secondChristmasDay', + 'orthodoxEaster', + 'orthodoxGoodFriday', + 'orthodoxEasterMonday', + ]; + + if ($this->year >= 1885) { + $holidays[] = 'unificationDay'; + } + + if ($this->year >= 1908) { + $holidays[] = 'independenceDay'; + } + + if ($this->year >= 1990) { + $holidays[] = 'liberationDay'; + $holidays[] = 'educationCultureSlavonicLiteratureDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Bulgaria/ChristmasDayTest.php b/tests/Bulgaria/ChristmasDayTest.php new file mode 100644 index 000000000..478644099 --- /dev/null +++ b/tests/Bulgaria/ChristmasDayTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class ChristmasDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'christmasDay'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Рождество Христово'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/ChristmasEveTest.php b/tests/Bulgaria/ChristmasEveTest.php new file mode 100644 index 000000000..193f74a1f --- /dev/null +++ b/tests/Bulgaria/ChristmasEveTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class ChristmasEveTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'christmasEve'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Бъдни вечер'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/EducationCultureSlavonicLiteratureDayTest.php b/tests/Bulgaria/EducationCultureSlavonicLiteratureDayTest.php new file mode 100644 index 000000000..d39d9220b --- /dev/null +++ b/tests/Bulgaria/EducationCultureSlavonicLiteratureDayTest.php @@ -0,0 +1,68 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class EducationCultureSlavonicLiteratureDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'educationCultureSlavonicLiteratureDay'; + + private const ESTABLISHMENT_YEAR = 1990; + + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testNotHoliday(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Ден на българската просвета и култура и на славянската писменост'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/IndependenceDayTest.php b/tests/Bulgaria/IndependenceDayTest.php new file mode 100644 index 000000000..3b4d79d86 --- /dev/null +++ b/tests/Bulgaria/IndependenceDayTest.php @@ -0,0 +1,68 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class IndependenceDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'independenceDay'; + + private const ESTABLISHMENT_YEAR = 1908; + + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-09-22", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testNotHoliday(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Ден на Независимостта на България'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/InternationalWorkersDayTest.php b/tests/Bulgaria/InternationalWorkersDayTest.php new file mode 100644 index 000000000..6b70b2b75 --- /dev/null +++ b/tests/Bulgaria/InternationalWorkersDayTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class InternationalWorkersDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'internationalWorkersDay'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Ден на труда и на международната работническа солидарност'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/LiberationDayTest.php b/tests/Bulgaria/LiberationDayTest.php new file mode 100644 index 000000000..eb398b93c --- /dev/null +++ b/tests/Bulgaria/LiberationDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Liberation Day on March 3 marks the Liberation of Bulgaria from Ottoman rule in 1878. + * However, it became an official holiday by decree 236 of the Chairman of the State + * Council on 27 February 1990, coming into effect on 5 March. + */ +class LiberationDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'liberationDay'; + + private const ESTABLISHMENT_YEAR = 1990; + + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-03", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testNotHoliday(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Ден на Освобождението на България от османско иго'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/NewYearsDayTest.php b/tests/Bulgaria/NewYearsDayTest.php new file mode 100644 index 000000000..a79682fef --- /dev/null +++ b/tests/Bulgaria/NewYearsDayTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class NewYearsDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'newYearsDay'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-01-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Нова година'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/OrthodoxEasterMondayTest.php b/tests/Bulgaria/OrthodoxEasterMondayTest.php new file mode 100644 index 000000000..b02a7ac85 --- /dev/null +++ b/tests/Bulgaria/OrthodoxEasterMondayTest.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +class OrthodoxEasterMondayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + public const HOLIDAY = 'orthodoxEasterMonday'; + + public function testHoliday(): void + { + $year = 2023; + $easter = $this->calculateOrthodoxEaster($year, self::TIMEZONE); + $easterMonday = clone $easter; + $easterMonday->add(new \DateInterval('P1D')); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + $easterMonday + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Велики понеделник'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/OrthodoxEasterTest.php b/tests/Bulgaria/OrthodoxEasterTest.php new file mode 100644 index 000000000..14c0abcd1 --- /dev/null +++ b/tests/Bulgaria/OrthodoxEasterTest.php @@ -0,0 +1,61 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +class OrthodoxEasterTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + public const HOLIDAY = 'orthodoxEaster'; + + public function testHoliday(): void + { + $year = 2023; + $expected = $this->calculateOrthodoxEaster($year, self::TIMEZONE); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + $expected + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Великден'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/OrthodoxGoodFridayTest.php b/tests/Bulgaria/OrthodoxGoodFridayTest.php new file mode 100644 index 000000000..b401d5d82 --- /dev/null +++ b/tests/Bulgaria/OrthodoxGoodFridayTest.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +class OrthodoxGoodFridayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + public const HOLIDAY = 'orthodoxGoodFriday'; + + public function testHoliday(): void + { + $year = 2023; + $easter = $this->calculateOrthodoxEaster($year, self::TIMEZONE); + $goodFriday = clone $easter; + $goodFriday->sub(new \DateInterval('P2D')); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + $goodFriday + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Разпети петък'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/SecondChristmasDayTest.php b/tests/Bulgaria/SecondChristmasDayTest.php new file mode 100644 index 000000000..3936d8806 --- /dev/null +++ b/tests/Bulgaria/SecondChristmasDayTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class SecondChristmasDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'secondChristmasDay'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Втори ден на Коледа'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/UnificationDayTest.php b/tests/Bulgaria/UnificationDayTest.php new file mode 100644 index 000000000..022768d73 --- /dev/null +++ b/tests/Bulgaria/UnificationDayTest.php @@ -0,0 +1,68 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class UnificationDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'unificationDay'; + + private const ESTABLISHMENT_YEAR = 1885; + + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-09-06", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testNotHoliday(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Ден на Съединението'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Bulgaria/stGeorgesDayTest.php b/tests/Bulgaria/stGeorgesDayTest.php new file mode 100644 index 000000000..b889056ea --- /dev/null +++ b/tests/Bulgaria/stGeorgesDayTest.php @@ -0,0 +1,57 @@ + + */ + +namespace Yasumi\tests\Bulgaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class stGeorgesDayTest extends BulgariaBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'stGeorgesDay'; + + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-06", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Гергьовден, ден на храбростта и Българската армия'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/Alberta/AlbertaBaseTestCase.php b/tests/Canada/Alberta/AlbertaBaseTestCase.php new file mode 100644 index 000000000..a59bbc47b --- /dev/null +++ b/tests/Canada/Alberta/AlbertaBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Alberta; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Alberta holiday provider. + */ +abstract class AlbertaBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Alberta'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Edmonton'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Alberta/AlbertaTest.php b/tests/Canada/Alberta/AlbertaTest.php new file mode 100644 index 000000000..8ff2d71bc --- /dev/null +++ b/tests/Canada/Alberta/AlbertaTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\Alberta; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Alberta. + */ +class AlbertaTest extends AlbertaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Alberta are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'heritageDay', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'familyDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Alberta are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Alberta are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Alberta are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Alberta are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/BritishColumbia/BritishColumbiaBaseTestCase.php b/tests/Canada/BritishColumbia/BritishColumbiaBaseTestCase.php new file mode 100644 index 000000000..484c0a824 --- /dev/null +++ b/tests/Canada/BritishColumbia/BritishColumbiaBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\BritishColumbia; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the British Columbia holiday provider. + */ +abstract class BritishColumbiaBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\BritishColumbia'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Vancouver'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/BritishColumbia/BritishColumbiaTest.php b/tests/Canada/BritishColumbia/BritishColumbiaTest.php new file mode 100644 index 000000000..535bcf910 --- /dev/null +++ b/tests/Canada/BritishColumbia/BritishColumbiaTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\BritishColumbia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in British Columbia. + */ +class BritishColumbiaTest extends BritishColumbiaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in BritishColumbia are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'civicHoliday', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'familyDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in BritishColumbia are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in BritishColumbia are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in BritishColumbia are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in BritishColumbia are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/CanadaBaseTestCase.php b/tests/Canada/CanadaBaseTestCase.php new file mode 100644 index 000000000..c12618763 --- /dev/null +++ b/tests/Canada/CanadaBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Canada; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Class CanadaBaseTestCase. + */ +abstract class CanadaBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Canada'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Toronto'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; +} diff --git a/tests/Canada/CanadaDayTest.php b/tests/Canada/CanadaDayTest.php new file mode 100644 index 000000000..9d38ee631 --- /dev/null +++ b/tests/Canada/CanadaDayTest.php @@ -0,0 +1,104 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Canada Day in Canada. + */ +class CanadaDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'canadaDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1983; + + /** + * Tests Canada Day on or after 1983. Canada Day was established in 1983 on July 1st. + * + * @throws \Exception + */ + public function testCanadaDayOnAfter1983(): void + { + $year = 2019; // July 1 is not Sunday + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-01", new \DateTimeZone(self::TIMEZONE)) + ); + $year = 2018; // July 1 is Sunday + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-02", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Canada Day before 1879. Canada Day was established as Dominion Day in 1879 on July 1st. + * + * @throws \Exception + */ + public function testCanadaDayBefore1879(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Canada Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/CanadaTest.php b/tests/Canada/CanadaTest.php new file mode 100644 index 000000000..f2312307b --- /dev/null +++ b/tests/Canada/CanadaTest.php @@ -0,0 +1,101 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in the Canada. + */ +class CanadaTest extends CanadaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1986); + } + + /** + * Tests if all official holidays in the USA are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $this->assertDefinedHolidays([ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'canadaDay', + 'labourDay', + 'remembranceDay', + 'thanksgivingDay', + 'christmasDay', + 'secondChristmasDay', + ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in the Canada are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in the Canada are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in the Canada are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in the Canada are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/ChristmasDayTest.php b/tests/Canada/ChristmasDayTest.php new file mode 100644 index 000000000..4f81481cf --- /dev/null +++ b/tests/Canada/ChristmasDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Years Day in the USA. + */ +class ChristmasDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day. Christmas Day is celebrated on December 25th. + * + * @throws \Exception + */ + public function testChristmasDay(): void + { + $year = 2001; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Christmas Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Canada/LabourDayTest.php b/tests/Canada/LabourDayTest.php new file mode 100644 index 000000000..8f93afc2b --- /dev/null +++ b/tests/Canada/LabourDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Labour Day in Canada. + */ +class LabourDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'labourDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1894; + + /** + * Tests Labour Day on or after 1894. Labour Day was established since 1894 on the first Monday of September. + * + * @throws \Exception + */ + public function testLabourDayOnAfter1894(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("first monday of september {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Labour Day before 1894. Labour Day was established since 1894 on the first Monday of September. + * + * @throws \Exception + */ + public function testLabourDayBefore1894(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Labour Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/Manitoba/ManitobaBaseTestCase.php b/tests/Canada/Manitoba/ManitobaBaseTestCase.php new file mode 100644 index 000000000..9f8dd5f71 --- /dev/null +++ b/tests/Canada/Manitoba/ManitobaBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Manitoba; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Manitoba holiday provider. + */ +abstract class ManitobaBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Manitoba'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Winnipeg'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Manitoba/ManitobaTest.php b/tests/Canada/Manitoba/ManitobaTest.php new file mode 100644 index 000000000..36b927cb4 --- /dev/null +++ b/tests/Canada/Manitoba/ManitobaTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\Manitoba; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Manitoba. + */ +class ManitobaTest extends ManitobaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Manitoba are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'terryFoxDay', + ]; + + if (2008 <= $this->year) { + $holidays[] = 'louisRielDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Manitoba are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Manitoba are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Manitoba are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Manitoba are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/NewBrunswick/NewBrunswickBaseTestCase.php b/tests/Canada/NewBrunswick/NewBrunswickBaseTestCase.php new file mode 100644 index 000000000..bceb947fb --- /dev/null +++ b/tests/Canada/NewBrunswick/NewBrunswickBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\NewBrunswick; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the New Brunswick holiday provider. + */ +abstract class NewBrunswickBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\NewBrunswick'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Halifax'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/NewBrunswick/NewBrunswickTest.php b/tests/Canada/NewBrunswick/NewBrunswickTest.php new file mode 100644 index 000000000..693396c02 --- /dev/null +++ b/tests/Canada/NewBrunswick/NewBrunswickTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\NewBrunswick; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in New Brunswick. + */ +class NewBrunswickTest extends NewBrunswickBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in NewBrunswick are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'civicHoliday', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'familyDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in NewBrunswick are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in NewBrunswick are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in NewBrunswick are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in NewBrunswick are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/NewYearsDayTest.php b/tests/Canada/NewYearsDayTest.php new file mode 100644 index 000000000..efcbf271e --- /dev/null +++ b/tests/Canada/NewYearsDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Years Day in Canada. + */ +class NewYearsDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Years Day. + * + * @throws \Exception + */ + public function testNewYearsDay(): void + { + $year = 1997; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'New Year’s Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorBaseTestCase.php b/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorBaseTestCase.php new file mode 100644 index 000000000..0939a0fa4 --- /dev/null +++ b/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\NewfoundlandAndLabrador; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Newfoundland and Labrador holiday provider. + */ +abstract class NewfoundlandAndLabradorBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\NewfoundlandAndLabrador'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/St_Johns'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorTest.php b/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorTest.php new file mode 100644 index 000000000..baacef0e3 --- /dev/null +++ b/tests/Canada/NewfoundlandAndLabrador/NewfoundlandAndLabradorTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Canada\NewfoundlandAndLabrador; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Newfoundland and Labrador. + */ +class NewfoundlandAndLabradorTest extends NewfoundlandAndLabradorBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in NewfoundlandAndLabrador are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $this->assertDefinedHolidays([ + 'goodFriday', + 'christmasDay', + 'stGeorgesDay', + ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in NewfoundlandAndLabrador are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in NewfoundlandAndLabrador are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in NewfoundlandAndLabrador are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([ + 'stPatricksDay', + 'orangemensDay', + ], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in NewfoundlandAndLabrador are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/NorthwestTerritories/NorthwestTerritoriesBaseTestCase.php b/tests/Canada/NorthwestTerritories/NorthwestTerritoriesBaseTestCase.php new file mode 100644 index 000000000..276e35252 --- /dev/null +++ b/tests/Canada/NorthwestTerritories/NorthwestTerritoriesBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\NorthwestTerritories; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Northwest Territories holiday provider. + */ +abstract class NorthwestTerritoriesBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\NorthwestTerritories'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Yellowknife'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/NorthwestTerritories/NorthwestTerritoriesTest.php b/tests/Canada/NorthwestTerritories/NorthwestTerritoriesTest.php new file mode 100644 index 000000000..8713dc406 --- /dev/null +++ b/tests/Canada/NorthwestTerritories/NorthwestTerritoriesTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\NorthwestTerritories; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Northwest Territories. + */ +class NorthwestTerritoriesTest extends NorthwestTerritoriesBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in NorthwestTerritories are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'civicHoliday', + ]; + + if (1996 <= $this->year) { + $holidays[] = 'nationalIndigenousPeoplesDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in NorthwestTerritories are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in NorthwestTerritories are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in NorthwestTerritories are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in NorthwestTerritories are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/NovaScotia/NovaScotiaBaseTestCase.php b/tests/Canada/NovaScotia/NovaScotiaBaseTestCase.php new file mode 100644 index 000000000..0aedd056a --- /dev/null +++ b/tests/Canada/NovaScotia/NovaScotiaBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\NovaScotia; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Nova Scotia holiday provider. + */ +abstract class NovaScotiaBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\NovaScotia'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Halifax'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/NovaScotia/NovaScotiaTest.php b/tests/Canada/NovaScotia/NovaScotiaTest.php new file mode 100644 index 000000000..3817f5337 --- /dev/null +++ b/tests/Canada/NovaScotia/NovaScotiaTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\NovaScotia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Nova Scotia. + */ +class NovaScotiaTest extends NovaScotiaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Nova Scotia are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'natalHoliday', + ]; + + if ($this->year >= 2015) { + $holidays[] = 'novaScotiaHeritageDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in NovaScotia are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in NovaScotia are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in NovaScotia are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in NovaScotia are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/Nunavut/NunavutBaseTestCase.php b/tests/Canada/Nunavut/NunavutBaseTestCase.php new file mode 100644 index 000000000..c968455e0 --- /dev/null +++ b/tests/Canada/Nunavut/NunavutBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Nunavut; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Nunavut holiday provider. + */ +abstract class NunavutBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Nunavut'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Iqaluit'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Nunavut/NunavutDayTest.php b/tests/Canada/Nunavut/NunavutDayTest.php new file mode 100644 index 000000000..39ff08a52 --- /dev/null +++ b/tests/Canada/Nunavut/NunavutDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Canada\Nunavut; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/* + * Nunavut Day – July 9, originated as a paid holiday for Nunavut Tunngavik Incorporated + * and regional Inuit associations. It became a half-day holiday for government employees + * in 1999 and a full day in 2001. + */ +class NunavutDayTest extends NunavutBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nunavutDay'; + + public const ESTABLISHMENT_YEAR = 1999; + + public function testNunavutDayOnAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-09", new \DateTimeZone(self::TIMEZONE)) + ); + } + + public function testLabourDayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Nunavut Day'] + ); + } + + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OBSERVANCE + ); + } +} diff --git a/tests/Canada/Nunavut/NunavutTest.php b/tests/Canada/Nunavut/NunavutTest.php new file mode 100644 index 000000000..609cdcfcb --- /dev/null +++ b/tests/Canada/Nunavut/NunavutTest.php @@ -0,0 +1,101 @@ + + */ + +namespace Yasumi\tests\Canada\Nunavut; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Nunavut. + */ +class NunavutTest extends NunavutBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Nunavut are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $this->assertDefinedHolidays([ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'civicHoliday', + ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Nunavut are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $holidays = []; + + if ($this->year >= 1999) { + $holidays[] = 'nunavutDay'; + } + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Nunavut are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Nunavut are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Nunavut are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/Ontario/OntarioBaseTestCase.php b/tests/Canada/Ontario/OntarioBaseTestCase.php new file mode 100644 index 000000000..af8e3aef2 --- /dev/null +++ b/tests/Canada/Ontario/OntarioBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Ontario; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Ontario holiday provider. + */ +abstract class OntarioBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Ontario'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Toronto'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Ontario/OntarioTest.php b/tests/Canada/Ontario/OntarioTest.php new file mode 100644 index 000000000..e3b00c7a0 --- /dev/null +++ b/tests/Canada/Ontario/OntarioTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\Ontario; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Ontario. + */ +class OntarioTest extends OntarioBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Ontario are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'civicHoliday', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'familyDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Ontario are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Ontario are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Ontario are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Ontario are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandBaseTestCase.php b/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandBaseTestCase.php new file mode 100644 index 000000000..9cd2f5281 --- /dev/null +++ b/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\PrinceEdwardIsland; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Prince Edward Island holiday provider. + */ +abstract class PrinceEdwardIslandBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\PrinceEdwardIsland'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Halifax'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandTest.php b/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandTest.php new file mode 100644 index 000000000..7dabc7b53 --- /dev/null +++ b/tests/Canada/PrinceEdwardIsland/PrinceEdwardIslandTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\PrinceEdwardIsland; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Prince Edward Island. + */ +class PrinceEdwardIslandTest extends PrinceEdwardIslandBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Prince Edward Island are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'goldCupParadeDay', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'islanderDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in PrinceEdwardIsland are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in PrinceEdwardIsland are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in PrinceEdwardIsland are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in PrinceEdwardIsland are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/Quebec/QuebecBaseTestCase.php b/tests/Canada/Quebec/QuebecBaseTestCase.php new file mode 100644 index 000000000..3e0b5de97 --- /dev/null +++ b/tests/Canada/Quebec/QuebecBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Quebec; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Quebec holiday provider. + */ +abstract class QuebecBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Quebec'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Toronto'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Quebec/QuebecTest.php b/tests/Canada/Quebec/QuebecTest.php new file mode 100644 index 000000000..5f2b287cb --- /dev/null +++ b/tests/Canada/Quebec/QuebecTest.php @@ -0,0 +1,101 @@ + + */ + +namespace Yasumi\tests\Canada\Quebec; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Quebec. + */ +class QuebecTest extends QuebecBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Quebec are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'saintJeanBaptisteDay', + ]; + + if ($this->year >= 2003) { + $holidays[] = 'nationalPatriotsDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Quebec are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Quebec are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Quebec are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Quebec are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/RemembranceDayTest.php b/tests/Canada/RemembranceDayTest.php new file mode 100644 index 000000000..cab9a6f03 --- /dev/null +++ b/tests/Canada/RemembranceDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Remembrance Day in Canada. + */ +class RemembranceDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'remembranceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1919; + + /** + * Tests Remembrance Day on or after 1919. Remembrance Day was established in 1919 on November 11. + * + * @throws \Exception + */ + public function testRemembranceDayOnAfter1919(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-11-11", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Remembrance Day before 1919. Remembrance Day was established in 1919 on November 11. + * + * @throws \Exception + */ + public function testVeteransDayBefore1919(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1954), + [self::LOCALE => 'Remembrance Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/Saskatchewan/SaskatchewanBaseTestCase.php b/tests/Canada/Saskatchewan/SaskatchewanBaseTestCase.php new file mode 100644 index 000000000..24f31cb1f --- /dev/null +++ b/tests/Canada/Saskatchewan/SaskatchewanBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Saskatchewan; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Saskatchewan holiday provider. + */ +abstract class SaskatchewanBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Saskatchewan'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Regina'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Saskatchewan/SaskatchewanTest.php b/tests/Canada/Saskatchewan/SaskatchewanTest.php new file mode 100644 index 000000000..717217987 --- /dev/null +++ b/tests/Canada/Saskatchewan/SaskatchewanTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Canada\Saskatchewan; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Saskatchewan. + */ +class SaskatchewanTest extends SaskatchewanBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Saskatchewan are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + 'victoriaDay', + 'saskatchewanDay', + ]; + + if ($this->year >= 2009) { + $holidays[] = 'familyDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Saskatchewan are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Saskatchewan are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Saskatchewan are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Saskatchewan are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Canada/ThanksgivingDayTest.php b/tests/Canada/ThanksgivingDayTest.php new file mode 100644 index 000000000..3550c86b9 --- /dev/null +++ b/tests/Canada/ThanksgivingDayTest.php @@ -0,0 +1,99 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Thanksgiving Day in Canada. + */ +class ThanksgivingDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'thanksgivingDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1879; + + /** + * Tests Thanksgiving Day on or after 1879. Thanksgiving Day is celebrated since 1879 on the second Monday + * of October. + * + * @throws \Exception + */ + public function testThanksgivingDayOnAfter1879(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("second monday of october {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Thanksgiving Day before 1879. ThanksgivingDay Day is celebrated since 1879 on the second Monday + * of October. + * + * @throws \Exception + */ + public function testThanksgivingDayBefore1879(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Thanksgiving'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/TruthAndReconciliationDayTest.php b/tests/Canada/TruthAndReconciliationDayTest.php new file mode 100644 index 000000000..704eca2bf --- /dev/null +++ b/tests/Canada/TruthAndReconciliationDayTest.php @@ -0,0 +1,99 @@ + + */ + +namespace Yasumi\tests\Canada; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing National Day For Truth And Reconciliation in Canada. + */ +class TruthAndReconciliationDayTest extends CanadaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'truthAndReconciliationDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2021; + + /** + * Tests TruthAndReconciliationDay on or after 2021. Thanksgiving Day is celebrated since 2021 on the last day + * of September. + * + * @throws \Exception + */ + public function testTruthAndReconciliationDayOnAfter2021(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("last day of september {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests TruthAndReconciliationDay before 2021. TruthAndReconciliationDay is celebrated since 2021 on the last day + * of September. + * + * @throws \Exception + */ + public function testTruthAndReconciliationDayBefore2021(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'National Day For Truth And Reconciliation'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Canada/Yukon/YukonBaseTestCase.php b/tests/Canada/Yukon/YukonBaseTestCase.php new file mode 100644 index 000000000..a96a2f243 --- /dev/null +++ b/tests/Canada/Yukon/YukonBaseTestCase.php @@ -0,0 +1,43 @@ + + */ + +namespace Yasumi\tests\Canada\Yukon; + +use Yasumi\tests\Canada\CanadaBaseTestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Yukon holiday provider. + */ +abstract class YukonBaseTestCase extends CanadaBaseTestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'Canada\Yukon'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Whitehorse'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'en_CA'; + + /** + * Number of iterations to be used for the various unit tests of this provider. + */ + public const TEST_ITERATIONS = 50; +} diff --git a/tests/Canada/Yukon/YukonTest.php b/tests/Canada/Yukon/YukonTest.php new file mode 100644 index 000000000..f9f058fea --- /dev/null +++ b/tests/Canada/Yukon/YukonTest.php @@ -0,0 +1,112 @@ + + */ + +namespace Yasumi\tests\Canada\Yukon; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Yukon. + */ +class YukonTest extends YukonBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } + + /** + * Tests if all official holidays in Yukon are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'goodFriday', + 'christmasDay', + ]; + + if (2009 < $this->year) { + $holidays[] = 'yukonHeritageDay'; + } + + if (1996 <= $this->year) { + $holidays[] = 'nationalIndigenousPeoplesDay'; + } + + if (1897 >= $this->year) { + $holidays[] = 'discoveryDay'; + } + + if (1845 >= $this->year) { + $holidays[] = 'victoriaDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Yukon are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Yukon are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Yukon are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Yukon are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 1); + } +} diff --git a/tests/Croatia/AllSaintsDayTest.php b/tests/Croatia/AllSaintsDayTest.php index 45658fede..232100044 100644 --- a/tests/Croatia/AllSaintsDayTest.php +++ b/tests/Croatia/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Croatia. */ -class AllSaintsDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dan svih svetih'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/AntifascistStruggleDayTest.php b/tests/Croatia/AntifascistStruggleDayTest.php index f6a29222e..a3f20862f 100644 --- a/tests/Croatia/AntifascistStruggleDayTest.php +++ b/tests/Croatia/AntifascistStruggleDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Day of Antifascist Struggle in Croatia. */ -class AntifascistStruggleDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class AntifascistStruggleDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'antifascistStruggleDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1941; /** * Tests Day of Antifascist Struggle on or after 1941. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAntifascistStruggleDayOnAfter1941() + public function testAntifascistStruggleDayOnAfter1941(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-22", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-22", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Day of Antifascist Struggle before 1941. - * @throws ReflectionException + * + * @throws \Exception */ - public function testAntifascistStruggleDayBefore1941() + public function testAntifascistStruggleDayBefore1941(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Day of Antifascist Struggle. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Dan antifašističke borbe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Croatia/AssumptionOfMaryTest.php b/tests/Croatia/AssumptionOfMaryTest.php index b0e573e28..c73942f9d 100644 --- a/tests/Croatia/AssumptionOfMaryTest.php +++ b/tests/Croatia/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Croatia. */ -class AssumptionOfMaryTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Velika Gospa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/ChristmasDayTest.php b/tests/Croatia/ChristmasDayTest.php index 31e40b6fe..130acb1d3 100644 --- a/tests/Croatia/ChristmasDayTest.php +++ b/tests/Croatia/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Croatia. */ -class ChristmasDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Božić'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/CorpusChristiTest.php b/tests/Croatia/CorpusChristiTest.php index 88898e19a..6c142034d 100644 --- a/tests/Croatia/CorpusChristiTest.php +++ b/tests/Croatia/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in the Croatia. */ -class CorpusChristiTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends CroatiaBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tijelovo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/CroatiaBaseTestCase.php b/tests/Croatia/CroatiaBaseTestCase.php index d10ba757e..4d17d3f1b 100644 --- a/tests/Croatia/CroatiaBaseTestCase.php +++ b/tests/Croatia/CroatiaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; @@ -25,17 +30,13 @@ abstract class CroatiaBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Croatia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zagreb'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'hr_HR'; } diff --git a/tests/Croatia/CroatiaTest.php b/tests/Croatia/CroatiaTest.php new file mode 100644 index 000000000..0b6c65db9 --- /dev/null +++ b/tests/Croatia/CroatiaTest.php @@ -0,0 +1,124 @@ + + */ + +namespace Yasumi\tests\Croatia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Croatia. + */ +class CroatiaTest extends CroatiaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1941); + } + + /** + * Tests if all official holidays in Croatia are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'internationalWorkersDay', + 'epiphany', + 'easter', + 'easterMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'christmasDay', + 'stStephensDay', + ]; + + if ($this->year >= 1941) { + $holidays[] = 'antifascistStruggleDay'; + } + + if ($this->year >= 1991) { + $holidays[] = 'statehoodDay'; + } + + if ($this->year >= 1995) { + $holidays[] = 'homelandThanksgiving'; + } + + if ($this->year >= 1991 && $this->year < 2020) { + $holidays[] = 'independenceDay'; + } + + if ($this->year >= 2020) { + $holidays[] = 'remembranceDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Croatia are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Croatia are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Croatia are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Croatia are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 3); + } +} diff --git a/tests/Croatia/EasterMondayTest.php b/tests/Croatia/EasterMondayTest.php index ba30e9c1b..c9725b171 100644 --- a/tests/Croatia/EasterMondayTest.php +++ b/tests/Croatia/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Croatia. */ -class EasterMondayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1677; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uskršnji ponedjeljak'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/EasterTest.php b/tests/Croatia/EasterTest.php index e8939d94e..4845dca52 100644 --- a/tests/Croatia/EasterTest.php +++ b/tests/Croatia/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Croatia. */ -class EasterTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1677; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uskrs'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/EpiphanyTest.php b/tests/Croatia/EpiphanyTest.php index 0429743a4..3621056e5 100644 --- a/tests/Croatia/EpiphanyTest.php +++ b/tests/Croatia/EpiphanyTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Croatia. */ -class EpiphanyTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sveta tri kralja'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/HomelandThanksgivingDayTest.php b/tests/Croatia/HomelandThanksgivingDayTest.php index b8cadac18..c89add0a5 100644 --- a/tests/Croatia/HomelandThanksgivingDayTest.php +++ b/tests/Croatia/HomelandThanksgivingDayTest.php @@ -1,92 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Homeland Thanksgiving Day in Croatia. */ -class HomelandThanksgivingDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class HomelandThanksgivingDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'homelandThanksgiving'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1995; + /** + * The year in which the holiday name was changed. + */ + public const NAME_CHANGED_YEAR = 2020; + /** * Tests Homeland Thanksgiving Day on or after 1995. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHomelandThanksgivingDayOnAfter1995() + public function testHomelandThanksgivingDayOnAfter1995(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-5", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Homeland Thanksgiving Day before 1995. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHomelandThanksgivingDayBefore1995() + public function testHomelandThanksgivingDayBefore1995(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Homeland Thanksgiving Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::NAME_CHANGED_YEAR - 1); + $expectedText = 'Dan domovinske zahvalnosti'; $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Dan domovinske zahvalnosti'] + $year, + [self::LOCALE => $expectedText] + ); + + $year = static::generateRandomYear(self::NAME_CHANGED_YEAR); + $expectedText = 'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja'; + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => $expectedText] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Croatia/IndependenceDayTest.php b/tests/Croatia/IndependenceDayTest.php index 381a47c33..5bbfba4f0 100644 --- a/tests/Croatia/IndependenceDayTest.php +++ b/tests/Croatia/IndependenceDayTest.php @@ -1,92 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class containing tests for Independece Day in Croatia. + * Class containing tests for Independence Day in Croatia. */ -class IndependenceDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1991; + /** + * The year after which this is no longer a holiday. + */ + public const DISBANDMENT_YEAR = 2020; + /** * Tests Independence Day on or after 1991. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayOnAfter1991() + public function testIndependenceDayOnAfter1991(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::DISBANDMENT_YEAR - 1); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-8", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Independence Day before 1991. + * + * @throws \Exception + */ + public function testIndependenceDayBefore1991(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests Independence Day before 1991. - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayBefore1991() + public function testIndependenceDayAfterDisbandment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(self::DISBANDMENT_YEAR) ); } /** * Tests translated name of Independence Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::DISBANDMENT_YEAR - 1), [self::LOCALE => 'Dan neovisnosti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::DISBANDMENT_YEAR - 1), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Croatia/InternationalWorkersDayTest.php b/tests/Croatia/InternationalWorkersDayTest.php index 1be11d255..50a449e26 100644 --- a/tests/Croatia/InternationalWorkersDayTest.php +++ b/tests/Croatia/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Croatia. */ -class InternationalWorkersDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Praznik rada'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Croatia/NewYearsDayTest.php b/tests/Croatia/NewYearsDayTest.php index 345943cd1..73d2f6b60 100644 --- a/tests/Croatia/NewYearsDayTest.php +++ b/tests/Croatia/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Croatia. */ -class NewYearsDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nova godina'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/RemembranceDayTest.php b/tests/Croatia/RemembranceDayTest.php new file mode 100644 index 000000000..7e032ab88 --- /dev/null +++ b/tests/Croatia/RemembranceDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Croatia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Statehood Day in Croatia. + */ +class RemembranceDayTest extends CroatiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'remembranceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2020; + + /** + * Tests Remembrance Day. + * + * @throws \Exception + */ + public function testRemembranceDayAfterItWasEstablished(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-11-18", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Remembrance Day. + * + * @throws \Exception + */ + public function testRemembranceDayBeforeItWasEstablished(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Remembrance Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Croatia/StStephensDayTest.php b/tests/Croatia/StStephensDayTest.php index 7f19b7a2f..0475ed46e 100644 --- a/tests/Croatia/StStephensDayTest.php +++ b/tests/Croatia/StStephensDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Croatia. */ -class StStephensDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the day of St. Stephen's Day. * - * @dataProvider stStephensDayDataProvider - * - * @param int $year the year for which St. Stephen's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Stephen's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function teststStephensDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('stStephensDayDataProvider')] + public function teststStephensDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function teststStephensDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Stephen's Day. * - * @return array list of test dates for St. Stephen's Day - * @throws Exception + * @return array list of test dates for St. Stephen's Day + * + * @throws \Exception */ - public function stStephensDayDataProvider(): array + public static function stStephensDayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests translated name of St. Stephen's Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sveti Stjepan'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Croatia/StatehoodDayTest.php b/tests/Croatia/StatehoodDayTest.php index 9a23a8635..497027865 100644 --- a/tests/Croatia/StatehoodDayTest.php +++ b/tests/Croatia/StatehoodDayTest.php @@ -1,92 +1,111 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Croatia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Statehood Day in Croatia. */ -class StatehoodDayTest extends CroatiaBaseTestCase implements YasumiTestCaseInterface +class StatehoodDayTest extends CroatiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'statehoodDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1991; /** - * Tests Statehood Day on or after 1991. - * @throws Exception - * @throws ReflectionException + * The year in which the holiday celebration date has changed. + */ + public const DATE_CHANGE_YEAR = 2020; + + /** + * Tests Statehood Day. + * + * @throws \Exception */ - public function testStatehoodDayOnAfter1991() + public function testStatehoodDay(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::DATE_CHANGE_YEAR - 1); + $expectedDate = "{$year}-6-25"; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expectedDate, new \DateTimeZone(self::TIMEZONE)) + ); + + $year = static::generateRandomYear(self::DATE_CHANGE_YEAR); + $expectedDate = "{$year}-5-30"; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime($expectedDate, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Statehood Day before 1991. - * @throws ReflectionException + * + * @throws \Exception */ - public function testStatehoodDayBefore1991() + public function testStatehoodDayBefore1991(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Statehood Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Dan državnosti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/CzechRepublic/ChristmasDayTest.php b/tests/CzechRepublic/ChristmasDayTest.php index 8113bd81b..8a2da6a29 100644 --- a/tests/CzechRepublic/ChristmasDayTest.php +++ b/tests/CzechRepublic/ChristmasDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas day in the Czech Republic. * * Class ChristmasDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class ChristmasDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '1. svátek vánoční'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/ChristmasEveTest.php b/tests/CzechRepublic/ChristmasEveTest.php index 96c633347..3b23a4c87 100644 --- a/tests/CzechRepublic/ChristmasEveTest.php +++ b/tests/CzechRepublic/ChristmasEveTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Eve in the Czech Republic. * * Class ChristmasDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class ChristmasEveTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasEve'; /** * Tests Christmas Eve. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Eve needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Eve needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Štědrý den'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/CzechRepublicBaseTestCase.php b/tests/CzechRepublic/CzechRepublicBaseTestCase.php index d3ada4e03..04be66cd3 100644 --- a/tests/CzechRepublic/CzechRepublicBaseTestCase.php +++ b/tests/CzechRepublic/CzechRepublicBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; @@ -19,25 +24,19 @@ * Base class for test cases of the Czech Republic holiday provider. * * Class CzechRepublicBaseTestCase - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ abstract class CzechRepublicBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'CzechRepublic'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Prague'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'cs_CZ'; } diff --git a/tests/CzechRepublic/CzechRepublicTest.php b/tests/CzechRepublic/CzechRepublicTest.php index 10eaaca3f..04f8bc9fd 100644 --- a/tests/CzechRepublic/CzechRepublicTest.php +++ b/tests/CzechRepublic/CzechRepublicTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Czech Republic. * * Class CzechRepublicTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class CzechRepublicTest extends CzechRepublicBaseTestCase +class CzechRepublicTest extends CzechRepublicBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Finland are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } + + /** + * Tests if all official holidays in Finland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -42,6 +56,7 @@ public function testOfficialHolidays(): void 'goodFriday', 'easterMonday', 'internationalWorkersDay', + 'christmasEve', 'christmasDay', 'secondChristmasDay', 'saintsCyrilAndMethodiusDay', @@ -53,17 +68,15 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the Czech Republic are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Czech Republic are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays(['christmasEve'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in the Czech Republic are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Czech Republic are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -71,8 +84,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Czech Republic are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Czech Republic are defined by the provider class. */ public function testBankHolidays(): void { @@ -80,8 +92,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Czech Republic are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Czech Republic are defined by the provider class. */ public function testOtherHolidays(): void { @@ -89,10 +100,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/CzechRepublic/CzechStateHoodDayTest.php b/tests/CzechRepublic/CzechStateHoodDayTest.php index bc186bd36..25d7fff23 100644 --- a/tests/CzechRepublic/CzechStateHoodDayTest.php +++ b/tests/CzechRepublic/CzechStateHoodDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Czech State Hood Day in the Czech Republic. * * Class CzechStateHoodDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class CzechStateHoodDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class CzechStateHoodDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'czechStateHoodDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(9, 28, self::TIMEZONE); + return static::generateRandomDates(9, 28, self::TIMEZONE); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den české státnosti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/EasterMondayTest.php b/tests/CzechRepublic/EasterMondayTest.php index 53f655171..d22bc22ac 100644 --- a/tests/CzechRepublic/EasterMondayTest.php +++ b/tests/CzechRepublic/EasterMondayTest.php @@ -1,74 +1,77 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in the Czech Republic. * * Class EasterMondayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class EasterMondayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2000; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Velikonoční pondělí'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/GoodFridayTest.php b/tests/CzechRepublic/GoodFridayTest.php index 4c0ab0b3d..76001f8fe 100644 --- a/tests/CzechRepublic/GoodFridayTest.php +++ b/tests/CzechRepublic/GoodFridayTest.php @@ -1,74 +1,77 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in the Czech Republic. * * Class GoodFridayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class GoodFridayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests Good Friday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testGoodFriday() + public function testGoodFriday(): void { $year = 1876; $this->assertHoliday( self::REGION, 'goodFriday', $year, - new DateTime("$year-4-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-14", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Velký pátek'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/IndependentCzechoslovakStateDayTest.php b/tests/CzechRepublic/IndependentCzechoslovakStateDayTest.php index 29f2e24fc..5e9a64839 100644 --- a/tests/CzechRepublic/IndependentCzechoslovakStateDayTest.php +++ b/tests/CzechRepublic/IndependentCzechoslovakStateDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Independent Czechoslovak State Day in the Czech Republic. */ -class IndependentCzechoslovakStateDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class IndependentCzechoslovakStateDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independentCzechoslovakStateDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(10, 28, self::TIMEZONE); + return static::generateRandomDates(10, 28, self::TIMEZONE); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den vzniku samostatného československého státu'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/InternationalWorkersDayTest.php b/tests/CzechRepublic/InternationalWorkersDayTest.php index 85ab5b39e..9ebd71e84 100644 --- a/tests/CzechRepublic/InternationalWorkersDayTest.php +++ b/tests/CzechRepublic/InternationalWorkersDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in the Czech Republic. * * Class InternationalWorkersDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class InternationalWorkersDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of International Workers' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Svátek práce'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/CzechRepublic/JanHusDayTest.php b/tests/CzechRepublic/JanHusDayTest.php index de27c6612..33d1f880e 100644 --- a/tests/CzechRepublic/JanHusDayTest.php +++ b/tests/CzechRepublic/JanHusDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Jan Hus Day in the Czech Republic. */ -class JanHusDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class JanHusDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'janHusDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(7, 6, self::TIMEZONE); + return static::generateRandomDates(7, 6, self::TIMEZONE); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den upálení mistra Jana Husa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/NewYearsDayTest.php b/tests/CzechRepublic/NewYearsDayTest.php index 1fc3f77af..ae86d5485 100644 --- a/tests/CzechRepublic/NewYearsDayTest.php +++ b/tests/CzechRepublic/NewYearsDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the Czech Republic. * * Class NewYearsDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class NewYearsDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nový rok'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/RenewalOfIndependentCzechStateDayTest.php b/tests/CzechRepublic/RenewalOfIndependentCzechStateDayTest.php index 76b1ecc49..7c2daa30e 100644 --- a/tests/CzechRepublic/RenewalOfIndependentCzechStateDayTest.php +++ b/tests/CzechRepublic/RenewalOfIndependentCzechStateDayTest.php @@ -1,84 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Day of renewal of independent czech state in Czechia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) * @author Jan Langer */ -class RenewalOfIndependentCzechStateDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class RenewalOfIndependentCzechStateDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'czechRenewalOfIndependentStateDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den obnovy samostatného českého státu'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/SaintsCyrilAndMethodiusDayTest.php b/tests/CzechRepublic/SaintsCyrilAndMethodiusDayTest.php index 6d0ba2042..866e2fb39 100644 --- a/tests/CzechRepublic/SaintsCyrilAndMethodiusDayTest.php +++ b/tests/CzechRepublic/SaintsCyrilAndMethodiusDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Saints Cyril and Methodius Day in the Czech Republic. * * Class SaintsCyrilAndMethodiusDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class SaintsCyrilAndMethodiusDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class SaintsCyrilAndMethodiusDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'saintsCyrilAndMethodiusDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(7, 5, self::TIMEZONE); + return static::generateRandomDates(7, 5, self::TIMEZONE); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den slovanských věrozvěstů Cyrila a Metoděje'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/SecondChristmasDayTest.php b/tests/CzechRepublic/SecondChristmasDayTest.php index fe56cf245..0e9c02df4 100644 --- a/tests/CzechRepublic/SecondChristmasDayTest.php +++ b/tests/CzechRepublic/SecondChristmasDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in the Czech Republic. * * Class SecondChristmasDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class SecondChristmasDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. svátek vánoční'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/StruggleForFreedomAndDemocracyDayTest.php b/tests/CzechRepublic/StruggleForFreedomAndDemocracyDayTest.php index 2f60fc6a1..4604ba145 100644 --- a/tests/CzechRepublic/StruggleForFreedomAndDemocracyDayTest.php +++ b/tests/CzechRepublic/StruggleForFreedomAndDemocracyDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Struggle for Freedom and Democracy Day in the Czech Republic. */ -class StruggleForFreedomAndDemocracyDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class StruggleForFreedomAndDemocracyDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'struggleForFreedomAndDemocracyDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 17, self::TIMEZONE); + return static::generateRandomDates(11, 17, self::TIMEZONE); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den boje za svobodu a demokracii'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/CzechRepublic/VictoryInEuropeDayTest.php b/tests/CzechRepublic/VictoryInEuropeDayTest.php index f079cc48b..252a41327 100644 --- a/tests/CzechRepublic/VictoryInEuropeDayTest.php +++ b/tests/CzechRepublic/VictoryInEuropeDayTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\CzechRepublic; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Victory In Europe Day in the Czech Republic. * * Class VictoryInEuropeDayTest - * @package Yasumi\tests\CzechRepublic + * * @author Dennis Fridrich */ -class VictoryInEuropeDayTest extends CzechRepublicBaseTestCase implements YasumiTestCaseInterface +class VictoryInEuropeDayTest extends CzechRepublicBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'victoryInEuropeDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 8, self::TIMEZONE); + return static::generateRandomDates(5, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Den vítězství'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/AscensionDayTest.php b/tests/Denmark/AscensionDayTest.php index c44814f05..602627541 100644 --- a/tests/Denmark/AscensionDayTest.php +++ b/tests/Denmark/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Denmark. */ -class AscensionDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 2806; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-4", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests translated name of Ascension Day - * @throws ReflectionException + * Tests translated name of Ascension Day. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kristi himmelfartsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/ChristmasDayTest.php b/tests/Denmark/ChristmasDayTest.php index 215eaeaee..f4cf78868 100644 --- a/tests/Denmark/ChristmasDayTest.php +++ b/tests/Denmark/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Denmark. */ -class ChristmasDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Juledag'] + static::generateRandomYear(), + [self::LOCALE => 'juledag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/ChristmasEveTest.php b/tests/Denmark/ChristmasEveTest.php index 92f7897cb..df1117740 100644 --- a/tests/Denmark/ChristmasEveTest.php +++ b/tests/Denmark/ChristmasEveTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Eve in Denmark. */ -class ChristmasEveTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Juleaften'] + static::generateRandomYear(), + [self::LOCALE => 'juleaften'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Denmark/ConstitutionDayTest.php b/tests/Denmark/ConstitutionDayTest.php index 3879fc4e5..859ff182e 100644 --- a/tests/Denmark/ConstitutionDayTest.php +++ b/tests/Denmark/ConstitutionDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Constitution Day of Denmark. */ -class ConstitutionDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constitutionDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1849; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2077; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-5", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Grundlovsdag'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'grundlovsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OBSERVANCE ); } diff --git a/tests/Denmark/DaylightSavingTime.php b/tests/Denmark/DaylightSavingTime.php new file mode 100644 index 000000000..cbd6389d4 --- /dev/null +++ b/tests/Denmark/DaylightSavingTime.php @@ -0,0 +1,52 @@ + + */ + +namespace Yasumi\tests\Denmark; + +use Yasumi\tests\HolidayTestCase; + +abstract class DaylightSavingTime extends DenmarkBaseTestCase implements HolidayTestCase +{ + /** @var int[] */ + public array $observedYears; + + /** @var int[] */ + public array $unobservedYears; + + public function __construct() + { + $observedYears = [1916, 1940]; + $observedYears = [...$observedYears, ...range(1942, 1948)]; + $observedYears = array_merge($observedYears, range(1980, 2037)); // PHP caps future DST transitions + + $this->observedYears = $observedYears; + $this->unobservedYears = array_diff(range(reset($observedYears), end($observedYears)), $observedYears); + + parent::__construct(); + } + + /* Swaps the observation from observed to unobserved for the given years */ + protected function swapObservation(array $years): void + { + foreach ($years as $y) { + $this->observedYears[] = $y; + if (false !== ($key = array_search($y, $this->unobservedYears, true))) { + unset($this->unobservedYears[(int) $key]); + } + } + } +} diff --git a/tests/Denmark/DenmarkBaseTestCase.php b/tests/Denmark/DenmarkBaseTestCase.php index 9a2c90dce..6a0df80c6 100644 --- a/tests/Denmark/DenmarkBaseTestCase.php +++ b/tests/Denmark/DenmarkBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; @@ -22,18 +27,12 @@ abstract class DenmarkBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Denmark'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Copenhagen'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'da_DK'; } diff --git a/tests/Denmark/DenmarkTest.php b/tests/Denmark/DenmarkTest.php index f1b2d741b..b20b3c890 100644 --- a/tests/Denmark/DenmarkTest.php +++ b/tests/Denmark/DenmarkTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Denmark. */ -class DenmarkTest extends DenmarkBaseTestCase +class DenmarkTest extends DenmarkBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Denmark are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2024); + } + + /** + * Tests if all official holidays in Denmark are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -37,7 +51,6 @@ public function testOfficialHolidays(): void 'goodFriday', 'easter', 'easterMonday', - 'greatPrayerDay', 'ascensionDay', 'pentecost', 'pentecostMonday', @@ -47,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Denmark are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Denmark are defined by the provider class. */ public function testObservedHolidays(): void { @@ -61,18 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Denmark are defined by the provider class - * @throws ReflectionException - */ - public function testSeasonalHolidays(): void - { - $year = $this->generateRandomYear(1980, 2037); - $this->assertDefinedHolidays(['summerTime', 'winterTime'], self::REGION, $year, Holiday::TYPE_SEASON); - } - - /** - * Tests if all bank holidays in Denmark are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Denmark are defined by the provider class. */ public function testBankHolidays(): void { @@ -80,8 +81,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Denmark are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Denmark are defined by the provider class. */ public function testOtherHolidays(): void { @@ -89,10 +89,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1849); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Denmark/EasterMondayTest.php b/tests/Denmark/EasterMondayTest.php index 49aff7ae5..1a1229ada 100644 --- a/tests/Denmark/EasterMondayTest.php +++ b/tests/Denmark/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Denmark. */ -class EasterMondayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2000; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. påskedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/EasterTest.php b/tests/Denmark/EasterTest.php index 1affea3a8..177300ede 100644 --- a/tests/Denmark/EasterTest.php +++ b/tests/Denmark/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Denmark. */ -class EasterTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2654; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-26", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-26", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Påskedag'] + static::generateRandomYear(), + [self::LOCALE => 'påskedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/GoodFridayTest.php b/tests/Denmark/GoodFridayTest.php index 0baea5c52..c21cee9e7 100644 --- a/tests/Denmark/GoodFridayTest.php +++ b/tests/Denmark/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Denmark. */ -class GoodFridayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2178; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Langfredag'] + static::generateRandomYear(), + [self::LOCALE => 'langfredag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/GreatPrayerDayTest.php b/tests/Denmark/GreatPrayerDayTest.php index ffcd70864..3f130563b 100644 --- a/tests/Denmark/GreatPrayerDayTest.php +++ b/tests/Denmark/GreatPrayerDayTest.php @@ -1,92 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Great Prayer Day in Denmark. */ -class GreatPrayerDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class GreatPrayerDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'greatPrayerDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1686; + /** + * The first year the holiday was no longer observed. + */ + public const ABOLISHMENT_YEAR = 2024; + /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2022; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-13", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-13", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the holiday defined in this test after abolishment. + * * @throws ReflectionException */ - public function testHolidayBeforeEstablishment() + public function testHolidayAfterAbolishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(self::ABOLISHMENT_YEAR) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Store bededag'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR - 1), + [self::LOCALE => 'store bededag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR - 1), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Denmark/InternationalWorkersDayTest.php b/tests/Denmark/InternationalWorkersDayTest.php index 8089a1516..df4688b21 100644 --- a/tests/Denmark/InternationalWorkersDayTest.php +++ b/tests/Denmark/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Denmark. */ -class InternationalWorkersDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testInternationalWorkersDay($year, $expected) /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Første maj'] + static::generateRandomYear(), + [self::LOCALE => 'første maj'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Denmark/MaundyThursdayTest.php b/tests/Denmark/MaundyThursdayTest.php index 5552a3357..dec941d3b 100644 --- a/tests/Denmark/MaundyThursdayTest.php +++ b/tests/Denmark/MaundyThursdayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Maundy Thursday in Denmark. */ -class MaundyThursdayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class MaundyThursdayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'maundyThursday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-29", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Skærtorsdag'] + static::generateRandomYear(), + [self::LOCALE => 'skærtorsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/NewYearsDayTest.php b/tests/Denmark/NewYearsDayTest.php index ee2157508..d1e935e4b 100644 --- a/tests/Denmark/NewYearsDayTest.php +++ b/tests/Denmark/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Denmark. */ -class NewYearsDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Nytårsdag'] + static::generateRandomYear(), + [self::LOCALE => 'nytårsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/NewYearsEveTest.php b/tests/Denmark/NewYearsEveTest.php index b1d72f816..b4bffe70a 100644 --- a/tests/Denmark/NewYearsEveTest.php +++ b/tests/Denmark/NewYearsEveTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Eve in Denmark. */ -class NewYearsEveTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class NewYearsEveTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 31, self::TIMEZONE); + return static::generateRandomDates(12, 31, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Nytårsaften'] + static::generateRandomYear(), + [self::LOCALE => 'nytårsaften'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Denmark/PentecostMondayTest.php b/tests/Denmark/PentecostMondayTest.php index 42200e399..86d754ae8 100644 --- a/tests/Denmark/PentecostMondayTest.php +++ b/tests/Denmark/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Denmark. */ -class PentecostMondayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. pinsedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/PentecostTest.php b/tests/Denmark/PentecostTest.php index bd6ec9ea2..eea3e006f 100644 --- a/tests/Denmark/PentecostTest.php +++ b/tests/Denmark/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Denmark. */ -class PentecostTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Pinsedag'] + static::generateRandomYear(), + [self::LOCALE => 'pinsedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/SecondChristmasDayTest.php b/tests/Denmark/SecondChristmasDayTest.php index 06f158cd6..75daa1d26 100644 --- a/tests/Denmark/SecondChristmasDayTest.php +++ b/tests/Denmark/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Denmark; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Denmark. */ -class SecondChristmasDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends DenmarkBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. juledag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Denmark/SummerTimeTest.php b/tests/Denmark/SummerTimeTest.php deleted file mode 100644 index 04e63ca8a..000000000 --- a/tests/Denmark/SummerTimeTest.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ - -namespace Yasumi\tests\Denmark; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing summer time in Denmark. - */ -class SummerTimeTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'summerTime'; - - /** - * Tests the holiday defined in this test. - * - * @throws Exception - * @throws ReflectionException - */ - public function testSummerTime() - { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1949, 1979)); - - $year = $this->generateRandomYear(1980, 2036); - $expectedDate = new DateTime("last sunday of march $year", new DateTimeZone(self::TIMEZONE)); - - // Since 1980 Summertime in Denmark starts on the last day of March. In 1980 itself however, it started on April, 6th. - if (1980 === $year) { - $expectedDate = new DateTime('1980-04-06', new DateTimeZone(self::TIMEZONE)); - } - - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - $expectedDate - ); - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1980, 2037), - [self::LOCALE => 'Sommertid starter'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1980, 2037), Holiday::TYPE_SEASON); - } -} diff --git a/tests/Denmark/WinterTimeTest.php b/tests/Denmark/WinterTimeTest.php deleted file mode 100644 index 8392c84bb..000000000 --- a/tests/Denmark/WinterTimeTest.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ - -namespace Yasumi\tests\Denmark; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing winter time in Denmark. - */ -class WinterTimeTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'winterTime'; - - /** - * Tests the holiday defined in this test. - * - * @throws Exception - * @throws ReflectionException - */ - public function testWinterTime() - { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1949, 1979)); - - $year = $this->generateRandomYear(1980, 1995); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("last sunday of september $year", new DateTimeZone(self::TIMEZONE)) - ); - - $year = $this->generateRandomYear(1996, 2036); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("last sunday of october $year", new DateTimeZone(self::TIMEZONE)) - ); - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1980, 2037), - [self::LOCALE => 'Sommertid slutter'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1980, 2037), Holiday::TYPE_SEASON); - } -} diff --git a/tests/Estonia/ChristmasDayTest.php b/tests/Estonia/ChristmasDayTest.php index 7ab5bd695..b17fc318c 100644 --- a/tests/Estonia/ChristmasDayTest.php +++ b/tests/Estonia/ChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas day in Estonia. * * @author Gedas Lukošius */ -class ChristmasDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Esimene jõulupüha'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/ChristmasEveDayTest.php b/tests/Estonia/ChristmasEveDayTest.php index ea85a12d1..7afb35c62 100644 --- a/tests/Estonia/ChristmasEveDayTest.php +++ b/tests/Estonia/ChristmasEveDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas Eve day in Estonia. * * @author Gedas Lukošius */ -class ChristmasEveDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasEve'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jõululaupäev'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/EasterDayTest.php b/tests/Estonia/EasterDayTest.php index 1549eb631..0cfd3ff63 100644 --- a/tests/Estonia/EasterDayTest.php +++ b/tests/Estonia/EasterDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter day in Estonia. * * @author Gedas Lukošius */ -class EasterDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class EasterDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomEasterDates(self::TIMEZONE); + return static::generateRandomEasterDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ülestõusmispühade 1. püha'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/EstoniaBaseTestCase.php b/tests/Estonia/EstoniaBaseTestCase.php index d83bcfbfa..dbc3987f7 100644 --- a/tests/Estonia/EstoniaBaseTestCase.php +++ b/tests/Estonia/EstoniaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; @@ -26,17 +30,13 @@ abstract class EstoniaBaseTestCase extends TestCase use YasumiBase; /** - * Name of the country to be tested + * Name of the country to be tested. */ public const REGION = 'Estonia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Tallinn'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'et_EE'; } diff --git a/tests/Estonia/EstoniaTest.php b/tests/Estonia/EstoniaTest.php index e0512973d..7a4fb5e3b 100644 --- a/tests/Estonia/EstoniaTest.php +++ b/tests/Estonia/EstoniaTest.php @@ -1,32 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Estonia; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Estonia. * * @author Gedas Lukošius */ -class EstoniaTest extends EstoniaBaseTestCase +class EstoniaTest extends EstoniaBaseTestCase implements ProviderTestCase { /** - * Tests if all official holidays in Estonia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Estonia are defined by the provider class. + * + * @throws \Exception */ public function testOfficialHolidays(): void { @@ -42,7 +47,7 @@ public function testOfficialHolidays(): void 'stJohnsDay', ]; - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); if ($year >= Estonia::DECLARATION_OF_INDEPENDENCE_YEAR) { $holidays[] = 'independenceDay'; @@ -60,38 +65,51 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Estonia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Estonia are defined by the provider class. + * + * @throws \Exception */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Estonia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Estonia are defined by the provider class. + * + * @throws \Exception */ public function testSeasonalHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_SEASON); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); } /** - * Tests if all bank holidays in Estonia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Estonia are defined by the provider class. + * + * @throws \Exception */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Estonia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Estonia are defined by the provider class. + * + * @throws \Exception */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Estonia/GoodFridayDayTest.php b/tests/Estonia/GoodFridayDayTest.php index d91fab815..f859035da 100644 --- a/tests/Estonia/GoodFridayDayTest.php +++ b/tests/Estonia/GoodFridayDayTest.php @@ -1,88 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Estonia's Good Friday day. * * @author Gedas Lukošius */ -class GoodFridayDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** - * @return array + * @return array list of test dates for the holiday defined in this test * - * @throws Exception + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomGoodFridayDates(self::TIMEZONE); + return static::generateRandomGoodFridayDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Suur Reede'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/IndependenceDayTest.php b/tests/Estonia/IndependenceDayTest.php index be538ca91..9b005ea0e 100644 --- a/tests/Estonia/IndependenceDayTest.php +++ b/tests/Estonia/IndependenceDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Estonia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Estonia's independence day. * * @author Gedas Lukošius */ -class IndependenceDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'independenceDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Estonia::DECLARATION_OF_INDEPENDENCE_YEAR - 1) + static::generateRandomYear(1000, Estonia::DECLARATION_OF_INDEPENDENCE_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR); + $year = static::generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-02-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-02-24", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), [self::LOCALE => 'Iseseisvuspäev'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), ['en' => 'Independence Day'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Estonia::DECLARATION_OF_INDEPENDENCE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Estonia/InternationalWorkersDayTest.php b/tests/Estonia/InternationalWorkersDayTest.php index e91005593..825dfbced 100644 --- a/tests/Estonia/InternationalWorkersDayTest.php +++ b/tests/Estonia/InternationalWorkersDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day in Estonia. * * @author Gedas Lukošius */ -class InternationalWorkersDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kevadpüha'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/NewYearsDayTest.php b/tests/Estonia/NewYearsDayTest.php index 5d0f94cca..68299ce8c 100644 --- a/tests/Estonia/NewYearsDayTest.php +++ b/tests/Estonia/NewYearsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's Day in Estonia. * * @author Gedas Lukošius */ -class NewYearsDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uusaasta'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/PentecostTest.php b/tests/Estonia/PentecostTest.php index 92bdd46ac..1c5c4b4da 100644 --- a/tests/Estonia/PentecostTest.php +++ b/tests/Estonia/PentecostTest.php @@ -1,88 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Pentecost in Estonia. * * @author Gedas Lukošius */ -class PentecostTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecost'; /** - * @return array + * @return array list of test dates for the holiday defined in this test * - * @throws Exception + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomPentecostDates(self::TIMEZONE); + return static::generateRandomPentecostDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nelipühade 1. püha'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/RestorationOfIndependenceDayTest.php b/tests/Estonia/RestorationOfIndependenceDayTest.php index ea16b7228..f5a92cf38 100644 --- a/tests/Estonia/RestorationOfIndependenceDayTest.php +++ b/tests/Estonia/RestorationOfIndependenceDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Estonia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Estonia's Restoration of Independence day. * * @author Gedas Lukošius */ -class RestorationOfIndependenceDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class RestorationOfIndependenceDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'restorationOfIndependenceDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Estonia::RESTORATION_OF_INDEPENDENCE_YEAR - 1) + static::generateRandomYear(1000, Estonia::RESTORATION_OF_INDEPENDENCE_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR); + $year = static::generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-08-20", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-08-20", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), - [self::LOCALE => 'Tasiseseisvumispäev'] + static::generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + [self::LOCALE => 'Taasiseseisvumispäev'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), ['en' => 'Day of Restoration of Independence'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Estonia::RESTORATION_OF_INDEPENDENCE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Estonia/SecondChristmasDayTest.php b/tests/Estonia/SecondChristmasDayTest.php index 9b43940bb..b53991963 100644 --- a/tests/Estonia/SecondChristmasDayTest.php +++ b/tests/Estonia/SecondChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Second Christmas day in Estonia. * * @author Gedas Lukošius */ -class SecondChristmasDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Teine Jõulupüha'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/StJohnsDayTest.php b/tests/Estonia/StJohnsDayTest.php index 5a688fd88..e01379c5e 100644 --- a/tests/Estonia/StJohnsDayTest.php +++ b/tests/Estonia/StJohnsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for St. John's Day in Estonia. * * @author Gedas Lukošius */ -class StJohnsDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class StJohnsDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(6, 24, self::TIMEZONE); + return static::generateRandomDates(6, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jaanipäev'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Estonia/VictoryDayTest.php b/tests/Estonia/VictoryDayTest.php index cd392d34f..241630d9a 100644 --- a/tests/Estonia/VictoryDayTest.php +++ b/tests/Estonia/VictoryDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Estonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Estonia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Estonia's Victory day. * * @author Gedas Lukošius */ -class VictoryDayTest extends EstoniaBaseTestCase implements YasumiTestCaseInterface +class VictoryDayTest extends EstoniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'victoryDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Estonia::VICTORY_DAY_START_YEAR - 1) + static::generateRandomYear(1000, Estonia::VICTORY_DAY_START_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR); + $year = static::generateRandomYear(Estonia::VICTORY_DAY_START_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-06-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-23", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + static::generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), [self::LOCALE => 'Võidupüha'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + static::generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), ['en' => 'Victory Day'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), + static::generateRandomYear(Estonia::VICTORY_DAY_START_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Finland/AllSaintsDayTest.php b/tests/Finland/AllSaintsDayTest.php index 01cfce9f4..5d5135a5a 100644 --- a/tests/Finland/AllSaintsDayTest.php +++ b/tests/Finland/AllSaintsDayTest.php @@ -1,63 +1,61 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Finland. */ -class AllSaintsDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE)); // Check between 31 October and 6th of November the day that is a Saturday for ($d = 0; $d <= 7; ++$d) { @@ -65,7 +63,7 @@ public function HolidayDataProvider(): array $data[] = [$year, $date]; break; } - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); } } @@ -74,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pyhäinpäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/AscensionDayTest.php b/tests/Finland/AscensionDayTest.php index 53efe6949..800d6cc17 100644 --- a/tests/Finland/AscensionDayTest.php +++ b/tests/Finland/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Finland. */ -class AscensionDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2005; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-5", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Helatorstai'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/ChristmasDayTest.php b/tests/Finland/ChristmasDayTest.php index 58a89a62d..9e96dc1c7 100644 --- a/tests/Finland/ChristmasDayTest.php +++ b/tests/Finland/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Finland. */ -class ChristmasDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Joulupäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/EasterMondayTest.php b/tests/Finland/EasterMondayTest.php index e1fcd7d12..b7e83c8bd 100644 --- a/tests/Finland/EasterMondayTest.php +++ b/tests/Finland/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Finland. */ -class EasterMondayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1677; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. pääsiäispäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/EasterTest.php b/tests/Finland/EasterTest.php index 799a42d58..c7341e2ad 100644 --- a/tests/Finland/EasterTest.php +++ b/tests/Finland/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Finland. */ -class EasterTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1677; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pääsiäispäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/EpiphanyTest.php b/tests/Finland/EpiphanyTest.php index b10e1cbca..8a66a09b8 100644 --- a/tests/Finland/EpiphanyTest.php +++ b/tests/Finland/EpiphanyTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Finland. */ -class EpiphanyTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Loppiainen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/FinlandBaseTestCase.php b/tests/Finland/FinlandBaseTestCase.php index b6165af06..ea212b08a 100644 --- a/tests/Finland/FinlandBaseTestCase.php +++ b/tests/Finland/FinlandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; @@ -22,18 +27,12 @@ abstract class FinlandBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Finland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Helsinki'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fi_FI'; } diff --git a/tests/Finland/FinlandTest.php b/tests/Finland/FinlandTest.php index fdb321168..36b695bf4 100644 --- a/tests/Finland/FinlandTest.php +++ b/tests/Finland/FinlandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Finland. */ -class FinlandTest extends FinlandBaseTestCase +class FinlandTest extends FinlandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1917); + } /** - * Tests if all official holidays in Finland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Finland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -49,8 +63,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Finland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Finland are defined by the provider class. */ public function testObservedHolidays(): void { @@ -58,8 +71,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Finland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Finland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +79,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Finland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Finland are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +87,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Finland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Finland are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +95,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1917); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Finland/GoodFridayTest.php b/tests/Finland/GoodFridayTest.php index 50bf6a15f..0aec9d6ad 100644 --- a/tests/Finland/GoodFridayTest.php +++ b/tests/Finland/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Finland. */ -class GoodFridayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1788; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pitkäperjantai'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/IndependenceDayTest.php b/tests/Finland/IndependenceDayTest.php index 513a49216..9a1b30a2e 100644 --- a/tests/Finland/IndependenceDayTest.php +++ b/tests/Finland/IndependenceDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Independence Day of Finland in Finland. */ -class IndependenceDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1917; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2018; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-6", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Itsenäisyyspäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Finland/InternationalWorkersDayTest.php b/tests/Finland/InternationalWorkersDayTest.php index bec52f655..4e0bfa863 100644 --- a/tests/Finland/InternationalWorkersDayTest.php +++ b/tests/Finland/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Finland. */ -class InternationalWorkersDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vappu'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Finland/NewYearsDayTest.php b/tests/Finland/NewYearsDayTest.php index 256b52db3..93a5572f3 100644 --- a/tests/Finland/NewYearsDayTest.php +++ b/tests/Finland/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Finland. */ -class NewYearsDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uudenvuodenpäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/PentecostTest.php b/tests/Finland/PentecostTest.php index 2e0d2bf81..4bd5cefe7 100644 --- a/tests/Finland/PentecostTest.php +++ b/tests/Finland/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Finland. */ -class PentecostTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1344; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Helluntaipäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/SecondChristmasDayTest.php b/tests/Finland/SecondChristmasDayTest.php index 49fc4d376..7ba8010f3 100644 --- a/tests/Finland/SecondChristmasDayTest.php +++ b/tests/Finland/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Finland. */ -class SecondChristmasDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends FinlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. joulupäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Finland/stJohnsDayTest.php b/tests/Finland/stJohnsDayTest.php index e1c63bc21..193c94e67 100644 --- a/tests/Finland/stJohnsDayTest.php +++ b/tests/Finland/stJohnsDayTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Finland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; use Yasumi\Yasumi; /** @@ -26,79 +27,79 @@ * Since 1955, the holiday has always been on a Saturday (between June 20 and June 26). Earlier it was always on * June 24. */ -class stJohnsDayTest extends FinlandBaseTestCase implements YasumiTestCaseInterface +class stJohnsDayTest extends FinlandBaseTestCase implements HolidayTestCase { - /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1955; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** * Tests the holiday before it was adjusted. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeAdjustment() + public function testHolidayBeforeAdjustment(): void { $year = 1944; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday before it was adjusted. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayAfterAdjustment() + public function testHolidayAfterAdjustment(): void { - $year = $this->generateRandomYear(self::ADJUSTMENT_YEAR); + $year = static::generateRandomYear(self::ADJUSTMENT_YEAR); $holidays = Yasumi::create(self::REGION, $year); $holiday = $holidays->getHoliday(self::HOLIDAY); // Some basic assertions - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', self::REGION), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); + self::assertInstanceOf(Holiday::class, $holiday); // Holiday specific assertions - $this->assertEquals('Saturday', $holiday->format('l')); - $this->assertGreaterThanOrEqual(20, $holiday->format('j')); - $this->assertLessThanOrEqual(26, $holiday->format('j')); + self::assertEquals('Saturday', $holiday->format('l')); + self::assertGreaterThanOrEqual(20, $holiday->format('j')); + self::assertLessThanOrEqual(26, $holiday->format('j')); unset($holiday, $holidays); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Juhannuspäivä'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/AllSaintsDayTest.php b/tests/France/AllSaintsDayTest.php index 86918086a..bcb4be3d6 100644 --- a/tests/France/AllSaintsDayTest.php +++ b/tests/France/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in France. */ -class AllSaintsDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Toussaint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/France/ArmisticeDayTest.php b/tests/France/ArmisticeDayTest.php index 462c0e507..211061788 100644 --- a/tests/France/ArmisticeDayTest.php +++ b/tests/France/ArmisticeDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Armistice Day in France. */ -class ArmisticeDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class ArmisticeDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'armisticeDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1919; /** * Tests Armistice Day on or after 1919. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testArmisticeDayOnAfter1919() + public function testArmisticeDayOnAfter1919(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-11", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Armistice Day before 1919. - * @throws ReflectionException + * + * @throws \Exception */ - public function testArmisticeDayBefore1919() + public function testArmisticeDayBefore1919(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Armistice Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Armistice 1918'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/France/AscensionDayTest.php b/tests/France/AscensionDayTest.php index c19e62280..1c99752fd 100644 --- a/tests/France/AscensionDayTest.php +++ b/tests/France/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in France. */ -class AscensionDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/AssumptionOfMaryTest.php b/tests/France/AssumptionOfMaryTest.php index 419351036..4247ada37 100644 --- a/tests/France/AssumptionOfMaryTest.php +++ b/tests/France/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in France. */ -class AssumptionOfMaryTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assomption'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/France/BasRhin/BasRhinBaseTestCase.php b/tests/France/BasRhin/BasRhinBaseTestCase.php index 9d8d4b4d0..0012fa28b 100644 --- a/tests/France/BasRhin/BasRhinBaseTestCase.php +++ b/tests/France/BasRhin/BasRhinBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\BasRhin; @@ -22,18 +27,12 @@ abstract class BasRhinBaseTestCase extends FranceBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'France/BasRhin'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Paris'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_FR'; } diff --git a/tests/France/BasRhin/BasRhinTest.php b/tests/France/BasRhin/BasRhinTest.php index 703858060..516480430 100644 --- a/tests/France/BasRhin/BasRhinTest.php +++ b/tests/France/BasRhin/BasRhinTest.php @@ -1,65 +1,88 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\BasRhin; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\Provider\France; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Bas-Rhin (France). */ -class BasRhinTest extends BasRhinBaseTestCase +class BasRhinTest extends BasRhinBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Bas-Rhin are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Bas-Rhin are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'victoryInEuropeDay', - 'goodFriday', - 'easterMonday', - 'internationalWorkersDay', - 'ascensionDay', - 'pentecostMonday', - 'assumptionOfMary', - 'allSaintsDay', - 'armisticeDay', - 'christmasDay', - 'stStephensDay', - 'bastilleDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + $holidays = + [ + 'newYearsDay', + 'victoryInEuropeDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'assumptionOfMary', + 'allSaintsDay', + 'armisticeDay', + 'christmasDay', + 'bastilleDay', + ]; + + if ($this->year < France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Bas-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Bas-Rhin (France) are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $holidays = []; + + if ($this->year >= France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Bas-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Bas-Rhin (France) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Bas-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Bas-Rhin (France) are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +98,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Bas-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Bas-Rhin (France) are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +106,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/France/BasRhin/GoodFridayTest.php b/tests/France/BasRhin/GoodFridayTest.php index 5b124a5b1..7ad5c66fa 100644 --- a/tests/France/BasRhin/GoodFridayTest.php +++ b/tests/France/BasRhin/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\BasRhin; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Bas-Rhin (France). */ -class GoodFridayTest extends BasRhinBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends BasRhinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/BasRhin/stStephensDayTest.php b/tests/France/BasRhin/stStephensDayTest.php index f8aec1e46..34fba8b6a 100644 --- a/tests/France/BasRhin/stStephensDayTest.php +++ b/tests/France/BasRhin/stStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\BasRhin; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Bas-Rhin (France). */ -class stStephensDayTest extends BasRhinBaseTestCase implements YasumiTestCaseInterface +class stStephensDayTest extends BasRhinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Saint-Étienne'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/BastilleDayTest.php b/tests/France/BastilleDayTest.php index 8b8044d4e..f3dc677be 100644 --- a/tests/France/BastilleDayTest.php +++ b/tests/France/BastilleDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Bastille Day in France. */ -class BastilleDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class BastilleDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bastilleDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1790; /** * Tests Bastille Day on or after 1790. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testBastilleDayOnAfter1790() + public function testBastilleDayOnAfter1790(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-14", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Bastille Day before 1790. - * @throws ReflectionException + * + * @throws \Exception */ - public function testBastilleDayBefore1790() + public function testBastilleDayBefore1790(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Bastille Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'La Fête nationale'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/France/ChristmasDayTest.php b/tests/France/ChristmasDayTest.php index 9b9e77742..d94613fd9 100644 --- a/tests/France/ChristmasDayTest.php +++ b/tests/France/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in France. */ -class ChristmasDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/EasterMondayTest.php b/tests/France/EasterMondayTest.php index 0f33d7257..369c26dc9 100644 --- a/tests/France/EasterMondayTest.php +++ b/tests/France/EasterMondayTest.php @@ -1,70 +1,80 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in France. */ -class EasterMondayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) + ); + $year = 2025; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/FranceBaseTestCase.php b/tests/France/FranceBaseTestCase.php index c08f34da9..87b493cac 100644 --- a/tests/France/FranceBaseTestCase.php +++ b/tests/France/FranceBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; @@ -23,17 +28,13 @@ abstract class FranceBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'France'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Paris'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_FR'; } diff --git a/tests/France/FranceTest.php b/tests/France/FranceTest.php index 973006c19..e21ab436f 100644 --- a/tests/France/FranceTest.php +++ b/tests/France/FranceTest.php @@ -1,63 +1,88 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\Provider\France; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in France. */ -class FranceTest extends FranceBaseTestCase +class FranceTest extends FranceBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in France are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in France are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'victoryInEuropeDay', - 'easterMonday', - 'internationalWorkersDay', - 'ascensionDay', - 'pentecostMonday', - 'assumptionOfMary', - 'allSaintsDay', - 'armisticeDay', - 'christmasDay', - 'bastilleDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + $holidays = + [ + 'newYearsDay', + 'victoryInEuropeDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'assumptionOfMary', + 'allSaintsDay', + 'armisticeDay', + 'christmasDay', + 'bastilleDay', + ]; + + if ($this->year < France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in France are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in France are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $holidays = []; + + if ($this->year >= France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in France are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in France are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -65,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in France are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in France are defined by the provider class. */ public function testBankHolidays(): void { @@ -74,8 +98,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in France are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in France are defined by the provider class. */ public function testOtherHolidays(): void { @@ -83,10 +106,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/France/HautRhin/GoodFridayTest.php b/tests/France/HautRhin/GoodFridayTest.php index 4a0035718..bb7c2fd23 100644 --- a/tests/France/HautRhin/GoodFridayTest.php +++ b/tests/France/HautRhin/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\HautRhin; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Haut-Rhin (France). */ -class GoodFridayTest extends HautRhinBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends HautRhinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/HautRhin/HautRhinBaseTestCase.php b/tests/France/HautRhin/HautRhinBaseTestCase.php index c8a557fd6..2bb174b21 100644 --- a/tests/France/HautRhin/HautRhinBaseTestCase.php +++ b/tests/France/HautRhin/HautRhinBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\HautRhin; @@ -22,18 +27,12 @@ abstract class HautRhinBaseTestCase extends FranceBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'France/HautRhin'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Paris'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_FR'; } diff --git a/tests/France/HautRhin/HautRhinTest.php b/tests/France/HautRhin/HautRhinTest.php index c22359657..53a273aa6 100644 --- a/tests/France/HautRhin/HautRhinTest.php +++ b/tests/France/HautRhin/HautRhinTest.php @@ -1,65 +1,88 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\HautRhin; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\Provider\France; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Haut-Rhin (France). */ -class HautRhinTest extends HautRhinBaseTestCase +class HautRhinTest extends HautRhinBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Haut-Rhin are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Haut-Rhin are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'victoryInEuropeDay', - 'goodFriday', - 'easterMonday', - 'internationalWorkersDay', - 'ascensionDay', - 'pentecostMonday', - 'assumptionOfMary', - 'allSaintsDay', - 'armisticeDay', - 'christmasDay', - 'stStephensDay', - 'bastilleDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + $holidays = + [ + 'newYearsDay', + 'victoryInEuropeDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'assumptionOfMary', + 'allSaintsDay', + 'armisticeDay', + 'christmasDay', + 'bastilleDay', + ]; + + if ($this->year < France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Haut-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Haut-Rhin (France) are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $holidays = []; + + if ($this->year >= France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Haut-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Haut-Rhin (France) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Haut-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Haut-Rhin (France) are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +98,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Haut-Rhin (France) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Haut-Rhin (France) are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +106,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/France/HautRhin/stStephensDayTest.php b/tests/France/HautRhin/stStephensDayTest.php index b56dffa4c..2b86cecef 100644 --- a/tests/France/HautRhin/stStephensDayTest.php +++ b/tests/France/HautRhin/stStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\HautRhin; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Haut-Rhin (France). */ -class stStephensDayTest extends HautRhinBaseTestCase implements YasumiTestCaseInterface +class stStephensDayTest extends HautRhinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Saint-Étienne'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/InternationalWorkersDayTest.php b/tests/France/InternationalWorkersDayTest.php index 14030c250..e91de006f 100644 --- a/tests/France/InternationalWorkersDayTest.php +++ b/tests/France/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in France. */ -class InternationalWorkersDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of International Workers' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fête du Travail'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/France/Moselle/GoodFridayTest.php b/tests/France/Moselle/GoodFridayTest.php index 23ed705d0..119d3ba23 100644 --- a/tests/France/Moselle/GoodFridayTest.php +++ b/tests/France/Moselle/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\Moselle; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Moselle (France). */ -class GoodFridayTest extends MoselleBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends MoselleBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/Moselle/MoselleBaseTestCase.php b/tests/France/Moselle/MoselleBaseTestCase.php index 0794b86d7..86a84e8fd 100644 --- a/tests/France/Moselle/MoselleBaseTestCase.php +++ b/tests/France/Moselle/MoselleBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\Moselle; @@ -22,18 +27,12 @@ abstract class MoselleBaseTestCase extends FranceBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'France/Moselle'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Paris'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_FR'; } diff --git a/tests/France/Moselle/MoselleTest.php b/tests/France/Moselle/MoselleTest.php index fe394b24a..f2e746602 100644 --- a/tests/France/Moselle/MoselleTest.php +++ b/tests/France/Moselle/MoselleTest.php @@ -1,65 +1,88 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\Moselle; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\Provider\France; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Moselle (France). */ -class MoselleTest extends MoselleBaseTestCase +class MoselleTest extends MoselleBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Moselle are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Moselle are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'victoryInEuropeDay', - 'goodFriday', - 'easterMonday', - 'internationalWorkersDay', - 'ascensionDay', - 'pentecostMonday', - 'assumptionOfMary', - 'allSaintsDay', - 'armisticeDay', - 'christmasDay', - 'stStephensDay', - 'bastilleDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + $holidays = + [ + 'newYearsDay', + 'victoryInEuropeDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'assumptionOfMary', + 'allSaintsDay', + 'armisticeDay', + 'christmasDay', + 'bastilleDay', + ]; + + if ($this->year < France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Moselle (France) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Moselle (France) are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $holidays = []; + + if ($this->year >= France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY) { + $holidays[] = 'pentecostMonday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Moselle (France) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Moselle (France) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Moselle (France) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Moselle (France) are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +98,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Moselle (France) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Moselle (France) are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +106,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/France/Moselle/stStephensDayTest.php b/tests/France/Moselle/stStephensDayTest.php index 09591f444..102819f9d 100644 --- a/tests/France/Moselle/stStephensDayTest.php +++ b/tests/France/Moselle/stStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France\Moselle; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Moselle (France). */ -class stStephensDayTest extends MoselleBaseTestCase implements YasumiTestCaseInterface +class stStephensDayTest extends MoselleBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Saint-Étienne'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/France/NewYearsDayTest.php b/tests/France/NewYearsDayTest.php index 16008a4df..6d40df078 100644 --- a/tests/France/NewYearsDayTest.php +++ b/tests/France/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in France. */ -class NewYearsDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Jour de l\'An'] + static::generateRandomYear(), + [self::LOCALE => 'Jour de l’An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/France/PentecostMondayTest.php b/tests/France/PentecostMondayTest.php index ac97ae08e..dbdcec793 100644 --- a/tests/France/PentecostMondayTest.php +++ b/tests/France/PentecostMondayTest.php @@ -1,70 +1,86 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\Provider\France; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in France. */ -class PentecostMondayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(null, France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY - 1), + Holiday::TYPE_OFFICIAL + ); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(France::EST_YEAR_DAY_OF_SOLIDARITY_WITH_ELDERLY), + Holiday::TYPE_OBSERVANCE + ); } } diff --git a/tests/France/VictoryInEuropeDayTest.php b/tests/France/VictoryInEuropeDayTest.php index ee023d35f..d1e11e4a0 100644 --- a/tests/France/VictoryInEuropeDayTest.php +++ b/tests/France/VictoryInEuropeDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\France; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Victory in Europe Day in France. */ -class VictoryInEuropeDayTest extends FranceBaseTestCase implements YasumiTestCaseInterface +class VictoryInEuropeDayTest extends FranceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'victoryInEuropeDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1945; /** * Tests Victory In Europe Day on or after 1945. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testVictoryInEuropeDayOnAfter1945() + public function testVictoryInEuropeDayOnAfter1945(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Victory In Europe Day before 1945. - * @throws ReflectionException + * + * @throws \Exception */ - public function testVictoryInEuropeDayBefore1945() + public function testVictoryInEuropeDayBefore1945(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Victory in Europe Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Victoire 1945'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Georgia/EasterTest.php b/tests/Georgia/EasterTest.php new file mode 100644 index 000000000..289fa027e --- /dev/null +++ b/tests/Georgia/EasterTest.php @@ -0,0 +1,71 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class EasterTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2019; + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-28", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'აღდგომა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/GeorgiaBaseTestCase.php b/tests/Georgia/GeorgiaBaseTestCase.php new file mode 100644 index 000000000..967053a3c --- /dev/null +++ b/tests/Georgia/GeorgiaBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Georgia holiday provider. + */ +abstract class GeorgiaBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Name of the country to be tested. + */ + public const REGION = 'Georgia'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Asia/Tbilisi'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'ka_GE'; +} diff --git a/tests/Georgia/GeorgiaTest.php b/tests/Georgia/GeorgiaTest.php new file mode 100644 index 000000000..aa5fb2fb7 --- /dev/null +++ b/tests/Georgia/GeorgiaTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\Provider\Georgia; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Georgia. + * + * @author Zurab Sardarov + */ +class GeorgiaTest extends GeorgiaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } + + /** + * Tests if all official holidays in Georgia are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'easter', + 'victoryDay', + 'mothersDay', + 'newYearsDay', + 'internationalWomensDay', + 'secondDayOfNewYear', + 'orthodoxChristmasDay', + 'stAndrewsDay', + 'orthodoxEpiphanyDay', + 'mtskhetobaDay', + 'stMarysDay', + 'stGeorgesDay', + ]; + + if ($this->year >= Georgia::PROCLAMATION_OF_INDEPENDENCE_YEAR) { + $holidays[] = 'independenceDay'; + } + if ($this->year >= Georgia::APRIL_NINE_TRAGEDY_YEAR) { + $holidays[] = 'unityDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Georgia are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Georgia are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Georgia are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Georgia are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 3); + } +} diff --git a/tests/Georgia/IndependenceDayTest.php b/tests/Georgia/IndependenceDayTest.php new file mode 100644 index 000000000..beeb64034 --- /dev/null +++ b/tests/Georgia/IndependenceDayTest.php @@ -0,0 +1,68 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class IndependenceDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'independenceDay'; + + /** + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2019; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-26", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $year = 2019; + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'საქართველოს დამოუკიდებლობის დღე'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $year = 2019; + + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/InternationalWomensDayTest.php b/tests/Georgia/InternationalWomensDayTest.php new file mode 100644 index 000000000..dcf8880b9 --- /dev/null +++ b/tests/Georgia/InternationalWomensDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class InternationalWomensDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'internationalWomensDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(3, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ქალთა საერთაშორისო დღე'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/MtskhetobaDayTest.php b/tests/Georgia/MtskhetobaDayTest.php new file mode 100644 index 000000000..fc1bcf4ae --- /dev/null +++ b/tests/Georgia/MtskhetobaDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class MtskhetobaDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'mtskhetobaDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(10, 14, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'მცხეთობა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/NewYearsDayTest.php b/tests/Georgia/NewYearsDayTest.php new file mode 100644 index 000000000..ea246567b --- /dev/null +++ b/tests/Georgia/NewYearsDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class NewYearsDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'newYearsDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ახალი წელი'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/OrthodoxChristmasDayTest.php b/tests/Georgia/OrthodoxChristmasDayTest.php new file mode 100644 index 000000000..d35b5a5bc --- /dev/null +++ b/tests/Georgia/OrthodoxChristmasDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class OrthodoxChristmasDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'orthodoxChristmasDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 7, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ქრისტეს შობა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/OrthodoxEpiphanyDayTest.php b/tests/Georgia/OrthodoxEpiphanyDayTest.php new file mode 100644 index 000000000..3d605c8e3 --- /dev/null +++ b/tests/Georgia/OrthodoxEpiphanyDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class OrthodoxEpiphanyDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'orthodoxEpiphanyDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 19, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ნათლისღება'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/SecondNewYearDayTest.php b/tests/Georgia/SecondNewYearDayTest.php new file mode 100644 index 000000000..c0b30ecd7 --- /dev/null +++ b/tests/Georgia/SecondNewYearDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class SecondNewYearDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'secondDayOfNewYear'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 2, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ბედობა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/StAndrewsDayTest.php b/tests/Georgia/StAndrewsDayTest.php new file mode 100644 index 000000000..40bd100de --- /dev/null +++ b/tests/Georgia/StAndrewsDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class StAndrewsDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'stAndrewsDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 12, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'წმინდა ანდრია პირველწოდებულის ხსენების დღე'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/StGeorgesDayTest.php b/tests/Georgia/StGeorgesDayTest.php new file mode 100644 index 000000000..fa5b45211 --- /dev/null +++ b/tests/Georgia/StGeorgesDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class StGeorgesDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'stGeorgesDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 23, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'გიორგობა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/StMarysDayTest.php b/tests/Georgia/StMarysDayTest.php new file mode 100644 index 000000000..dbb5c0f1e --- /dev/null +++ b/tests/Georgia/StMarysDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class StMarysDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'stMarysDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 28, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'მარიამობა'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/UnityDayTest.php b/tests/Georgia/UnityDayTest.php new file mode 100644 index 000000000..f6681d20a --- /dev/null +++ b/tests/Georgia/UnityDayTest.php @@ -0,0 +1,68 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class UnityDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'unityDay'; + + /** + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2019; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-09", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $year = 2019; + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'ეროვნული ერთიანობის დღე'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $year = 2019; + + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Georgia/VictoryDayTest.php b/tests/Georgia/VictoryDayTest.php new file mode 100644 index 000000000..1afb03494 --- /dev/null +++ b/tests/Georgia/VictoryDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Georgia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class VictoryDayTest extends GeorgiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'victoryDay'; + + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 9, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'ფაშიზმზე გამარჯვების დღე'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Germany/AscensionDayTest.php b/tests/Germany/AscensionDayTest.php index efe055a89..eadeb8f9c 100644 --- a/tests/Germany/AscensionDayTest.php +++ b/tests/Germany/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Germany. */ -class AscensionDayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1754; $this->assertHoliday( self::REGION, 'ascensionDay', $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christi Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/BadenWurttemberg/AllSaintsDayTest.php b/tests/Germany/BadenWurttemberg/AllSaintsDayTest.php index 6d8cb92fa..8770385bf 100644 --- a/tests/Germany/BadenWurttemberg/AllSaintsDayTest.php +++ b/tests/Germany/BadenWurttemberg/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Baden-Württemberg (Germany). */ -class AllSaintsDayTest extends BadenWurttembergBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends BadenWurttembergBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/BadenWurttemberg/BadenWurttembergBaseTestCase.php b/tests/Germany/BadenWurttemberg/BadenWurttembergBaseTestCase.php index 87212f52f..3d1753d96 100644 --- a/tests/Germany/BadenWurttemberg/BadenWurttembergBaseTestCase.php +++ b/tests/Germany/BadenWurttemberg/BadenWurttembergBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; @@ -22,13 +27,9 @@ abstract class BadenWurttembergBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/BadenWurttemberg'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/BadenWurttemberg/BadenWurttembergTest.php b/tests/Germany/BadenWurttemberg/BadenWurttembergTest.php index df9839523..b2064c88a 100644 --- a/tests/Germany/BadenWurttemberg/BadenWurttembergTest.php +++ b/tests/Germany/BadenWurttemberg/BadenWurttembergTest.php @@ -1,52 +1,68 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Baden-Württemberg (Germany). */ -class BadenWurttembergTest extends BadenWurttembergBaseTestCase +class BadenWurttembergTest extends BadenWurttembergBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Baden-Württemberg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Baden-Württemberg (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { $this->assertDefinedHolidays([ 'newYearsDay', + 'epiphany', 'goodFriday', 'easterMonday', 'internationalWorkersDay', 'ascensionDay', 'pentecostMonday', + 'corpusChristi', 'germanUnityDay', 'christmasDay', 'secondChristmasDay', + 'allSaintsDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Baden-Württemberg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Baden-Württemberg (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +70,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Baden-Württemberg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Baden-Württemberg (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +78,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Baden-Württemberg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Baden-Württemberg (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,13 +86,15 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Baden-Württemberg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Baden-Württemberg (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { $this->assertDefinedHolidays( - ['epiphany', 'corpusChristi', 'allSaintsDay'], + [ + 'pentecost', + 'newYearsEve', + ], self::REGION, $this->year, Holiday::TYPE_OTHER @@ -86,10 +102,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/BadenWurttemberg/CorpusChristiTest.php b/tests/Germany/BadenWurttemberg/CorpusChristiTest.php index be245a028..75865e708 100644 --- a/tests/Germany/BadenWurttemberg/CorpusChristiTest.php +++ b/tests/Germany/BadenWurttemberg/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in Baden-Württemberg (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in Baden-Württemberg (Germany). */ -class CorpusChristiTest extends BadenWurttembergBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends BadenWurttembergBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/BadenWurttemberg/EpiphanyTest.php b/tests/Germany/BadenWurttemberg/EpiphanyTest.php index ee583ef2d..ed3e3cf87 100644 --- a/tests/Germany/BadenWurttemberg/EpiphanyTest.php +++ b/tests/Germany/BadenWurttemberg/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Baden-Württemberg (Germany). */ -class EpiphanyTest extends BadenWurttembergBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends BadenWurttembergBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige 3 Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/BadenWurttemberg/GermanUnityDayTest.php b/tests/Germany/BadenWurttemberg/GermanUnityDayTest.php index 590c3b500..cc2b87073 100644 --- a/tests/Germany/BadenWurttemberg/GermanUnityDayTest.php +++ b/tests/Germany/BadenWurttemberg/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; diff --git a/tests/Germany/BadenWurttemberg/ReformationDay2017Test.php b/tests/Germany/BadenWurttemberg/ReformationDay2017Test.php index 0d7617ff9..2518b7dac 100644 --- a/tests/Germany/BadenWurttemberg/ReformationDay2017Test.php +++ b/tests/Germany/BadenWurttemberg/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\BadenWurttemberg; diff --git a/tests/Germany/Bavaria/AllSaintsDayTest.php b/tests/Germany/Bavaria/AllSaintsDayTest.php index 2ad3503bc..01fe4c67f 100644 --- a/tests/Germany/Bavaria/AllSaintsDayTest.php +++ b/tests/Germany/Bavaria/AllSaintsDayTest.php @@ -1,79 +1,82 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Bavaria (Germany). */ -class AllSaintsDayTest extends BavariaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends BavariaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Bavaria/AssumptionOfMaryTest.php b/tests/Germany/Bavaria/AssumptionOfMaryTest.php new file mode 100644 index 000000000..f53eceacf --- /dev/null +++ b/tests/Germany/Bavaria/AssumptionOfMaryTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\tests\Germany\Bavaria; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of the Assumption of Mary in Bavaria (Germany). + */ +class AssumptionOfMaryTest extends BavariaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the holiday defined in this test. + * + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests translated name of the Assumption of Mary. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Mariä Himmelfahrt'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Germany/Bavaria/BavariaBaseTestCase.php b/tests/Germany/Bavaria/BavariaBaseTestCase.php index c5100e5d5..dff53640a 100644 --- a/tests/Germany/Bavaria/BavariaBaseTestCase.php +++ b/tests/Germany/Bavaria/BavariaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; @@ -22,13 +27,9 @@ abstract class BavariaBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Bavaria'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Bavaria/BavariaTest.php b/tests/Germany/Bavaria/BavariaTest.php index c24b53e8b..3d6656fea 100644 --- a/tests/Germany/Bavaria/BavariaTest.php +++ b/tests/Germany/Bavaria/BavariaTest.php @@ -1,52 +1,68 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Bavaria (Germany) + * Class for testing holidays in Bavaria (Germany). */ -class BavariaTest extends BavariaBaseTestCase +class BavariaTest extends BavariaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Bavaria (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Bavaria (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { $this->assertDefinedHolidays([ 'newYearsDay', + 'epiphany', 'goodFriday', 'easterMonday', 'internationalWorkersDay', 'ascensionDay', + 'corpusChristi', 'pentecostMonday', 'germanUnityDay', 'christmasDay', 'secondChristmasDay', + 'allSaintsDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Bavaria (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Bavaria (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +70,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Bavaria (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Bavaria (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +78,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Bavaria (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Bavaria (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,13 +86,16 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Bavaria (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Bavaria (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { $this->assertDefinedHolidays( - ['epiphany', 'corpusChristi', 'allSaintsDay'], + [ + 'pentecost', + 'assumptionOfMary', + 'newYearsEve', + ], self::REGION, $this->year, Holiday::TYPE_OTHER @@ -86,10 +103,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Bavaria/CorpusChristiTest.php b/tests/Germany/Bavaria/CorpusChristiTest.php index 9f919e04a..8d00cdf35 100644 --- a/tests/Germany/Bavaria/CorpusChristiTest.php +++ b/tests/Germany/Bavaria/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in Bavaria (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in Bavaria (Germany). */ -class CorpusChristiTest extends BavariaBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends BavariaBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Bavaria/EpiphanyTest.php b/tests/Germany/Bavaria/EpiphanyTest.php index 8f8792b21..ce05cc339 100644 --- a/tests/Germany/Bavaria/EpiphanyTest.php +++ b/tests/Germany/Bavaria/EpiphanyTest.php @@ -1,45 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Bavaria (Germany). */ -class EpiphanyTest extends BavariaBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends BavariaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +46,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige 3 Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Bavaria/GermanUnityDayTest.php b/tests/Germany/Bavaria/GermanUnityDayTest.php index ae642c92d..0541aff35 100644 --- a/tests/Germany/Bavaria/GermanUnityDayTest.php +++ b/tests/Germany/Bavaria/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; diff --git a/tests/Germany/Bavaria/ReformationDay2017Test.php b/tests/Germany/Bavaria/ReformationDay2017Test.php index 373fa1fe8..c1cd5bd46 100644 --- a/tests/Germany/Bavaria/ReformationDay2017Test.php +++ b/tests/Germany/Bavaria/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bavaria; diff --git a/tests/Germany/Berlin/BerlinBaseTestCase.php b/tests/Germany/Berlin/BerlinBaseTestCase.php index 67ad394b6..a710c6a38 100644 --- a/tests/Germany/Berlin/BerlinBaseTestCase.php +++ b/tests/Germany/Berlin/BerlinBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Berlin; @@ -22,13 +27,9 @@ abstract class BerlinBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Berlin'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Berlin/BerlinTest.php b/tests/Germany/Berlin/BerlinTest.php index 72d398b02..9b34fe3d5 100644 --- a/tests/Germany/Berlin/BerlinTest.php +++ b/tests/Germany/Berlin/BerlinTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Berlin; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Berlin (Germany) + * Class for testing holidays in Berlin (Germany). */ -class BerlinTest extends BerlinBaseTestCase +class BerlinTest extends BerlinBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Berlin (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Berlin (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Berlin (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Berlin (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Berlin (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Berlin (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Berlin (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Berlin (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Berlin (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Berlin (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Berlin/DayOfLiberationTest.php b/tests/Germany/Berlin/DayOfLiberationTest.php new file mode 100644 index 000000000..4ded74e89 --- /dev/null +++ b/tests/Germany/Berlin/DayOfLiberationTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\Germany\Berlin; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Day of Liberation in Berlin (Germany). + */ +class DayOfLiberationTest extends BerlinBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'dayOfLiberation'; + + /** + * The years in which the holiday takes place. + */ + public static array $years = [2020, 2025]; + + /** + * Test the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayInYear(): void + { + foreach (self::$years as $year) { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($year . '-05-08', new \DateTimeZone(self::TIMEZONE)) + ); + } + } + + /** + * Test the holiday defined in this test in the years before. + * + * @throws \Exception + */ + public function testHolidayBeforeYear(): void + { + reset(self::$years); + + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, current(self::$years) - 1) + ); + } + + /** + * Test the holiday defined in this test in the years after. + * + * @throws \Exception + */ + public function testHolidayAfterYear(): void + { + end(self::$years); + + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(current(self::$years) + 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + reset(self::$years); + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + current(self::$years), + [self::LOCALE => 'Tag der Befreiung'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + reset(self::$years); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + current(self::$years), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Germany/Berlin/GermanUnityDayTest.php b/tests/Germany/Berlin/GermanUnityDayTest.php index 3bbd0daa3..516d57a75 100644 --- a/tests/Germany/Berlin/GermanUnityDayTest.php +++ b/tests/Germany/Berlin/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Berlin; diff --git a/tests/Germany/Berlin/InternationalWomensDay2019Test.php b/tests/Germany/Berlin/InternationalWomensDay2019Test.php index c5da7eec6..e9e0ff3c0 100644 --- a/tests/Germany/Berlin/InternationalWomensDay2019Test.php +++ b/tests/Germany/Berlin/InternationalWomensDay2019Test.php @@ -1,100 +1,105 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Berlin; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Reformation Day in Germany. */ -class InternationalWomensDay2019Test extends BerlinBaseTestCase implements YasumiTestCaseInterface +class InternationalWomensDay2019Test extends BerlinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWomensDay'; /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 2019; /** - * Test the holiday defined in this test upon establishment - * @throws Exception - * @throws ReflectionException + * Test the holiday defined in this test upon establishment. + * + * @throws \Exception */ - public function testHolidayOnEstablishment() + public function testHolidayOnEstablishment(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR, - new DateTime(self::ESTABLISHMENT_YEAR . '-03-08', new DateTimeZone(self::TIMEZONE)) + new \DateTime(self::ESTABLISHMENT_YEAR . '-03-08', new \DateTimeZone(self::TIMEZONE)) ); } /** - * Test the holiday defined in this test before establishment - * @throws ReflectionException + * Test the holiday defined in this test before establishment. + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * Test the holiday defined in this test after completion - * @throws ReflectionException + * Test the holiday defined in this test after completion. + * + * @throws \Exception */ - public function testHolidayAfterCompletion() + public function testHolidayAfterCompletion(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1900, self::ESTABLISHMENT_YEAR - 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(1900, self::ESTABLISHMENT_YEAR - 1)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Internationaler Frauentag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Berlin/ReformationDay2017Test.php b/tests/Germany/Berlin/ReformationDay2017Test.php index 9d1b85160..8cf5260f4 100644 --- a/tests/Germany/Berlin/ReformationDay2017Test.php +++ b/tests/Germany/Berlin/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Berlin; diff --git a/tests/Germany/Brandenburg/BrandenburgBaseTestCase.php b/tests/Germany/Brandenburg/BrandenburgBaseTestCase.php index c664e73b3..68639743c 100644 --- a/tests/Germany/Brandenburg/BrandenburgBaseTestCase.php +++ b/tests/Germany/Brandenburg/BrandenburgBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Brandenburg; @@ -22,13 +27,9 @@ abstract class BrandenburgBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Brandenburg'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Brandenburg/BrandenburgTest.php b/tests/Germany/Brandenburg/BrandenburgTest.php index fb0d3a30d..2603e60f7 100644 --- a/tests/Germany/Brandenburg/BrandenburgTest.php +++ b/tests/Germany/Brandenburg/BrandenburgTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Brandenburg; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Brandenburg (Germany) + * Class for testing holidays in Brandenburg (Germany). */ -class BrandenburgTest extends BrandenburgBaseTestCase +class BrandenburgTest extends BrandenburgBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Brandenburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Brandenburg (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -56,8 +70,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Brandenburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Brandenburg (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -65,8 +78,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Brandenburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Brandenburg (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -74,8 +86,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Brandenburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Brandenburg (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -83,19 +94,26 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Brandenburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Brandenburg (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Brandenburg/GermanUnityDayTest.php b/tests/Germany/Brandenburg/GermanUnityDayTest.php index 9bc4e62d6..333a50074 100644 --- a/tests/Germany/Brandenburg/GermanUnityDayTest.php +++ b/tests/Germany/Brandenburg/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Brandenburg; diff --git a/tests/Germany/Brandenburg/ReformationDayTest.php b/tests/Germany/Brandenburg/ReformationDayTest.php index a72d8f4fb..e638bf42b 100644 --- a/tests/Germany/Brandenburg/ReformationDayTest.php +++ b/tests/Germany/Brandenburg/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Brandenburg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Brandenburg (Germany). */ -class ReformationDayTest extends BrandenburgBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends BrandenburgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1517; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Bremen/BremenBaseTestCase.php b/tests/Germany/Bremen/BremenBaseTestCase.php index c82cbdb08..cff4b826d 100644 --- a/tests/Germany/Bremen/BremenBaseTestCase.php +++ b/tests/Germany/Bremen/BremenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bremen; @@ -22,13 +27,9 @@ abstract class BremenBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Bremen'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Bremen/BremenTest.php b/tests/Germany/Bremen/BremenTest.php index 4c3bbfa10..d1118a0bb 100644 --- a/tests/Germany/Bremen/BremenTest.php +++ b/tests/Germany/Bremen/BremenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bremen; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Bremen (Germany) + * Class for testing holidays in Bremen (Germany). */ -class BremenTest extends BremenBaseTestCase +class BremenTest extends BremenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Bremen (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Bremen (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Bremen (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Bremen (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Bremen (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Bremen (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Bremen (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Bremen (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Bremen (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Bremen (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Bremen/GermanUnityDayTest.php b/tests/Germany/Bremen/GermanUnityDayTest.php index 9d2758b62..65393124f 100644 --- a/tests/Germany/Bremen/GermanUnityDayTest.php +++ b/tests/Germany/Bremen/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bremen; diff --git a/tests/Germany/Bremen/ReformationDay2017Test.php b/tests/Germany/Bremen/ReformationDay2017Test.php index b05439e38..b5687d8bd 100644 --- a/tests/Germany/Bremen/ReformationDay2017Test.php +++ b/tests/Germany/Bremen/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bremen; diff --git a/tests/Germany/Bremen/ReformationDayTest.php b/tests/Germany/Bremen/ReformationDayTest.php index 7497439d1..9a67e2bd2 100644 --- a/tests/Germany/Bremen/ReformationDayTest.php +++ b/tests/Germany/Bremen/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Bremen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Bremen (Germany). */ -class ReformationDayTest extends BremenBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends BremenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2018; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/ChristmasTest.php b/tests/Germany/ChristmasTest.php index 64182a0ad..4459c29a1 100644 --- a/tests/Germany/ChristmasTest.php +++ b/tests/Germany/ChristmasTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Germany. */ -class ChristmasTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '1. Weihnachtsfeiertag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/EasterMondayTest.php b/tests/Germany/EasterMondayTest.php index 1d079d466..7bc9b1a2c 100644 --- a/tests/Germany/EasterMondayTest.php +++ b/tests/Germany/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Germany. */ -class EasterMondayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2000; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/GermanUnityDayTest.php b/tests/Germany/GermanUnityDayTest.php index f717c09ec..940e02e4a 100644 --- a/tests/Germany/GermanUnityDayTest.php +++ b/tests/Germany/GermanUnityDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the German Unity Day in Germany. */ -class GermanUnityDayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class GermanUnityDayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1990; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'germanUnityDay'; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2022; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2080), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2080), [self::LOCALE => 'Tag der Deutschen Einheit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/GermanyBaseTestCase.php b/tests/Germany/GermanyBaseTestCase.php index a4ab386dc..9d1c356e7 100644 --- a/tests/Germany/GermanyBaseTestCase.php +++ b/tests/Germany/GermanyBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; @@ -22,23 +27,17 @@ abstract class GermanyBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_DE'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/Germany/GermanyTest.php b/tests/Germany/GermanyTest.php index 9bd522eb8..429d8c53d 100644 --- a/tests/Germany/GermanyTest.php +++ b/tests/Germany/GermanyTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Germany. */ -class GermanyTest extends GermanyBaseTestCase +class GermanyTest extends GermanyBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Finland are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } + + /** + * Tests if all official holidays in Finland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Germany are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Germany are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Germany are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Germany are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Germany are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Germany are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,22 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Germany are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Germany are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([ + 'newYearsEve', + 'pentecost', + ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/GoodFridayTest.php b/tests/Germany/GoodFridayTest.php index 9c2dc7def..bd3e95dcc 100644 --- a/tests/Germany/GoodFridayTest.php +++ b/tests/Germany/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in Germany. */ -class GoodFridayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests Good Friday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testGoodFriday() + public function testGoodFriday(): void { $year = 1876; $this->assertHoliday( self::REGION, 'goodFriday', $year, - new DateTime("$year-4-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-14", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Hamburg/DayOfReformationTest.php b/tests/Germany/Hamburg/DayOfReformationTest.php index b0b39597a..c5a194919 100644 --- a/tests/Germany/Hamburg/DayOfReformationTest.php +++ b/tests/Germany/Hamburg/DayOfReformationTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hamburg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Hamburg (Germany). */ -class DayOfReformationTest extends HamburgBaseTestCase implements YasumiTestCaseInterface +class DayOfReformationTest extends HamburgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'dayOfReformation'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2018; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Tag der Reformation'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Hamburg/GermanUnityDay.php b/tests/Germany/Hamburg/GermanUnityDay.php index cb6a41586..e5b37175a 100644 --- a/tests/Germany/Hamburg/GermanUnityDay.php +++ b/tests/Germany/Hamburg/GermanUnityDay.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hamburg; @@ -19,4 +24,8 @@ */ class GermanUnityDay extends BaseGermanUnityDayTest { + public function __construct() + { + parent::__construct(static::class); + } } diff --git a/tests/Germany/Hamburg/HamburgBaseTestCase.php b/tests/Germany/Hamburg/HamburgBaseTestCase.php index b1f9851e9..8d51918a6 100644 --- a/tests/Germany/Hamburg/HamburgBaseTestCase.php +++ b/tests/Germany/Hamburg/HamburgBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hamburg; @@ -22,13 +27,9 @@ abstract class HamburgBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Hamburg'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Hamburg/HamburgTest.php b/tests/Germany/Hamburg/HamburgTest.php index 166bdf723..cead26a00 100644 --- a/tests/Germany/Hamburg/HamburgTest.php +++ b/tests/Germany/Hamburg/HamburgTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hamburg; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Hamburg (Germany) + * Class for testing holidays in Hamburg (Germany). */ -class HamburgTest extends HamburgBaseTestCase +class HamburgTest extends HamburgBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Hamburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Hamburg (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Hamburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Hamburg (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Hamburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Hamburg (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Hamburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Hamburg (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Hamburg (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Hamburg (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Hamburg/ReformationDay2017Test.php b/tests/Germany/Hamburg/ReformationDay2017Test.php index c75c04639..07217ebb2 100644 --- a/tests/Germany/Hamburg/ReformationDay2017Test.php +++ b/tests/Germany/Hamburg/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hamburg; diff --git a/tests/Germany/Hesse/CorpusChristiTest.php b/tests/Germany/Hesse/CorpusChristiTest.php index 0a06e3570..cadf5ba0e 100644 --- a/tests/Germany/Hesse/CorpusChristiTest.php +++ b/tests/Germany/Hesse/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hesse; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in Hesse (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in Hesse (Germany). */ -class CorpusChristiTest extends HesseBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends HesseBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Hesse/GermanUnityDayTest.php b/tests/Germany/Hesse/GermanUnityDayTest.php index 5c680f1fb..d32b13ec8 100644 --- a/tests/Germany/Hesse/GermanUnityDayTest.php +++ b/tests/Germany/Hesse/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hesse; diff --git a/tests/Germany/Hesse/HesseBaseTestCase.php b/tests/Germany/Hesse/HesseBaseTestCase.php index 815be1739..4ff0c1b13 100644 --- a/tests/Germany/Hesse/HesseBaseTestCase.php +++ b/tests/Germany/Hesse/HesseBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hesse; @@ -22,13 +27,9 @@ abstract class HesseBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Hesse'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Hesse/HesseTest.php b/tests/Germany/Hesse/HesseTest.php index 56c451bc6..cfdcdf37e 100644 --- a/tests/Germany/Hesse/HesseTest.php +++ b/tests/Germany/Hesse/HesseTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hesse; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Hesse (Germany) + * Class for testing holidays in Hesse (Germany). */ -class HesseTest extends HesseBaseTestCase +class HesseTest extends HesseBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Hesse (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Hesse (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -37,6 +51,7 @@ public function testOfficialHolidays(): void 'easterMonday', 'internationalWorkersDay', 'ascensionDay', + 'corpusChristi', 'pentecostMonday', 'germanUnityDay', 'christmasDay', @@ -45,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Hesse (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Hesse (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +68,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Hesse (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Hesse (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +76,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Hesse (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Hesse (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +84,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Hesse (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Hesse (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays(['corpusChristi'], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Hesse/ReformationDay2017Test.php b/tests/Germany/Hesse/ReformationDay2017Test.php index c37254259..a8c43a99b 100644 --- a/tests/Germany/Hesse/ReformationDay2017Test.php +++ b/tests/Germany/Hesse/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Hesse; diff --git a/tests/Germany/InternationalWorkersDayTest.php b/tests/Germany/InternationalWorkersDayTest.php index 9837081aa..2df5b3ef8 100644 --- a/tests/Germany/InternationalWorkersDayTest.php +++ b/tests/Germany/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Germany. */ -class InternationalWorkersDayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of International Workers' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Germany/LowerSaxony/GermanUnityDayTest.php b/tests/Germany/LowerSaxony/GermanUnityDayTest.php index d8a04f3de..7237f8d05 100644 --- a/tests/Germany/LowerSaxony/GermanUnityDayTest.php +++ b/tests/Germany/LowerSaxony/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\LowerSaxony; diff --git a/tests/Germany/LowerSaxony/LowerSaxonyBaseTestCase.php b/tests/Germany/LowerSaxony/LowerSaxonyBaseTestCase.php index 0623dd8e2..ce544c867 100644 --- a/tests/Germany/LowerSaxony/LowerSaxonyBaseTestCase.php +++ b/tests/Germany/LowerSaxony/LowerSaxonyBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\LowerSaxony; @@ -22,13 +27,9 @@ abstract class LowerSaxonyBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/LowerSaxony'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/LowerSaxony/LowerSaxonyTest.php b/tests/Germany/LowerSaxony/LowerSaxonyTest.php index d0a82f31b..3cd7eff6e 100644 --- a/tests/Germany/LowerSaxony/LowerSaxonyTest.php +++ b/tests/Germany/LowerSaxony/LowerSaxonyTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\LowerSaxony; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Lower Saxony (Germany) + * Class for testing holidays in Lower Saxony (Germany). */ -class LowerSaxonyTest extends LowerSaxonyBaseTestCase +class LowerSaxonyTest extends LowerSaxonyBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Lower Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Lower Saxony (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Lower Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Lower Saxony (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Lower Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Lower Saxony (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Lower Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Lower Saxony (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Lower Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Lower Saxony (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/LowerSaxony/ReformationDay2017Test.php b/tests/Germany/LowerSaxony/ReformationDay2017Test.php index e14ef79ba..7cc109093 100644 --- a/tests/Germany/LowerSaxony/ReformationDay2017Test.php +++ b/tests/Germany/LowerSaxony/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\LowerSaxony; diff --git a/tests/Germany/LowerSaxony/ReformationDayTest.php b/tests/Germany/LowerSaxony/ReformationDayTest.php index 54092c616..28b998ca7 100644 --- a/tests/Germany/LowerSaxony/ReformationDayTest.php +++ b/tests/Germany/LowerSaxony/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\LowerSaxony; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Lower Saxony (Germany). */ -class ReformationDayTest extends LowerSaxonyBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends LowerSaxonyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2018; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/MecklenburgWesternPomerania/GermanUnityDayTest.php b/tests/Germany/MecklenburgWesternPomerania/GermanUnityDayTest.php index 793aecfc8..4b4471987 100644 --- a/tests/Germany/MecklenburgWesternPomerania/GermanUnityDayTest.php +++ b/tests/Germany/MecklenburgWesternPomerania/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\MecklenburgWesternPomerania; diff --git a/tests/Germany/MecklenburgWesternPomerania/InternationalWomensDayTest.php b/tests/Germany/MecklenburgWesternPomerania/InternationalWomensDayTest.php new file mode 100644 index 000000000..dc3f03049 --- /dev/null +++ b/tests/Germany/MecklenburgWesternPomerania/InternationalWomensDayTest.php @@ -0,0 +1,106 @@ + + */ + +namespace Yasumi\tests\Germany\MecklenburgWesternPomerania; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for International Women's Day in Mecklenburg–Western Pomerania, Germany. + */ +class InternationalWomensDayTest extends MecklenburgWesternPomeraniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'internationalWomensDay'; + + /** + * The year in which the holiday was established. + */ + public const ESTABLISHMENT_YEAR = 2023; + + /** + * Test the holiday defined in this test upon establishment. + * + * @throws \Exception + */ + public function testHolidayOnEstablishment(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::ESTABLISHMENT_YEAR, + new \DateTime(self::ESTABLISHMENT_YEAR . '-03-08', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Test the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Test the holiday defined in this test after completion. + * + * @throws \Exception + */ + public function testHolidayAfterCompletion(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(1900, self::ESTABLISHMENT_YEAR - 1)); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Internationaler Frauentag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaBaseTestCase.php b/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaBaseTestCase.php index 345493eed..a3190c006 100644 --- a/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaBaseTestCase.php +++ b/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\MecklenburgWesternPomerania; @@ -22,13 +27,9 @@ abstract class MecklenburgWesternPomeraniaBaseTestCase extends GermanyBaseTestCa { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/MecklenburgWesternPomerania'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaTest.php b/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaTest.php index dbff7ca3f..3a02a63a6 100644 --- a/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaTest.php +++ b/tests/Germany/MecklenburgWesternPomerania/MecklenburgWesternPomeraniaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\MecklenburgWesternPomerania; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Mecklenburg-Western Pomerania (Germany) + * Class for testing holidays in Mecklenburg-Western Pomerania (Germany). */ -class MecklenburgWesternPomeraniaTest extends MecklenburgWesternPomeraniaBaseTestCase +class MecklenburgWesternPomeraniaTest extends MecklenburgWesternPomeraniaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -54,8 +68,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -63,8 +76,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -72,8 +84,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -81,19 +92,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Mecklenburg-Western Pomerania (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Germany/MecklenburgWesternPomerania/ReformationDayTest.php b/tests/Germany/MecklenburgWesternPomerania/ReformationDayTest.php index 5e8a7d3a8..9d67a4df7 100644 --- a/tests/Germany/MecklenburgWesternPomerania/ReformationDayTest.php +++ b/tests/Germany/MecklenburgWesternPomerania/ReformationDayTest.php @@ -1,52 +1,54 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\MecklenburgWesternPomerania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Mecklenburg-Western Pomerania (Germany). */ -class ReformationDayTest extends MecklenburgWesternPomeraniaBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends MecklenburgWesternPomeraniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1517; /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -54,41 +56,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/NewYearsDayTest.php b/tests/Germany/NewYearsDayTest.php index 8d6ba2530..951d5545c 100644 --- a/tests/Germany/NewYearsDayTest.php +++ b/tests/Germany/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Germany. */ -class NewYearsDayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/NewYearsEveTest.php b/tests/Germany/NewYearsEveTest.php new file mode 100644 index 000000000..6fe785e4d --- /dev/null +++ b/tests/Germany/NewYearsEveTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Germany; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Years Eve in Germany. + */ +class NewYearsEveTest extends GermanyBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'newYearsEve'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 31, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Silvester'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Germany/NorthRhineWestphalia/AllSaintsDayTest.php b/tests/Germany/NorthRhineWestphalia/AllSaintsDayTest.php index bab33d448..758d13edb 100644 --- a/tests/Germany/NorthRhineWestphalia/AllSaintsDayTest.php +++ b/tests/Germany/NorthRhineWestphalia/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in North Rhine-Westphalia (Germany). */ -class AllSaintsDayTest extends NorthRhineWestphaliaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends NorthRhineWestphaliaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/NorthRhineWestphalia/CorpusChristiTest.php b/tests/Germany/NorthRhineWestphalia/CorpusChristiTest.php index b99c60d1d..fba2615e3 100644 --- a/tests/Germany/NorthRhineWestphalia/CorpusChristiTest.php +++ b/tests/Germany/NorthRhineWestphalia/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in North Rhine-Westphalia (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in North Rhine-Westphalia (Germany). */ -class CorpusChristiTest extends NorthRhineWestphaliaBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends NorthRhineWestphaliaBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/NorthRhineWestphalia/GermanUnityDayTest.php b/tests/Germany/NorthRhineWestphalia/GermanUnityDayTest.php index ad8e8580a..1fd89053f 100644 --- a/tests/Germany/NorthRhineWestphalia/GermanUnityDayTest.php +++ b/tests/Germany/NorthRhineWestphalia/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; diff --git a/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaBaseTestCase.php b/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaBaseTestCase.php index 8a0d8d9e6..541c2423e 100644 --- a/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaBaseTestCase.php +++ b/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; @@ -22,13 +27,9 @@ abstract class NorthRhineWestphaliaBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/NorthRhineWestphalia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaTest.php b/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaTest.php index c275b29b3..350b4bf60 100644 --- a/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaTest.php +++ b/tests/Germany/NorthRhineWestphalia/NorthRhineWestphaliaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in North Rhine-Westphalia (Germany) + * Class for testing holidays in North Rhine-Westphalia (Germany). */ -class NorthRhineWestphaliaTest extends NorthRhineWestphaliaBaseTestCase +class NorthRhineWestphaliaTest extends NorthRhineWestphaliaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in North Rhine-Westphalia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in North Rhine-Westphalia (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -37,16 +51,17 @@ public function testOfficialHolidays(): void 'easterMonday', 'internationalWorkersDay', 'ascensionDay', + 'corpusChristi', 'pentecostMonday', 'germanUnityDay', 'christmasDay', 'secondChristmasDay', + 'allSaintsDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in North Rhine-Westphalia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in North Rhine-Westphalia (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +69,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in North Rhine-Westphalia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in North Rhine-Westphalia (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +77,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in North Rhine-Westphalia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in North Rhine-Westphalia (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +85,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in North Rhine-Westphalia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in North Rhine-Westphalia (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays(['corpusChristi', 'allSaintsDay'], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/NorthRhineWestphalia/ReformationDay2017Test.php b/tests/Germany/NorthRhineWestphalia/ReformationDay2017Test.php index 9bbdeed81..4e02fac9e 100644 --- a/tests/Germany/NorthRhineWestphalia/ReformationDay2017Test.php +++ b/tests/Germany/NorthRhineWestphalia/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\NorthRhineWestphalia; diff --git a/tests/Germany/PentecostMondayTest.php b/tests/Germany/PentecostMondayTest.php index e00059c6b..7bf7cee1c 100644 --- a/tests/Germany/PentecostMondayTest.php +++ b/tests/Germany/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Germany. */ -class PentecostMondayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/PentecostTest.php b/tests/Germany/PentecostTest.php new file mode 100644 index 000000000..c8d8d2a23 --- /dev/null +++ b/tests/Germany/PentecostTest.php @@ -0,0 +1,78 @@ + + */ + +namespace Yasumi\tests\Germany; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Pentecost in Germany. + */ +class PentecostTest extends GermanyBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'pentecost'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $time_stamp = strtotime( + $year . '-03-21' . easter_days($year) . ' day + 49 day' + ); + $date = date('Y-m-d', $time_stamp); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($date, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Pfingstsonntag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Germany/ReformationDay2017Test.php b/tests/Germany/ReformationDay2017Test.php index 609666a0c..96a9f63a8 100644 --- a/tests/Germany/ReformationDay2017Test.php +++ b/tests/Germany/ReformationDay2017Test.php @@ -1,100 +1,105 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Reformation Day in Germany. */ -class ReformationDay2017Test extends GermanyBaseTestCase implements YasumiTestCaseInterface +class ReformationDay2017Test extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 2017; /** - * Test the holiday defined in this test upon establishment - * @throws Exception - * @throws ReflectionException + * Test the holiday defined in this test upon establishment. + * + * @throws \Exception */ - public function testHolidayOnEstablishment() + public function testHolidayOnEstablishment(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR, - new DateTime(self::ESTABLISHMENT_YEAR . '-10-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime(self::ESTABLISHMENT_YEAR . '-10-31', new \DateTimeZone(self::TIMEZONE)) ); } /** - * Test the holiday defined in this test before establishment - * @throws ReflectionException + * Test the holiday defined in this test before establishment. + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * Test the holiday defined in this test after completion - * @throws ReflectionException + * Test the holiday defined in this test after completion. + * + * @throws \Exception */ - public function testHolidayAfterCompletion() + public function testHolidayAfterCompletion(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/RhinelandPalatinate/AllSaintsDayTest.php b/tests/Germany/RhinelandPalatinate/AllSaintsDayTest.php index c027b926d..8c409266b 100644 --- a/tests/Germany/RhinelandPalatinate/AllSaintsDayTest.php +++ b/tests/Germany/RhinelandPalatinate/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Rhineland Palatinate (Germany). */ -class AllSaintsDayTest extends RhinelandPalatinateBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends RhinelandPalatinateBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/RhinelandPalatinate/CorpusChristiTest.php b/tests/Germany/RhinelandPalatinate/CorpusChristiTest.php index b1a93458e..accecaaaa 100644 --- a/tests/Germany/RhinelandPalatinate/CorpusChristiTest.php +++ b/tests/Germany/RhinelandPalatinate/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in Rhineland Palatinate (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in Rhineland Palatinate (Germany). */ -class CorpusChristiTest extends RhinelandPalatinateBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends RhinelandPalatinateBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/RhinelandPalatinate/GermanUnityDayTest.php b/tests/Germany/RhinelandPalatinate/GermanUnityDayTest.php index f228b71fb..e3bbd0aeb 100644 --- a/tests/Germany/RhinelandPalatinate/GermanUnityDayTest.php +++ b/tests/Germany/RhinelandPalatinate/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; diff --git a/tests/Germany/RhinelandPalatinate/ReformationDay2017Test.php b/tests/Germany/RhinelandPalatinate/ReformationDay2017Test.php index 3b2bf0219..ba1d1a30c 100644 --- a/tests/Germany/RhinelandPalatinate/ReformationDay2017Test.php +++ b/tests/Germany/RhinelandPalatinate/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; diff --git a/tests/Germany/RhinelandPalatinate/RhinelandPalatinateBaseTestCase.php b/tests/Germany/RhinelandPalatinate/RhinelandPalatinateBaseTestCase.php index 45d61ab88..3f6cd8cda 100644 --- a/tests/Germany/RhinelandPalatinate/RhinelandPalatinateBaseTestCase.php +++ b/tests/Germany/RhinelandPalatinate/RhinelandPalatinateBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; @@ -22,13 +27,9 @@ abstract class RhinelandPalatinateBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/RhinelandPalatinate'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/RhinelandPalatinate/RhinelandPalatinateTest.php b/tests/Germany/RhinelandPalatinate/RhinelandPalatinateTest.php index fb2e3f982..1c8d55cb4 100644 --- a/tests/Germany/RhinelandPalatinate/RhinelandPalatinateTest.php +++ b/tests/Germany/RhinelandPalatinate/RhinelandPalatinateTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\RhinelandPalatinate; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Rhineland Palatinate (Germany) + * Class for testing holidays in Rhineland Palatinate (Germany). */ -class RhinelandPalatinateTest extends RhinelandPalatinateBaseTestCase +class RhinelandPalatinateTest extends RhinelandPalatinateBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Rhineland Palatinate (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Rhineland Palatinate (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -37,16 +51,17 @@ public function testOfficialHolidays(): void 'easterMonday', 'internationalWorkersDay', 'ascensionDay', + 'corpusChristi', 'pentecostMonday', 'germanUnityDay', 'christmasDay', 'secondChristmasDay', + 'allSaintsDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Rhineland Palatinate (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Rhineland Palatinate (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +69,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Rhineland Palatinate (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Rhineland Palatinate (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +77,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Rhineland Palatinate (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Rhineland Palatinate (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +85,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Rhineland Palatinate (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Rhineland Palatinate (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays(['corpusChristi', 'allSaintsDay'], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Saarland/AllSaintsDayTest.php b/tests/Germany/Saarland/AllSaintsDayTest.php index 415fd6389..95a28dda2 100644 --- a/tests/Germany/Saarland/AllSaintsDayTest.php +++ b/tests/Germany/Saarland/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Saarland (Germany). */ -class AllSaintsDayTest extends SaarlandBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends SaarlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Saarland/AssumptionOfMaryTest.php b/tests/Germany/Saarland/AssumptionOfMaryTest.php index 17f851a15..e00ca9ea0 100644 --- a/tests/Germany/Saarland/AssumptionOfMaryTest.php +++ b/tests/Germany/Saarland/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Saarland (Germany). */ -class AssumptionOfMaryTest extends SaarlandBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends SaarlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests translated name of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Germany/Saarland/CorpusChristiTest.php b/tests/Germany/Saarland/CorpusChristiTest.php index 09c869ca2..756faeae4 100644 --- a/tests/Germany/Saarland/CorpusChristiTest.php +++ b/tests/Germany/Saarland/CorpusChristiTest.php @@ -1,73 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing Corpus Christi in Saarland (Germany). + * Class for testing Corpus Christi ('Fronleichnam') in Saarland (Germany). */ -class CorpusChristiTest extends SaarlandBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends SaarlandBaseTestCase implements HolidayTestCase { - use ChristianHolidays; - /** - * The name of the holiday + * The name of the holiday to be tested. */ public const HOLIDAY = 'corpusChristi'; /** - * Tests Corpus Christi. + * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testHoliday(): void { - $year = 2016; + $year = static::generateRandomYear(); + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** - * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Saarland/GermanUnityDayTest.php b/tests/Germany/Saarland/GermanUnityDayTest.php index 52d087060..1ef81e7fd 100644 --- a/tests/Germany/Saarland/GermanUnityDayTest.php +++ b/tests/Germany/Saarland/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; diff --git a/tests/Germany/Saarland/ReformationDay2017Test.php b/tests/Germany/Saarland/ReformationDay2017Test.php index 1a6ccff4f..11392ac22 100644 --- a/tests/Germany/Saarland/ReformationDay2017Test.php +++ b/tests/Germany/Saarland/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; diff --git a/tests/Germany/Saarland/SaarlandBaseTestCase.php b/tests/Germany/Saarland/SaarlandBaseTestCase.php index 2d69bc726..39d5bfe1b 100644 --- a/tests/Germany/Saarland/SaarlandBaseTestCase.php +++ b/tests/Germany/Saarland/SaarlandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; @@ -22,13 +27,9 @@ abstract class SaarlandBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Saarland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Saarland/SaarlandTest.php b/tests/Germany/Saarland/SaarlandTest.php index bff89901c..74fc6faa2 100644 --- a/tests/Germany/Saarland/SaarlandTest.php +++ b/tests/Germany/Saarland/SaarlandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saarland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Saarland (Germany) + * Class for testing holidays in Saarland (Germany). */ -class SaarlandTest extends SaarlandBaseTestCase +class SaarlandTest extends SaarlandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Saarland (Germany) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } + + /** + * Tests if all official holidays in Saarland (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -37,16 +51,17 @@ public function testOfficialHolidays(): void 'easterMonday', 'internationalWorkersDay', 'ascensionDay', + 'corpusChristi', 'pentecostMonday', 'germanUnityDay', 'christmasDay', 'secondChristmasDay', + 'allSaintsDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Saarland (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Saarland (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +69,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Saarland (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Saarland (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +77,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Saarland (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Saarland (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,23 +85,19 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Saarland (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Saarland (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([ - 'corpusChristi', - 'assumptionOfMary', - 'allSaintsDay', - ], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays(['assumptionOfMary'], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Saxony/GermanUnityDayTest.php b/tests/Germany/Saxony/GermanUnityDayTest.php index bd29c3873..eb2c1e69d 100644 --- a/tests/Germany/Saxony/GermanUnityDayTest.php +++ b/tests/Germany/Saxony/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saxony; diff --git a/tests/Germany/Saxony/ReformationDayTest.php b/tests/Germany/Saxony/ReformationDayTest.php index 7f7a88f4c..d0fd24e30 100644 --- a/tests/Germany/Saxony/ReformationDayTest.php +++ b/tests/Germany/Saxony/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saxony; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Saxony (Germany). */ -class ReformationDayTest extends SaxonyBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends SaxonyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1517; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Saxony/RepentanceAndPrayerDayTest.php b/tests/Germany/Saxony/RepentanceAndPrayerDayTest.php index b71f94c95..96ba5fa46 100644 --- a/tests/Germany/Saxony/RepentanceAndPrayerDayTest.php +++ b/tests/Germany/Saxony/RepentanceAndPrayerDayTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saxony; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Repentance And Prayer Day in Saxony (Germany). @@ -27,74 +28,77 @@ * Buß- und Bettag has undergone many changes as either a working or non-working holiday in Germany. At the moment, * Yasumi only considers (for now) the time it was established as non-working day in Saxony. */ -class RepentanceAndPrayerDayTest extends SaxonyBaseTestCase implements YasumiTestCaseInterface +class RepentanceAndPrayerDayTest extends SaxonyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'repentanceAndPrayerDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1995; /** * Tests the holiday defined in this test on or after establishment. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { // Check between the 16th and 22nd day the one that is a Wednesday - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $holiday = new DateTime("next wednesday $year-11-15", new DateTimeZone(self::TIMEZONE)); // Default date + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $holiday = new \DateTime("next wednesday {$year}-11-15", new \DateTimeZone(self::TIMEZONE)); // Default date $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $holiday); // Holiday specific assertions - $this->assertEquals('Wednesday', $holiday->format('l')); - $this->assertGreaterThanOrEqual(16, $holiday->format('j')); - $this->assertLessThanOrEqual(22, $holiday->format('j')); + self::assertEquals('Wednesday', $holiday->format('l')); + self::assertGreaterThanOrEqual(16, $holiday->format('j')); + self::assertLessThanOrEqual(22, $holiday->format('j')); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Buß- und Bettag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Saxony/SaxonyBaseTestCase.php b/tests/Germany/Saxony/SaxonyBaseTestCase.php index bbddd0658..6678e160d 100644 --- a/tests/Germany/Saxony/SaxonyBaseTestCase.php +++ b/tests/Germany/Saxony/SaxonyBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saxony; @@ -22,13 +27,9 @@ abstract class SaxonyBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Saxony'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Saxony/SaxonyTest.php b/tests/Germany/Saxony/SaxonyTest.php index 4e0bfccb0..5fcb2abe9 100644 --- a/tests/Germany/Saxony/SaxonyTest.php +++ b/tests/Germany/Saxony/SaxonyTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Saxony; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Saxony (Germany) + * Class for testing holidays in Saxony (Germany). */ -class SaxonyTest extends SaxonyBaseTestCase +class SaxonyTest extends SaxonyBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Saxony (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -58,8 +72,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Saxony (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -67,8 +80,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Saxony (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -76,8 +88,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Saxony (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -85,19 +96,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Saxony (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Saxony (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/SaxonyAnhalt/EpiphanyTest.php b/tests/Germany/SaxonyAnhalt/EpiphanyTest.php index cc37034e9..c115ce684 100644 --- a/tests/Germany/SaxonyAnhalt/EpiphanyTest.php +++ b/tests/Germany/SaxonyAnhalt/EpiphanyTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SaxonyAnhalt; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Saxony-Anhalt (Germany). */ -class EpiphanyTest extends SaxonyAnhaltBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends SaxonyAnhaltBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige 3 Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/SaxonyAnhalt/GermanUnityDayTest.php b/tests/Germany/SaxonyAnhalt/GermanUnityDayTest.php index 6b223a1ae..2b70ab1b6 100644 --- a/tests/Germany/SaxonyAnhalt/GermanUnityDayTest.php +++ b/tests/Germany/SaxonyAnhalt/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SaxonyAnhalt; diff --git a/tests/Germany/SaxonyAnhalt/ReformationDayTest.php b/tests/Germany/SaxonyAnhalt/ReformationDayTest.php index 933fbc766..adf9c59db 100644 --- a/tests/Germany/SaxonyAnhalt/ReformationDayTest.php +++ b/tests/Germany/SaxonyAnhalt/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SaxonyAnhalt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Saxony-Anhalt (Germany). */ -class ReformationDayTest extends SaxonyAnhaltBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends SaxonyAnhaltBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1517; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/SaxonyAnhalt/SaxonyAnhaltBaseTestCase.php b/tests/Germany/SaxonyAnhalt/SaxonyAnhaltBaseTestCase.php index a0d134c34..042920a5e 100644 --- a/tests/Germany/SaxonyAnhalt/SaxonyAnhaltBaseTestCase.php +++ b/tests/Germany/SaxonyAnhalt/SaxonyAnhaltBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SaxonyAnhalt; @@ -22,13 +27,9 @@ abstract class SaxonyAnhaltBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/SaxonyAnhalt'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/SaxonyAnhalt/SaxonyAnhaltTest.php b/tests/Germany/SaxonyAnhalt/SaxonyAnhaltTest.php index 47c01d4c1..dabd70b5f 100644 --- a/tests/Germany/SaxonyAnhalt/SaxonyAnhaltTest.php +++ b/tests/Germany/SaxonyAnhalt/SaxonyAnhaltTest.php @@ -1,38 +1,53 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SaxonyAnhalt; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Saxony-Anhalt (Germany) + * Class for testing holidays in Saxony-Anhalt (Germany). */ -class SaxonyAnhaltTest extends SaxonyAnhaltBaseTestCase +class SaxonyAnhaltTest extends SaxonyAnhaltBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Saxony-Anhalt (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Saxony-Anhalt (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { $holidays = [ 'newYearsDay', + 'epiphany', 'goodFriday', 'easterMonday', 'internationalWorkersDay', @@ -54,8 +69,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Saxony-Anhalt (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Saxony-Anhalt (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -63,8 +77,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Saxony-Anhalt (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Saxony-Anhalt (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -72,8 +85,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Saxony-Anhalt (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Saxony-Anhalt (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -81,19 +93,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Saxony-Anhalt (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Saxony-Anhalt (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays(['epiphany'], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/SchleswigHolstein/GermanUnityDayTest.php b/tests/Germany/SchleswigHolstein/GermanUnityDayTest.php index 6770c526a..2889a4386 100644 --- a/tests/Germany/SchleswigHolstein/GermanUnityDayTest.php +++ b/tests/Germany/SchleswigHolstein/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SchleswigHolstein; diff --git a/tests/Germany/SchleswigHolstein/ReformationDay2017Test.php b/tests/Germany/SchleswigHolstein/ReformationDay2017Test.php index 00e90aeae..237b23ec8 100644 --- a/tests/Germany/SchleswigHolstein/ReformationDay2017Test.php +++ b/tests/Germany/SchleswigHolstein/ReformationDay2017Test.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SchleswigHolstein; diff --git a/tests/Germany/SchleswigHolstein/ReformationDayTest.php b/tests/Germany/SchleswigHolstein/ReformationDayTest.php index db483c223..97f75cb8b 100644 --- a/tests/Germany/SchleswigHolstein/ReformationDayTest.php +++ b/tests/Germany/SchleswigHolstein/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SchleswigHolstein; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Schleswig-Holstein (Germany). */ -class ReformationDayTest extends SchleswigHolsteinBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends SchleswigHolsteinBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2018; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 2) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/SchleswigHolstein/SchleswigHolsteinBaseTestCase.php b/tests/Germany/SchleswigHolstein/SchleswigHolsteinBaseTestCase.php index a810d1115..009d7a461 100644 --- a/tests/Germany/SchleswigHolstein/SchleswigHolsteinBaseTestCase.php +++ b/tests/Germany/SchleswigHolstein/SchleswigHolsteinBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SchleswigHolstein; @@ -22,13 +27,9 @@ abstract class SchleswigHolsteinBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/SchleswigHolstein'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/SchleswigHolstein/SchleswigHolsteinTest.php b/tests/Germany/SchleswigHolstein/SchleswigHolsteinTest.php index 64fe32c0f..e3b62bddf 100644 --- a/tests/Germany/SchleswigHolstein/SchleswigHolsteinTest.php +++ b/tests/Germany/SchleswigHolstein/SchleswigHolsteinTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\SchleswigHolstein; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Schleswig-Holstein (Germany) + * Class for testing holidays in Schleswig-Holstein (Germany). */ -class SchleswigHolsteinTest extends SchleswigHolsteinBaseTestCase +class SchleswigHolsteinTest extends SchleswigHolsteinBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1990); + } /** - * Tests if all official holidays in Schleswig-Holstein (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Schleswig-Holstein (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Schleswig-Holstein (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Schleswig-Holstein (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Schleswig-Holstein (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Schleswig-Holstein (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Schleswig-Holstein (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Schleswig-Holstein (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,19 +83,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Schleswig-Holstein (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Schleswig-Holstein (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1990); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/SecondChristmasDayTest.php b/tests/Germany/SecondChristmasDayTest.php index b435ffb31..0051d4063 100644 --- a/tests/Germany/SecondChristmasDayTest.php +++ b/tests/Germany/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Germany. */ -class SecondChristmasDayTest extends GermanyBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends GermanyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => '2. Weihnachtsfeiertag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Germany/Thuringia/GermanUnityDayTest.php b/tests/Germany/Thuringia/GermanUnityDayTest.php index de1ee7e7d..2f840f8cb 100644 --- a/tests/Germany/Thuringia/GermanUnityDayTest.php +++ b/tests/Germany/Thuringia/GermanUnityDayTest.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Thuringia; diff --git a/tests/Germany/Thuringia/ReformationDayTest.php b/tests/Germany/Thuringia/ReformationDayTest.php index 9430086f3..0a4a3afd5 100644 --- a/tests/Germany/Thuringia/ReformationDayTest.php +++ b/tests/Germany/Thuringia/ReformationDayTest.php @@ -1,67 +1,66 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Thuringia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Reformation Day in Thuringia (Germany). */ -class ReformationDayTest extends ThuringiaBaseTestCase implements YasumiTestCaseInterface +class ReformationDayTest extends ThuringiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reformationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1517; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $data[] = [$year, new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE))]; + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE))]; } return $data; @@ -69,41 +68,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Reformationstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/Thuringia/ThuringiaBaseTestCase.php b/tests/Germany/Thuringia/ThuringiaBaseTestCase.php index 692851a6c..306f67c48 100644 --- a/tests/Germany/Thuringia/ThuringiaBaseTestCase.php +++ b/tests/Germany/Thuringia/ThuringiaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Thuringia; @@ -22,13 +27,9 @@ abstract class ThuringiaBaseTestCase extends GermanyBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Germany/Thuringia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Berlin'; } diff --git a/tests/Germany/Thuringia/ThuringiaTest.php b/tests/Germany/Thuringia/ThuringiaTest.php index 00e7e2cc7..220334520 100644 --- a/tests/Germany/Thuringia/ThuringiaTest.php +++ b/tests/Germany/Thuringia/ThuringiaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Germany\Thuringia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class for testing holidays in Thuringia (Germany) + * Class for testing holidays in Thuringia (Germany). */ -class ThuringiaTest extends ThuringiaBaseTestCase +class ThuringiaTest extends ThuringiaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Thuringia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Thuringia (Germany) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -50,12 +64,15 @@ public function testOfficialHolidays(): void $holidays[] = 'reformationDay'; } + if ($this->year >= 2019) { + $holidays[] = 'worldChildrensDay'; + } + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Thuringia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Thuringia (Germany) are defined by the provider class. */ public function testObservedHolidays(): void { @@ -63,8 +80,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Thuringia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Thuringia (Germany) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -72,8 +88,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Thuringia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Thuringia (Germany) are defined by the provider class. */ public function testBankHolidays(): void { @@ -81,19 +96,27 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Thuringia (Germany) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Thuringia (Germany) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'pentecost', + 'newYearsEve', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Germany/Thuringia/WorldChildrensDayTest.php b/tests/Germany/Thuringia/WorldChildrensDayTest.php new file mode 100644 index 000000000..db9cb6c72 --- /dev/null +++ b/tests/Germany/Thuringia/WorldChildrensDayTest.php @@ -0,0 +1,112 @@ + + */ + +namespace Yasumi\tests\Germany\Thuringia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing World Children's Day in Thuringia (Germany). + */ +class WorldChildrensDayTest extends ThuringiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'worldChildrensDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2019; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $data[] = [$year, new \DateTime("{$year}-09-20", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Weltkindertag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Greece/AnnunciationTest.php b/tests/Greece/AnnunciationTest.php index 774e7047a..0e12984bd 100644 --- a/tests/Greece/AnnunciationTest.php +++ b/tests/Greece/AnnunciationTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Annunciation in Greece. */ -class AnnunciationTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class AnnunciationTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'annunciation'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(3, 25, self::TIMEZONE); + return static::generateRandomDates(3, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ευαγγελισμός της Θεοτόκου'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/AscensionDayTest.php b/tests/Greece/AscensionDayTest.php index 323657637..6bd34a5f1 100644 --- a/tests/Greece/AscensionDayTest.php +++ b/tests/Greece/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Greece. */ -class AscensionDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ανάληψη του Χριστού'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/AssumptionOfMaryTest.php b/tests/Greece/AssumptionOfMaryTest.php index 6867461bb..c684239dc 100644 --- a/tests/Greece/AssumptionOfMaryTest.php +++ b/tests/Greece/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Greece. */ -class AssumptionOfMaryTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests translated name of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Κοίμηση της Θεοτόκου'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/ChristmasDayTest.php b/tests/Greece/ChristmasDayTest.php index 993caf1ab..63d6841f5 100644 --- a/tests/Greece/ChristmasDayTest.php +++ b/tests/Greece/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Greece. */ -class ChristmasDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Χριστούγεννα'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/CleanMondayTest.php b/tests/Greece/CleanMondayTest.php index a3cb67451..46af7e46c 100644 --- a/tests/Greece/CleanMondayTest.php +++ b/tests/Greece/CleanMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Clean Monday in Greece. */ -class CleanMondayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class CleanMondayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'cleanMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-14", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Καθαρά Δευτέρα'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/EasterMondayTest.php b/tests/Greece/EasterMondayTest.php index 1d2f857bb..69c0a725f 100644 --- a/tests/Greece/EasterMondayTest.php +++ b/tests/Greece/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Greece. */ -class EasterMondayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Δευτέρα του Πάσχα'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/EasterTest.php b/tests/Greece/EasterTest.php index 861edfc44..a6f0aca89 100644 --- a/tests/Greece/EasterTest.php +++ b/tests/Greece/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Greece. */ -class EasterTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the first holiday of Easter + * The name of the first holiday of Easter. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Κυριακή του Πάσχα'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/EpiphanyTest.php b/tests/Greece/EpiphanyTest.php index 2ae97e706..5f5ce3d7c 100644 --- a/tests/Greece/EpiphanyTest.php +++ b/tests/Greece/EpiphanyTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Greece. */ -class EpiphanyTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests translated name of Epiphany. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Θεοφάνεια'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/GreeceBaseTestCase.php b/tests/Greece/GreeceBaseTestCase.php index 0e27ee814..caedbb438 100644 --- a/tests/Greece/GreeceBaseTestCase.php +++ b/tests/Greece/GreeceBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; @@ -23,17 +28,13 @@ abstract class GreeceBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Greece'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Athens'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'el_GR'; } diff --git a/tests/Greece/GreeceTest.php b/tests/Greece/GreeceTest.php index 96414bf85..ac9d4ae8e 100644 --- a/tests/Greece/GreeceTest.php +++ b/tests/Greece/GreeceTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Greece. */ -class GreeceTest extends GreeceBaseTestCase +class GreeceTest extends GreeceBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1985); + } /** - * Tests if all official holidays in Greece are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Greece are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -51,8 +65,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Greece are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Greece are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Greece are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Greece are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Greece are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Greece are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Greece are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Greece are defined by the provider class. */ public function testOtherHolidays(): void { @@ -92,10 +102,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1985); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Greece/IndepencenceDayTest.php b/tests/Greece/IndependenceDayTest.php similarity index 58% rename from tests/Greece/IndepencenceDayTest.php rename to tests/Greece/IndependenceDayTest.php index c6b866fe0..f197bf4c6 100644 --- a/tests/Greece/IndepencenceDayTest.php +++ b/tests/Greece/IndependenceDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Independence Day of Greece in Greece. */ -class IndepencenceDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1821; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2018; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Εικοστή Πέμπτη Μαρτίου'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Greece/InternationalWorkersDayTest.php b/tests/Greece/InternationalWorkersDayTest.php index 1ea404314..5cd4bf03a 100644 --- a/tests/Greece/InternationalWorkersDayTest.php +++ b/tests/Greece/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Greece. */ -class InternationalWorkersDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of International Workers' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Εργατική Πρωτομαγιά'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Greece/NewYearsDayTest.php b/tests/Greece/NewYearsDayTest.php index 8a2b3eccb..764c25162 100644 --- a/tests/Greece/NewYearsDayTest.php +++ b/tests/Greece/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Greece. */ -class NewYearsDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Πρωτοχρονιά'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Greece/OhiDayTest.php b/tests/Greece/OhiDayTest.php index 724200038..e23289303 100644 --- a/tests/Greece/OhiDayTest.php +++ b/tests/Greece/OhiDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Ohi Day in Greece. */ -class OhiDayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class OhiDayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1940; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ohiDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2018; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Επέτειος του Όχι'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Greece/PentecostMondayTest.php b/tests/Greece/PentecostMondayTest.php index 2769161ec..b75a1010f 100644 --- a/tests/Greece/PentecostMondayTest.php +++ b/tests/Greece/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Greece. */ -class PentecostMondayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-20", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-20", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Αγίου Πνεύματος'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/PentecostTest.php b/tests/Greece/PentecostTest.php index 23675914a..cd4bee069 100644 --- a/tests/Greece/PentecostTest.php +++ b/tests/Greece/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Greece. */ -class PentecostTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-19", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-19", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Πεντηκοστή'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Greece/PolytechnioTest.php b/tests/Greece/PolytechnioTest.php index 72fe61d9b..01d738f3a 100644 --- a/tests/Greece/PolytechnioTest.php +++ b/tests/Greece/PolytechnioTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Polytechnio in Greece. */ -class PolytechnioTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class PolytechnioTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1973; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'polytechnio'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2018; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Πολυτεχνείο'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OTHER ); } diff --git a/tests/Greece/ThreeHolyHierarchsTest.php b/tests/Greece/ThreeHolyHierarchsTest.php index d5f0d093d..dcff8ab94 100644 --- a/tests/Greece/ThreeHolyHierarchsTest.php +++ b/tests/Greece/ThreeHolyHierarchsTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for The Three Holy Hierarchs in Greece. */ -class ThreeHolyHierarchsTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class ThreeHolyHierarchsTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'threeHolyHierarchs'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 30, self::TIMEZONE); + return static::generateRandomDates(1, 30, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Τριών Ιεραρχών'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Greece/goodFridayTest.php b/tests/Greece/goodFridayTest.php index b75038cdc..6b022496a 100644 --- a/tests/Greece/goodFridayTest.php +++ b/tests/Greece/goodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Greece; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Greece. */ -class goodFridayTest extends GreeceBaseTestCase implements YasumiTestCaseInterface +class goodFridayTest extends GreeceBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-29", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Μεγάλη Παρασκευή'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/YasumiTestCaseInterface.php b/tests/HolidayTestCase.php similarity index 52% rename from tests/YasumiTestCaseInterface.php rename to tests/HolidayTestCase.php index 0c5203db8..f9fb2e15f 100644 --- a/tests/YasumiTestCaseInterface.php +++ b/tests/HolidayTestCase.php @@ -1,34 +1,36 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests; /** - * Interface YasumiTestCaseInterface - Yasumi TestCase Interface. - * - * This interface class defines the standard functions that any holiday provider PHPUnit test case needs to define. + * This interface class defines the standard functions that any holiday PHPUnit test case needs to define. * * @see AbstractProvider */ -interface YasumiTestCaseInterface +interface HolidayTestCase { - /** * Tests the translated name of the holiday defined in this test. */ - public function testTranslation(); + public function testTranslation(): void; /** * Tests type of the holiday defined in this test. */ - public function testHolidayType(); + public function testHolidayType(): void; } diff --git a/tests/Hungary/AllSaintsDayTest.php b/tests/Hungary/AllSaintsDayTest.php index d42a56bfb..e83e71743 100644 --- a/tests/Hungary/AllSaintsDayTest.php +++ b/tests/Hungary/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Hungary. */ -class AllSaintsDayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mindenszentek'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/ChristmasTest.php b/tests/Hungary/ChristmasTest.php index 671ccabe6..4b01eb70c 100644 --- a/tests/Hungary/ChristmasTest.php +++ b/tests/Hungary/ChristmasTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Hungary. */ -class ChristmasTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karácsony'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/EasterMondayTest.php b/tests/Hungary/EasterMondayTest.php index 74080fbed..7866fe7ab 100644 --- a/tests/Hungary/EasterMondayTest.php +++ b/tests/Hungary/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Hungary. */ -class EasterMondayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Húsvéthétfő'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/EasterTest.php b/tests/Hungary/EasterTest.php index ef50cfb14..e2b43a88a 100644 --- a/tests/Hungary/EasterTest.php +++ b/tests/Hungary/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Hungary. */ -class EasterTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2009; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Húsvét'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/HungaryBaseTestCase.php b/tests/Hungary/HungaryBaseTestCase.php index 44bdf4d9b..0cf0c6607 100644 --- a/tests/Hungary/HungaryBaseTestCase.php +++ b/tests/Hungary/HungaryBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; @@ -22,18 +27,12 @@ abstract class HungaryBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Hungary'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Budapest'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'hu_HU'; } diff --git a/tests/Hungary/HungaryTest.php b/tests/Hungary/HungaryTest.php index 05decc0fa..6fcf2dfed 100644 --- a/tests/Hungary/HungaryTest.php +++ b/tests/Hungary/HungaryTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Hungary. */ -class HungaryTest extends HungaryBaseTestCase +class HungaryTest extends HungaryBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1955); + } /** - * Tests if all official holidays in Hungary are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Hungary are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -62,8 +76,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Hungary are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Hungary are defined by the provider class. */ public function testObservedHolidays(): void { @@ -71,8 +84,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Hungary are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Hungary are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +92,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Hungary are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Hungary are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,8 +100,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Hungary are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Hungary are defined by the provider class. */ public function testOtherHolidays(): void { @@ -98,10 +108,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1955); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Hungary/InternationalWorkersDayTest.php b/tests/Hungary/InternationalWorkersDayTest.php index 171b6e328..aaafd9c43 100644 --- a/tests/Hungary/InternationalWorkersDayTest.php +++ b/tests/Hungary/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Hungary. */ -class InternationalWorkersDayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'A munka ünnepe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/MemorialDay1848Test.php b/tests/Hungary/MemorialDay1848Test.php index 8a70b6d3d..d515dad83 100644 --- a/tests/Hungary/MemorialDay1848Test.php +++ b/tests/Hungary/MemorialDay1848Test.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Memorial Day of 1848 in Hungary. */ -class MemorialDay1848Test extends HungaryBaseTestCase implements YasumiTestCaseInterface +class MemorialDay1848Test extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'memorialDay1848'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1927; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Az 1848-as forradalom ünnepe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Hungary/MemorialDay1956Test.php b/tests/Hungary/MemorialDay1956Test.php index 8d870ed5e..9b1002147 100644 --- a/tests/Hungary/MemorialDay1956Test.php +++ b/tests/Hungary/MemorialDay1956Test.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Memorial Day of 1986 in Hungary. */ -class MemorialDay1956Test extends HungaryBaseTestCase implements YasumiTestCaseInterface +class MemorialDay1956Test extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'memorialDay1956'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1991; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Az 1956-os forradalom ünnepe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Hungary/NewYearsDayTest.php b/tests/Hungary/NewYearsDayTest.php index 28e2467cd..c4ec87626 100644 --- a/tests/Hungary/NewYearsDayTest.php +++ b/tests/Hungary/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Hungary. */ -class NewYearsDayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Újév'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/PentecostMondayTest.php b/tests/Hungary/PentecostMondayTest.php index 426733548..3c2b6d81c 100644 --- a/tests/Hungary/PentecostMondayTest.php +++ b/tests/Hungary/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Hungary. */ -class PentecostMondayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pünkösdhétfő'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/PentecostTest.php b/tests/Hungary/PentecostTest.php index c8658a693..e0020a560 100644 --- a/tests/Hungary/PentecostTest.php +++ b/tests/Hungary/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Hungary. */ -class PentecostTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1344; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pünkösd'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Hungary/SecondChristmasDayTest.php b/tests/Hungary/SecondChristmasDayTest.php index e907e4383..287fdb79a 100644 --- a/tests/Hungary/SecondChristmasDayTest.php +++ b/tests/Hungary/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Hungary. */ -class SecondChristmasDayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karácsony másnapja'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Hungary/StateFoundationDayTest.php b/tests/Hungary/StateFoundationDayTest.php index f5c478226..dbe1a336d 100644 --- a/tests/Hungary/StateFoundationDayTest.php +++ b/tests/Hungary/StateFoundationDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Hungary; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for the State Foundation Day in Hungary. */ -class StateFoundationDayTest extends HungaryBaseTestCase implements YasumiTestCaseInterface +class StateFoundationDayTest extends HungaryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stateFoundation'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1891; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-20", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-20", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Az államalapítás ünnepe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Iran/AnniversaryOfIslamicRevolutionTest.php b/tests/Iran/AnniversaryOfIslamicRevolutionTest.php new file mode 100644 index 000000000..eb216b55e --- /dev/null +++ b/tests/Iran/AnniversaryOfIslamicRevolutionTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class AnniversaryOfIslamicRevolutionTest extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'anniversaryOfIslamicRevolution'; + + public const ESTABLISHMENT_YEAR = 1979; + + public function testAnniversaryOfIslamicRevolutionBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testAnniversaryOfIslamicRevolutionAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-02-11", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'انقلاب اسلامی پنجاه و هفت', + 'en' => 'Enqelab e Eslami', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/DeathOfKhomeiniTest.php b/tests/Iran/DeathOfKhomeiniTest.php new file mode 100644 index 000000000..5db1b22ee --- /dev/null +++ b/tests/Iran/DeathOfKhomeiniTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class DeathOfKhomeiniTest extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'deathOfKhomeini'; + + public const ESTABLISHMENT_YEAR = 1989; + + public function testDeathOfKhomeiniBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testDeathOfKhomeiniAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-04", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'مرگ خمینی', + 'en' => 'Marg e Khomeini', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/IranBaseTestCase.php b/tests/Iran/IranBaseTestCase.php new file mode 100644 index 000000000..85e15054a --- /dev/null +++ b/tests/Iran/IranBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Iran; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +class IranBaseTestCase extends TestCase +{ + use YasumiBase; + + public const REGION = 'Iran'; + + public const TIMEZONE = 'Asia/Tehran'; + + public const LOCALE = 'fa'; +} diff --git a/tests/Iran/IranTest.php b/tests/Iran/IranTest.php new file mode 100644 index 000000000..33e695c16 --- /dev/null +++ b/tests/Iran/IranTest.php @@ -0,0 +1,93 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +class IranTest extends IranBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } + + public function testOfficialHolidays(): void + { + $holidays = [ + 'nowruz1', + 'nowruz2', + 'nowruz3', + 'nowruz4', + 'sizdahBedar', + ]; + + if (1979 <= $this->year) { + $holidays[] = 'islamicRepublicDay'; + $holidays[] = 'revoltOfKhordad15'; + $holidays[] = 'anniversaryOfIslamicRevolution'; + } + + if (1989 <= $this->year) { + $holidays[] = 'deathOfKhomeini'; + } + + if (1951 <= $this->year) { + $holidays[] = 'nationalizationOfTheIranianOilIndustry'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Iran/IslamicRepublicDayTest.php b/tests/Iran/IslamicRepublicDayTest.php new file mode 100644 index 000000000..d77d353a2 --- /dev/null +++ b/tests/Iran/IslamicRepublicDayTest.php @@ -0,0 +1,109 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class IslamicRepublicDayTest extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'islamicRepublicDay'; + + public const ESTABLISHMENT_YEAR = 1979; + + public const EQUINOX_YEAR = 2016; + + /** + * @throws \Exception + */ + public function testIslamicRepublicDayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testIslamicRepublicDayBeforeEquinoxYear(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::EQUINOX_YEAR - 1); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testIslamicRepublicDayOnEquinoxYear(): void + { + $year = static::generateRandomYear(self::EQUINOX_YEAR, self::EQUINOX_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-31", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testIslamicRepublicDayAfterEquinoxYear(): void + { + $year = static::generateRandomYear(self::EQUINOX_YEAR + 1); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::EQUINOX_YEAR), + [ + self::LOCALE => 'روز جمهوری اسلامی', + 'en' => 'Ruz e Jomhuri ye Eslami', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::EQUINOX_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/NationalizationOfTheIranianOilIndustryTest.php b/tests/Iran/NationalizationOfTheIranianOilIndustryTest.php new file mode 100644 index 000000000..a343eb32b --- /dev/null +++ b/tests/Iran/NationalizationOfTheIranianOilIndustryTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class NationalizationOfTheIranianOilIndustryTest extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nationalizationOfTheIranianOilIndustry'; + + public const ESTABLISHMENT_YEAR = 1951; + + public function testNationalizationOfTheIranianOilIndustryBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testNationalizationOfTheIranianOilIndustryAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'ملی شدن صنعت نفت', + 'en' => 'Melli Shodan e Saneat e Naft', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz1Test.php b/tests/Iran/Nowruz1Test.php new file mode 100644 index 000000000..fcb6d50b2 --- /dev/null +++ b/tests/Iran/Nowruz1Test.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class Nowruz1Test extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nowruz1'; + + /** + * @throws \Exception + */ + public function testNowruz1(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-21", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz2Test.php b/tests/Iran/Nowruz2Test.php new file mode 100644 index 000000000..f3528b55f --- /dev/null +++ b/tests/Iran/Nowruz2Test.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class Nowruz2Test extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nowruz2'; + + /** + * @throws \Exception + */ + public function testNowruz2(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-22", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz3Test.php b/tests/Iran/Nowruz3Test.php new file mode 100644 index 000000000..ef323da62 --- /dev/null +++ b/tests/Iran/Nowruz3Test.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class Nowruz3Test extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nowruz3'; + + /** + * @throws \Exception + */ + public function testNowruz3(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-23", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz4Test.php b/tests/Iran/Nowruz4Test.php new file mode 100644 index 000000000..2b04571b1 --- /dev/null +++ b/tests/Iran/Nowruz4Test.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class Nowruz4Test extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nowruz4'; + + /** + * @throws \Exception + */ + public function testNowruz4(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/RevoltOfKhordad15Test.php b/tests/Iran/RevoltOfKhordad15Test.php new file mode 100644 index 000000000..eaa43589d --- /dev/null +++ b/tests/Iran/RevoltOfKhordad15Test.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class RevoltOfKhordad15Test extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'revoltOfKhordad15'; + + public const ESTABLISHMENT_YEAR = 1979; + + public function testRevoltOfKhordad15BeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testRevoltOfKhordad15AfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-05", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'قیام ۱۵ خرداد', + 'en' => 'Qiam e Panzdah e Khordad', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/SizdahBedarTest.php b/tests/Iran/SizdahBedarTest.php new file mode 100644 index 000000000..12e94757f --- /dev/null +++ b/tests/Iran/SizdahBedarTest.php @@ -0,0 +1,64 @@ + + */ + +namespace Yasumi\tests\Iran; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class SizdahBedarTest extends IranBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'sizdahBedar'; + + /** + * @throws \Exception + */ + public function testSizdahBedar(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-02", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [ + self::LOCALE => 'سیزده بدر', + 'en' => 'Sizdah be dar', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Ireland/AugustHolidayTest.php b/tests/Ireland/AugustHolidayTest.php index 8daa2dbd0..12e2a8eeb 100644 --- a/tests/Ireland/AugustHolidayTest.php +++ b/tests/Ireland/AugustHolidayTest.php @@ -1,69 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the August Holiday in Ireland. */ -class AugustHolidayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class AugustHolidayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'augustHoliday'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); $this->assertDayOfWeek(self::REGION, self::HOLIDAY, $year, 'Monday'); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("next monday $year-7-31", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("next monday {$year}-7-31", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,30 +74,31 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'August Holiday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Lá Saoire i mí Lúnasa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ireland/ChristmasDayTest.php b/tests/Ireland/ChristmasDayTest.php index 455404b37..2e89e91dd 100644 --- a/tests/Ireland/ChristmasDayTest.php +++ b/tests/Ireland/ChristmasDayTest.php @@ -1,69 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas Day in Ireland. */ -class ChristmasDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next tuesday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -73,30 +73,31 @@ public function HolidayDataProvider(): array /** * Tests translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Lá Nollag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ireland/EasterMondayTest.php b/tests/Ireland/EasterMondayTest.php index a98e21955..49bd6a513 100644 --- a/tests/Ireland/EasterMondayTest.php +++ b/tests/Ireland/EasterMondayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Ireland. */ -class EasterMondayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,30 +74,31 @@ public function HolidayDataProvider(): array /** * Tests translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Luan Cásca'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ireland/EasterTest.php b/tests/Ireland/EasterTest.php index 90c15c919..c91fa0564 100644 --- a/tests/Ireland/EasterTest.php +++ b/tests/Ireland/EasterTest.php @@ -1,68 +1,68 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Ireland. */ -class EasterTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); $data[] = [$year, $date->format('Y-m-d')]; } @@ -73,30 +73,31 @@ public function HolidayDataProvider(): array /** * Tests translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Sunday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Domhnach Cásca'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Ireland/GoodFridayTest.php b/tests/Ireland/GoodFridayTest.php index e82577821..3f76f2967 100644 --- a/tests/Ireland/GoodFridayTest.php +++ b/tests/Ireland/GoodFridayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in Ireland. */ -class GoodFridayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->sub(new DateInterval('P2D')); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P2D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,30 +73,31 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Aoine an Chéasta'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Ireland/IrelandBaseTestCase.php b/tests/Ireland/IrelandBaseTestCase.php index d7f6e5c5f..717be8bb9 100644 --- a/tests/Ireland/IrelandBaseTestCase.php +++ b/tests/Ireland/IrelandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; @@ -22,23 +27,17 @@ abstract class IrelandBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Ireland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Dublin'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_IE'; /** - * Number of iterations to be used for the various unit test of this provider + * Number of iterations to be used for the various unit test of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/Ireland/IrelandTest.php b/tests/Ireland/IrelandTest.php index e4b9b2442..ad8c239c1 100644 --- a/tests/Ireland/IrelandTest.php +++ b/tests/Ireland/IrelandTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Ireland. */ -class IrelandTest extends IrelandBaseTestCase +class IrelandTest extends IrelandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1974); + } /** - * Tests if all official holidays in Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Ireland are defined by the provider class. */ public function testOfficialHolidays(): void { - $officialHolidays = ['easter', 'easterMonday', 'augustHoliday', 'christmasDay', 'stStephensDay']; + $officialHolidays = ['easterMonday', 'augustHoliday', 'christmasDay', 'stStephensDay']; if ($this->year >= 1974) { $officialHolidays[] = 'newYearsDay'; $officialHolidays[] = 'juneHoliday'; @@ -53,21 +67,23 @@ public function testOfficialHolidays(): void $officialHolidays[] = 'octoberHoliday'; } + if ($this->year >= 2023) { + $officialHolidays[] = 'stBrigidsDay'; + } + $this->assertDefinedHolidays($officialHolidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Ireland are defined by the provider class. */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays(['goodFriday', 'pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays(['easter', 'goodFriday', 'pentecost'], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Ireland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -75,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Ireland are defined by the provider class. */ public function testBankHolidays(): void { @@ -84,8 +99,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Ireland are defined by the provider class. */ public function testOtherHolidays(): void { @@ -93,10 +107,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1974); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Ireland/JuneHolidayTest.php b/tests/Ireland/JuneHolidayTest.php index 48f397feb..27e4d8c89 100644 --- a/tests/Ireland/JuneHolidayTest.php +++ b/tests/Ireland/JuneHolidayTest.php @@ -1,74 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the June Holiday in Ireland. */ -class JuneHolidayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class JuneHolidayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'juneHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1974; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); $this->assertDayOfWeek(self::REGION, self::HOLIDAY, $year, 'Monday'); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("next monday $year-5-31", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("next monday {$year}-5-31", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -78,48 +78,50 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'June Holiday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), ['ga_IE' => 'Lá Saoire i mí an Mheithimh'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ireland/MayDayTest.php b/tests/Ireland/MayDayTest.php index d40a5677f..5de06305d 100644 --- a/tests/Ireland/MayDayTest.php +++ b/tests/Ireland/MayDayTest.php @@ -1,75 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing May Day in Ireland. */ -class MayDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class MayDayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); $this->assertDayOfWeek(self::REGION, self::HOLIDAY, $year, 'Monday'); } - /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("next monday $year-4-30", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("next monday {$year}-4-30", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -79,48 +78,50 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), ['ga_IE' => 'Lá Bealtaine'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ireland/NewYearsDayTest.php b/tests/Ireland/NewYearsDayTest.php index e57e89849..f3ad12501 100644 --- a/tests/Ireland/NewYearsDayTest.php +++ b/tests/Ireland/NewYearsDayTest.php @@ -1,74 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Ireland. */ -class NewYearsDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1974; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (0 === (int)$date->format('w')) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -77,48 +77,50 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), ['ga_IE' => 'Lá Caille'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ireland/OctoberHolidayTest.php b/tests/Ireland/OctoberHolidayTest.php index ed156e591..dd038f684 100644 --- a/tests/Ireland/OctoberHolidayTest.php +++ b/tests/Ireland/OctoberHolidayTest.php @@ -1,75 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the October Holiday in Ireland. */ -class OctoberHolidayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class OctoberHolidayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'octoberHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1977; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); $this->assertDayOfWeek(self::REGION, self::HOLIDAY, $year, 'Monday'); } - /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("previous monday $year-11-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("previous monday {$year}-11-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -79,48 +78,50 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'October Holiday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), ['ga_IE' => 'Lá Saoire i mí Dheireadh Fómhair'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ireland/PentecostTest.php b/tests/Ireland/PentecostTest.php index c6a8f40b2..76900bc82 100644 --- a/tests/Ireland/PentecostTest.php +++ b/tests/Ireland/PentecostTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost in Ireland. */ -class PentecostTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - //for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - for ($y = 0; $y < 2; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P49D')); + // for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { + for ($y = 0; $y < 2; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P49D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,30 +74,31 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Whitsunday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Domhnach Cincíse'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Ireland/StBrigidsDayTest.php b/tests/Ireland/StBrigidsDayTest.php new file mode 100644 index 000000000..a8c6218f8 --- /dev/null +++ b/tests/Ireland/StBrigidsDayTest.php @@ -0,0 +1,131 @@ + + */ + +namespace Yasumi\tests\Ireland; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the Saint Brigid's Day in Ireland. + */ +class StBrigidsDayTest extends IrelandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stBrigidsDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2023; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $dateTime = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + $dateTime + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-02-01", new \DateTimeZone(self::TIMEZONE)); + if ('Friday' !== $date->format('l')) { + $date = new \DateTime("{$year}-02-01 first monday", new \DateTimeZone(self::TIMEZONE)); + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Saint Brigid’s Day'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + ['ga' => 'Lá Fhéile Bríde'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Ireland/StPatricksDayTest.php b/tests/Ireland/StPatricksDayTest.php index 2b9d84d2a..0d2034c01 100644 --- a/tests/Ireland/StPatricksDayTest.php +++ b/tests/Ireland/StPatricksDayTest.php @@ -1,74 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Patrick's Day in Ireland. */ -class StPatricksDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class StPatricksDayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stPatricksDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1903; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-3-17", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-3-17", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -77,48 +77,50 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'St. Patrick\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'St. Patrick’s Day'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), ['ga_IE' => 'Lá Fhéile Pádraig'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ireland/StStephensDayTest.php b/tests/Ireland/StStephensDayTest.php index 00f849dcc..d233ecd6b 100644 --- a/tests/Ireland/StStephensDayTest.php +++ b/tests/Ireland/StStephensDayTest.php @@ -1,69 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Ireland. */ -class StStephensDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -73,30 +73,31 @@ public function HolidayDataProvider(): array /** * Tests translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'St. Stephen\'s Day'] + static::generateRandomYear(), + [self::LOCALE => 'St. Stephen’s Day'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), ['ga_IE' => 'Lá Fhéile Stiofáin'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ireland/pentecostMondayTest.php b/tests/Ireland/pentecostMondayTest.php index b2fc3c88a..8ce15cdf9 100644 --- a/tests/Ireland/pentecostMondayTest.php +++ b/tests/Ireland/pentecostMondayTest.php @@ -1,75 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ireland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost in Ireland. */ -class pentecostMondayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface +class pentecostMondayTest extends IrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecostMonday'; /** - * The year in which the holiday was abolished + * The year in which the holiday was abolished. */ public const ABOLISHMENT_YEAR = 1973; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(1000, self::ABOLISHMENT_YEAR); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P50D')); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(1000, self::ABOLISHMENT_YEAR); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P50D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -78,44 +77,46 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test after abolishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayDayAfterAbolishment() + public function testHolidayDayAfterAbolishment(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ABOLISHMENT_YEAR + 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ABOLISHMENT_YEAR + 1)); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ABOLISHMENT_YEAR), + static::generateRandomYear(1000, self::ABOLISHMENT_YEAR), [self::LOCALE => 'Whitmonday'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ABOLISHMENT_YEAR), + static::generateRandomYear(1000, self::ABOLISHMENT_YEAR), ['ga_IE' => 'Luan Cincíse'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ABOLISHMENT_YEAR), + static::generateRandomYear(1000, self::ABOLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Italy/AllSaintsDayTest.php b/tests/Italy/AllSaintsDayTest.php index 3a078f785..1ca2be2c8 100644 --- a/tests/Italy/AllSaintsDayTest.php +++ b/tests/Italy/AllSaintsDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Italy. */ -class AllSaintsDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testAssumptionOfMary($year, $expected) /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Festa di Tutti i Santi'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/AssumptionOfMaryTest.php b/tests/Italy/AssumptionOfMaryTest.php index ca0ef5932..cab6ca8a6 100644 --- a/tests/Italy/AssumptionOfMaryTest.php +++ b/tests/Italy/AssumptionOfMaryTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Italy. */ -class AssumptionOfMaryTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testAssumptionOfMary($year, $expected) /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests translated name of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assunzione di Maria Vergine'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/ChristmasTest.php b/tests/Italy/ChristmasTest.php index 02108ef34..e656612e7 100644 --- a/tests/Italy/ChristmasTest.php +++ b/tests/Italy/ChristmasTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Italy. */ -class ChristmasTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Natale'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/EasterMondayTest.php b/tests/Italy/EasterMondayTest.php index 308ea3066..36598c0ec 100644 --- a/tests/Italy/EasterMondayTest.php +++ b/tests/Italy/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in the Italy. */ -class EasterMondayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => "Lunedì dell'Angelo"] + static::generateRandomYear(), + [self::LOCALE => 'Lunedì dell’Angelo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/EasterTest.php b/tests/Italy/EasterTest.php index 7aa753b69..a4329d156 100644 --- a/tests/Italy/EasterTest.php +++ b/tests/Italy/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Italy. */ -class EasterTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the first holiday of Easter + * The name of the first holiday of Easter. */ public const HOLIDAY = 'easter'; /** * Tests Easter. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEaster() + public function testEaster(): void { $year = 2009; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pasqua'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/EpiphanyTest.php b/tests/Italy/EpiphanyTest.php index a4c9f315f..9148a2280 100644 --- a/tests/Italy/EpiphanyTest.php +++ b/tests/Italy/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Italy. */ -class EpiphanyTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'epiphany'; /** * Tests Epiphany. * - * @dataProvider EpiphanyDataProvider - * - * @param int $year the year for which Epiphany needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Epiphany needs to be tested + * @param \DateTime $expected the expected date */ - public function testEpiphany($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('EpiphanyDataProvider')] + public function testEpiphany(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testEpiphany($year, $expected) /** * Returns a list of random test dates used for assertion of Epiphany. * - * @return array list of test dates for Epiphany - * @throws Exception + * @return array list of test dates for Epiphany + * + * @throws \Exception */ - public function EpiphanyDataProvider(): array + public static function EpiphanyDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests translated name of Epiphany. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Epifania'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/ImmaculateConceptionTest.php b/tests/Italy/ImmaculateConceptionTest.php index 34437910c..f69e351d2 100644 --- a/tests/Italy/ImmaculateConceptionTest.php +++ b/tests/Italy/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Italy. */ -class ImmaculateConceptionTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the day of Immaculate Conception. * - * @dataProvider ImmaculateConceptionDataProvider - * - * @param int $year the year for which the day of Immaculate Conception needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of Immaculate Conception needs to be tested + * @param \DateTime $expected the expected date */ - public function testImmaculateConception($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ImmaculateConceptionDataProvider')] + public function testImmaculateConception(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testImmaculateConception($year, $expected) /** * Returns a list of random test dates used for assertion of the day of Immaculate Conception. * - * @return array list of test dates for the day of Immaculate Conception - * @throws Exception + * @return array list of test dates for the day of Immaculate Conception + * + * @throws \Exception */ - public function ImmaculateConceptionDataProvider(): array + public static function ImmaculateConceptionDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests translated name of the day of Immaculate Conception. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Immacolata Concezione'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/InternationalWorkersDayTest.php b/tests/Italy/InternationalWorkersDayTest.php index 358d14db9..3390673d6 100644 --- a/tests/Italy/InternationalWorkersDayTest.php +++ b/tests/Italy/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Italy. */ -class InternationalWorkersDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testInternationalWorkersDay($year, $expected) /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests translated name of International Workers' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Festa del Lavoro'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/ItalyBaseTestCase.php b/tests/Italy/ItalyBaseTestCase.php index 67547ae93..201c0926d 100644 --- a/tests/Italy/ItalyBaseTestCase.php +++ b/tests/Italy/ItalyBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; @@ -22,18 +27,12 @@ abstract class ItalyBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Italy'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Rome'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'it_IT'; } diff --git a/tests/Italy/ItalyTest.php b/tests/Italy/ItalyTest.php index 5f18b4c34..a5c1a9356 100644 --- a/tests/Italy/ItalyTest.php +++ b/tests/Italy/ItalyTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Italy. */ -class ItalyTest extends ItalyBaseTestCase +class ItalyTest extends ItalyBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1949); + } /** - * Tests if all official holidays in Italy are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Italy are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -48,8 +62,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Italy are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Italy are defined by the provider class. */ public function testObservedHolidays(): void { @@ -57,8 +70,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Italy are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Italy are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -66,8 +78,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Italy are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Italy are defined by the provider class. */ public function testBankHolidays(): void { @@ -75,8 +86,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Italy are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Italy are defined by the provider class. */ public function testOtherHolidays(): void { @@ -84,10 +94,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1949); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Italy/LiberationDayTest.php b/tests/Italy/LiberationDayTest.php index fb85309bd..566544b60 100644 --- a/tests/Italy/LiberationDayTest.php +++ b/tests/Italy/LiberationDayTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Liberation Day in Italy. @@ -27,73 +28,76 @@ * April 25 is a national Italian holiday commemorating the end of the second world war and the end of Nazi occupation * of the country. On May 27, 1949, bill 260 made the anniversary a permanent, annual national holiday. * - * @link https://en.wikipedia.org/wiki/Liberation_Day_%28Italy%29 + * @see https://en.wikipedia.org/wiki/Liberation_Day_%28Italy%29 */ -class LiberationDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class LiberationDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'liberationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests Liberation Day on or after 1949. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testLiberationDayOnAfter1949() + public function testLiberationDayOnAfter1949(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Liberation Day before 1949. - * @throws ReflectionException + * + * @throws \Exception */ - public function testLiberationDayBefore1949() + public function testLiberationDayBefore1949(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Liberation Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Festa della Liberazione'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Italy/NewYearsDayTest.php b/tests/Italy/NewYearsDayTest.php index b3dd808ff..1d89ae280 100644 --- a/tests/Italy/NewYearsDayTest.php +++ b/tests/Italy/NewYearsDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Italy. */ -class NewYearsDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testNewYearsDay($year, $expected) /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Capodanno'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Italy/RepublicDayTest.php b/tests/Italy/RepublicDayTest.php index 7e269d073..7eb1cb8a5 100644 --- a/tests/Italy/RepublicDayTest.php +++ b/tests/Italy/RepublicDayTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Republic Day in Italy. @@ -27,73 +28,76 @@ * the Italian people were called to the polls to decide on the form of government, following the Second World War and * the fall of Fascism. * - * @link https://en.wikipedia.org/wiki/Festa_della_Repubblica + * @see https://en.wikipedia.org/wiki/Festa_della_Repubblica */ -class RepublicDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class RepublicDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'republicDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1946; /** * Tests Republic Day on or after 1946. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testRepublicDayOnAfter1946() + public function testRepublicDayOnAfter1946(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Republic Day before 1946. - * @throws ReflectionException + * + * @throws \Exception */ - public function testRepublicDayBefore1946() + public function testRepublicDayBefore1946(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Republic Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Festa della Repubblica'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Italy/stStephensDayTest.php b/tests/Italy/stStephensDayTest.php index 25e5e70ab..3b78f1bf8 100644 --- a/tests/Italy/stStephensDayTest.php +++ b/tests/Italy/stStephensDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Italy; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Italy. */ -class stStephensDayTest extends ItalyBaseTestCase implements YasumiTestCaseInterface +class stStephensDayTest extends ItalyBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the day of St. Stephen's Day. * - * @dataProvider stStephensDayDataProvider - * - * @param int $year the year for which St. Stephen's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Stephen's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function teststStephensDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('stStephensDayDataProvider')] + public function teststStephensDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function teststStephensDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Stephen's Day. * - * @return array list of test dates for St. Stephen's Day - * @throws Exception + * @return array list of test dates for St. Stephen's Day + * + * @throws \Exception */ - public function stStephensDayDataProvider(): array + public static function stStephensDayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests translated name of St. Stephen's Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Santo Stefano'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Japan/AutumnalEquinoxDayTest.php b/tests/Japan/AutumnalEquinoxDayTest.php index 0e962d950..e9d8d857b 100644 --- a/tests/Japan/AutumnalEquinoxDayTest.php +++ b/tests/Japan/AutumnalEquinoxDayTest.php @@ -1,84 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Autumnal Equinox Day in Japan. */ -class AutumnalEquinoxDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class AutumnalEquinoxDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'autumnalEquinoxDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** - * Tests Vernal Equinox Day after 2150. This national holiday was established in 1948 as a day on which to honor + * Tests Autumnal Equinox Day after 2150. This national holiday was established in 1948 as a day on which to honor * one's ancestors and remember the dead. Prior to 1948, the autumnal equinox was an imperial ancestor worship * festival called Shūki kōrei-sai (秋季皇霊祭). * * After 2150 no calculations are available yet. - * @throws ReflectionException + * + * @throws \Exception */ - public function testAutumnalEquinoxDayOnAfter2150() + public function testAutumnalEquinoxDayOnAfter2150(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(2151)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(2151)); } /** - * Tests Vernal Equinox Day between 1948 and 2150. This national holiday was established in 1948 as a day on which + * Tests Autumnal Equinox Day between 1948 and 2150. This national holiday was established in 1948 as a day on which * to honor one's ancestors and remember the dead. Prior to 1948, the autumnal equinox was an imperial ancestor * worship festival called Shūki kōrei-sai (秋季皇霊祭). * * After 2150 no calculations are available yet. * - * @dataProvider autumnalEquinoxHolidaysProvider - * - * @param int $year year of example data to be tested + * @param int $year year of example data to be tested * @param int $month month (number) of example data to be tested - * @param int $day day of the month (number) of example data to be tested + * @param int $day day of the month (number) of example data to be tested * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testAutumnalEquinoxDayBetween1948And2150($year, $month, $day) + #[\PHPUnit\Framework\Attributes\DataProvider('autumnalEquinoxHolidaysProvider')] + public function testAutumnalEquinoxDayBetween1948And2150(int $year, int $month, int $day): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-$month-$day", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-{$month}-{$day}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Returns a list of all Japanese Autumnal Equinox holidays used for assertions. * - * @return array list of Japanese Autumnal Equinox holidays + * @return array list of test dates for the holiday defined in this test */ - public function autumnalEquinoxHolidaysProvider(): array + public static function autumnalEquinoxHolidaysProvider(): array { return [ [1951, 9, 24], @@ -90,59 +90,47 @@ public function autumnalEquinoxHolidaysProvider(): array } /** - * Tests Vernal Equinox Day before 1948. This national holiday was established in 1948 as a day on which to honor + * Tests Autumnal Equinox Day before 1948. This national holiday was established in 1948 as a day on which to honor * one's ancestors and remember the dead. Prior to 1948, the autumnal equinox was an imperial ancestor worship * festival called Shūki kōrei-sai (秋季皇霊祭). - * @throws ReflectionException - */ - public function testAutumnalEquinoxDayBefore1948() - { - $this->assertNotHoliday( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) - ); - } - - /** - * Tests Vernal Equinox Day between 1851 and 1948. This national holiday was established in 1948 as a day on - * which to honor one's ancestors and remember the dead. Prior to 1948, the autumnal equinox was an imperial - * ancestor worship festival called Shūki kōrei-sai (秋季皇霊祭). - * @throws ReflectionException + * + * @throws \Exception */ - public function testAutumnalEquinoxDayBetween1851And1948() + public function testAutumnalEquinoxDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1851, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), [self::LOCALE => '秋分の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/ChildrensDayTest.php b/tests/Japan/ChildrensDayTest.php index d83decaa6..f456f3400 100644 --- a/tests/Japan/ChildrensDayTest.php +++ b/tests/Japan/ChildrensDayTest.php @@ -1,108 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class testing Childrens Day in Japan. + * Class testing Children's Day in Japan. */ -class ChildrensDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class ChildrensDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'childrensDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** - * Tests Children's Day after 1948. Children's Day was established after 1948 - * @throws Exception - * @throws ReflectionException + * Tests Children's Day after 1948. Children's Day was established after 1948. + * + * @throws \Exception */ - public function testChildrensDayOnAfter1948() + public function testChildrensDayOnAfter1948(): void { $year = 1955; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-5", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Children's Day after 1948 substituted next working day (when Children's Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Children's Day after 1948 substituted next working day (when Children's Day falls on a Sunday). + * + * @throws \Exception */ - public function testChildrensDayOnAfter1948SubstitutedNextWorkingDay() + public function testChildrensDayOnAfter1948SubstitutedNextWorkingDay(): void { $year = 2120; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-5-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-6", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Children's Day before 1948. Children's Day was established after 1948 - * @throws ReflectionException + * Tests Children's Day before 1948. Children's Day was established after 1948. + * + * @throws \Exception */ - public function testChildrensDayBefore1948() + public function testChildrensDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'こどもの日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/ComingOfAgeDayTest.php b/tests/Japan/ComingOfAgeDayTest.php index 0b5fa84f1..14529ce15 100644 --- a/tests/Japan/ComingOfAgeDayTest.php +++ b/tests/Japan/ComingOfAgeDayTest.php @@ -1,112 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Coming Of Age Day in Japan. */ -class ComingOfAgeDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class ComingOfAgeDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'comingOfAgeDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** * Tests Coming of Age Day after 2000. Coming of Age Day was established after 1948 on January 15th. After 2000 it * was changed to be the second monday of January. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testComingOfAgeDayOnAfter2000() + public function testComingOfAgeDayOnAfter2000(): void { - $year = $this->generateRandomYear(2001); + $year = static::generateRandomYear(2001); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("second monday of january $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("second monday of january {$year}", new \DateTimeZone(self::TIMEZONE)) ); } - /** * Tests Coming of Age Day between 1948 and 2000. Coming of Age Day was established after 1948 on January 15th. * After 2000 it was changed to be the second monday of January. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testComingOfAgeDayBetween1948And2000() + public function testComingOfAgeDayBetween1948And2000(): void { $year = 1991; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-1-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Coming of Age Day before 1948. Coming of Age Day was established after 1948 on January 15th. After 2000 it * was changed to be the second monday of January. - * @throws ReflectionException + * + * @throws \Exception */ - public function testConstitutionMemorialDayBefore1948() + public function testConstitutionMemorialDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '成人の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/ConstitutionMemorialDayTest.php b/tests/Japan/ConstitutionMemorialDayTest.php index 0cef87b31..0e6e36835 100644 --- a/tests/Japan/ConstitutionMemorialDayTest.php +++ b/tests/Japan/ConstitutionMemorialDayTest.php @@ -1,109 +1,113 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for teting Constitution Memorial Day in Japan. */ -class ConstitutionMemorialDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class ConstitutionMemorialDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'constitutionMemorialDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** - * Tests Constitution Memorial Day after 1948. Constitution Memorial Day was established after 1948 - * @throws Exception - * @throws ReflectionException + * Tests Constitution Memorial Day after 1948. Constitution Memorial Day was established after 1948. + * + * @throws \Exception */ - public function testConstitutionMemorialDayOnAfter1948() + public function testConstitutionMemorialDayOnAfter1948(): void { $year = 1967; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Constitution Memorial Day after 1948 substituted next working day (when Constitution Memorial Day falls on - * a Sunday) - * @throws Exception - * @throws ReflectionException + * a Sunday). + * + * @throws \Exception */ - public function testConstitutionMemorialDayOnAfter1948SubstitutedNextWorkingDay() + public function testConstitutionMemorialDayOnAfter1948SubstitutedNextWorkingDay(): void { $year = 2009; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-5-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-6", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Constitution Memorial Day before 1948. Constitution Memorial Day was established after 1948 - * @throws ReflectionException + * Tests Constitution Memorial Day before 1948. Constitution Memorial Day was established after 1948. + * + * @throws \Exception */ - public function testConstitutionMemorialDayBefore1948() + public function testConstitutionMemorialDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '憲法記念日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/CoronationDayTest.php b/tests/Japan/CoronationDayTest.php index 6ddc0e43e..327ab282e 100644 --- a/tests/Japan/CoronationDayTest.php +++ b/tests/Japan/CoronationDayTest.php @@ -1,85 +1,79 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing the Emperors Coronation day in Japan. */ -class CoronationDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class CoronationDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'coronationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2019; /** - * - * - * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsCoronationDay() + public function testEmperorsCoronationDay(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 2019, - new DateTime('2019-5-1', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2019-5-1', new \DateTimeZone(self::TIMEZONE)) ); } - /** - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsBirthdayBefore2019() + public function testEmperorsBirthdayBefore2019(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsBirthdayAfter2020() + public function testEmperorsBirthdayAfter2020(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR + 1) + static::generateRandomYear(self::ESTABLISHMENT_YEAR + 1) ); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -93,7 +87,6 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { diff --git a/tests/Japan/CultureDayTest.php b/tests/Japan/CultureDayTest.php index 814b324a9..641e37f4e 100644 --- a/tests/Japan/CultureDayTest.php +++ b/tests/Japan/CultureDayTest.php @@ -1,108 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Culture Day in Japan. */ -class CultureDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class CultureDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'cultureDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** - * Tests Culture Day after 1948. Culture Day Day was established after 1948 - * @throws Exception - * @throws ReflectionException + * Tests Culture Day after 1948. Culture Day Day was established after 1948. + * + * @throws \Exception */ - public function testCultureDayOnAfter1948() + public function testCultureDayOnAfter1948(): void { $year = 1973; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-3", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Culture Day after 1948 substituted next working day (when Culture Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Culture Day after 1948 substituted next working day (when Culture Day falls on a Sunday). + * + * @throws \Exception */ - public function testCultureDayOnAfter1948SubstitutedNextWorkingDay() + public function testCultureDayOnAfter1948SubstitutedNextWorkingDay(): void { $year = 2661; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-11-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-4", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Culture Day before 1948. Culture Day was established after 1948 - * @throws ReflectionException + * Tests Culture Day before 1948. Culture Day was established after 1948. + * + * @throws \Exception */ - public function testCultureDayBefore1948() + public function testCultureDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '文化の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/EmperorsBirthdayTest.php b/tests/Japan/EmperorsBirthdayTest.php index 9ac892b80..241fa557b 100644 --- a/tests/Japan/EmperorsBirthdayTest.php +++ b/tests/Japan/EmperorsBirthdayTest.php @@ -1,54 +1,56 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing the Emperors Birthday in Japan. + * + * @source https://en.wikipedia.org/wiki/The_Emperor's_Birthday */ -class EmperorsBirthdayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class EmperorsBirthdayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'emperorsBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; - // public const ESTABLISHMENT_YEAR = 1989; /** * Tests the Emperors Birthday after 1949 to 1988. The Emperors Birthday is on April 28rd and celebrated as such since * 1949. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEmperorsBirthdayOnAfter1949() + public function testEmperorsBirthdayOnAfter1949(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1987); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1988); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-29", new \DateTimeZone(self::TIMEZONE)) ); } @@ -56,75 +58,72 @@ public function testEmperorsBirthdayOnAfter1949() * Tests the Emperors Birthday after 1989 to 2018. The Emperors Birthday is on December 23rd and celebrated as such since * 1989. Prior to the death of Emperor Hirohito in 1989, this holiday was celebrated on April 29. See also "Shōwa * Day". - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEmperorsBirthdayOnAfter1989() + public function testEmperorsBirthdayOnAfter1989(): void { - $year = $this->generateRandomYear(1989, 2018); + $year = static::generateRandomYear(1989, 2018); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the Emperors Birthday after 2020. The Emperors Birthday is on February 23rd and celebrated as such since * 2020. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEmperorsBirthdayOnAfter2020() + public function testEmperorsBirthdayOnAfter2020(): void { - $year = $this->generateRandomYear(2020); + $year = static::generateRandomYear(2020); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the Emperors Birthday after 1989 substituted next working day (when the Emperors Birthday falls on a - * Sunday) - * @throws Exception - * @throws ReflectionException + * Sunday). + * + * @throws \Exception */ - public function testEmperorsBirthdayOnAfter1989SubstitutedNextWorkingDay() + public function testEmperorsBirthdayOnAfter1989SubstitutedNextWorkingDay(): void { $year = 2001; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-12-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-24", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests the Emperors Birthday before 1989. The Emperors Birthday is on December 23rd and celebrated as such since - * 1989. Prior to the death of Emperor Hirohito in 1989, this holiday was celebrated on April 29. See also "Shōwa - * Day"/"Greenery Day" - * @throws ReflectionException + * Tests the Emperors Birthday before 1949. + * + * @throws \Exception */ - public function testEmperorsBirthdayBefore1989() + public function testEmperorsBirthdayBefore1949(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * Tests the Emperors Birthday at 2019. - * - * @throws ReflectionException + * Tests the Emperors Birthday in 2019. */ - public function testEmperorsBirthdayAt2019() + public function testEmperorsBirthdayIn2019(): void { $this->assertNotHoliday( self::REGION, @@ -135,28 +134,30 @@ public function testEmperorsBirthdayAt2019() /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '天皇誕生日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/EnthronementProclamationCeremonyTest.php b/tests/Japan/EnthronementProclamationCeremonyTest.php index 4b908beb6..9effce40d 100644 --- a/tests/Japan/EnthronementProclamationCeremonyTest.php +++ b/tests/Japan/EnthronementProclamationCeremonyTest.php @@ -1,84 +1,79 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing the Emperors Coronation day in Japan. */ -class EnthronementProclamationCeremonyTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class EnthronementProclamationCeremonyTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'enthronementProclamationCeremony'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const IMPLEMENT_YEAR = 2019; /** - * - * - * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsCoronationDay() + public function testEmperorsCoronationDay(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 2019, - new DateTime('2019-10-22', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2019-10-22', new \DateTimeZone(self::TIMEZONE)) ); } - /** - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsBirthdayBefore2019() + public function testEmperorsBirthdayBefore2019(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::IMPLEMENT_YEAR - 1) + static::generateRandomYear(1000, self::IMPLEMENT_YEAR - 1) ); } /** - * @throws ReflectionException + * @throws \Exception */ - public function testEmperorsBirthdayAfter2020() + public function testEmperorsBirthdayAfter2020(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::IMPLEMENT_YEAR + 1) + static::generateRandomYear(self::IMPLEMENT_YEAR + 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -92,7 +87,6 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { diff --git a/tests/Japan/GreeneryDayTest.php b/tests/Japan/GreeneryDayTest.php index 2042efe9e..4b969cbcf 100644 --- a/tests/Japan/GreeneryDayTest.php +++ b/tests/Japan/GreeneryDayTest.php @@ -1,143 +1,147 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing Greenery Day in Japan. */ -class GreeneryDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class GreeneryDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday defined in the test + * The name of the holiday defined in the test. */ public const HOLIDAY = 'greeneryDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1989; /** * Tests Greenery Day after 2007. Greenery Day was established from 1989 on April 29th. After 2007 * it was changed to be May 4th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfter2007() + public function testHolidayOnAfter2007(): void { $year = 2112; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-4", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Greenery Day after 2007 substituted next working day (when Greenery Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Greenery Day after 2007 substituted next working day (when Greenery Day falls on a Sunday). + * + * @throws \Exception */ - public function testHolidayOnAfter2007SubstitutedNextWorkingDay() + public function testHolidayOnAfter2007SubstitutedNextWorkingDay(): void { $year = 2014; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-5-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-6", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Greenery Day between 1989 and 2007. Greenery Day was established from 1989 on April 29th. After 2007 * it was changed to be May 4th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBetween1989And2007() + public function testHolidayBetween1989And2007(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-29", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Greenery Day between 1989 and 2007 substituted next working day (when Greenery Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Greenery Day between 1989 and 2007 substituted next working day (when Greenery Day falls on a Sunday). + * + * @throws \Exception */ - public function testHolidayBetween1989And2007SubstitutedNextWorkingDay() + public function testHolidayBetween1989And2007SubstitutedNextWorkingDay(): void { $year = 2001; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-4-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Greenery Day before 1989. Greenery Day was established from 1989 on April 29th. After 2007 * it was changed to be May 4th. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBefore1989() + public function testHolidayBefore1989(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'みどりの日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/JapanBaseTestCase.php b/tests/Japan/JapanBaseTestCase.php index 37b024e11..a1e0b65cd 100644 --- a/tests/Japan/JapanBaseTestCase.php +++ b/tests/Japan/JapanBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; @@ -23,22 +28,18 @@ abstract class JapanBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Japan'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Asia/Tokyo'; /** - * Prefix for short name used when holiday is substituted + * Prefix for holiday key used when holiday is substituted. */ public const SUBSTITUTE_PREFIX = 'substituteHoliday:'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'ja_JP'; } diff --git a/tests/Japan/JapanTest.php b/tests/Japan/JapanTest.php index a311ab825..412ab9905 100644 --- a/tests/Japan/JapanTest.php +++ b/tests/Japan/JapanTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Japan. */ -class JapanTest extends JapanBaseTestCase +class JapanTest extends JapanBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2020, 2150); + } /** - * Tests if all official holidays in Japan are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Japan are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -52,8 +66,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all official holidays in Japan At 2019 are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Japan At 2019 are defined by the provider class. */ public function testOfficialHolidaysAt2019(): void { @@ -79,8 +92,7 @@ public function testOfficialHolidaysAt2019(): void } /** - * Tests if all observed holidays in Japan are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Japan are defined by the provider class. */ public function testObservedHolidays(): void { @@ -88,8 +100,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Japan are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Japan are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -97,8 +108,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Japan are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Japan are defined by the provider class. */ public function testBankHolidays(): void { @@ -106,8 +116,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Japan are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Japan are defined by the provider class. */ public function testOtherHolidays(): void { @@ -115,10 +124,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2020, 2150); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Japan/LabourThanksgivingDayTest.php b/tests/Japan/LabourThanksgivingDayTest.php index 929088bfd..78f1c65e3 100644 --- a/tests/Japan/LabourThanksgivingDayTest.php +++ b/tests/Japan/LabourThanksgivingDayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Labor Thanksgiving Day in Japan. */ -class LabourThanksgivingDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class LabourThanksgivingDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'laborThanksgivingDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** * Tests Labor Thanksgiving Day after 1948. Labor Thanksgiving Day is held on November 23rd and established since * 1948. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testLabourThanksgivingDayOnAfter1948() + public function testLabourThanksgivingDayOnAfter1948(): void { $year = 4884; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Labor Thanksgiving Day after 1948 substituted next working day (when Labor Thanksgiving Day falls on a - * Sunday) - * @throws Exception - * @throws ReflectionException + * Sunday). + * + * @throws \Exception */ - public function testLabourThanksgivingDayOnAfter1948SubstitutedNextWorkingDay() + public function testLabourThanksgivingDayOnAfter1948SubstitutedNextWorkingDay(): void { $year = 1986; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-11-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Labor Thanksgiving Day before 1948. Labor Thanksgiving Day is held on November 23rd and established since * 1948. - * @throws ReflectionException + * + * @throws \Exception */ - public function testLabourThanksgivingDayBefore1948() + public function testLabourThanksgivingDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '勤労感謝の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/MarineDayTest.php b/tests/Japan/MarineDayTest.php index 1a14ad340..47e6abb61 100644 --- a/tests/Japan/MarineDayTest.php +++ b/tests/Japan/MarineDayTest.php @@ -1,143 +1,164 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; -/** - * Class for testing Marine Day in Japan. - */ -class MarineDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +final class MarineDayTest extends JapanBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday - */ public const HOLIDAY = 'marineDay'; - /** - * The year in which the holiday was first established - */ + // The year in which the holiday was first established. public const ESTABLISHMENT_YEAR = 1996; /** - * Tests Marine Day in 2020. Marine Day in 2020 is July 23th for the Olympic Games. - * @throws Exception - * @throws ReflectionException + * Tests Marine Day in 2020. Marine Day in 2020 is July 23th for rescheduled Olympic Games after COVID-19. + * + * @see https://en.wikipedia.org/wiki/Marine_Day + * + * @throws \Exception */ - public function testMarineDayIn2020() + public function testMarineDayIn2020(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-23", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Marine Day in 2021. Marine Day in 2021 is July 22th for rescheduled Olympic Games after COVID-19. + * + * @see https://en.wikipedia.org/wiki/Marine_Day + * + * @throws \Exception + */ + public function testMarineDayIn2021(): void + { + $year = 2021; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-7-22", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Marine Day after 2003. Marine Day was established since 1996 on July 20th. After 2003 it was changed * to be the third monday of July. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMarineDayOnAfter2003() + public function testMarineDayOnAfter2003(): void { - $year = $this->generateRandomYear(2004); + $year = self::generateRandomYear(2004); + + if (in_array($year, [2020, 2021])) { + return; + } + $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third monday of july $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third monday of july {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Marine Day between 1996 and 2003. Marine Day was established since 1996 on July 20th. After 2003 it was * changed to be the third monday of July. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMarineDayBetween1996And2003() + public function testMarineDayBetween1996And2003(): void { $year = 2001; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-20", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-20", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Marine Day between 1996 and 2003 substituted next working day (when Marine Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Marine Day between 1996 and 2003 substituted next working day (when Marine Day falls on a Sunday). + * + * @throws \Exception */ - public function testMarineDayBetween1996And2003SubstitutedNextWorkingDay() + public function testMarineDayBetween1996And2003SubstitutedNextWorkingDay(): void { $year = 1997; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-7-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Marine Day before 1996. Marine Day was established since 1996 on July 20th. After 2003 it was changed * to be the third monday of July. - * @throws ReflectionException + * + * @throws \Exception */ - public function testMarineDayBefore1996() + public function testMarineDayBefore1996(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + self::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + self::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '海の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + self::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/MountainDayTest.php b/tests/Japan/MountainDayTest.php index 6a1f6089c..496a166f7 100644 --- a/tests/Japan/MountainDayTest.php +++ b/tests/Japan/MountainDayTest.php @@ -1,124 +1,144 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Mountain Day in Japan. */ -class MountainDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class MountainDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mountainDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2016; + /** + * Tests Mountain Day in 2021. Mountain Day in 2021 is August 8th for rescheduled Olympic Games after COVID-19. + * + * @throws \Exception + */ + public function testMountainDayIn2021(): void + { + $year = 2021; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-8-8", new \DateTimeZone(self::TIMEZONE)) + ); + } + /** * Tests Mountain Day in 2020. Mountain Day in 2020 is August 10th for the Olympic Games. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMountainDayIn2020() + public function testMountainDayIn2020(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Mountain Day after 2016. Mountain Day was established in 2014 and is held from 2016 on August 11th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMountainDayOnAfter2016() + public function testMountainDayOnAfter2016(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-11", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Mountain Day after 2016 substituted next working day (when Mountain Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Mountain Day after 2016 substituted next working day (when Mountain Day falls on a Sunday). + * + * @throws \Exception */ - public function testMountainDayOnAfter2016SubstitutedNextWorkingDay() + public function testMountainDayOnAfter2016SubstitutedNextWorkingDay(): void { $year = 2019; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-8-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Mountain Day before 2016. Mountain Day was established in 2014 and is held from 2016 on August 11th. - * @throws ReflectionException + * + * @throws \Exception */ - public function testMountainDayBefore2016() + public function testMountainDayBefore2016(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '山の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/NationalFoundationDayTest.php b/tests/Japan/NationalFoundationDayTest.php index 40f177474..45a84d30b 100644 --- a/tests/Japan/NationalFoundationDayTest.php +++ b/tests/Japan/NationalFoundationDayTest.php @@ -1,109 +1,113 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing National Foundation Day in Japan. */ -class NationalFoundationDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class NationalFoundationDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'nationalFoundationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1966; /** - * Tests National Foundation Day after 1966. National Foundation day was established after 1966 - * @throws Exception - * @throws ReflectionException + * Tests National Foundation Day after 1966. National Foundation day was established after 1966. + * + * @throws \Exception */ - public function testNationalFoundationDayOnAfter1966() + public function testNationalFoundationDayOnAfter1966(): void { $year = 1972; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-11", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests National Foundation Day after 1966. substituted next working day (when National Foundation Day falls on a - * Sunday) - * @throws Exception - * @throws ReflectionException + * Sunday). + * + * @throws \Exception */ - public function testNationalFoundationDayOnAfter1966SubstitutedNextWorkingDay() + public function testNationalFoundationDayOnAfter1966SubstitutedNextWorkingDay(): void { $year = 2046; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-2-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-12", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests National Foundation Day before 1966. National Foundation day was established after 1966 - * @throws ReflectionException + * Tests National Foundation Day before 1966. National Foundation day was established after 1966. + * + * @throws \Exception */ - public function testNationalFoundationDayBefore1966() + public function testNationalFoundationDayBefore1966(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '建国記念の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/NewYearsDayTest.php b/tests/Japan/NewYearsDayTest.php index 4ef09cfb2..aa11b4a5f 100644 --- a/tests/Japan/NewYearsDayTest.php +++ b/tests/Japan/NewYearsDayTest.php @@ -1,108 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Japan. */ -class NewYearsDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; /** - * Tests New Years Day after 1948. New Years Day was established after 1948 - * @throws Exception - * @throws ReflectionException + * Tests New Years Day after 1948. New Years Day was established after 1948. + * + * @throws \Exception */ - public function testNewYearsDayOnAfter1948() + public function testNewYearsDayOnAfter1948(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests New Years Day after 1948 substituted next working day (when New Years Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests New Years Day after 1948 substituted next working day (when New Years Day falls on a Sunday). + * + * @throws \Exception */ - public function testNewYearsDayOnAfter1948SubstitutedNextWorkingDay() + public function testNewYearsDayOnAfter1948SubstitutedNextWorkingDay(): void { $year = 4473; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-1-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-2", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests New Years Day before 1948. New Years Day was established after 1948 - * @throws ReflectionException + * Tests New Years Day before 1948. New Years Day was established after 1948. + * + * @throws \Exception */ - public function testNewYearsDayBefore1948() + public function testNewYearsDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '元日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/PublicBridgeDayTest.php b/tests/Japan/PublicBridgeDayTest.php index 8b6c590cd..07a24e878 100644 --- a/tests/Japan/PublicBridgeDayTest.php +++ b/tests/Japan/PublicBridgeDayTest.php @@ -1,62 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing public bridge days in Japan. */ -class PublicBridgeDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class PublicBridgeDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bridgeDay'; + /** * @var number representing the calendar year to be tested against */ - private $year; + private int $year; + + /** + * Initial setup of this Test Case. + */ + protected function setUp(): void + { + $this->year = 2019; + } /** * Tests public bridge days. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPublicBridgeDay() + public function testPublicBridgeDay(): void { $this->assertHoliday( self::REGION, self::HOLIDAY . '1', $this->year, - new DateTime("$this->year-4-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$this->year}-4-30", new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY . '2', $this->year, - new DateTime("$this->year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$this->year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -65,18 +74,9 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { $this->assertHolidayType(self::REGION, self::HOLIDAY . '1', $this->year, Holiday::TYPE_OFFICIAL); } - - /** - * Initial setup of this Test Case - */ - protected function setUp(): void - { - $this->year = 2019; - } } diff --git a/tests/Japan/RespectForTheAgedDayTest.php b/tests/Japan/RespectForTheAgedDayTest.php index d9b6f8794..81f35fe27 100644 --- a/tests/Japan/RespectForTheAgedDayTest.php +++ b/tests/Japan/RespectForTheAgedDayTest.php @@ -1,128 +1,132 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing Respect For The Aged Day in Japan. */ -class RespectForTheAgedDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class RespectForTheAgedDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'respectfortheAgedDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1996; /** * Tests Respect for the Aged Day after 2003. Respect for the Aged Day was established since 1996 on September * 15th. After 2003 it was changed to be the third monday of September. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testRespectForTheAgedDayOnAfter2003() + public function testRespectForTheAgedDayOnAfter2003(): void { - $year = $this->generateRandomYear(2004); + $year = static::generateRandomYear(2004); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third monday of september $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third monday of september {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Respect for the Aged Day between 1996 and 2003. Respect for the Aged Day was established since 1996 on * September 15th. After 2003 it was changed to be the third monday of September. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testRespectForTheAgedDayBetween1996And2003() + public function testRespectForTheAgedDayBetween1996And2003(): void { $year = 1998; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Respect for the Aged Day between 1996 and 2003 substituted next working day (when Respect for the Aged Day - * falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * falls on a Sunday). + * + * @throws \Exception */ - public function testRespectForTheAgedDayBetween1996And2003SubstitutedNextWorkingDay() + public function testRespectForTheAgedDayBetween1996And2003SubstitutedNextWorkingDay(): void { $year = 2002; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-9-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Respect for the Aged Day before 1996. Respect for the Aged Day was established since 1996 on September * 15th. After 2003 it was changed to be the third monday of September. - * @throws ReflectionException + * + * @throws \Exception */ - public function testRespectForTheAgedDayBefore1996() + public function testRespectForTheAgedDayBefore1996(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '敬老の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/ShowaDayTest.php b/tests/Japan/ShowaDayTest.php index a8bc471e8..8d1d906cb 100644 --- a/tests/Japan/ShowaDayTest.php +++ b/tests/Japan/ShowaDayTest.php @@ -1,108 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing Showa Day in Japan. */ -class ShowaDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class ShowaDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday defined in the test + * The name of the holiday defined in the test. */ public const HOLIDAY = 'showaDay'; /** - * The year in which the holiday defined in the test was first established + * The year in which the holiday defined in the test was first established. */ public const ESTABLISHMENT_YEAR = 2007; /** * Tests the holiday defined in the test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfter2007() + public function testHolidayOnAfter2007(): void { $year = 2110; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-29", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in the test on or after the establishment and substituted next working day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishmentSubstitutedNextWorkingDay() + public function testHolidayOnAfterEstablishmentSubstitutedNextWorkingDay(): void { $year = 2210; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-4-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in the test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '昭和の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/SportsDayTest.php b/tests/Japan/SportsDayTest.php index 0b03d16db..6ad586245 100644 --- a/tests/Japan/SportsDayTest.php +++ b/tests/Japan/SportsDayTest.php @@ -1,139 +1,164 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Health And Sports Day in Japan. */ -class SportsDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class SportsDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'sportsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1996; /** - * Tests Health And Sports Day in 2020. Health And Sports Day in 2020 is July 24th for the Olympic Games. - * @throws Exception - * @throws ReflectionException + * Tests Health And Sports Day in 2021. Health And Sports Day in 2021 is July 23th for rescheduled Olympic Games + * after COVID-19. + * + * @throws \Exception */ - public function testSportsDayIn2020() + public function testSportsDayIn2021(): void { - $year = 2020; + $year = 2021; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-23", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Health And Sports Day after 2000. Health And Sports Day was established since 1996 on October 10th. After - * 2000 it was changed to be the second monday of October. - * @throws Exception - * @throws ReflectionException + * Tests Health And Sports Day in 2020. Health And Sports Day in 2020 is July 24th for the Olympic Games. + * + * @throws \Exception */ - public function testSportsDayOnAfter2000() + public function testSportsDayIn2020(): void { - $year = $this->generateRandomYear(2001); + $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("second monday of october $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-24", new \DateTimeZone(self::TIMEZONE)) ); } + /** + * Tests Health And Sports Day after 2000. Health And Sports Day was established since 1996 on October 10th. After + * 2000 it was changed to be the second monday of October. + * + * @throws \Exception + */ + public function testSportsDayAfter2000(): void + { + $year = static::generateRandomYear(2001); + + // Some years the date has changed, so in this test we need to skip them. + if (! in_array($year, [2020, 2021])) { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("second monday of october {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + } + /** * Tests Health And Sports Day between 1996 and 2000. Health And Sports Day was established since 1996 on October * 10th. After 2000 it was changed to be the second monday of October. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testSportsDayBetween1996And2000() + public function testSportsDayBetween1996And2000(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Health And Sports Day between 1996 and 2000 substituted next working day (when Health And Sports Day falls - * on a Sunday) - * @throws Exception - * @throws ReflectionException + * on a Sunday). + * + * @throws \Exception */ - public function testSportsDayBetween1996And2000SubstitutedNextWorkingDay() + public function testSportsDayBetween1996And2000SubstitutedNextWorkingDay(): void { $year = 1999; $this->assertHoliday( self::REGION, self::SUBSTITUTE_PREFIX . self::HOLIDAY, $year, - new DateTime("$year-10-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-11", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Health And Sports Day before. Health And Sports Day was established since 1996 on October 10th. After * 2000 it was changed to be the second monday of October. - * @throws ReflectionException + * + * @throws \Exception */ - public function testSportsDayBefore1996() + public function testSportsDayBefore1996(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * 1996-2019:Health And Sports Day - * @throws ReflectionException + * 1996-2019:Health And Sports Day. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2019), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2019), [self::LOCALE => '体育の日'] ); } /** * Tests the translated name of the holiday defined in this test. - * 2020 - :Sports Day - * @throws ReflectionException + * 2020 - :Sports Day. + * + * @throws \Exception */ public function testTranslationFrom2020(): void { @@ -141,21 +166,22 @@ public function testTranslationFrom2020(): void $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear($year), + static::generateRandomYear($year), [self::LOCALE => 'スポーツの日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Japan/VernalEquinoxDayTest.php b/tests/Japan/VernalEquinoxDayTest.php index b5f24bae0..7af809e7a 100644 --- a/tests/Japan/VernalEquinoxDayTest.php +++ b/tests/Japan/VernalEquinoxDayTest.php @@ -1,36 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Japan; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class testing Vernal Equinox Day in Japan. */ -class VernalEquinoxDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface +class VernalEquinoxDayTest extends JapanBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'vernalEquinoxDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1948; @@ -40,11 +41,12 @@ class VernalEquinoxDayTest extends JapanBaseTestCase implements YasumiTestCaseIn * festival called Shunki kōrei-sai (春季皇霊祭). * * After 2150 no calculations are available yet. - * @throws ReflectionException + * + * @throws \Exception */ - public function testVernalEquinoxDayOnAfter2150() + public function testVernalEquinoxDayOnAfter2150(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(2151)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(2151)); } /** @@ -54,32 +56,29 @@ public function testVernalEquinoxDayOnAfter2150() * * After 2150 no calculations are available yet. * - * @dataProvider vernalEquinoxHolidaysProvider - * - * @param int $year year of example data to be tested + * @param int $year year of example data to be tested * @param int $month month (number) of example data to be tested - * @param int $day day of the month (number) of example data to be tested + * @param int $day day of the month (number) of example data to be tested * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testVernalEquinoxDayBetween1948And2150($year, $month, $day) + #[\PHPUnit\Framework\Attributes\DataProvider('vernalEquinoxHolidaysProvider')] + public function testVernalEquinoxDayBetween1948And2150(int $year, int $month, int $day): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-$month-$day", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-{$month}-{$day}", new \DateTimeZone(self::TIMEZONE)) ); } - /** * Returns a list of all Japanese Vernal Equinox holidays used for assertions. * - * @return array list of Japanese Vernal Equinox holidays + * @return array list of test dates for the holiday defined in this test */ - public function vernalEquinoxHolidaysProvider(): array + public static function vernalEquinoxHolidaysProvider(): array { return [ [1948, 3, 22], @@ -94,56 +93,44 @@ public function vernalEquinoxHolidaysProvider(): array * Tests Vernal Equinox Day before 1948. This national holiday was established in 1948 as a day for the admiration * of nature and the love of living things. Prior to 1948, the vernal equinox was an imperial ancestor worship * festival called Shunki kōrei-sai (春季皇霊祭). - * @throws ReflectionException - */ - public function testVernalEquinoxDayBefore1948() - { - $this->assertNotHoliday( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) - ); - } - - /** - * Tests Vernal Equinox Day between 1851 and 1948. This national holiday was established in 1948 as a day for - * the admiration of nature and the love of living things. Prior to 1948, the vernal equinox was an imperial - * ancestor worship festival called Shunki kōrei-sai (春季皇霊祭). - * @throws ReflectionException + * + * @throws \Exception */ - public function testVernalEquinoxDayBetween1851And1948() + public function testVernalEquinoxDayBefore1948(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1851, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), [self::LOCALE => '春分の日'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2150), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Latvia/ChristmasDayTest.php b/tests/Latvia/ChristmasDayTest.php index 8e4e1ddc1..5fd2651bd 100644 --- a/tests/Latvia/ChristmasDayTest.php +++ b/tests/Latvia/ChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas day in Latvia. * * @author Gedas Lukošius */ -class ChristmasDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ziemassvētki'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/ChristmasEveDayTest.php b/tests/Latvia/ChristmasEveDayTest.php index a2aea141b..6fb51af52 100644 --- a/tests/Latvia/ChristmasEveDayTest.php +++ b/tests/Latvia/ChristmasEveDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas Eve day in Latvia. * * @author Gedas Lukošius */ -class ChristmasEveDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasEve'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ziemassvētku vakars'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/EasterDayTest.php b/tests/Latvia/EasterDayTest.php index e60e1b5dd..84fc7bb2a 100644 --- a/tests/Latvia/EasterDayTest.php +++ b/tests/Latvia/EasterDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter day in Latvia. * * @author Gedas Lukošius */ -class EasterDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class EasterDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomEasterDates(self::TIMEZONE); + return static::generateRandomEasterDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lieldienas'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/EasterMondayDayTest.php b/tests/Latvia/EasterMondayDayTest.php index e5373fb40..ba1f8935f 100644 --- a/tests/Latvia/EasterMondayDayTest.php +++ b/tests/Latvia/EasterMondayDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday day in Latvia. * * @author Gedas Lukošius */ -class EasterMondayDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomEasterMondayDates(self::TIMEZONE); + return static::generateRandomEasterMondayDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Otrās Lieldienas'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/GoodFridayDayTest.php b/tests/Latvia/GoodFridayDayTest.php index e9536ba55..3150eead6 100644 --- a/tests/Latvia/GoodFridayDayTest.php +++ b/tests/Latvia/GoodFridayDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Latvia. * * @author Gedas Lukošius */ -class GoodFridayDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomGoodFridayDates(self::TIMEZONE); + return static::generateRandomGoodFridayDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lielā Piektdiena'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/InternationalWorkersDayTest.php b/tests/Latvia/InternationalWorkersDayTest.php index a091b70bb..9e375dfb0 100644 --- a/tests/Latvia/InternationalWorkersDayTest.php +++ b/tests/Latvia/InternationalWorkersDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day in Latvia. * * @author Gedas Lukošius */ -class InternationalWorkersDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Darba svētki'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/LatviaBaseTestCase.php b/tests/Latvia/LatviaBaseTestCase.php index 982709c14..657103a3c 100644 --- a/tests/Latvia/LatviaBaseTestCase.php +++ b/tests/Latvia/LatviaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; @@ -26,17 +30,13 @@ abstract class LatviaBaseTestCase extends TestCase use YasumiBase; /** - * Name of the country to be tested + * Name of the country to be tested. */ public const REGION = 'Latvia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Riga'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'lv_LV'; } diff --git a/tests/Latvia/LatviaTest.php b/tests/Latvia/LatviaTest.php index dc89c0407..aeb60437d 100644 --- a/tests/Latvia/LatviaTest.php +++ b/tests/Latvia/LatviaTest.php @@ -1,32 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Latvia; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Latvia. * * @author Gedas Lukošius */ -class LatviaTest extends LatviaBaseTestCase +class LatviaTest extends LatviaBaseTestCase implements ProviderTestCase { /** - * Tests if all official holidays in Latvia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Latvia are defined by the provider class. + * + * @throws \Exception */ public function testOfficialHolidays(): void { @@ -35,6 +40,7 @@ public function testOfficialHolidays(): void 'goodFriday', 'easter', 'easterMonday', + 'pentecost', 'internationalWorkersDay', 'midsummerEveDay', 'stJohnsDay', @@ -44,12 +50,16 @@ public function testOfficialHolidays(): void 'newYearsEve', ]; - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); if ($year >= Latvia::RESTORATION_OF_INDEPENDENCE_YEAR) { $holidays[] = 'restorationOfIndependenceOfLatviaDay'; } + if ($year >= Latvia::MOTHERS_DAY_YEAR) { + $holidays[] = 'mothersDay'; + } + if ($year >= Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR) { $holidays[] = 'proclamationOfTheRepublicOfLatviaDay'; } @@ -58,38 +68,51 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Latvia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Latvia are defined by the provider class. + * + * @throws \Exception */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Latvia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Latvia are defined by the provider class. + * + * @throws \Exception */ public function testSeasonalHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_SEASON); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); } /** - * Tests if all bank holidays in Latvia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Latvia are defined by the provider class. + * + * @throws \Exception */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Latvia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Latvia are defined by the provider class. + * + * @throws \Exception */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 4); } } diff --git a/tests/Latvia/MidsummerEveDayTest.php b/tests/Latvia/MidsummerEveDayTest.php index 08ae9772d..b0ceea670 100644 --- a/tests/Latvia/MidsummerEveDayTest.php +++ b/tests/Latvia/MidsummerEveDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Midsummer Eve day in Latvia. * * @author Gedas Lukošius */ -class MidsummerEveDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class MidsummerEveDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'midsummerEveDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(6, 23, self::TIMEZONE); + return static::generateRandomDates(6, 23, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Līgo Diena', 'en' => 'Midsummer Eve'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/MothersDayTest.php b/tests/Latvia/MothersDayTest.php new file mode 100644 index 000000000..c044099c5 --- /dev/null +++ b/tests/Latvia/MothersDayTest.php @@ -0,0 +1,69 @@ + + */ + +namespace Yasumi\tests\Latvia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Mother's Day in Latvia. + */ +class MothersDayTest extends LatviaBaseTestCase implements HolidayTestCase +{ + public const ESTABLISHMENT_YEAR = 1992; + + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'mothersDay'; + + /** + * Test defined holiday in the test. + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("second sunday of may {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Mātes dienu'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Latvia/NewYearsDayTest.php b/tests/Latvia/NewYearsDayTest.php index 5ed364458..c58b9732c 100644 --- a/tests/Latvia/NewYearsDayTest.php +++ b/tests/Latvia/NewYearsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's Day in Latvia. * * @author Gedas Lukošius */ -class NewYearsDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jaunais Gads'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/NewYearsEveDayTest.php b/tests/Latvia/NewYearsEveDayTest.php index 1d8f07337..759baf72d 100644 --- a/tests/Latvia/NewYearsEveDayTest.php +++ b/tests/Latvia/NewYearsEveDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's Eve day in Latvia. * * @author Gedas Lukošius */ -class NewYearsEveDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class NewYearsEveDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsEve'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 31, self::TIMEZONE); + return static::generateRandomDates(12, 31, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Vecgada vakars', 'en' => 'New Year\'s Eve'] + static::generateRandomYear(), + [self::LOCALE => 'Vecgada vakars', 'en' => 'New Year’s Eve'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/PentecostTest.php b/tests/Latvia/PentecostTest.php new file mode 100644 index 000000000..021f0671d --- /dev/null +++ b/tests/Latvia/PentecostTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\tests\Latvia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Pentecost in Latvia. + */ +class PentecostTest extends LatviaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'pentecost'; + + /** + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function holidayDataProvider(): array + { + return static::generateRandomPentecostDates(self::TIMEZONE); + } + + /** + * Test defined holiday in the test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Vasarsvētkus'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Latvia/ProclamationOfTheRepublicOfLatviaDayTest.php b/tests/Latvia/ProclamationOfTheRepublicOfLatviaDayTest.php index da73f2125..fbc59afc0 100644 --- a/tests/Latvia/ProclamationOfTheRepublicOfLatviaDayTest.php +++ b/tests/Latvia/ProclamationOfTheRepublicOfLatviaDayTest.php @@ -1,58 +1,60 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Latvia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Restoration of Independence of Latvia day. * * @author Gedas Lukošius */ -class ProclamationOfTheRepublicOfLatviaDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class ProclamationOfTheRepublicOfLatviaDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'proclamationOfTheRepublicOfLatviaDay'; /** - * Test if holiday is not defined before proclamation - * @throws ReflectionException + * Test if holiday is not defined before proclamation. + * + * @throws \Exception */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR - 1) + static::generateRandomYear(1000, Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR - 1) ); } /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday( + return static::generateRandomDatesWithHolidayMovedToMonday( 11, 18, self::TIMEZONE, @@ -62,36 +64,33 @@ public function holidayDataProvider(): array } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR), [ self::LOCALE => 'Latvijas Republikas proklamēšanas diena', 'en' => 'Proclamation Day of the Republic of Latvia', @@ -100,15 +99,14 @@ public function testTranslation(): void } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Latvia::PROCLAMATION_OF_INDEPENDENCE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Latvia/RestorationOfIndependenceDayTest.php b/tests/Latvia/RestorationOfIndependenceDayTest.php index 13c91b7fe..81f25e274 100644 --- a/tests/Latvia/RestorationOfIndependenceDayTest.php +++ b/tests/Latvia/RestorationOfIndependenceDayTest.php @@ -1,58 +1,60 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Latvia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Restoration of Independence of Latvia day. * * @author Gedas Lukošius */ -class RestorationOfIndependenceDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class RestorationOfIndependenceDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'restorationOfIndependenceOfLatviaDay'; /** - * Test if holiday is not defined before restoration - * @throws ReflectionException + * Test if holiday is not defined before restoration. + * + * @throws \Exception */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Latvia::RESTORATION_OF_INDEPENDENCE_YEAR - 1) + static::generateRandomYear(1000, Latvia::RESTORATION_OF_INDEPENDENCE_YEAR - 1) ); } /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday( + return static::generateRandomDatesWithHolidayMovedToMonday( 5, 4, self::TIMEZONE, @@ -62,36 +64,33 @@ public function holidayDataProvider(): array } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Latvia::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Latvia::RESTORATION_OF_INDEPENDENCE_YEAR), [ self::LOCALE => 'Latvijas Republikas Neatkarības atjaunošanas diena', 'en' => 'Restoration of Independence day', @@ -100,15 +99,14 @@ public function testTranslation(): void } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Latvia::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Latvia::RESTORATION_OF_INDEPENDENCE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Latvia/SecondChristmasDayTest.php b/tests/Latvia/SecondChristmasDayTest.php index 429dfc98e..5f7359e87 100644 --- a/tests/Latvia/SecondChristmasDayTest.php +++ b/tests/Latvia/SecondChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Second Christmas day in Latvia. * * @author Gedas Lukošius */ -class SecondChristmasDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Otrie Ziemassvētki'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Latvia/StJohnsDayTest.php b/tests/Latvia/StJohnsDayTest.php index 5d00d3940..a3e97299f 100644 --- a/tests/Latvia/StJohnsDayTest.php +++ b/tests/Latvia/StJohnsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Latvia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for St. John's Day in Latvia. * * @author Gedas Lukošius */ -class StJohnsDayTest extends LatviaBaseTestCase implements YasumiTestCaseInterface +class StJohnsDayTest extends LatviaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(6, 24, self::TIMEZONE); + return static::generateRandomDates(6, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jāņi'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/AllSaintsDayTest.php b/tests/Lithuania/AllSaintsDayTest.php index 271b45a81..6c8efe1d0 100644 --- a/tests/Lithuania/AllSaintsDayTest.php +++ b/tests/Lithuania/AllSaintsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints' Day in Lithuania. * * @author Gedas Lukošius */ -class AllSaintsDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Visų šventųjų diena (Vėlinės)'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/AllSoulsDayTest.php b/tests/Lithuania/AllSoulsDayTest.php new file mode 100644 index 000000000..a7a16aedf --- /dev/null +++ b/tests/Lithuania/AllSoulsDayTest.php @@ -0,0 +1,90 @@ + + */ + +namespace Yasumi\tests\Lithuania; + +use Yasumi\Holiday; +use Yasumi\Provider\Lithuania; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for All Souls' Day in Lithuania. + * + * @author Tomas Norkūnas + */ +class AllSoulsDayTest extends LithuaniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'allSoulsDay'; + + /** + * @throws \Exception + */ + public function testHolidayBeforeAnnounce(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, Lithuania::ALL_SOULS_DAY - 1) + ); + } + + /** + * Test if holiday is defined after restoration. + * + * @throws \Exception + */ + public function testHolidayAfterAnnounce(): void + { + $year = static::generateRandomYear(Lithuania::ALL_SOULS_DAY); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-11-02", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Lithuania::ALL_SOULS_DAY), + [self::LOCALE => 'Vėlinės'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Lithuania::ALL_SOULS_DAY), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Lithuania/AssumptionOfMaryDayTest.php b/tests/Lithuania/AssumptionOfMaryDayTest.php index bbe083681..cc3d04c9b 100644 --- a/tests/Lithuania/AssumptionOfMaryDayTest.php +++ b/tests/Lithuania/AssumptionOfMaryDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Assumption of Mary day in Lithuania. * * @author Gedas Lukošius */ -class AssumptionOfMaryDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Žolinė (Švč. Mergelės Marijos ėmimo į dangų diena)'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/ChristmasDayTest.php b/tests/Lithuania/ChristmasDayTest.php index 7f99b30f8..fa14453c5 100644 --- a/tests/Lithuania/ChristmasDayTest.php +++ b/tests/Lithuania/ChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas day in Lithuania. * * @author Gedas Lukošius */ -class ChristmasDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Šv. Kalėdos'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/ChristmasEveDayTest.php b/tests/Lithuania/ChristmasEveDayTest.php index ba5cdbd98..b26b809e6 100644 --- a/tests/Lithuania/ChristmasEveDayTest.php +++ b/tests/Lithuania/ChristmasEveDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Christmas Eve day in Lithuania. * * @author Gedas Lukošius */ -class ChristmasEveDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasEve'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Šv. Kūčios'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/EasterDayTest.php b/tests/Lithuania/EasterDayTest.php index 609977bf3..8a9d66fc9 100644 --- a/tests/Lithuania/EasterDayTest.php +++ b/tests/Lithuania/EasterDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter day in Lithuania. * * @author Gedas Lukošius */ -class EasterDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class EasterDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomEasterDates(self::TIMEZONE); + return static::generateRandomEasterDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Velykos'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/EasterMondayDayTest.php b/tests/Lithuania/EasterMondayDayTest.php index fab4603b1..cc415e1de 100644 --- a/tests/Lithuania/EasterMondayDayTest.php +++ b/tests/Lithuania/EasterMondayDayTest.php @@ -1,87 +1,84 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday day in Lithuania. * * @author Gedas Lukošius */ -class EasterMondayDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomEasterMondayDates(self::TIMEZONE); + return static::generateRandomEasterMondayDates(self::TIMEZONE); } /** - * Test defined holiday in the test - * - * @dataProvider holidayDataProvider + * Test defined holiday in the test. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Antroji Velykų diena'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/FathersDayTest.php b/tests/Lithuania/FathersDayTest.php new file mode 100644 index 000000000..9e6931c8b --- /dev/null +++ b/tests/Lithuania/FathersDayTest.php @@ -0,0 +1,83 @@ + + */ + +namespace Yasumi\tests\Lithuania; + +use Yasumi\Holiday; +use Yasumi\Provider\Lithuania; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Father's Day in Lithuania. + * + * @author Gedas Lukošius + */ +class FathersDayTest extends LithuaniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'fathersDay'; + + /** + * Test if holiday is not defined before restoration. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("first sunday of june {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Tėvo dieną'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + ['en' => 'Father’s Day'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Lithuania/InternationalWorkersDayTest.php b/tests/Lithuania/InternationalWorkersDayTest.php index dc7353b42..6d116f8da 100644 --- a/tests/Lithuania/InternationalWorkersDayTest.php +++ b/tests/Lithuania/InternationalWorkersDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day in Lithuania. * * @author Gedas Lukošius */ -class InternationalWorkersDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tarptautinė darbo diena'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/LithuaniaBaseTestCase.php b/tests/Lithuania/LithuaniaBaseTestCase.php index b958d9919..0f67afa73 100644 --- a/tests/Lithuania/LithuaniaBaseTestCase.php +++ b/tests/Lithuania/LithuaniaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; @@ -26,17 +30,13 @@ abstract class LithuaniaBaseTestCase extends TestCase use YasumiBase; /** - * Name of the country to be tested + * Name of the country to be tested. */ public const REGION = 'Lithuania'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Vilnius'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'lt_LT'; } diff --git a/tests/Lithuania/LithuaniaTest.php b/tests/Lithuania/LithuaniaTest.php index f1ce85678..ac6e24e2a 100644 --- a/tests/Lithuania/LithuaniaTest.php +++ b/tests/Lithuania/LithuaniaTest.php @@ -1,19 +1,22 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Lithuania; @@ -25,8 +28,9 @@ class LithuaniaTest extends LithuaniaBaseTestCase { /** - * Tests if all official holidays in Lithuania are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Lithuania are defined by the provider class. + * + * @throws \Exception */ public function testOfficialHolidays(): void { @@ -35,6 +39,8 @@ public function testOfficialHolidays(): void 'easter', 'easterMonday', 'internationalWorkersDay', + 'mothersDay', + 'fathersDay', 'stJohnsDay', 'assumptionOfMary', 'allSaintsDay', @@ -43,7 +49,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', ]; - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); if ($year >= Lithuania::RESTORATION_OF_THE_STATE_YEAR) { $holidays[] = 'restorationOfTheStateOfLithuaniaDay'; @@ -61,38 +67,51 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Lithuania are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Lithuania are defined by the provider class. + * + * @throws \Exception */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Lithuania are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Lithuania are defined by the provider class. + * + * @throws \Exception */ public function testSeasonalHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_SEASON); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); } /** - * Tests if all bank holidays in Lithuania are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Lithuania are defined by the provider class. + * + * @throws \Exception */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Lithuania are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Lithuania are defined by the provider class. + * + * @throws \Exception */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Lithuania/MothersDayTest.php b/tests/Lithuania/MothersDayTest.php new file mode 100644 index 000000000..9562d58f4 --- /dev/null +++ b/tests/Lithuania/MothersDayTest.php @@ -0,0 +1,83 @@ + + */ + +namespace Yasumi\tests\Lithuania; + +use Yasumi\Holiday; +use Yasumi\Provider\Lithuania; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Mother's Day in Lithuania. + * + * @author Gedas Lukošius + */ +class MothersDayTest extends LithuaniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'mothersDay'; + + /** + * Test if holiday is not defined before restoration. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("first sunday of may {$year}", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Motinos dieną'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + ['en' => 'Mother’s Day'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Lithuania/NewYearsDayTest.php b/tests/Lithuania/NewYearsDayTest.php index c75511f69..499f362ed 100644 --- a/tests/Lithuania/NewYearsDayTest.php +++ b/tests/Lithuania/NewYearsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's Day in Lithuania. * * @author Gedas Lukošius */ -class NewYearsDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Naujųjų metų diena'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/RestorationOfIndependenceOfLithuaniaDayTest.php b/tests/Lithuania/RestorationOfIndependenceOfLithuaniaDayTest.php index 4004a48b5..3a35346a5 100644 --- a/tests/Lithuania/RestorationOfIndependenceOfLithuaniaDayTest.php +++ b/tests/Lithuania/RestorationOfIndependenceOfLithuaniaDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Lithuania; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Restoration of Independence of Lithuania day. * * @author Gedas Lukošius */ -class RestorationOfIndependenceOfLithuaniaDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class RestorationOfIndependenceOfLithuaniaDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'restorationOfIndependenceOfLithuaniaDay'; /** - * Test if holiday is not defined before restoration - * @throws ReflectionException + * Test if holiday is not defined before restoration. + * + * @throws \Exception */ - public function testHolidayBeforeRestoration() + public function testHolidayBeforeRestoration(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR - 1) + static::generateRandomYear(1000, Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR - 1) ); } /** - * Test if holiday is defined after restoration - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after restoration. + * + * @throws \Exception */ - public function testHolidayAfterRestoration() + public function testHolidayAfterRestoration(): void { - $year = $this->generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR); + $year = static::generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-03-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-03-11", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), [self::LOCALE => 'Lietuvos nepriklausomybės atkūrimo diena'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), ['en' => 'Day of Restoration of Independence of Lithuania'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_INDEPENDENCE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Lithuania/RestorationOfTheStateOfLithuaniaDayTest.php b/tests/Lithuania/RestorationOfTheStateOfLithuaniaDayTest.php index 8eea1cd02..37aac7757 100644 --- a/tests/Lithuania/RestorationOfTheStateOfLithuaniaDayTest.php +++ b/tests/Lithuania/RestorationOfTheStateOfLithuaniaDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Lithuania; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Restoration of the State of Lithuania day. * * @author Gedas Lukošius */ -class RestorationOfTheStateOfLithuaniaDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class RestorationOfTheStateOfLithuaniaDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'restorationOfTheStateOfLithuaniaDay'; /** - * Test if holiday is not defined before restoration - * @throws ReflectionException + * Test if holiday is not defined before restoration. + * + * @throws \Exception */ - public function testHolidayBeforeRestoration() + public function testHolidayBeforeRestoration(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Lithuania::RESTORATION_OF_THE_STATE_YEAR - 1) + static::generateRandomYear(1000, Lithuania::RESTORATION_OF_THE_STATE_YEAR - 1) ); } /** - * Test if holiday is defined after restoration - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after restoration. + * + * @throws \Exception */ - public function testHolidayAfterRestoration() + public function testHolidayAfterRestoration(): void { - $year = $this->generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR); + $year = static::generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-02-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-02-16", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), [self::LOCALE => 'Lietuvos valstybės atkūrimo diena'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), ['en' => 'Day of Restoration of the State of Lithuania'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), + static::generateRandomYear(Lithuania::RESTORATION_OF_THE_STATE_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Lithuania/SecondChristmasDayTest.php b/tests/Lithuania/SecondChristmasDayTest.php index 9caae05bf..b9389ad98 100644 --- a/tests/Lithuania/SecondChristmasDayTest.php +++ b/tests/Lithuania/SecondChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Second Christmas day in Lithuania. * * @author Gedas Lukošius */ -class SecondChristmasDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kalėdos (antra diena)'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/StJohnsDayTest.php b/tests/Lithuania/StJohnsDayTest.php index 531eb3d9a..80c20df32 100644 --- a/tests/Lithuania/StJohnsDayTest.php +++ b/tests/Lithuania/StJohnsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for St. John's Day in Lithuania. * * @author Gedas Lukošius */ -class StJohnsDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class StJohnsDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(6, 24, self::TIMEZONE); + return static::generateRandomDates(6, 24, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Rasos ir Joninių diena'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Lithuania/StatehoodDayTest.php b/tests/Lithuania/StatehoodDayTest.php index 22341ed7c..50870aa39 100644 --- a/tests/Lithuania/StatehoodDayTest.php +++ b/tests/Lithuania/StatehoodDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Lithuania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Lithuania; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Statehood Day day in Lithuania. * * @author Gedas Lukošius */ -class StatehoodDayTest extends LithuaniaBaseTestCase implements YasumiTestCaseInterface +class StatehoodDayTest extends LithuaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'statehoodDay'; /** - * Test if holiday is not defined before restoration - * @throws ReflectionException + * Test if holiday is not defined before restoration. + * + * @throws \Exception */ - public function testHolidayBeforeRestoration() + public function testHolidayBeforeRestoration(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Lithuania::STATEHOOD_YEAR - 1) + static::generateRandomYear(1000, Lithuania::STATEHOOD_YEAR - 1) ); } /** - * Test if holiday is defined after restoration - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after restoration. + * + * @throws \Exception */ - public function testHolidayAfterRestoration() + public function testHolidayAfterRestoration(): void { - $year = $this->generateRandomYear(Lithuania::STATEHOOD_YEAR); + $year = static::generateRandomYear(Lithuania::STATEHOOD_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-07-06", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-07-06", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::STATEHOOD_YEAR), + static::generateRandomYear(Lithuania::STATEHOOD_YEAR), [self::LOCALE => 'Valstybės (Lietuvos karaliaus Mindaugo karūnavimo) diena'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::STATEHOOD_YEAR), + static::generateRandomYear(Lithuania::STATEHOOD_YEAR), ['en' => 'Statehood Day (Lithuania)'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Lithuania::STATEHOOD_YEAR), + static::generateRandomYear(Lithuania::STATEHOOD_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Luxembourg/AllSaintsDayTest.php b/tests/Luxembourg/AllSaintsDayTest.php new file mode 100644 index 000000000..662b17b05 --- /dev/null +++ b/tests/Luxembourg/AllSaintsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing All Saints' Day in Luxembourg. + */ +class AllSaintsDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'allSaintsDay'; + + /** + * Tests All Saints' Day. + * + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests translated name of All Saints' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Toussaint'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } + + /** + * Returns a list of random test dates used for assertion of All Saints' Day. + * + * @return array list of test dates for All Saints' Day + * + * @throws \Exception + */ + public static function AllSaintsDayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } +} diff --git a/tests/Luxembourg/AscensionDayTest.php b/tests/Luxembourg/AscensionDayTest.php new file mode 100644 index 000000000..1426a32fc --- /dev/null +++ b/tests/Luxembourg/AscensionDayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Ascension Day in Luxembourg. + */ +class AscensionDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'ascensionDay'; + + /** + * Tests Ascension Day. + * + * @throws \Exception + */ + public function testAscensionDay(): void + { + $year = 1901; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of Ascension Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Ascension'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/AssumptionOfMaryTest.php b/tests/Luxembourg/AssumptionOfMaryTest.php new file mode 100644 index 000000000..101ef4fc2 --- /dev/null +++ b/tests/Luxembourg/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of the Assumption of Mary in Luxembourg. + */ +class AssumptionOfMaryTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Assomption'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/ChristmasDayTest.php b/tests/Luxembourg/ChristmasDayTest.php new file mode 100644 index 000000000..aec628d75 --- /dev/null +++ b/tests/Luxembourg/ChristmasDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas in Luxembourg. + */ +class ChristmasDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day. + * + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of Christmas Day. + * + * @return array list of test dates for Christmas Day + * + * @throws \Exception + */ + public static function ChristmasDayDataProvider(): array + { + return static::generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * Tests translated name of Christmas Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Noël'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/EasterMondayTest.php b/tests/Luxembourg/EasterMondayTest.php new file mode 100644 index 000000000..d8bba5cc1 --- /dev/null +++ b/tests/Luxembourg/EasterMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter Monday in Luxembourg. + */ +class EasterMondayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterMonday'; + + /** + * Tests Easter Monday. + * + * @throws \Exception + */ + public function testEasterMonday(): void + { + $year = 2016; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of Easter Monday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Lundi de Pâques'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/EuropeDayTest.php b/tests/Luxembourg/EuropeDayTest.php new file mode 100644 index 000000000..a9ab55482 --- /dev/null +++ b/tests/Luxembourg/EuropeDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Europe Day in Luxembourg. + */ +class EuropeDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'europeDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2019; + + /** + * Tests Europe Day on or after 2019. + * + * @throws \Exception + */ + public function testEuropeDayOnAfter2019(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-9", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Europe Day before 2019. + * + * @throws \Exception + */ + public function testEuropeDayBefore2019(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Europe Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'La Journée de l’Europe'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Luxembourg/InternationalWorkersDayTest.php b/tests/Luxembourg/InternationalWorkersDayTest.php new file mode 100644 index 000000000..fe00f83c6 --- /dev/null +++ b/tests/Luxembourg/InternationalWorkersDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for International Workers' Day (i.e. Labour Day) in Luxembourg. + */ +class InternationalWorkersDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests International Workers' Day. + * + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests translated name of International Workers' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Fête du Travail'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } + + /** + * Returns a list of random test dates used for assertion of International Workers' Day. + * + * @return array list of test dates for International Workers' Day + * + * @throws \Exception + */ + public static function InternationalWorkersDayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } +} diff --git a/tests/Luxembourg/LuxembourgBaseTestCase.php b/tests/Luxembourg/LuxembourgBaseTestCase.php new file mode 100644 index 000000000..b116c17ca --- /dev/null +++ b/tests/Luxembourg/LuxembourgBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the France holiday provider. + */ +abstract class LuxembourgBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Luxembourg'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Europe/Luxembourg'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'fr_LU'; +} diff --git a/tests/Luxembourg/LuxembourgTest.php b/tests/Luxembourg/LuxembourgTest.php new file mode 100644 index 000000000..ff582829a --- /dev/null +++ b/tests/Luxembourg/LuxembourgTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\Provider\Luxembourg; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Luxembourg. + */ +class LuxembourgTest extends LuxembourgBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Tests if all official holidays in Luxembourg are defined by the provider class. + * + * @throws \Exception + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'nationalDay', + 'assumptionOfMary', + 'allSaintsDay', + 'christmasDay', + 'secondChristmasDay', + ]; + + $year = static::generateRandomYear(); + + if ($year >= Luxembourg::EUROPE_DAY_START_YEAR) { + $holidays[] = 'europeDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Luxembourg are defined by the provider class. + * + * @throws \Exception + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Luxembourg are defined by the provider class. + * + * @throws \Exception + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Luxembourg are defined by the provider class. + * + * @throws \Exception + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Luxembourg are defined by the provider class. + * + * @throws \Exception + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Luxembourg/NationalDayTest.php b/tests/Luxembourg/NationalDayTest.php new file mode 100644 index 000000000..d911a3934 --- /dev/null +++ b/tests/Luxembourg/NationalDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the National Day of Luxembourg. + */ +class NationalDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'nationalDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(6, 23, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'La Fête nationale'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/NewYearsDayTest.php b/tests/Luxembourg/NewYearsDayTest.php new file mode 100644 index 000000000..bae8397b0 --- /dev/null +++ b/tests/Luxembourg/NewYearsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for New Years Day in France. + */ +class NewYearsDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Years Day. + * + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests translated name of New Years Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Jour de l’An'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } + + /** + * Returns a list of random test dates used for assertion of New Years Day. + * + * @return array list of test dates for New Years Day + * + * @throws \Exception + */ + public static function NewYearsDayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } +} diff --git a/tests/Luxembourg/PentecostMondayTest.php b/tests/Luxembourg/PentecostMondayTest.php new file mode 100644 index 000000000..31ef7d023 --- /dev/null +++ b/tests/Luxembourg/PentecostMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Pentecost Monday in Luxembourg. + */ +class PentecostMondayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'pentecostMonday'; + + /** + * Tests Pentecost Monday. + * + * @throws \Exception + */ + public function testPentecostMonday(): void + { + $year = 1977; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of Pentecost Monday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Lundi de Pentecôte'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Luxembourg/SecondChristmasDayTest.php b/tests/Luxembourg/SecondChristmasDayTest.php new file mode 100644 index 000000000..5320bb30d --- /dev/null +++ b/tests/Luxembourg/SecondChristmasDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Luxembourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the Second Christmas Day in Luxembourg. + */ +class SecondChristmasDayTest extends LuxembourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'secondChristmasDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 26, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Deuxième jour de Noël'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/AllSaintsDayTest.php b/tests/Mexico/AllSaintsDayTest.php new file mode 100644 index 000000000..d7f90e36e --- /dev/null +++ b/tests/Mexico/AllSaintsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing All Saints' Day in Mexico. + */ +class AllSaintsDayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'allSaintsDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Día de todos los Santos'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/AssumptionOfMaryTest.php b/tests/Mexico/AssumptionOfMaryTest.php new file mode 100644 index 000000000..694d387b0 --- /dev/null +++ b/tests/Mexico/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of the Assumption of Mary in Mexico. + */ +class AssumptionOfMaryTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Asunción de la Virgen María'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/BenitoJuarezBirthdayTest.php b/tests/Mexico/BenitoJuarezBirthdayTest.php new file mode 100644 index 000000000..58614d0b5 --- /dev/null +++ b/tests/Mexico/BenitoJuarezBirthdayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class BenitoJuarezBirthdayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'benitoJuarezBirthday'; + + public const ESTABLISHMENT_YEAR = 1806; + + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-03-21", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Natalicio de Benito Juárez'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/ChristmasTest.php b/tests/Mexico/ChristmasTest.php new file mode 100644 index 000000000..c955bdea5 --- /dev/null +++ b/tests/Mexico/ChristmasTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas in Mexico. + */ +class ChristmasTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Navidad'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/EasterMondayTest.php b/tests/Mexico/EasterMondayTest.php new file mode 100644 index 000000000..8d1de30da --- /dev/null +++ b/tests/Mexico/EasterMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter Monday in Mexico. + */ +class EasterMondayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'easterMonday'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2216; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-8", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Lunes de Pascua'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/EpiphanyTest.php b/tests/Mexico/EpiphanyTest.php new file mode 100644 index 000000000..e9d7dcfeb --- /dev/null +++ b/tests/Mexico/EpiphanyTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Epiphany in Mexico. + */ +class EpiphanyTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'epiphany'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 6, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Día de Reyes'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/GoodFridayTest.php b/tests/Mexico/GoodFridayTest.php new file mode 100644 index 000000000..cdc682dcf --- /dev/null +++ b/tests/Mexico/GoodFridayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Good Friday in Mexico. + */ +class GoodFridayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'goodFriday'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2066; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-9", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Viernes Santo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/ImmaculateConceptionTest.php b/tests/Mexico/ImmaculateConceptionTest.php new file mode 100644 index 000000000..5a6ce8b96 --- /dev/null +++ b/tests/Mexico/ImmaculateConceptionTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of Immaculate Conception in Mexico. + */ +class ImmaculateConceptionTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'immaculateConception'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Inmaculada Concepción'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/IndependenceDayTest.php b/tests/Mexico/IndependenceDayTest.php new file mode 100644 index 000000000..fbe96c334 --- /dev/null +++ b/tests/Mexico/IndependenceDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Independence Day in Mexico. + */ +class IndependenceDayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'independenceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1810; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-09-16", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Día de la Independencia'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/InternationalWorkersDayTest.php b/tests/Mexico/InternationalWorkersDayTest.php new file mode 100644 index 000000000..0985e4de5 --- /dev/null +++ b/tests/Mexico/InternationalWorkersDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for International Workers' Day (i.e. Labour Day) in Mexico. + */ +class InternationalWorkersDayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Día del Trabajador'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/MexicoBaseTestCase.php b/tests/Mexico/MexicoBaseTestCase.php new file mode 100644 index 000000000..e9d93a73e --- /dev/null +++ b/tests/Mexico/MexicoBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Class MexicoBaseTestCase. + */ +abstract class MexicoBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Mexico'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Mexico_City'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'es'; +} diff --git a/tests/Mexico/NewYearsDayTest.php b/tests/Mexico/NewYearsDayTest.php new file mode 100644 index 000000000..4310596d5 --- /dev/null +++ b/tests/Mexico/NewYearsDayTest.php @@ -0,0 +1,78 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class NewYearsDayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Years Day. + * + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of New Years Day. + * + * @return array list of test dates for New Years Day + * + * @throws \Exception + */ + public static function NewYearsDayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests translated name of New Years Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Año Nuevo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/TransmissionOfFederalPowerDayTest.php b/tests/Mexico/TransmissionOfFederalPowerDayTest.php new file mode 100644 index 000000000..33522dd16 --- /dev/null +++ b/tests/Mexico/TransmissionOfFederalPowerDayTest.php @@ -0,0 +1,102 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class TransmissionOfFederalPowerDayTest extends MexicoBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'transmissionOfFederalPowerDay'; + + public const ESTABLISHMENT_YEAR = 1934; + + /** + * Tests that holiday is in December in 1934-2018. + */ + public function testHolidayBefore2018(): void + { + $year = self::ESTABLISHMENT_YEAR; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is in October since 2024. + */ + public function testHolidayAfter2024(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime('2024-10-01', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is in October since 2024. + */ + public function testNotHolidayOutsideElectionYear(): void + { + $year = $this->numberBetween(2019, 2023); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + $year + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHolidayBefore1934(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 6); + } + + /** + * Tests translated name of the holiday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::ESTABLISHMENT_YEAR, + [self::LOCALE => 'Transmisión de Poder Ejecutivo Federal'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/VirginOfGuadalupeTest.php b/tests/Mexico/VirginOfGuadalupeTest.php new file mode 100644 index 000000000..3c8f4cdda --- /dev/null +++ b/tests/Mexico/VirginOfGuadalupeTest.php @@ -0,0 +1,75 @@ + + */ + +namespace Yasumi\tests\Mexico; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Virgin of Guadalupe in Mexico. + */ +class VirginOfGuadalupeTest extends MexicoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'virginOfGuadalupe'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1531; + + /** + * Tests Virgin of Guadalupe. + * + * @throws \Exception + */ + public function testVirginOfGuadalupe(): void + { + $year = 2023; // Year to test + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-12", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Día de la Virgen de Guadalupe']); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Netherlands/AscensionDayTest.php b/tests/Netherlands/AscensionDayTest.php index 9f7aaed84..3766aa508 100644 --- a/tests/Netherlands/AscensionDayTest.php +++ b/tests/Netherlands/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in the Netherlands. */ -class AscensionDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1754; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Hemelvaart'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/AshWednesdayTest.php b/tests/Netherlands/AshWednesdayTest.php index e83bb229b..881a6d1a0 100644 --- a/tests/Netherlands/AshWednesdayTest.php +++ b/tests/Netherlands/AshWednesdayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ash Wednesday in the Netherlands. */ -class AshWednesdayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class AshWednesdayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ashWednesday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1999; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ash Wednesday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Aswoensdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Netherlands/ChristmasDayTest.php b/tests/Netherlands/ChristmasDayTest.php index 782251d48..272f0ec94 100644 --- a/tests/Netherlands/ChristmasDayTest.php +++ b/tests/Netherlands/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in the Netherlands. */ -class ChristmasDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Eerste kerstdag'] + static::generateRandomYear(), + [self::LOCALE => 'eerste kerstdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/CommemorationDayTest.php b/tests/Netherlands/CommemorationDayTest.php index 4c66e4cb3..322eeeccc 100644 --- a/tests/Netherlands/CommemorationDayTest.php +++ b/tests/Netherlands/CommemorationDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Commemoration Day in the Netherlands. */ -class CommemorationDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class CommemorationDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'commemorationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1947; /** * Tests Commemoration Day before 1947. Commemoration Day was established after WWII in 1947. - * @throws ReflectionException + * + * @throws \Exception */ - public function testCommemorationDayBefore1947() + public function testCommemorationDayBefore1947(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests Commemoration Day after 1947. Commemoration Day was established after WWII in 1947. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testCommemorationDayOnAfter1947() + public function testCommemorationDayOnAfter1947(): void { $year = 2105; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-4", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Dodenherdenking'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'dodenherdenking'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OBSERVANCE ); } diff --git a/tests/Netherlands/DaylightSavingTime.php b/tests/Netherlands/DaylightSavingTime.php new file mode 100644 index 000000000..6dbb4a271 --- /dev/null +++ b/tests/Netherlands/DaylightSavingTime.php @@ -0,0 +1,52 @@ + + */ + +namespace Yasumi\tests\Netherlands; + +use Yasumi\tests\HolidayTestCase; + +abstract class DaylightSavingTime extends NetherlandsBaseTestCase implements HolidayTestCase +{ + /** @var int[] */ + public array $observedYears; + + /** @var int[] */ + public array $unobservedYears; + + public function __construct() + { + $startYear = 1916; + $endYear = 2037; // PHP caps future DST transitions + $observedYears = array_merge(range($startYear, 1940), range(1942, 1945), range(1977, $endYear)); + + $this->observedYears = $observedYears; + $this->unobservedYears = array_diff(range($startYear, $endYear), $observedYears); + + parent::__construct(); + } + + /* Swaps the observation from observed to unobserved for the given years */ + protected function swapObservation(array $years): void + { + foreach ($years as $y) { + $this->observedYears[] = $y; + if (false !== ($key = array_search($y, $this->unobservedYears, true))) { + unset($this->unobservedYears[(int) $key]); + } + } + } +} diff --git a/tests/Netherlands/EasterMondayTest.php b/tests/Netherlands/EasterMondayTest.php index b92040171..348fad6a6 100644 --- a/tests/Netherlands/EasterMondayTest.php +++ b/tests/Netherlands/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in the Netherlands. */ -class EasterMondayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Tweede paasdag'] + static::generateRandomYear(), + [self::LOCALE => 'tweede paasdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/EasterTest.php b/tests/Netherlands/EasterTest.php index 6c30b083d..dbe54128b 100644 --- a/tests/Netherlands/EasterTest.php +++ b/tests/Netherlands/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter in the Netherlands. */ -class EasterTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easter'; /** * Tests Easter. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEaster() + public function testEaster(): void { $year = 2010; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-4", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Eerste paasdag'] + static::generateRandomYear(), + [self::LOCALE => 'eerste paasdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/EpiphanyTest.php b/tests/Netherlands/EpiphanyTest.php index 445654039..d1692198c 100644 --- a/tests/Netherlands/EpiphanyTest.php +++ b/tests/Netherlands/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Epiphany in the Netherlands. */ -class EpiphanyTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests Epiphany. * - * @dataProvider EpiphanyDataProvider - * - * @param int $year the year for which Epiphany needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Epiphany needs to be tested + * @param \DateTime $expected the expected date */ - public function testEpiphany($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('EpiphanyDataProvider')] + public function testEpiphany(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testEpiphany($year, $expected) /** * Returns a list of random test dates used for assertion of Epiphany. * - * @return array list of test dates for Epiphany - * @throws Exception + * @return array list of test dates for Epiphany + * + * @throws \Exception */ - public function EpiphanyDataProvider(): array + public static function EpiphanyDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Drie Koningen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Netherlands/FathersDayTest.php b/tests/Netherlands/FathersDayTest.php index 99d963302..1a09ce9bb 100644 --- a/tests/Netherlands/FathersDayTest.php +++ b/tests/Netherlands/FathersDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Father's Day in the Netherlands. */ -class FathersDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class FathersDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'fathersDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third sunday of june $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third sunday of june {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vaderdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Netherlands/GoodFridayTest.php b/tests/Netherlands/GoodFridayTest.php index 11e9b40a6..688ba2a46 100644 --- a/tests/Netherlands/GoodFridayTest.php +++ b/tests/Netherlands/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in the Netherlands. */ -class GoodFridayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests Good Friday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testGoodFriday() + public function testGoodFriday(): void { $year = 1876; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-14", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Goede Vrijdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Netherlands/HalloweenTest.php b/tests/Netherlands/HalloweenTest.php index fc903f079..28d6f09fc 100644 --- a/tests/Netherlands/HalloweenTest.php +++ b/tests/Netherlands/HalloweenTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Halloween in the Netherlands. */ -class HalloweenTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class HalloweenTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'halloween'; /** * Tests Halloween. * - * @dataProvider HalloweenDataProvider - * - * @param int $year the year for which Halloween needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Halloween needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HalloweenDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of Halloween. * - * @return array list of test dates for Halloween - * @throws Exception + * @return array list of test dates for Halloween + * + * @throws \Exception */ - public function HalloweenDataProvider(): array + public static function HalloweenDataProvider(): array { - return $this->generateRandomDates(10, 31, self::TIMEZONE); + return static::generateRandomDates(10, 31, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Halloween'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Netherlands/InternationalWorkersDayTest.php b/tests/Netherlands/InternationalWorkersDayTest.php index ba7d8e17e..c8dc80eda 100644 --- a/tests/Netherlands/InternationalWorkersDayTest.php +++ b/tests/Netherlands/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in the Netherlands. */ -class InternationalWorkersDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testInternationalWorkersDay($year, $expected) /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dag van de arbeid'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Netherlands/KingsDayTest.php b/tests/Netherlands/KingsDayTest.php index aefc2cc91..4ca433c57 100644 --- a/tests/Netherlands/KingsDayTest.php +++ b/tests/Netherlands/KingsDayTest.php @@ -1,108 +1,112 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Kings Day in the Netherlands. */ -class KingsDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class KingsDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'kingsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2014; /** * Tests Kings Day on or after 2014. King's Day is celebrated from 2014 onwards on April 27th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testKingsDayOnAfter2014() + public function testKingsDayOnAfter2014(): void { $year = 2015; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-27", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-27", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Kings Day substituted on Saturday (when Kings Day falls on a Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Kings Day substituted on Saturday (when Kings Day falls on a Sunday). + * + * @throws \Exception */ - public function testKingsDayOnAfter2014SubstitutedDay() + public function testKingsDayOnAfter2014SubstitutedDay(): void { $year = 2188; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-26", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-26", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Kings Day before 2014. King's Day is celebrated from 2014 onwards on April 27th. - * @throws ReflectionException + * + * @throws \Exception */ - public function testKingsDayBefore2014() + public function testKingsDayBefore2014(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Koningsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Netherlands/LiberationDayTest.php b/tests/Netherlands/LiberationDayTest.php index 38a8383c3..a8874d82f 100644 --- a/tests/Netherlands/LiberationDayTest.php +++ b/tests/Netherlands/LiberationDayTest.php @@ -1,92 +1,110 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Liberation Day in the Netherlands. */ -class LiberationDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class LiberationDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'liberationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1947; /** * Tests Liberation Day before 1947. Liberation Day was established after WWII in 1947. - * @throws ReflectionException + * + * @throws \Exception */ - public function testLiberationDayBefore1947() + public function testLiberationDayBefore1947(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests Liberation Day after 1947. Liberation Day was established after WWII in 1947. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testLiberationDayOnAfter1947() + public function testLiberationDayOnAfter1947(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-5", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Bevrijdingsdag'] ); } /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException + * Tests Liberation Day official holiday type every 5 years, observance type on other years. + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(2001, 2004), + Holiday::TYPE_OBSERVANCE + ); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + 2000, + Holiday::TYPE_OFFICIAL + ); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + 2005, Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Netherlands/MothersDayTest.php b/tests/Netherlands/MothersDayTest.php index 280d12386..20c9c4086 100644 --- a/tests/Netherlands/MothersDayTest.php +++ b/tests/Netherlands/MothersDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Mother's Day in the Netherlands. */ -class MothersDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class MothersDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'mothersDay'; /** * Tests Mother's Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMothersDay() + public function testMothersDay(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("second sunday of may $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("second sunday of may {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Moederdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Netherlands/NetherlandsBaseTestCase.php b/tests/Netherlands/NetherlandsBaseTestCase.php index 742c84af2..48ace0d64 100644 --- a/tests/Netherlands/NetherlandsBaseTestCase.php +++ b/tests/Netherlands/NetherlandsBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; @@ -22,18 +27,12 @@ abstract class NetherlandsBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Netherlands'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Amsterdam'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'nl_NL'; } diff --git a/tests/Netherlands/NetherlandsTest.php b/tests/Netherlands/NetherlandsTest.php index 410247746..e03dc5af4 100644 --- a/tests/Netherlands/NetherlandsTest.php +++ b/tests/Netherlands/NetherlandsTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Netherlands. */ -class NetherlandsTest extends NetherlandsBaseTestCase +class NetherlandsTest extends NetherlandsBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2014); + } /** - * Tests if all official holidays in Netherlands are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Netherlands are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,15 +53,16 @@ public function testOfficialHolidays(): void 'ascensionDay', 'pentecost', 'pentecostMonday', - 'liberationDay', 'christmasDay', 'secondChristmasDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + + $this->assertDefinedHolidays(['liberationDay'], self::REGION, 2015, Holiday::TYPE_OFFICIAL); + $this->assertDefinedHolidays(['liberationDay'], self::REGION, 2020, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Netherlands are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Netherlands are defined by the provider class. */ public function testObservedHolidays(): void { @@ -62,21 +77,14 @@ public function testObservedHolidays(): void 'secondCarnivalDay', 'thirdCarnivalDay', ], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); - } - /** - * Tests if all seasonal holidays in Netherlands are defined by the provider class - * @throws ReflectionException - */ - public function testSeasonalHolidays(): void - { - $year = $this->generateRandomYear(1978, 2037); - $this->assertDefinedHolidays(['summerTime', 'winterTime'], self::REGION, $year, Holiday::TYPE_SEASON); + $this->assertDefinedHolidays([ + 'liberationDay', + ], self::REGION, static::generateRandomYear(2011, 2014), Holiday::TYPE_OBSERVANCE); } /** - * Tests if all bank holidays in Netherlands are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Netherlands are defined by the provider class. */ public function testBankHolidays(): void { @@ -84,8 +92,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Netherlands are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Netherlands are defined by the provider class. */ public function testOtherHolidays(): void { @@ -98,13 +105,28 @@ public function testOtherHolidays(): void 'epiphany', 'princesDay', ], self::REGION, $this->year, Holiday::TYPE_OTHER); + + $this->assertDefinedHolidays([ + 'dayAfterNewYearsDay', + 'dayAfterAscensionDay', + ], self::REGION, 2026, Holiday::TYPE_OTHER); + + $this->assertDefinedHolidays([ + 'dayAfterAscensionDay', + ], self::REGION, 2027, Holiday::TYPE_OTHER); + + $this->assertDefinedHolidays([ + 'dayAfterKingsDay', + 'dayAfterAscensionDay', + ], self::REGION, 2028, Holiday::TYPE_OTHER); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2014); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Netherlands/NewYearsDayTest.php b/tests/Netherlands/NewYearsDayTest.php index 5b0e7921f..0a1de82ae 100644 --- a/tests/Netherlands/NewYearsDayTest.php +++ b/tests/Netherlands/NewYearsDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the Netherlands. */ -class NewYearsDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testNewYearsDay($year, $expected) /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nieuwjaar'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/PentecostTest.php b/tests/Netherlands/PentecostTest.php index 2b6ceabf3..990843040 100644 --- a/tests/Netherlands/PentecostTest.php +++ b/tests/Netherlands/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost in the Netherlands. */ -class PentecostTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, 'pentecost', $year, - new DateTime("$year-5-31", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-31", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Eerste pinksterdag'] + static::generateRandomYear(), + [self::LOCALE => 'eerste pinksterdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/QueensDayTest.php b/tests/Netherlands/QueensDayTest.php index 848daf7f2..96291f75d 100644 --- a/tests/Netherlands/QueensDayTest.php +++ b/tests/Netherlands/QueensDayTest.php @@ -1,156 +1,161 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Queen's Day in the Netherlands. */ -class QueensDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class QueensDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensDay'; /** * Tests Queens Day between 1891 and 1948. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensBetween1891and1948() + public function testQueensBetween1891and1948(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-31", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-31", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Queens Day between 1891 and 1948 substituted one day later (when Queens Day falls on a Sunday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensBetween1891and1948SubstitutedLater() + public function testQueensBetween1891and1948SubstitutedLater(): void { $year = 1947; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Queens Day between 1949 and 2013. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensBetween1949and2013() + public function testQueensBetween1949and2013(): void { $year = 1965; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Queens Day between 1949 and 2013 substituted one day later. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensBetween1949and2013SubstitutedLater() + public function testQueensBetween1949and2013SubstitutedLater(): void { $year = 1967; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Queens Day between 1949 and 2013 substituted one day earlier. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensBetween1949and2013SubstitutedEarlier() + public function testQueensBetween1949and2013SubstitutedEarlier(): void { $year = 2006; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-29", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Queen's Day before 1891. - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensDayBefore1891() + public function testQueensDayBefore1891(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1000, 1890)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(1000, 1890)); } /** * Tests Queen's Day after 2013. - * @throws ReflectionException + * + * @throws \Exception */ - public function testQueensDayAfter2013() + public function testQueensDayAfter2013(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(2014)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(2014)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1891, 2013), + static::generateRandomYear(1891, 2013), [self::LOCALE => 'Koninginnedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1891, 2013), + static::generateRandomYear(1891, 2013), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Netherlands/SummertimeTest.php b/tests/Netherlands/SummertimeTest.php deleted file mode 100644 index ce978a17e..000000000 --- a/tests/Netherlands/SummertimeTest.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ - -namespace Yasumi\tests\Netherlands; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Summertime in the Netherlands. - */ -class SummertimeTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'summerTime'; - - /** - * Tests Summertime. - * - * @throws Exception - * @throws ReflectionException - */ - public function testSummertime() - { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1946, 1976)); - - $year = $this->generateRandomYear(1977, 1980); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("first sunday of april $year", new DateTimeZone(self::TIMEZONE)) - ); - - $year = $this->generateRandomYear(1981, 2036); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("last sunday of march $year", new DateTimeZone(self::TIMEZONE)) - ); - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1978, 2037), - [self::LOCALE => 'Zomertijd'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1978, 2037), Holiday::TYPE_SEASON); - } -} diff --git a/tests/Netherlands/ValentinesDayTest.php b/tests/Netherlands/ValentinesDayTest.php index e4e8702e8..f78c60f8b 100644 --- a/tests/Netherlands/ValentinesDayTest.php +++ b/tests/Netherlands/ValentinesDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Valentines Day in the Netherlands. */ -class ValentinesDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class ValentinesDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'valentinesDay'; /** * Tests Valentines Day. * - * @dataProvider ValentinesDayDataProvider - * - * @param int $year the year for which Valentines Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Valentines Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testValentinesDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ValentinesDayDataProvider')] + public function testValentinesDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,36 @@ public function testValentinesDay($year, $expected) /** * Returns a list of random test dates used for assertion of Valentines Day. * - * @return array list of test dates for Valentines Day - * @throws Exception + * @return array list of test dates for Valentines Day + * + * @throws \Exception */ - public function ValentinesDayDataProvider(): array + public static function ValentinesDayDataProvider(): array { - return $this->generateRandomDates(2, 14, self::TIMEZONE); + return static::generateRandomDates(2, 14, self::TIMEZONE); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Valentijnsdag'] ); } diff --git a/tests/Netherlands/WintertimeTest.php b/tests/Netherlands/WintertimeTest.php deleted file mode 100644 index 902d580a1..000000000 --- a/tests/Netherlands/WintertimeTest.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ - -namespace Yasumi\tests\Netherlands; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Wintertime in the Netherlands. - */ -class WintertimeTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'winterTime'; - - /** - * Tests Wintertime. - * @throws Exception - * @throws ReflectionException - */ - public function testWintertime() - { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1946, 1976)); - - $year = $this->generateRandomYear(1979, 1995); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("last sunday of september $year", new DateTimeZone(self::TIMEZONE)) - ); - - $year = $this->generateRandomYear(1996, 2037); - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("last sunday of october $year", new DateTimeZone(self::TIMEZONE)) - ); - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(1978, 2037), - [self::LOCALE => 'Wintertijd'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1978, 2037), Holiday::TYPE_SEASON); - } -} diff --git a/tests/Netherlands/WorldAnimalDayTest.php b/tests/Netherlands/WorldAnimalDayTest.php index 0ec5097c8..0d7fc32be 100644 --- a/tests/Netherlands/WorldAnimalDayTest.php +++ b/tests/Netherlands/WorldAnimalDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing World Animal Day in the Netherlands. */ -class WorldAnimalDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class WorldAnimalDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'worldAnimalDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1931; /** * Tests World Animal Day on or after 1931. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testWorldAnimalDayOnAfter1931() + public function testWorldAnimalDayOnAfter1931(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-4", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests World Animal Day before 1931. - * @throws ReflectionException + * + * @throws \Exception */ - public function testWorldAnimalBefore1931() + public function testWorldAnimalBefore1931(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OTHER ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Werelddierendag'] ); } diff --git a/tests/Netherlands/carnivalDayTest.php b/tests/Netherlands/carnivalDayTest.php index 2cc6b331f..5cdfa7e6f 100644 --- a/tests/Netherlands/carnivalDayTest.php +++ b/tests/Netherlands/carnivalDayTest.php @@ -1,70 +1,72 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Carnival in the Netherlands. */ -class carnivalDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class carnivalDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'carnivalDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2015; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Carnaval'] ); } diff --git a/tests/Netherlands/pentecostMondayTest.php b/tests/Netherlands/pentecostMondayTest.php index e8700703d..891bf3828 100644 --- a/tests/Netherlands/pentecostMondayTest.php +++ b/tests/Netherlands/pentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost in the Netherlands. */ -class pentecostMondayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class pentecostMondayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 2020; $this->assertHoliday( self::REGION, 'pentecostMonday', $year, - new DateTime("$year-6-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Tweede pinksterdag'] + static::generateRandomYear(), + [self::LOCALE => 'tweede pinksterdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/princesDayTest.php b/tests/Netherlands/princesDayTest.php index f0a5d86f6..a5036ff7e 100644 --- a/tests/Netherlands/princesDayTest.php +++ b/tests/Netherlands/princesDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Prince's Day in the Netherlands. */ -class princesDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class princesDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'princesDay'; /** * Tests Prince's Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPrincesDay() + public function testPrincesDay(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third tuesday of september $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third tuesday of september {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Prinsjesdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Netherlands/secondCarnivalDay.php b/tests/Netherlands/secondCarnivalDay.php index cc6b2bd0b..7a35d8e58 100644 --- a/tests/Netherlands/secondCarnivalDay.php +++ b/tests/Netherlands/secondCarnivalDay.php @@ -1,89 +1,87 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use InvalidArgumentException; -use PHPUnit_Framework_AssertionFailedError; -use ReflectionException; -use RuntimeException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the second day of Carnival in the Netherlands. */ -class secondCarnivalDay extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class secondCarnivalDay extends NetherlandsBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondCarnivalDay'; + public function __construct() + { + parent::__construct(static::class); + } + /** * Tests the holiday defined in this test. * * @throws UnknownLocaleException - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException - * @throws ReflectionException - * @throws Exception + * @throws \InvalidArgumentException + * @throws \RuntimeException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2015; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests type of the holiday defined in this test. * - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** * Tests the translated name of the holiday defined in this test. * - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Carnaval'] ); } diff --git a/tests/Netherlands/secondChristmasdayTest.php b/tests/Netherlands/secondChristmasdayTest.php index 0abdc265d..96c31f5f4 100644 --- a/tests/Netherlands/secondChristmasdayTest.php +++ b/tests/Netherlands/secondChristmasdayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the second day ofChristmas in the Netherlands. */ -class secondChristmasdayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class secondChristmasdayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Tweede kerstdag'] + static::generateRandomYear(), + [self::LOCALE => 'tweede kerstdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Netherlands/stMartinsDayTest.php b/tests/Netherlands/stMartinsDayTest.php index a368c0b30..b51c74cb9 100644 --- a/tests/Netherlands/stMartinsDayTest.php +++ b/tests/Netherlands/stMartinsDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing st Martins Day in the Netherlands. */ -class stMartinsDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class stMartinsDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stMartinsDay'; /** * Tests Sint Martins Day. * - * @dataProvider stMartinsDayDataProvider - * - * @param int $year the year for which Sint Martins Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Sint Martins Day needs to be tested + * @param \DateTime $expected the expected date */ - public function teststMartinsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('stMartinsDayDataProvider')] + public function teststMartinsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function teststMartinsDay($year, $expected) /** * Returns a list of random test dates used for assertion of Sint Martins Day. * - * @return array list of test dates for Sint Martins Day - * @throws Exception + * @return array list of test dates for Sint Martins Day + * + * @throws \Exception */ - public function stMartinsDayDataProvider(): array + public static function stMartinsDayDataProvider(): array { - return $this->generateRandomDates(11, 11, self::TIMEZONE); + return static::generateRandomDates(11, 11, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sint Maarten'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Netherlands/stNicholasDayTest.php b/tests/Netherlands/stNicholasDayTest.php index d06d44e64..6cf4b01d4 100644 --- a/tests/Netherlands/stNicholasDayTest.php +++ b/tests/Netherlands/stNicholasDayTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing st Nicholas Day in the Netherlands. */ -class stNicholasDayTest extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class stNicholasDayTest extends NetherlandsBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stNicholasDay'; /** * Tests Sint Nicholas Day. * - * @dataProvider stNicholasDayDataProvider - * - * @param int $year the year for which Sint Nicholas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Sint Nicholas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function teststNicholasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('stNicholasDayDataProvider')] + public function teststNicholasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function teststNicholasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Sint Nicholas Day. * - * @return array list of test dates for Sint Nicholas Day - * @throws Exception + * @return array list of test dates for Sint Nicholas Day + * + * @throws \Exception */ - public function stNicholasDayDataProvider(): array + public static function stNicholasDayDataProvider(): array { - return $this->generateRandomDates(12, 5, self::TIMEZONE); + return static::generateRandomDates(12, 5, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sinterklaas'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Netherlands/thirdCarnivalDay.php b/tests/Netherlands/thirdCarnivalDay.php index 1fdb87681..f8233788b 100644 --- a/tests/Netherlands/thirdCarnivalDay.php +++ b/tests/Netherlands/thirdCarnivalDay.php @@ -1,89 +1,87 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Netherlands; -use DateTime; -use DateTimeZone; -use Exception; -use InvalidArgumentException; -use PHPUnit_Framework_AssertionFailedError; -use ReflectionException; -use RuntimeException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Carnival in the Netherlands. */ -class thirdCarnivalDay extends NetherlandsBaseTestCase implements YasumiTestCaseInterface +class thirdCarnivalDay extends NetherlandsBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'thirdCarnivalDay'; + public function __construct() + { + parent::__construct(static::class); + } + /** * Tests the holiday defined in this test. * * @throws UnknownLocaleException - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException - * @throws ReflectionException - * @throws Exception + * @throws \InvalidArgumentException + * @throws \RuntimeException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2015; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests type of the holiday defined in this test. * - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** * Tests the translated name of the holiday defined in this test. * - * @throws InvalidArgumentException - * @throws PHPUnit_Framework_AssertionFailedError - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Carnaval'] ); } diff --git a/tests/NewZealand/AnzacDayTest.php b/tests/NewZealand/AnzacDayTest.php index 06fdfbd2b..d5d5306bd 100644 --- a/tests/NewZealand/AnzacDayTest.php +++ b/tests/NewZealand/AnzacDayTest.php @@ -1,109 +1,116 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing ANZAC day in the New Zealand. */ -class AnzacDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class AnzacDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'anzacDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1921; /** - * Tests ANZAC Day + * Tests ANZAC Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests that Labour Day is not present before 1921 - * @throws ReflectionException + * Tests that Labour Day is not present before 1921. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithModifier(4, 25, function ($year, DateTime $date) { + return static::generateRandomDatesWithModifier(4, 25, function ($year, \DateTime $date): void { // in 2015 some policy was introduced to make sure this holiday was celebrated during the working week. - if ($year >= 2015 && $this->isWeekend($date)) { - $date->modify('next monday'); + if ($year < 2015) { + return; } - }, self::TIMEZONE, 100, self::ESTABLISHMENT_YEAR); + + if (! static::isWeekend($date)) { + return; + } + + $date->modify('next monday'); + }, 100, self::ESTABLISHMENT_YEAR, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'ANZAC Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/NewZealand/BoxingDayTest.php b/tests/NewZealand/BoxingDayTest.php index 233511bed..96c1c2acd 100644 --- a/tests/NewZealand/BoxingDayTest.php +++ b/tests/NewZealand/BoxingDayTest.php @@ -1,72 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in the New Zealand. */ -class BoxingDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** - * Tests Boxing Day - * - * @dataProvider HolidayDataProvider + * Tests Boxing Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); } $data[] = [$year, $date->format('Y-m-d')]; @@ -77,24 +76,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/NewZealand/ChristmasDayTest.php b/tests/NewZealand/ChristmasDayTest.php index 9effe55b3..1e7a5df0b 100644 --- a/tests/NewZealand/ChristmasDayTest.php +++ b/tests/NewZealand/ChristmasDayTest.php @@ -1,72 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in the New Zealand. */ -class ChristmasDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** - * Tests Christmas Day - * - * @dataProvider HolidayDataProvider + * Tests Christmas Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); } $data[] = [$year, $date->format('Y-m-d')]; @@ -77,24 +76,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/NewZealand/DayAfterNewYearsDayTest.php b/tests/NewZealand/DayAfterNewYearsDayTest.php index b68d5b4d7..cae5cb7cf 100644 --- a/tests/NewZealand/DayAfterNewYearsDayTest.php +++ b/tests/NewZealand/DayAfterNewYearsDayTest.php @@ -1,100 +1,101 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Day After New Years Day in the New Zealand. */ -class DayAfterNewYearsDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class DayAfterNewYearsDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'dayAfterNewYearsDay'; /** - * Tests Day After New Years Day - * - * @dataProvider HolidayDataProvider + * Tests Day After New Years Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Day after New Year\'s Day'] + static::generateRandomYear(), + [self::LOCALE => 'Day after New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-01-02", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-01-02", new \DateTimeZone(self::TIMEZONE)); switch ($date->format('w')) { case 0: case 6: - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); break; case 1: - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); } $data[] = [$year, $date->format('Y-m-d')]; diff --git a/tests/NewZealand/EasterMondayTest.php b/tests/NewZealand/EasterMondayTest.php index 05df75333..85aeaf06d 100644 --- a/tests/NewZealand/EasterMondayTest.php +++ b/tests/NewZealand/EasterMondayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Monday in New Zealand. */ -class EasterMondayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider + * Tests Easter Monday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,24 +73,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/NewZealand/GoodFridayTest.php b/tests/NewZealand/GoodFridayTest.php index 02894c8ed..f75621278 100644 --- a/tests/NewZealand/GoodFridayTest.php +++ b/tests/NewZealand/GoodFridayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in New Zealand. */ -class GoodFridayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'goodFriday'; /** - * Tests Good Friday - * - * @dataProvider HolidayDataProvider + * Tests Good Friday. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->sub(new DateInterval('P2D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P2D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -73,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/NewZealand/LabourDayTest.php b/tests/NewZealand/LabourDayTest.php index 8bbacf10f..37c89b065 100644 --- a/tests/NewZealand/LabourDayTest.php +++ b/tests/NewZealand/LabourDayTest.php @@ -1,84 +1,83 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Labour Day in the New Zealand. */ -class LabourDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1900; /** - * Tests Labour Day - * - * @dataProvider HolidayDataProvider + * Tests Labour Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests that Labour Day is not present before 1900 - * @throws ReflectionException + * Tests that Labour Day is not present before 1900. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 100; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $expected = new DateTime( - (($year < 1910) ? 'second wednesday of october' : 'fourth monday of october') . " $year", - new DateTimeZone(self::TIMEZONE) + for ($y = 0; $y < 100; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $expected = new \DateTime( + (($year < 1910) ? 'second wednesday of october' : 'fourth monday of october') . " {$year}", + new \DateTimeZone(self::TIMEZONE) ); $data[] = [$year, $expected->format('Y-m-d')]; @@ -89,28 +88,30 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Labour Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/NewZealand/MatarikiTest.php b/tests/NewZealand/MatarikiTest.php new file mode 100644 index 000000000..ae63df6e8 --- /dev/null +++ b/tests/NewZealand/MatarikiTest.php @@ -0,0 +1,149 @@ + + */ + +namespace Yasumi\tests\NewZealand; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Matariki in New Zealand. + */ +class MatarikiTest extends NewZealandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'matariki'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2022; + + /** + * The year the Matariki Advisory Committee have calculated dates until + */ + public const CALCULATED_UNTIL_YEAR = 2052; + + /** + * Tests Matariki. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests that Holiday is not present before 2022. + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + $matarikiDates = [ + 2022 => ['month' => 6, 'day' => 24], + 2023 => ['month' => 7, 'day' => 14], + 2024 => ['month' => 6, 'day' => 28], + 2025 => ['month' => 6, 'day' => 20], + 2026 => ['month' => 7, 'day' => 10], + 2027 => ['month' => 6, 'day' => 25], + 2028 => ['month' => 7, 'day' => 14], + 2029 => ['month' => 7, 'day' => 6], + 2030 => ['month' => 6, 'day' => 21], + 2031 => ['month' => 7, 'day' => 11], + 2032 => ['month' => 7, 'day' => 2], + 2033 => ['month' => 6, 'day' => 24], + 2034 => ['month' => 7, 'day' => 7], + 2035 => ['month' => 6, 'day' => 29], + 2036 => ['month' => 7, 'day' => 18], + 2037 => ['month' => 7, 'day' => 10], + 2038 => ['month' => 6, 'day' => 25], + 2039 => ['month' => 7, 'day' => 15], + 2040 => ['month' => 7, 'day' => 6], + 2041 => ['month' => 7, 'day' => 19], + 2042 => ['month' => 7, 'day' => 11], + 2043 => ['month' => 7, 'day' => 3], + 2044 => ['month' => 6, 'day' => 24], + 2045 => ['month' => 7, 'day' => 7], + 2046 => ['month' => 6, 'day' => 29], + 2047 => ['month' => 7, 'day' => 19], + 2048 => ['month' => 7, 'day' => 3], + 2049 => ['month' => 6, 'day' => 25], + 2050 => ['month' => 7, 'day' => 15], + 2051 => ['month' => 6, 'day' => 30], + 2052 => ['month' => 6, 'day' => 21], + ]; + + for ($y = 1; $y <= 100; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::CALCULATED_UNTIL_YEAR); + $expected = new \DateTime( + sprintf('%04d-%02d-%02d', $year, $matarikiDates[$year]['month'], $matarikiDates[$year]['day']), + new \DateTimeZone(self::TIMEZONE) + ); + $data[] = [$year, $expected]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::CALCULATED_UNTIL_YEAR), + [self::LOCALE => 'Matariki'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::CALCULATED_UNTIL_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/NewZealand/NewYearsDayTest.php b/tests/NewZealand/NewYearsDayTest.php index 6608cf688..562120792 100644 --- a/tests/NewZealand/NewYearsDayTest.php +++ b/tests/NewZealand/NewYearsDayTest.php @@ -1,76 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the New Zealand. */ -class NewYearsDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** - * Tests New Years Day - * - * @dataProvider HolidayDataProvider + * Tests New Years Day. * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-01-01", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-01-01", new \DateTimeZone(self::TIMEZONE)); switch ($date->format('w')) { case 0: - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); break; case 6: - $date->add(new DateInterval('P2D')); + $date->add(new \DateInterval('P2D')); break; } @@ -82,24 +81,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/NewZealand/NewZealandBaseTestCase.php b/tests/NewZealand/NewZealandBaseTestCase.php index 68b12ac62..c41f2f775 100644 --- a/tests/NewZealand/NewZealandBaseTestCase.php +++ b/tests/NewZealand/NewZealandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; @@ -22,18 +27,12 @@ abstract class NewZealandBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'NewZealand'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Pacific/Auckland'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_NZ'; } diff --git a/tests/NewZealand/NewZealandTest.php b/tests/NewZealand/NewZealandTest.php index 6dcf3e716..ca210c716 100644 --- a/tests/NewZealand/NewZealandTest.php +++ b/tests/NewZealand/NewZealandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in New Zealand. */ -class NewZealandTest extends NewZealandBaseTestCase +class NewZealandTest extends NewZealandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1987); + } /** - * Tests if all official holidays in New Zealand are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in New Zealand are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -45,8 +59,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in New Zealand are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in New Zealand are defined by the provider class. */ public function testObservedHolidays(): void { @@ -54,8 +67,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in New Zealand are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in New Zealand are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -63,8 +75,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in New Zealand are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in New Zealand are defined by the provider class. */ public function testBankHolidays(): void { @@ -72,8 +83,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in New Zealand are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in New Zealand are defined by the provider class. */ public function testOtherHolidays(): void { @@ -81,10 +91,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1987); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/NewZealand/QueensBirthdayTest.php b/tests/NewZealand/QueensBirthdayTest.php index c5ce4236d..23feaaab3 100644 --- a/tests/NewZealand/QueensBirthdayTest.php +++ b/tests/NewZealand/QueensBirthdayTest.php @@ -1,76 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Queens Birthday in the New Zealand. */ -class QueensBirthdayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class QueensBirthdayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'queensBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1952; /** - * Tests Queens Birthday - * - * @dataProvider HolidayDataProvider + * Tests Queens Birthday. * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Tests that Holiday is not present before 1952 - * @throws ReflectionException + * Tests that Holiday is not present before 1952. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 1; $y <= 100; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $expected = new DateTime("first monday of june $year", new DateTimeZone(self::TIMEZONE)); + for ($y = 1; $y <= 100; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $expected = new \DateTime("first monday of june {$year}", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $expected]; } @@ -79,28 +77,30 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Queens Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Queen’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/NewZealand/WaitangiDayTest.php b/tests/NewZealand/WaitangiDayTest.php index d2ca5b388..6fad312c1 100644 --- a/tests/NewZealand/WaitangiDayTest.php +++ b/tests/NewZealand/WaitangiDayTest.php @@ -1,110 +1,117 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\NewZealand; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Waitangi day in the New Zealand. */ -class WaitangiDayTest extends NewZealandBaseTestCase implements YasumiTestCaseInterface +class WaitangiDayTest extends NewZealandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'waitangiDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1974; /** - * Tests Waitangi Day + * Tests Waitangi Day. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests that Holiday is not present before 1974 - * @throws ReflectionException + * Tests that Holiday is not present before 1974. */ - public function testNotHoliday() + public function testNotHoliday(): void { $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Waitangi Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } /** - * Returns a list of test dates + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithModifier(2, 06, function ($year, DateTime $date) { + return static::generateRandomDatesWithModifier(2, 06, function ($year, \DateTime $date): void { // in 2015 some policy was introduced to make sure this holiday was celebrated during the working week. - if ($year >= 2015 && $this->isWeekend($date)) { - $date->modify('next monday'); + if ($year < 2015) { + return; } - }, self::TIMEZONE, 100, self::ESTABLISHMENT_YEAR); + + if (! static::isWeekend($date)) { + return; + } + + $date->modify('next monday'); + }, 100, self::ESTABLISHMENT_YEAR, self::TIMEZONE); } } diff --git a/tests/Norway/AscensionDayTest.php b/tests/Norway/AscensionDayTest.php index 31604890e..284a0db54 100644 --- a/tests/Norway/AscensionDayTest.php +++ b/tests/Norway/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Norway. */ -class AscensionDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1877; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-10", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests translated name of Ascension Day - * @throws ReflectionException + * Tests translated name of Ascension Day. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kristi himmelfartsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/ChristmasDayTest.php b/tests/Norway/ChristmasDayTest.php index 40514307f..2c06b433e 100644 --- a/tests/Norway/ChristmasDayTest.php +++ b/tests/Norway/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Norway. */ -class ChristmasDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Første juledag'] + static::generateRandomYear(), + [self::LOCALE => 'første juledag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/ConstitutionDayTest.php b/tests/Norway/ConstitutionDayTest.php index ecc54718d..e1dd3a5a1 100644 --- a/tests/Norway/ConstitutionDayTest.php +++ b/tests/Norway/ConstitutionDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Norway. */ -class ConstitutionDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constitutionDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1836; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2077; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Grunnlovsdagen'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'grunnlovsdagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Norway/EasterMondayTest.php b/tests/Norway/EasterMondayTest.php index 4b2bc040e..1c3af1570 100644 --- a/tests/Norway/EasterMondayTest.php +++ b/tests/Norway/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Norway. */ -class EasterMondayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2355; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-4", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Andre påskedag'] + static::generateRandomYear(), + [self::LOCALE => 'andre påskedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/EasterTest.php b/tests/Norway/EasterTest.php index c279b4716..aa6191edf 100644 --- a/tests/Norway/EasterTest.php +++ b/tests/Norway/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Norway. */ -class EasterTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2355; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Første påskedag'] + static::generateRandomYear(), + [self::LOCALE => 'første påskedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/GoodFridayTest.php b/tests/Norway/GoodFridayTest.php index d63ef604e..a0ce58b38 100644 --- a/tests/Norway/GoodFridayTest.php +++ b/tests/Norway/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Norway. */ -class GoodFridayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1908; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Langfredag'] + static::generateRandomYear(), + [self::LOCALE => 'langfredag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/InternationalWorkersDayTest.php b/tests/Norway/InternationalWorkersDayTest.php index 633a7a4cb..7532087bd 100644 --- a/tests/Norway/InternationalWorkersDayTest.php +++ b/tests/Norway/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Norway. */ -class InternationalWorkersDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Arbeidernes dag'] + static::generateRandomYear(), + [self::LOCALE => 'arbeidernes dag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Norway/MaundyThursdayTest.php b/tests/Norway/MaundyThursdayTest.php index e43b6d03a..39c272f87 100644 --- a/tests/Norway/MaundyThursdayTest.php +++ b/tests/Norway/MaundyThursdayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Maundy Thursday in Norway. */ -class MaundyThursdayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class MaundyThursdayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'maundyThursday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1655; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Skjærtorsdag'] + static::generateRandomYear(), + [self::LOCALE => 'skjærtorsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/NewYearsDayTest.php b/tests/Norway/NewYearsDayTest.php index 8daaa6cbc..ef951758d 100644 --- a/tests/Norway/NewYearsDayTest.php +++ b/tests/Norway/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Norway. */ -class NewYearsDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Første nyttårsdag'] + static::generateRandomYear(), + [self::LOCALE => 'første nyttårsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/NorwayBaseTestCase.php b/tests/Norway/NorwayBaseTestCase.php index 29ec2539d..1a6485aae 100644 --- a/tests/Norway/NorwayBaseTestCase.php +++ b/tests/Norway/NorwayBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; @@ -22,18 +27,12 @@ abstract class NorwayBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Norway'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Oslo'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'nb_NO'; } diff --git a/tests/Norway/NorwayTest.php b/tests/Norway/NorwayTest.php index 10871ce95..0f68df370 100644 --- a/tests/Norway/NorwayTest.php +++ b/tests/Norway/NorwayTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Norway. */ -class NorwayTest extends NorwayBaseTestCase +class NorwayTest extends NorwayBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1836); + } /** - * Tests if all official holidays in Norway are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Norway are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -48,8 +62,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Norway are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Norway are defined by the provider class. */ public function testObservedHolidays(): void { @@ -57,8 +70,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Norway are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Norway are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -66,8 +78,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Norway are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Norway are defined by the provider class. */ public function testBankHolidays(): void { @@ -75,8 +86,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Norway are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Norway are defined by the provider class. */ public function testOtherHolidays(): void { @@ -84,10 +94,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1836); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Norway/PentecostMondayTest.php b/tests/Norway/PentecostMondayTest.php index 3a3046f1d..a2934489b 100644 --- a/tests/Norway/PentecostMondayTest.php +++ b/tests/Norway/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Norway. */ -class PentecostMondayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Andre pinsedag'] + static::generateRandomYear(), + [self::LOCALE => 'andre pinsedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/PentecostTest.php b/tests/Norway/PentecostTest.php index af94d3a32..ef2628de3 100644 --- a/tests/Norway/PentecostTest.php +++ b/tests/Norway/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Norway. */ -class PentecostTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Første pinsedag'] + static::generateRandomYear(), + [self::LOCALE => 'første pinsedag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Norway/SecondChristmasDayTest.php b/tests/Norway/SecondChristmasDayTest.php index 62b249e6f..3698aa4c8 100644 --- a/tests/Norway/SecondChristmasDayTest.php +++ b/tests/Norway/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Norway; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Norway. */ -class SecondChristmasDayTest extends NorwayBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends NorwayBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Andre juledag'] + static::generateRandomYear(), + [self::LOCALE => 'andre juledag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/AllSaintsDayTest.php b/tests/Poland/AllSaintsDayTest.php index bf892d0d6..1a6841474 100644 --- a/tests/Poland/AllSaintsDayTest.php +++ b/tests/Poland/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Poland. */ -class AllSaintsDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Uroczystość Wszystkich Świętych'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/AssumptionOfMaryTest.php b/tests/Poland/AssumptionOfMaryTest.php index a468a6486..b2e0bd385 100644 --- a/tests/Poland/AssumptionOfMaryTest.php +++ b/tests/Poland/AssumptionOfMaryTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Poland. */ -class AssumptionOfMaryTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Wniebowzięcie Najświętszej Marii Panny'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/ChristmasEveTest.php b/tests/Poland/ChristmasEveTest.php new file mode 100644 index 000000000..6768af1b4 --- /dev/null +++ b/tests/Poland/ChristmasEveTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\tests\Poland; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas Eve in Poland. + */ +class ChristmasEveTest extends PolandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasEve'; + + public const ESTABLISHMENT_YEAR = 2025; + + /** + * Tests Christmas Eve Day. + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests that holiday is not present before establishment year. + */ + public function testNotHoliday(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests translated name of Christmas Eve Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Wigilia Bożego Narodzenia'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Poland/ChristmasTest.php b/tests/Poland/ChristmasTest.php index 35835791f..145e4c5ae 100644 --- a/tests/Poland/ChristmasTest.php +++ b/tests/Poland/ChristmasTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Poland. */ -class ChristmasTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'pierwszy dzień Bożego Narodzenia'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/ConstitutionDayTest.php b/tests/Poland/ConstitutionDayTest.php index 809f4aea9..0d426f956 100644 --- a/tests/Poland/ConstitutionDayTest.php +++ b/tests/Poland/ConstitutionDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Poland. */ -class ConstitutionDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constitutionDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1791; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2077; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Święto Narodowe Trzeciego Maja'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Poland/CorpusChristiTest.php b/tests/Poland/CorpusChristiTest.php index dcb53605c..444727fbf 100644 --- a/tests/Poland/CorpusChristiTest.php +++ b/tests/Poland/CorpusChristiTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Corpus Christi in Poland. */ -class CorpusChristiTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2017; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Corpus Christi. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boże Ciało'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/EasterMondayTest.php b/tests/Poland/EasterMondayTest.php index 7e6cbeb4a..6da546e3c 100644 --- a/tests/Poland/EasterMondayTest.php +++ b/tests/Poland/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Poland. */ -class EasterMondayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2017; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Poniedziałek Wielkanocny'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/EasterTest.php b/tests/Poland/EasterTest.php index 4683facec..c90d08dd5 100644 --- a/tests/Poland/EasterTest.php +++ b/tests/Poland/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Poland. */ -class EasterTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Wielkanoc'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/EpiphanyTest.php b/tests/Poland/EpiphanyTest.php index 63fa4cb0d..7d50ef631 100644 --- a/tests/Poland/EpiphanyTest.php +++ b/tests/Poland/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Poland. */ -class EpiphanyTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'epiphany'; /** * Tests Epiphany. * - * @dataProvider EpiphanyDataProvider - * - * @param int $year the year for which Epiphany needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Epiphany needs to be tested + * @param \DateTime $expected the expected date */ - public function testEpiphany($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('EpiphanyDataProvider')] + public function testEpiphany(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testEpiphany($year, $expected) /** * Returns a list of random test dates used for assertion of Epiphany. * - * @return array list of test dates for Epiphany - * @throws Exception + * @return array list of test dates for Epiphany + * + * @throws \Exception */ - public function EpiphanyDataProvider(): array + public static function EpiphanyDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests translated name of Epiphany. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Święto Trzech Króli'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/IndependenceDayTest.php b/tests/Poland/IndependenceDayTest.php index 90e544714..574513fbb 100644 --- a/tests/Poland/IndependenceDayTest.php +++ b/tests/Poland/IndependenceDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Independence Day of Poland in Poland. */ -class IndependenceDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1918; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2018; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-11", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Narodowe Święto Niepodległości'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Poland/InternationalWorkersDayTest.php b/tests/Poland/InternationalWorkersDayTest.php index 9175cb44c..6357e827b 100644 --- a/tests/Poland/InternationalWorkersDayTest.php +++ b/tests/Poland/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Poland. */ -class InternationalWorkersDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Święto Pracy'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Poland/NewYearsDayTest.php b/tests/Poland/NewYearsDayTest.php index 1b2a4117d..7cf563f96 100644 --- a/tests/Poland/NewYearsDayTest.php +++ b/tests/Poland/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Poland. */ -class NewYearsDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nowy Rok'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/PentecostTest.php b/tests/Poland/PentecostTest.php index 6d5eb2658..6e659d4a1 100644 --- a/tests/Poland/PentecostTest.php +++ b/tests/Poland/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Poland. */ -class PentecostTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2019; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Zielone Świątki'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Poland/PolandBaseTestCase.php b/tests/Poland/PolandBaseTestCase.php index b04821389..367155adf 100644 --- a/tests/Poland/PolandBaseTestCase.php +++ b/tests/Poland/PolandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; @@ -22,18 +27,12 @@ abstract class PolandBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Poland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Warsaw'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'pl_PL'; } diff --git a/tests/Poland/PolandTest.php b/tests/Poland/PolandTest.php index a9eab30ef..d3e633eb3 100644 --- a/tests/Poland/PolandTest.php +++ b/tests/Poland/PolandTest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Poland. */ -class PolandTest extends PolandBaseTestCase +class PolandTest extends PolandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1918); + } /** - * Tests if all official holidays in Poland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Poland are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $holidays = [ 'newYearsDay', 'internationalWorkersDay', 'allSaintsDay', @@ -45,12 +59,17 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'constitutionDay', 'independenceDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if ($this->year >= 2025) { + $holidays[] = 'christmasEve'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Poland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Poland are defined by the provider class. */ public function testObservedHolidays(): void { @@ -58,8 +77,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Poland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Poland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -67,8 +85,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Poland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Poland are defined by the provider class. */ public function testBankHolidays(): void { @@ -76,8 +93,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Poland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Poland are defined by the provider class. */ public function testOtherHolidays(): void { @@ -85,10 +101,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1918); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Poland/SecondChristmasDayTest.php b/tests/Poland/SecondChristmasDayTest.php index bbd2e79a7..bc3cec017 100644 --- a/tests/Poland/SecondChristmasDayTest.php +++ b/tests/Poland/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Poland; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Poland. */ -class SecondChristmasDayTest extends PolandBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends PolandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'drugi dzień Bożego Narodzenia'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/AllSaintsDayTest.php b/tests/Portugal/AllSaintsDayTest.php index 218e9389a..e08b431a1 100644 --- a/tests/Portugal/AllSaintsDayTest.php +++ b/tests/Portugal/AllSaintsDayTest.php @@ -1,31 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for All Saints Day in Portugal. */ -class AllSaintsDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; @@ -41,39 +42,39 @@ class AllSaintsDayTest extends PortugalBaseTestCase implements YasumiTestCaseInt /** * Tests the holiday defined in this test. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; - $expected = new DateTime("$year-11-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-11-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); $year = 2012; - $expected = new DateTime("$year-11-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-11-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Test that the holiday did not happen in 2013-2015. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNotHoliday() + public function testNotHoliday(): void { - $year = $this->generateRandomYear(2013, 2015); + $year = static::generateRandomYear(2013, 2015); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Corpus Christi. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -85,16 +86,16 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { // After restoration - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); // Before abolishment - $year = $this->generateRandomYear(1000, self::HOLIDAY_YEAR_ABOLISHED - 1); + $year = static::generateRandomYear(1000, self::HOLIDAY_YEAR_ABOLISHED - 1); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/AssumptionOfMaryTest.php b/tests/Portugal/AssumptionOfMaryTest.php index d8d9c0f65..abc464fb9 100644 --- a/tests/Portugal/AssumptionOfMaryTest.php +++ b/tests/Portugal/AssumptionOfMaryTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Portugal. */ -class AssumptionOfMaryTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assunção de Nossa Senhora'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/CarnationRevolutionDayTest.php b/tests/Portugal/CarnationRevolutionDayTest.php index bce45a56c..b7cb8983a 100644 --- a/tests/Portugal/CarnationRevolutionDayTest.php +++ b/tests/Portugal/CarnationRevolutionDayTest.php @@ -1,78 +1,82 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Portugal Day in Portugal. */ -class CarnationRevolutionDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class CarnationRevolutionDayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = '25thApril'; /** - * Test that the holiday is valid after the year of establishment - * @throws ReflectionException - * @throws Exception + * Test that the holiday is valid after the year of establishment. + * + * @throws \Exception */ - public function testHolidayAfterEstablishment() + public function testHolidayAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $expected = new DateTime("$year-04-25", new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $expected = new \DateTime("{$year}-04-25", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Tests that the holiday is not a holiday before the year of establishment - * @throws ReflectionException + * Tests that the holiday is not a holiday before the year of establishment. + * + * @throws \Exception */ - public function testNotHolidayBeforeEstablishment() + public function testNotHolidayBeforeEstablishment(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Dia da Liberdade']); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/ChristmasTest.php b/tests/Portugal/ChristmasTest.php index 30e08f62d..30265b3f6 100644 --- a/tests/Portugal/ChristmasTest.php +++ b/tests/Portugal/ChristmasTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Portugal. */ -class ChristmasTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Natal'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/CorpusChristiTest.php b/tests/Portugal/CorpusChristiTest.php index e1e453075..b0edaecaa 100644 --- a/tests/Portugal/CorpusChristiTest.php +++ b/tests/Portugal/CorpusChristiTest.php @@ -1,31 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Corpus Christi in Portugal. */ -class CorpusChristiTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; @@ -41,49 +42,51 @@ class CorpusChristiTest extends PortugalBaseTestCase implements YasumiTestCaseIn /** * Tests the holiday defined in this test. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; - $expected = new DateTime("$year-5-26", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-5-26", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Test that the holiday did not happen in 2013-2015. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNotHoliday() + public function testNotHoliday(): void { - $year = $this->generateRandomYear(2013, 2015); + $year = static::generateRandomYear(2013, 2015); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Corpus Christi. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Corpo de Deus']); } /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { // Before abolishment - $year = $this->generateRandomYear(1000, self::HOLIDAY_YEAR_ABOLISHED - 1); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); + $year = static::generateRandomYear(1000, self::HOLIDAY_YEAR_ABOLISHED - 1); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); // After restoration - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/EasterTest.php b/tests/Portugal/EasterTest.php index 371cd633b..bfe535fa0 100644 --- a/tests/Portugal/EasterTest.php +++ b/tests/Portugal/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Norway. */ -class EasterTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-03-27", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-03-27", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Páscoa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/GoodFridayTest.php b/tests/Portugal/GoodFridayTest.php index ef8c2ead4..c12b82927 100644 --- a/tests/Portugal/GoodFridayTest.php +++ b/tests/Portugal/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Norway. */ -class GoodFridayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sexta-feira Santa'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/ImmaculateConceptionTest.php b/tests/Portugal/ImmaculateConceptionTest.php index 92d500b02..abe7cd1f0 100644 --- a/tests/Portugal/ImmaculateConceptionTest.php +++ b/tests/Portugal/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Portugal. */ -class ImmaculateConceptionTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dia da Imaculada Conceição'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/InternationalWorkersDayTest.php b/tests/Portugal/InternationalWorkersDayTest.php index 6f37a2e79..c781afc42 100644 --- a/tests/Portugal/InternationalWorkersDayTest.php +++ b/tests/Portugal/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Portugal. */ -class InternationalWorkersDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dia do Trabalhador'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Portugal/NewYearsDayTest.php b/tests/Portugal/NewYearsDayTest.php index 376f651f4..93216289d 100644 --- a/tests/Portugal/NewYearsDayTest.php +++ b/tests/Portugal/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Portugal. */ -class NewYearsDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Dia de Ano Novo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/PortugalBaseTestCase.php b/tests/Portugal/PortugalBaseTestCase.php index ad1c6bbcf..ab13b31dc 100644 --- a/tests/Portugal/PortugalBaseTestCase.php +++ b/tests/Portugal/PortugalBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; @@ -22,18 +27,12 @@ abstract class PortugalBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Portugal'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Lisbon'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'pt_PT'; } diff --git a/tests/Portugal/PortugalDayTest.php b/tests/Portugal/PortugalDayTest.php index 554c9f8fa..539659bf4 100644 --- a/tests/Portugal/PortugalDayTest.php +++ b/tests/Portugal/PortugalDayTest.php @@ -1,80 +1,83 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\Portugal; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Portugal Day in Portugal. */ -class PortugalDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class PortugalDayTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was abolished + * The year in which the holiday was abolished. */ public const ESTABLISHMENT_YEAR_BEFORE = 1932; /** - * The year in which the holiday was restored + * The year in which the holiday was restored. */ public const ESTABLISHMENT_YEAR_AFTER = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'portugalDay'; /** * Tests the holiday defined in this test before it was abolished. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception + * * @see Portugal::calculatePortugalDay() */ - public function testHolidayBeforeAbolishment() + public function testHolidayBeforeAbolishment(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); - $expected = new DateTime("$year-06-10", new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); + $expected = new \DateTime("{$year}-06-10", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Tests the holiday defined in this test after it was restored - * @throws ReflectionException - * @throws Exception + * Tests the holiday defined in this test after it was restored. + * + * @throws \Exception + * * @see Portugal::calculatePortugalDay() */ - public function testHolidayAfterRestoration() + public function testHolidayAfterRestoration(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); - $expected = new DateTime("$year-06-10", new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); + $expected = new \DateTime("{$year}-06-10", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Tests that the holiday defined in this test does not exist during the period that it was abolished - * @throws ReflectionException - * @see Portugal::calculatePortugalDay() + * Tests that the holiday defined in this test does not exist during the period that it was abolished. * + * @throws \Exception + * + * @see Portugal::calculatePortugalDay() */ - public function testNotHolidayDuringAbolishment() + public function testNotHolidayDuringAbolishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR_BEFORE + 1, self::ESTABLISHMENT_YEAR_AFTER - 1); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR_BEFORE + 1, self::ESTABLISHMENT_YEAR_AFTER - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); $this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR_BEFORE + 1); @@ -84,28 +87,28 @@ public function testNotHolidayDuringAbolishment() /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Dia de Portugal']); - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); $this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Dia de Portugal']); } /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR_BEFORE); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR_AFTER); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Portugal/PortugalTest.php b/tests/Portugal/PortugalTest.php index e247be2aa..b241dc92d 100644 --- a/tests/Portugal/PortugalTest.php +++ b/tests/Portugal/PortugalTest.php @@ -1,55 +1,79 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Poland. */ -class PortugalTest extends PortugalBaseTestCase +class PortugalTest extends PortugalBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1974); + } /** - * Tests if all official holidays in Portugal are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Portugal are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $holidays = [ 'newYearsDay', 'internationalWorkersDay', 'easter', 'goodFriday', 'assumptionOfMary', - 'allSaintsDay', 'immaculateConception', 'christmasDay', '25thApril', - 'portugueseRepublic', - 'restorationOfIndependence', 'portugalDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if ($this->year <= 2012 || $this->year >= 2016) { + $holidays[] = 'allSaintsDay'; + } + + if (($this->year >= 1910 && $this->year <= 2012) || $this->year >= 2016) { + $holidays[] = 'portugueseRepublic'; + } + + if (($this->year >= 1850 && $this->year <= 2012) || $this->year >= 2016) { + $holidays[] = 'restorationOfIndependence'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Portugal are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Portugal are defined by the provider class. */ public function testObservedHolidays(): void { @@ -57,8 +81,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Portugal are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Portugal are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -66,8 +89,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Portugal are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Portugal are defined by the provider class. */ public function testBankHolidays(): void { @@ -75,8 +97,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in PortugalPortugal are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in PortugalPortugal are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,14 +107,15 @@ public function testOtherHolidays(): void $holidays[] = 'corpusChristi'; } - $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1974); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Portugal/PortugueseRepublicDayTest.php b/tests/Portugal/PortugueseRepublicDayTest.php index 4eb574081..3abb4a9c1 100644 --- a/tests/Portugal/PortugueseRepublicDayTest.php +++ b/tests/Portugal/PortugueseRepublicDayTest.php @@ -1,132 +1,153 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; -/** - * Class for testing Restoration of Independence Day in Portugal. - */ -class PortugueseRepublicDayTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class PortugueseRepublicDayTest extends PortugalBaseTestCase implements HolidayTestCase { - /** - * The year in which the holiday was first established - */ public const ESTABLISHMENT_YEAR = 1910; - /** - * Holiday was restored by the portuguese government in 2016. - */ + public const HOLIDAY_YEAR_SUSPENDED = 2013; + public const HOLIDAY_YEAR_RESTORED = 2016; - /** - * The name of the holiday to be tested - */ public const HOLIDAY = 'portugueseRepublic'; /** - * Test that the holiday if in effect in 2016 and later dates. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterRestoration() + public function testHolidayOnAfterRestoration(): void { - $year = self::HOLIDAY_YEAR_RESTORED; - - $expected = new DateTime("$year-10-05", new DateTimeZone(self::TIMEZONE)); - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); - - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); - - $expected = new DateTime("$year-10-05", new DateTimeZone(self::TIMEZONE)); - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + foreach ($this->randomYearsOnAfterRestoration() as $year) { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-05", new \DateTimeZone(self::TIMEZONE)) + ); + } } /** - * Test that the holiday did not happen in 2013-2015. - * @throws ReflectionException + * @throws \Exception */ - public function testNotHolidayDuringAbolishment() + public function testNotHolidayDuringAbolishment(): void { - $year = $this->generateRandomYear(2013, 2015); - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::HOLIDAY_YEAR_SUSPENDED, self::HOLIDAY_YEAR_RESTORED - 1) + ); } /** - * Tests the holiday defined in this test on or after establishment. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + foreach ($this->randomYearsOnAfterEstablishment() as $year) { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-05", new \DateTimeZone(self::TIMEZONE)) + ); + } + } - $expected = new DateTime("$year-10-05", new DateTimeZone(self::TIMEZONE)); - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + public function testHolidayBeforeEstablishment(): void + { + try { + foreach ($this->randomYearsBeforeEstablishment() as $year) { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } - $year = self::ESTABLISHMENT_YEAR; - $expected = new DateTime("$year-10-05", new DateTimeZone(self::TIMEZONE)); - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + public function testTranslation(): void + { + try { + foreach ($this->randomEstablishedYear() as $year) { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Implantação da República Portuguesa'] + ); + } + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); + } } - /** - * Tests the holiday defined in this test before establishment. - * - * @throws ReflectionException + public function testHolidayType(): void + { + try { + foreach ($this->randomEstablishedYear() as $year) { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $year, + Holiday::TYPE_OFFICIAL + ); + } + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } + + /** @return \Generator + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + private function randomEstablishedYear(): \Generator { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + yield static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_SUSPENDED - 1); + yield static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + } - $year = self::ESTABLISHMENT_YEAR - 1; - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + /** @return \Generator + * @throws \Exception + */ + private function randomYearsBeforeEstablishment(): \Generator + { + yield static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + yield self::ESTABLISHMENT_YEAR - 1; } - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + /** @return \Generator + * @throws \Exception */ - public function testTranslation(): void + private function randomYearsOnAfterEstablishment(): \Generator { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Implantação da República Portuguesa'] - ); + yield static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_SUSPENDED - 1); + yield self::ESTABLISHMENT_YEAR; } - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException + /** @return \Generator + * @throws \Exception */ - public function testHolidayType(): void + private function randomYearsOnAfterRestoration(): \Generator { - $this->assertHolidayType( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - Holiday::TYPE_OFFICIAL - ); + yield static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + yield self::HOLIDAY_YEAR_RESTORED; } } diff --git a/tests/Portugal/RestorationOfIndependenceTest.php b/tests/Portugal/RestorationOfIndependenceTest.php index 18fb4cd89..90cf9016a 100644 --- a/tests/Portugal/RestorationOfIndependenceTest.php +++ b/tests/Portugal/RestorationOfIndependenceTest.php @@ -1,31 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Portugal; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Restoration of Independence Day in Portugal. */ -class RestorationOfIndependenceTest extends PortugalBaseTestCase implements YasumiTestCaseInterface +class RestorationOfIndependenceTest extends PortugalBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1850; @@ -40,67 +41,65 @@ class RestorationOfIndependenceTest extends PortugalBaseTestCase implements Yasu public const HOLIDAY_YEAR_RESTORED = 2016; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'restorationOfIndependence'; /** * Tests the holiday defined in this test on or after establishment. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); - $expected = new DateTime("$year-12-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-12-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); $year = self::ESTABLISHMENT_YEAR; - $expected = new DateTime("$year-12-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-12-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Test that the holiday if in effect in 2016 and later dates. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception + * @throws \Exception */ - public function testHolidayOnAfterRestoration() + public function testHolidayOnAfterRestoration(): void { $year = 2016; - $expected = new DateTime("$year-12-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-12-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); - $expected = new DateTime("$year-12-01", new DateTimeZone(self::TIMEZONE)); + $expected = new \DateTime("{$year}-12-01", new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Test that the holiday did not happen in 2013-2015. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNotHolidayDuringAbolishment() + public function testNotHolidayDuringAbolishment(): void { - $year = $this->generateRandomYear(2013, 2015); + $year = static::generateRandomYear(2013, 2015); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the holiday defined in this test before establishment. * - * @throws ReflectionException + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); $year = 1849; @@ -110,11 +109,11 @@ public function testHolidayBeforeEstablishment() /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -122,7 +121,7 @@ public function testTranslation(): void [self::LOCALE => 'Restauração da Independência'] ); - $year = $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + $year = static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, @@ -134,16 +133,16 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { // After establishment and before abolishment - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_ABOLISHED - 1); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); // After restoration - $this->generateRandomYear(self::HOLIDAY_YEAR_RESTORED); + static::generateRandomYear(self::HOLIDAY_YEAR_RESTORED); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); } } diff --git a/tests/ProviderTestCase.php b/tests/ProviderTestCase.php new file mode 100644 index 000000000..d41f95383 --- /dev/null +++ b/tests/ProviderTestCase.php @@ -0,0 +1,29 @@ + + */ + +namespace Yasumi\tests; + +/** + * This interface class defines the standard functions that any holiday provider PHPUnit test case needs to define. + */ +interface ProviderTestCase +{ + /** + * Tests whether the expected number of sources are actually defined. + */ + public function testSources(): void; +} diff --git a/tests/Randomizer.php b/tests/Randomizer.php new file mode 100644 index 000000000..99bc88b6d --- /dev/null +++ b/tests/Randomizer.php @@ -0,0 +1,465 @@ + + */ + +namespace Yasumi\tests; + +/** + * Trait containing useful functions that generate random dates/years. + */ +trait Randomizer +{ + protected static string $defaultTimezone; + + /** + * Returns a list of random test dates used for assertion of holidays. + * + * @param int $month month (number) for which the test date needs to be generated + * @param int $day day (number) for which the test date needs to be generated + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomDates( + int $month, + int $day, + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $data = []; + $range ??= 1000; + for ($y = 1; $y <= ($iterations ?? 10); ++$y) { + $year = (int) self::dateTimeBetween("-{$range} years", "+{$range} years")->format('Y'); + $data[] = [$year, new \DateTime("{$year}-{$month}-{$day}", new \DateTimeZone($timezone ?? 'UTC'))]; + } + + return $data; + } + + /** + * Returns a list of random easter test dates used for assertion of holidays. + * + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random easter test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomEasterDates( + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $data = []; + $range ??= 1000; + + for ($i = 1; $i <= ($iterations ?? 10); ++$i) { + $year = (int) self::dateTimeBetween("-{$range} years", "+{$range} years")->format('Y'); + $date = static::computeEaster($year, $timezone ?? 'UTC'); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Returns a list of random Easter Monday test dates used for assertion of holidays. + * + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random Easter Monday test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomEasterMondayDates( + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $range ??= 1000; + + return static::generateRandomModifiedEasterDates(static function (\DateTime $date): void { + $date->add(new \DateInterval('P1D')); + }, $timezone ?? 'UTC', $iterations ?? 10, $range); + } + + /** + * Returns a list of random modified Easter day test dates for assertion of holidays. + * + * @param callable $cb callback(DateTime $date) to modify $date by custom rules + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random modified Easter day test dates for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomModifiedEasterDates( + callable $cb, + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $data = []; + $range ??= 1000; + for ($i = 1; $i <= ($iterations ?? 10); ++$i) { + $year = (int) self::dateTimeBetween("-{$range} years", "+{$range} years")->format('Y'); + $date = static::computeEaster($year, $timezone ?? 'UTC'); + + $cb($date); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Returns a list of random Good Friday test dates used for assertion of holidays. + * + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random Good Friday test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomGoodFridayDates( + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $range ??= 1000; + + return static::generateRandomModifiedEasterDates(static function (\DateTime $date): void { + $date->sub(new \DateInterval('P2D')); + }, $timezone ?? 'UTC', $iterations ?? 10, $range); + } + + /** + * Returns a list of random Pentecost test dates used for assertion of holidays. + * + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random Pentecost test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomPentecostDates( + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + $range ??= 1000; + + return static::generateRandomModifiedEasterDates(static function (\DateTime $date): void { + $date->add(new \DateInterval('P49D')); + }, $timezone ?? 'UTC', $iterations ?? 10, $range); + } + + /** + * Returns a list of random test dates used for assertion of holidays. If the date falls in a weekend, the random + * holiday day moves to Monday. + * + * @param int $month month (number) for which the test date needs to be generated + * @param int $day day (number) for which the test date needs to be generated + * @param string|null $timezone name of the timezone for which the dates need to be generated + * @param int|null $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int|null $range year range from which dates will be generated (default: 1000) + * + * @return array list of random test dates used for assertion of holidays + * + * @throws \Exception + */ + public static function generateRandomDatesWithHolidayMovedToMonday( + int $month, + int $day, + ?string $timezone = null, + ?int $iterations = null, + ?int $range = null, + ): array { + return static::generateRandomDatesWithModifier($month, $day, static function ($range, \DateTime $date): void { + if (static::isWeekend($date)) { + $date->modify('next monday'); + } + }, $iterations ?? 10, $range, $timezone ?? 'UTC'); + } + + /** + * Returns a list of random test dates used for assertion of holidays with an applied callback. + * + * @param int $month month (number) for which the test date needs to be generated + * @param int $day day (number) for which the test date needs to be generated + * @param callable $callback callback(int $year, \DateTime $dateTime) to modify $dateTime by custom rules + * @param int $iterations number of iterations (i.e., samples) that need to be generated (default: 10). + * @param int $range year range from which dates will be generated (default: 1000) + * @param string|null $timezone name of the timezone for which the dates need to be generated + * + * @return array list of random test dates used for assertion of holidays with an applied callback + * + * @throws \Exception + */ + public static function generateRandomDatesWithModifier( + int $month, + int $day, + callable $callback, + int $iterations, + int $range, + ?string $timezone = null, + ): array { + $data = []; + + for ($i = 1; $i <= $iterations; ++$i) { + $year = static::generateRandomYear($range); + $date = new \DateTime("{$year}-{$month}-{$day}", new \DateTimeZone($timezone ?? 'UTC')); + + if (false === $callback($year, $date)) { + --$i; + continue; + } + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Generates a random year (number). + * + * @param int|null $lowerLimit lower limit for generating a year number (default: 1000) + * @param int|null $upperLimit upper limit for generating a year number (default: 9999) + * + * @return int a year number + * + * @throws \Exception + */ + public static function generateRandomYear( + ?int $lowerLimit = null, + ?int $upperLimit = null, + ): int { + return self::numberBetween($lowerLimit ?? 1800, $upperLimit ?? 2200); + } + + /** + * Checks if given $dateTime is a weekend. + * + * @param \DateTimeInterface $dateTime date for which weekend will be checked + * @param array $weekendDays weekend days. Saturday and Sunday are used by default. + * + * @return bool true if $dateTime is a weekend, false otherwise + */ + public static function isWeekend( + \DateTimeInterface $dateTime, + array $weekendDays = [0, 6], + ): bool { + return \in_array((int) $dateTime->format('w'), $weekendDays, true); + } + + /** + * Returns a random number between $int1 and $int2 (any order). + * + * @throws \Exception + * + * @example 79907610 + */ + public static function numberBetween(int $int1 = 0, int $int2 = 2_147_483_647): int + { + $min = min($int1, $int2); + $max = max($int1, $int2); + + return random_int($min, $max); + } + + /** + * Get a DateTime object based on a random date between two given dates. + * Accepts date strings that can be recognized by `strtotime`. + * + * @param \DateTime|string $startDate Defaults to 30 years ago + * @param \DateTime|string $endDate Defaults to "now" + * @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get` + * + * @throws \Exception + * + * @see http://php.net/manual/en/timezones.php + * @see http://php.net/manual/en/function.date-default-timezone-get.php + * + * @example DateTime('1999-02-02 11:42:52') + */ + public static function dateTimeBetween($startDate = '-30 years', $endDate = 'now', ?string $timezone = null): \DateTimeInterface + { + $startTimestamp = $startDate instanceof \DateTime ? $startDate->getTimestamp() : strtotime($startDate); + + if (! $startTimestamp) { + throw new \RuntimeException('unable to get timestamp for the start date'); + } + + $endTimestamp = static::getMaxTimestamp($endDate); + + if (! $endTimestamp) { + throw new \RuntimeException('unable to get timestamp for the end date'); + } + + if ($startTimestamp > $endTimestamp) { + throw new \InvalidArgumentException('Start date must be anterior to end date.'); + } + + $timestamp = random_int($startTimestamp, $endTimestamp); + + return static::setTimezone( + new \DateTime('@' . $timestamp), + $timezone + ); + } + + public static function randomYearFromArray(array $years): int + { + if ([] === $years) { + throw new \InvalidArgumentException(' years array must not be empty'); + } + + return $years[(int) array_rand($years)]; + } + + /** + * Calculates the date for Easter. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. + * + * This function uses the standard PHP 'easter_days' function if the calendar extension is enabled. In case the + * calendar function is not enabled, a fallback calculation has been implemented that is based on the same + * 'easter_days' c function. + * + * Note: In calendrical calculations, frequently operations called integer division are used. + * + * @param int $year year for which Easter needs to be calculated + * @param string $timezone timezone in which Easter is celebrated + * + * @return \DateTime date of Easter + * + * @throws \Exception + * + * @see easter_days + * @see https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/ext/calendar/easter.c + * @see http://www.gmarts.org/index.php?go=415#EasterMallen + * @see http://www.tondering.dk/claus/cal/easter.php + */ + /** + * Static Easter calculation used by data providers (avoids conflict with ChristianHolidays::calculateEaster). + */ + protected static function computeEaster(int $year, string $timezone): \DateTimeInterface + { + if (\extension_loaded('calendar')) { + $easter_days = easter_days($year); + } else { + $golden = (($year % 19) + 1); // The Golden Number + + // The Julian calendar applies to the original method from 326AD. The Gregorian calendar was first + // introduced in October 1582 in Italy. Easter algorithms using the Gregorian calendar apply to years + // 1583 AD to 4099 (A day adjustment is required in or shortly after 4100 AD). + // After 1752, most western churches have adopted the current algorithm. + if ($year <= 1752) { + $dom = ($year + (int) ($year / 4) + 5) % 7; // The 'Dominical number' - finding a Sunday + if ($dom < 0) { + $dom += 7; + } + + $pfm = (3 - (11 * $golden) - 7) % 30; // Uncorrected date of the Paschal full moon + if ($pfm < 0) { + $pfm += 30; + } + } else { + $dom = ($year + (int) ($year / 4) - (int) ($year / 100) + (int) ($year / 400)) % 7; // The 'Dominical number' - finding a Sunday + if ($dom < 0) { + $dom += 7; + } + + $solar = (int) (($year - 1600) / 100) - (int) (($year - 1600) / 400); // The solar correction + $lunar = (int) (((int) (($year - 1400) / 100) * 8) / 25); // The lunar correction + + $pfm = (3 - (11 * $golden) + $solar - $lunar) % 30; // Uncorrected date of the Paschal full moon + if ($pfm < 0) { + $pfm += 30; + } + } + + // Corrected date of the Paschal full moon, - days after 21st March + if ((29 === $pfm) || (28 === $pfm && $golden > 11)) { + --$pfm; + } + + $tmp = (4 - $pfm - $dom) % 7; + if ($tmp < 0) { + $tmp += 7; + } + + $easter_days = ($pfm + $tmp + 1); // Easter as the number of days after 21st March + } + + $easter = new \DateTime("{$year}-3-21", new \DateTimeZone($timezone)); + $easter->add(new \DateInterval('P' . $easter_days . 'D')); + + return $easter; + } + + protected function calculateEaster(int $year, string $timezone): \DateTimeInterface + { + return static::computeEaster($year, $timezone); + } + + /** + * @param \DateTime|string|float|int $max + * + * @return int|false + */ + protected static function getMaxTimestamp($max = 'now') + { + if (is_numeric($max)) { + $ts = (int) $max; + } elseif ($max instanceof \DateTime) { + $ts = $max->getTimestamp(); + } else { + $ts = strtotime('' === $max ? 'now' : $max); + } + + return $ts; + } + + private static function setTimezone(\DateTimeInterface $dt, ?string $timezone): \DateTimeInterface + { + return $dt->setTimezone(new \DateTimeZone(static::resolveTimezone($timezone))); + } + + private static function resolveTimezone(?string $timezone): string + { + return $timezone ?? (static::$defaultTimezone ?? date_default_timezone_get()); + } +} diff --git a/tests/Romania/AssumptionOfMaryTest.php b/tests/Romania/AssumptionOfMaryTest.php index b7776b76c..1a3746af6 100644 --- a/tests/Romania/AssumptionOfMaryTest.php +++ b/tests/Romania/AssumptionOfMaryTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Romania. */ -class AssumptionOfMaryTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2008; /** * Tests Assumption Of Mary Day on or after 2008. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAssumptionOfMaryDayOnAfter2008() + public function testAssumptionOfMaryDayOnAfter2008(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-15", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Assumption of Mary Day before 2008. - * @throws ReflectionException + * + * @throws \Exception */ - public function testAssumptionOfMaryDayBefore2008() + public function testAssumptionOfMaryDayBefore2008(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Adormirea Maicii Domnului'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Romania/ChildrensDayTest.php b/tests/Romania/ChildrensDayTest.php index 5f2920f53..ff205c4fc 100644 --- a/tests/Romania/ChildrensDayTest.php +++ b/tests/Romania/ChildrensDayTest.php @@ -1,78 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Children's Day in Romania. */ -class ChildrensDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class ChildrensDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'childrensDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** * Tests Children's Day on or after 1950. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testChildrensDayOnAfter1950() + public function testChildrensDayOnAfter1950(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-01", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-01", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Children's Day before 1950. - * @throws ReflectionException + * + * @throws \Exception */ - public function testChildrensDayBefore1950() + public function testChildrensDayBefore1950(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Ziua Copilului'] ); } @@ -80,16 +83,16 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2016), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2016), Holiday::TYPE_OBSERVANCE ); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(2017), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(2017), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/ChristmasDayTest.php b/tests/Romania/ChristmasDayTest.php index fcb8e947f..3a21a10de 100644 --- a/tests/Romania/ChristmasDayTest.php +++ b/tests/Romania/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Romania. */ -class ChristmasDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Crăciunul'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/ConstantinBrancusiDayTest.php b/tests/Romania/ConstantinBrancusiDayTest.php index 57e1ea6da..74bc3d38a 100644 --- a/tests/Romania/ConstantinBrancusiDayTest.php +++ b/tests/Romania/ConstantinBrancusiDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Constantin Brancusi Day in Romania. */ -class ConstantinBrancusiDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class ConstantinBrancusiDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constantinBrancusiDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2016; /** * Tests Constantin Brancusi Day on or after 2016. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testConstantinBrancusiDayOnAfter2016() + public function testConstantinBrancusiDayOnAfter2016(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-02-19", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-02-19", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Constantin Brancusi Day before 2016. - * @throws ReflectionException + * + * @throws \Exception */ - public function testConstantinBrancusiDayBefore2016() + public function testConstantinBrancusiDayBefore2016(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Ziua Constantin Brâncuși'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OBSERVANCE ); } diff --git a/tests/Romania/DayAfterNewYearsDayTest.php b/tests/Romania/DayAfterNewYearsDayTest.php index a582e0d5a..f0df9429c 100644 --- a/tests/Romania/DayAfterNewYearsDayTest.php +++ b/tests/Romania/DayAfterNewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Day after New Years Day in Romania. */ -class DayAfterNewYearsDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class DayAfterNewYearsDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'dayAfterNewYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 2, self::TIMEZONE); + return static::generateRandomDates(1, 2, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'A doua zi după Anul Nou'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/EasterMondayTest.php b/tests/Romania/EasterMondayTest.php old mode 100755 new mode 100644 index f2255b200..637fbe337 --- a/tests/Romania/EasterMondayTest.php +++ b/tests/Romania/EasterMondayTest.php @@ -1,71 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class EasterMondayTest - * @package Yasumi\tests\Romania + * Class EasterMondayTest. */ -class EasterMondayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-04-20", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-04-20", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'A doua zi de Paște'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/EasterTest.php b/tests/Romania/EasterTest.php old mode 100755 new mode 100644 index eb86d0350..2a695b766 --- a/tests/Romania/EasterTest.php +++ b/tests/Romania/EasterTest.php @@ -1,71 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class EasterTest - * @package Yasumi\tests\Romania + * Class EasterTest. */ -class EasterTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-04-19", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-04-19", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Paștele'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/EpiphanyTest.php b/tests/Romania/EpiphanyTest.php new file mode 100644 index 000000000..e277010f5 --- /dev/null +++ b/tests/Romania/EpiphanyTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Romania; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class EphyphanyTest. + */ +class EpiphanyTest extends RomaniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'epiphany'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2024; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testEpiphanyAfter2024(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-01-06", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test before the establishment year. + * + * @throws \Exception + */ + public function testEpiphanyBefore2024(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Bobotează'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Romania/InternationalWorkersDayTest.php b/tests/Romania/InternationalWorkersDayTest.php old mode 100755 new mode 100644 index 4d6c132da..f6b7ab120 --- a/tests/Romania/InternationalWorkersDayTest.php +++ b/tests/Romania/InternationalWorkersDayTest.php @@ -1,80 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class InternationalWorkersDayTest - * @package Yasumi\tests\Romania + * Class InternationalWorkersDayTest. */ -class InternationalWorkersDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ziua internațională a muncii'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Romania/NationalDayTest.php b/tests/Romania/NationalDayTest.php index d357331bd..7c0cafb2f 100644 --- a/tests/Romania/NationalDayTest.php +++ b/tests/Romania/NationalDayTest.php @@ -1,124 +1,128 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing National Day in Romania. */ -class NationalDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class NationalDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1866; /** * Tests National Day on or after 1990. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayOnAfter1990() + public function testNationalDayOnAfter1990(): void { - $year = $this->generateRandomYear(1990); + $year = static::generateRandomYear(1990); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests National Day between 1948 - 1989. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayBetween1948_1989() + public function testNationalDayBetween19481989(): void { - $year = $this->generateRandomYear(1948, 1989); + $year = static::generateRandomYear(1948, 1989); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-08-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-08-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests National Day between 1866 - 1947. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayBetween1866_1947() + public function testNationalDayBetween18661947(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1947); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1947); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-05-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-05-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests National Day before 1865. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayBefore1865() + public function testNationalDayBefore1865(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Ziua Națională'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Romania/NewYearsDayTest.php b/tests/Romania/NewYearsDayTest.php index a6437d9b1..9e3aa738d 100644 --- a/tests/Romania/NewYearsDayTest.php +++ b/tests/Romania/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Romania. */ -class NewYearsDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Anul Nou'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/PentecostMondayTest.php b/tests/Romania/PentecostMondayTest.php index ae5abdc8c..1ec80bd7d 100644 --- a/tests/Romania/PentecostMondayTest.php +++ b/tests/Romania/PentecostMondayTest.php @@ -1,93 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class PentecostMondayTest - * @package Yasumi\tests\Romania + * Class PentecostMondayTest. */ -class PentecostMondayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2008; /** * Tests the Pentecost Monday Day on and after 2008. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMondayOnAfter2008() + public function testPentecostMondayOnAfter2008(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-08", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-08", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the Pentecost Day before 2008. - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMondayBefore2008() + public function testPentecostMondayBefore2008(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'A doua zi de Rusalii'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Romania/PentecostTest.php b/tests/Romania/PentecostTest.php index 56f321b66..a97695bb1 100644 --- a/tests/Romania/PentecostTest.php +++ b/tests/Romania/PentecostTest.php @@ -1,93 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class PentecostTest - * @package Yasumi\tests\Romania + * Class PentecostTest. */ -class PentecostTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2008; /** * Tests the Pentecost Day on and after 2008. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostDayOnAfter2008() + public function testPentecostDayOnAfter2008(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-07", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-07", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the Pentecost Day before 2008. - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostDayBefore2008() + public function testPentecostDayBefore2008(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Rusaliile'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Romania/RomaniaBaseTestCase.php b/tests/Romania/RomaniaBaseTestCase.php old mode 100755 new mode 100644 index 59ed0f88f..db4b5d29d --- a/tests/Romania/RomaniaBaseTestCase.php +++ b/tests/Romania/RomaniaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; @@ -16,25 +21,18 @@ use Yasumi\tests\YasumiBase; /** - * Class RomaniaBaseTestCase - * @package Yasumi\tests\Romania + * Class RomaniaBaseTestCase. */ class RomaniaBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Romania'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Bucharest'; - /** - * Locale that is considered common for this provider - */ - public const LOCALE = 'ro_RO'; + /** Locale that is considered common for this provider. */ + public const LOCALE = 'ro'; } diff --git a/tests/Romania/RomaniaTest.php b/tests/Romania/RomaniaTest.php old mode 100755 new mode 100644 index 806cd74f4..757248510 --- a/tests/Romania/RomaniaTest.php +++ b/tests/Romania/RomaniaTest.php @@ -1,35 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class RomaniaTest - * @package Yasumi\tests\Romania + * Class RomaniaTest. */ -class RomaniaTest extends RomaniaBaseTestCase +class RomaniaTest extends RomaniaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Romania are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2015, 2028); + } + + /** + * Tests if all official holidays in Romania are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -53,12 +65,16 @@ public function testOfficialHolidays(): void $national_holidays[] = 'childrensDay'; } + if ($this->year >= 2024) { + $national_holidays[] = 'epiphany'; + $national_holidays[] = 'stJohnsDay'; + } + $this->assertDefinedHolidays($national_holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in Romania are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Romania are defined by the provider class. */ public function testObservedHolidays(): void { @@ -76,8 +92,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Romania are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Romania are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -85,8 +100,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Romania are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Romania are defined by the provider class. */ public function testBankHolidays(): void { @@ -94,8 +108,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Romania are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Romania are defined by the provider class. */ public function testOtherHolidays(): void { @@ -103,10 +116,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2015, 2025); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Romania/SecondChristmasDayTest.php b/tests/Romania/SecondChristmasDayTest.php index a60fce4e5..4f5ee3f51 100644 --- a/tests/Romania/SecondChristmasDayTest.php +++ b/tests/Romania/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Romania. */ -class SecondChristmasDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'A doua zi de Crăciun'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Romania/StAndrewsDayTest.php b/tests/Romania/StAndrewsDayTest.php index fcb748e1d..cd699afb6 100644 --- a/tests/Romania/StAndrewsDayTest.php +++ b/tests/Romania/StAndrewsDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Saint Andrew Day in Romania. */ -class StAndrewsDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class StAndrewsDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stAndrewsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2012; /** * Tests Saint Andrew Day on or after 2012. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testStAndrewDayOnAfter2012() + public function testStAndrewDayOnAfter2012(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Saint Andrew before 2012. - * @throws ReflectionException + * + * @throws \Exception */ - public function testStAndrewDayBefore2012() + public function testStAndrewDayBefore2012(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Sfântul Andrei'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Romania/StJohnsDayTest.php b/tests/Romania/StJohnsDayTest.php new file mode 100644 index 000000000..dbe65826c --- /dev/null +++ b/tests/Romania/StJohnsDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Romania; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Saint John the Baptist Day in Romania. + */ +class StJohnsDayTest extends RomaniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'stJohnsDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2024; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testStJohnsAfter2024(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-01-07", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test before the establishment year. + * + * @throws \Exception + */ + public function testStJohnsDayBefore2024(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Sfântul Ioan Botezătorul'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Romania/UnitedPrincipalitiesDayTest.php b/tests/Romania/UnitedPrincipalitiesDayTest.php index 97ef7cbfd..b2ecc7eda 100644 --- a/tests/Romania/UnitedPrincipalitiesDayTest.php +++ b/tests/Romania/UnitedPrincipalitiesDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Romania; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing United Principalities Day in Romania. */ -class UnitedPrincipalitiesDayTest extends RomaniaBaseTestCase implements YasumiTestCaseInterface +class UnitedPrincipalitiesDayTest extends RomaniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'unitedPrincipalitiesDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2015; /** * Tests united Principalities Day on or after 2015. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testUnitedPrincipalitiesDayOnAfter2015() + public function testUnitedPrincipalitiesDayOnAfter2015(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-1-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests unitedPrincipalitiesDay before 2015. - * @throws ReflectionException + * + * @throws \Exception */ - public function testUnitedPrincipalitiesDayBefore2015() + public function testUnitedPrincipalitiesDayBefore2015(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Unirea Principatelor Române / Mica Unire'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Russia/DefenceOfTheFatherlandDayTest.php b/tests/Russia/DefenceOfTheFatherlandDayTest.php index c2d45a76b..8091cea0f 100644 --- a/tests/Russia/DefenceOfTheFatherlandDayTest.php +++ b/tests/Russia/DefenceOfTheFatherlandDayTest.php @@ -1,98 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Russia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Defence of the Fatherland day in Russia. * * @author Gedas Lukošius */ -class DefenceOfTheFatherlandDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class DefenceOfTheFatherlandDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'defenceOfTheFatherlandDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR - 1) + static::generateRandomYear(1000, Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR); + $year = static::generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-02-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-02-23", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), + static::generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), [self::LOCALE => 'День защитника Отечества'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), + static::generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), ['en' => 'Defence of the Fatherland Day'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), + static::generateRandomYear(Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Russia/InternationalWomensDayTest.php b/tests/Russia/InternationalWomensDayTest.php index d5b896275..a1e4773f3 100644 --- a/tests/Russia/InternationalWomensDayTest.php +++ b/tests/Russia/InternationalWomensDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Women's day in Russia. * * @author Gedas Lukošius */ -class InternationalWomensDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class InternationalWomensDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWomensDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(3, 8, self::TIMEZONE); + return static::generateRandomDates(3, 8, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Международный женский день'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay2Test.php b/tests/Russia/NewYearHolidaysDay2Test.php index e3ab7d697..4d07d008d 100644 --- a/tests/Russia/NewYearHolidaysDay2Test.php +++ b/tests/Russia/NewYearHolidaysDay2Test.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 2 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay2Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay2Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay2'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 2, self::TIMEZONE); + return static::generateRandomDates(1, 2, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay3Test.php b/tests/Russia/NewYearHolidaysDay3Test.php index 52c19e6eb..e50bcb793 100644 --- a/tests/Russia/NewYearHolidaysDay3Test.php +++ b/tests/Russia/NewYearHolidaysDay3Test.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 3 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay3Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay3Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay3'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 3, self::TIMEZONE); + return static::generateRandomDates(1, 3, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay4Test.php b/tests/Russia/NewYearHolidaysDay4Test.php index 98e993b25..6773bc290 100644 --- a/tests/Russia/NewYearHolidaysDay4Test.php +++ b/tests/Russia/NewYearHolidaysDay4Test.php @@ -1,77 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 4 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay4Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay4Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay4'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 4, self::TIMEZONE); + return static::generateRandomDates(1, 4, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay5Test.php b/tests/Russia/NewYearHolidaysDay5Test.php index f123bc6a5..c070f7cbd 100644 --- a/tests/Russia/NewYearHolidaysDay5Test.php +++ b/tests/Russia/NewYearHolidaysDay5Test.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 5 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay5Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay5Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay5'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 5, self::TIMEZONE); + return static::generateRandomDates(1, 5, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay6Test.php b/tests/Russia/NewYearHolidaysDay6Test.php index f7ef80f91..731d84223 100644 --- a/tests/Russia/NewYearHolidaysDay6Test.php +++ b/tests/Russia/NewYearHolidaysDay6Test.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 6 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay6Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay6Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay6'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearHolidaysDay8Test.php b/tests/Russia/NewYearHolidaysDay8Test.php index 7e0b51171..b37dd59ad 100644 --- a/tests/Russia/NewYearHolidaysDay8Test.php +++ b/tests/Russia/NewYearHolidaysDay8Test.php @@ -1,77 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's holidays day 8 in Russia. * * @author Gedas Lukošius */ -class NewYearHolidaysDay8Test extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearHolidaysDay8Test extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearHolidaysDay8'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 8, self::TIMEZONE); + return static::generateRandomDates(1, 8, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новогодние каникулы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/NewYearsDayTest.php b/tests/Russia/NewYearsDayTest.php index 2a639b0b5..f4d6221c7 100644 --- a/tests/Russia/NewYearsDayTest.php +++ b/tests/Russia/NewYearsDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Year's Day in Russia. * * @author Gedas Lukošius */ -class NewYearsDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новый год'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/OrthodoxChristmasDayTest.php b/tests/Russia/OrthodoxChristmasDayTest.php index 90aa966dc..2cff4d971 100644 --- a/tests/Russia/OrthodoxChristmasDayTest.php +++ b/tests/Russia/OrthodoxChristmasDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Orthodox Christmas Day in Russia. * * @author Gedas Lukošius */ -class OrthodoxChristmasDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class OrthodoxChristmasDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'orthodoxChristmasDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(1, 7, self::TIMEZONE); + return static::generateRandomDates(1, 7, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Рождество'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/RussiaBaseTestCase.php b/tests/Russia/RussiaBaseTestCase.php index 4b3769c47..f43c39286 100644 --- a/tests/Russia/RussiaBaseTestCase.php +++ b/tests/Russia/RussiaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; @@ -26,17 +30,13 @@ abstract class RussiaBaseTestCase extends TestCase use YasumiBase; /** - * Name of the country to be tested + * Name of the country to be tested. */ public const REGION = 'Russia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Moscow'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'ru_RU'; } diff --git a/tests/Russia/RussiaDayTest.php b/tests/Russia/RussiaDayTest.php index c465d2e86..1c79f10c4 100644 --- a/tests/Russia/RussiaDayTest.php +++ b/tests/Russia/RussiaDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Russia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Russia day. * * @author Gedas Lukošius */ -class RussiaDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class RussiaDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'russiaDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Russia::RUSSIA_DAY_START_YEAR - 1) + static::generateRandomYear(1000, Russia::RUSSIA_DAY_START_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Russia::RUSSIA_DAY_START_YEAR); + $year = static::generateRandomYear(Russia::RUSSIA_DAY_START_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-06-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-12", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), + static::generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), [self::LOCALE => 'День России'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), + static::generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), ['en' => 'Russia Day'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), + static::generateRandomYear(Russia::RUSSIA_DAY_START_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Russia/RussiaTest.php b/tests/Russia/RussiaTest.php index 925536d93..65b29568b 100644 --- a/tests/Russia/RussiaTest.php +++ b/tests/Russia/RussiaTest.php @@ -1,32 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Russia; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Russia. * * @author Gedas Lukošius */ -class RussiaTest extends RussiaBaseTestCase +class RussiaTest extends RussiaBaseTestCase implements ProviderTestCase { /** - * Tests if all official holidays in Russia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Russia are defined by the provider class. + * + * @throws \Exception */ public function testOfficialHolidays(): void { @@ -44,7 +49,7 @@ public function testOfficialHolidays(): void 'victoryDay', ]; - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); if ($year >= Russia::DEFENCE_OF_THE_FATHERLAND_START_YEAR) { $holidays[] = 'defenceOfTheFatherlandDay'; @@ -62,38 +67,51 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Russia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Russia are defined by the provider class. + * + * @throws \Exception */ public function testObservedHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } /** - * Tests if all seasonal holidays in Russia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Russia are defined by the provider class. + * + * @throws \Exception */ public function testSeasonalHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_SEASON); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_SEASON); } /** - * Tests if all bank holidays in Russia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Russia are defined by the provider class. + * + * @throws \Exception */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Russia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Russia are defined by the provider class. + * + * @throws \Exception */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([], self::REGION, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Russia/SpringAndLabourDayTest.php b/tests/Russia/SpringAndLabourDayTest.php index 419b9138e..cd350c3f9 100644 --- a/tests/Russia/SpringAndLabourDayTest.php +++ b/tests/Russia/SpringAndLabourDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Spring and Labour day in Russia. * * @author Gedas Lukošius */ -class SpringAndLabourDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class SpringAndLabourDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'springAndLabourDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Праздник Весны и Труда'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Russia/UnityDayTest.php b/tests/Russia/UnityDayTest.php index fa07dfd90..4c6c35492 100644 --- a/tests/Russia/UnityDayTest.php +++ b/tests/Russia/UnityDayTest.php @@ -1,99 +1,97 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\Russia; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Unity day in Russia. * * @author Gedas Lukošius */ -class UnityDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class UnityDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'unityDay'; /** - * Test if holiday is not defined before - * @throws ReflectionException + * Test if holiday is not defined before. + * + * @throws \Exception */ - public function testHolidayBefore() + public function testHolidayBefore(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, Russia::UNITY_DAY_START_YEAR - 1) + static::generateRandomYear(1000, Russia::UNITY_DAY_START_YEAR - 1) ); } /** - * Test if holiday is defined after - * @throws Exception - * @throws ReflectionException + * Test if holiday is defined after. + * + * @throws \Exception */ - public function testHolidayAfter() + public function testHolidayAfter(): void { - $year = $this->generateRandomYear(Russia::UNITY_DAY_START_YEAR); + $year = static::generateRandomYear(Russia::UNITY_DAY_START_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("{$year}-11-04", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-04", new \DateTimeZone(self::TIMEZONE)) ); } /** - * {@inheritdoc} - * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::UNITY_DAY_START_YEAR), + static::generateRandomYear(Russia::UNITY_DAY_START_YEAR), [self::LOCALE => 'День народного единства'] ); $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::UNITY_DAY_START_YEAR), + static::generateRandomYear(Russia::UNITY_DAY_START_YEAR), ['en' => 'Unity Day'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(Russia::UNITY_DAY_START_YEAR), + static::generateRandomYear(Russia::UNITY_DAY_START_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Russia/VictoryDayTest.php b/tests/Russia/VictoryDayTest.php index fa43a4fd1..8616c4688 100644 --- a/tests/Russia/VictoryDayTest.php +++ b/tests/Russia/VictoryDayTest.php @@ -1,78 +1,71 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Russia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Victory day in Russia. * * @author Gedas Lukošius */ -class VictoryDayTest extends RussiaBaseTestCase implements YasumiTestCaseInterface +class VictoryDayTest extends RussiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'victoryDay'; /** - * @return array - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function holidayDataProvider(): array + public static function holidayDataProvider(): array { - return $this->generateRandomDates(5, 9, self::TIMEZONE); + return static::generateRandomDates(5, 9, self::TIMEZONE); } - /** - * @dataProvider holidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, DateTime $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('holidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'День Победы'] ); } /** - * {@inheritdoc} - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/SanMarino/AllSaintsDayTest.php b/tests/SanMarino/AllSaintsDayTest.php new file mode 100644 index 000000000..b51fff523 --- /dev/null +++ b/tests/SanMarino/AllSaintsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for All Saints' Day in San Marino. + */ +class AllSaintsDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'allSaintsDay'; + + /** + * Tests All Saints' Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of All Saints' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Festa di Tutti i Santi'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/AnniversaryOfArengoTest.php b/tests/SanMarino/AnniversaryOfArengoTest.php new file mode 100644 index 000000000..d7d213039 --- /dev/null +++ b/tests/SanMarino/AnniversaryOfArengoTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\Provider\SanMarino; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Anniversary of the Arengo in San Marino. + * + * Celebrated on 25 March, this holiday commemorates the reconvening of the Arengo (popular assembly) + * in 1906, which granted democratic rights to San Marino's citizens. + * + * @see https://en.wikipedia.org/wiki/Arengo_(San_Marino) + */ +class AnniversaryOfArengoTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'anniversaryOfArengo'; + + /** + * Tests the Anniversary of the Arengo on or after 1906. + * + * @throws \Exception + */ + public function testAnniversaryOfArengoOnAfter1906(): void + { + $year = static::generateRandomYear(SanMarino::ARENGO_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-3-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the Anniversary of the Arengo before 1906. + * + * @throws \Exception + */ + public function testAnniversaryOfArengoBefore1906(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, SanMarino::ARENGO_YEAR - 1) + ); + } + + /** + * Tests translated name of the Anniversary of the Arengo. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(SanMarino::ARENGO_YEAR), + [self::LOCALE => "Anniversario dell\u{2019}Arengo"] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(SanMarino::ARENGO_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/SanMarino/AssumptionOfMaryTest.php b/tests/SanMarino/AssumptionOfMaryTest.php new file mode 100644 index 000000000..9666bf4c2 --- /dev/null +++ b/tests/SanMarino/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Assumption of Mary in San Marino. + */ +class AssumptionOfMaryTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the Assumption of Mary. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests the translated name of the Assumption of Mary. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Assunzione di Maria Vergine'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/ChristmasDayTest.php b/tests/SanMarino/ChristmasDayTest.php new file mode 100644 index 000000000..c9b6f8466 --- /dev/null +++ b/tests/SanMarino/ChristmasDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Christmas Day in San Marino. + */ +class ChristmasDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests Christmas Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * Tests the translated name of Christmas Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Natale'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/CommemorationOfTheFallenTest.php b/tests/SanMarino/CommemorationOfTheFallenTest.php new file mode 100644 index 000000000..fe8cc0ee6 --- /dev/null +++ b/tests/SanMarino/CommemorationOfTheFallenTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Commemoration of the Fallen in San Marino. + * + * Observed on 2 November, this official public holiday honours all deceased persons, coinciding + * with All Souls' Day in the Catholic tradition. + * + * @see https://en.wikipedia.org/wiki/All_Souls%27_Day + */ +class CommemorationOfTheFallenTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'commemorationOfTheFallen'; + + /** + * Tests the Commemoration of the Fallen. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 2, self::TIMEZONE); + } + + /** + * Tests the translated name of the Commemoration of the Fallen. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Commemorazione dei Defunti'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/CorpusChristiTest.php b/tests/SanMarino/CorpusChristiTest.php new file mode 100644 index 000000000..12a18e3a5 --- /dev/null +++ b/tests/SanMarino/CorpusChristiTest.php @@ -0,0 +1,95 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Corpus Christi in San Marino. + * + * Corpus Christi (Italian: Corpus Domini) is celebrated on the Thursday 60 days after Easter Sunday. + * + * @see https://en.wikipedia.org/wiki/Corpus_Christi_(feast) + */ +class CorpusChristiTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'corpusChristi'; + + /** + * Tests Corpus Christi. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return [ + [2020, new \DateTime('2020-6-11', new \DateTimeZone(self::TIMEZONE))], + [2021, new \DateTime('2021-6-3', new \DateTimeZone(self::TIMEZONE))], + [2022, new \DateTime('2022-6-16', new \DateTimeZone(self::TIMEZONE))], + [2023, new \DateTime('2023-6-8', new \DateTimeZone(self::TIMEZONE))], + [2024, new \DateTime('2024-5-30', new \DateTimeZone(self::TIMEZONE))], + [2025, new \DateTime('2025-6-19', new \DateTimeZone(self::TIMEZONE))], + [2026, new \DateTime('2026-6-4', new \DateTimeZone(self::TIMEZONE))], + ]; + } + + /** + * Tests the translated name of Corpus Christi. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Corpus Domini'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/EasterMondayTest.php b/tests/SanMarino/EasterMondayTest.php new file mode 100644 index 000000000..861aac092 --- /dev/null +++ b/tests/SanMarino/EasterMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter Monday in San Marino. + */ +class EasterMondayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterMonday'; + + /** + * Tests Easter Monday. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of Easter Monday. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => "Lunedì dell\u{2019}Angelo"] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/EasterTest.php b/tests/SanMarino/EasterTest.php new file mode 100644 index 000000000..8ef97d6c9 --- /dev/null +++ b/tests/SanMarino/EasterTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter in San Marino. + */ +class EasterTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter. + * + * @throws \Exception + */ + public function testEaster(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-3-31", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of Easter. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Pasqua'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/EpiphanyTest.php b/tests/SanMarino/EpiphanyTest.php new file mode 100644 index 000000000..17d3599aa --- /dev/null +++ b/tests/SanMarino/EpiphanyTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Epiphany in San Marino. + */ +class EpiphanyTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'epiphany'; + + /** + * Tests Epiphany. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 6, self::TIMEZONE); + } + + /** + * Tests the translated name of Epiphany. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Epifania'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/FallOfFascismTest.php b/tests/SanMarino/FallOfFascismTest.php new file mode 100644 index 000000000..287c2da63 --- /dev/null +++ b/tests/SanMarino/FallOfFascismTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\Provider\SanMarino; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Fall of Fascism in San Marino. + * + * Observed on 28 July, this holiday commemorates the coup d'état of 28 July 1943 that overthrew + * San Marino's Fascist government. It has been observed since 1944. + * + * @see https://en.wikipedia.org/wiki/San_Marino_in_World_War_II + */ +class FallOfFascismTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'fallOfFascism'; + + /** + * Tests the Fall of Fascism on or after 1944. + * + * @throws \Exception + */ + public function testFallOfFascismOnAfter1944(): void + { + $year = static::generateRandomYear(SanMarino::FALL_OF_FASCISM_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-7-28", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the Fall of Fascism before 1944. + * + * @throws \Exception + */ + public function testFallOfFascismBefore1944(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, SanMarino::FALL_OF_FASCISM_YEAR - 1) + ); + } + + /** + * Tests translated name of the Fall of Fascism. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(SanMarino::FALL_OF_FASCISM_YEAR), + [self::LOCALE => 'Caduta del Fascismo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(SanMarino::FALL_OF_FASCISM_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/SanMarino/FeastOfSaintAgathaTest.php b/tests/SanMarino/FeastOfSaintAgathaTest.php new file mode 100644 index 000000000..85d4686d2 --- /dev/null +++ b/tests/SanMarino/FeastOfSaintAgathaTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Feast of Saint Agatha in San Marino. + * + * The Feast of Saint Agatha is celebrated on 5 February. Saint Agatha is the patron saint of San Marino. + * The day also commemorates the liberation from the occupation by Cardinal Giulio Alberoni on 5 February 1740. + * + * @see https://en.wikipedia.org/wiki/Saint_Agatha + */ +class FeastOfSaintAgathaTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'feastOfSaintAgatha'; + + /** + * Tests the Feast of Saint Agatha. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(2, 5, self::TIMEZONE); + } + + /** + * Tests the translated name of the Feast of Saint Agatha. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => "Festa di Sant\u{2019}Agata"] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/FoundationDayTest.php b/tests/SanMarino/FoundationDayTest.php new file mode 100644 index 000000000..523bd4c6c --- /dev/null +++ b/tests/SanMarino/FoundationDayTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Foundation Day in San Marino. + * + * Foundation Day (Italian: Anniversario della Fondazione della Repubblica), observed on 3 September, + * commemorates the traditional founding of San Marino on 3 September 301 AD by Saint Marinus of Rab. + * + * @see https://en.wikipedia.org/wiki/San_Marino + */ +class FoundationDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'foundationDay'; + + /** + * Tests Foundation Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(9, 3, self::TIMEZONE); + } + + /** + * Tests the translated name of Foundation Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Anniversario della Fondazione della Repubblica'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/ImmaculateConceptionTest.php b/tests/SanMarino/ImmaculateConceptionTest.php new file mode 100644 index 000000000..ca9eb39b0 --- /dev/null +++ b/tests/SanMarino/ImmaculateConceptionTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Immaculate Conception in San Marino. + */ +class ImmaculateConceptionTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'immaculateConception'; + + /** + * Tests the Immaculate Conception. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of the Immaculate Conception. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Immacolata Concezione'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/InternationalWorkersDayTest.php b/tests/SanMarino/InternationalWorkersDayTest.php new file mode 100644 index 000000000..1dc50a7e5 --- /dev/null +++ b/tests/SanMarino/InternationalWorkersDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for International Workers' Day in San Marino. + */ +class InternationalWorkersDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests International Workers' Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of International Workers' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Festa del Lavoro'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/InvestitureCaptainsRegentAprilTest.php b/tests/SanMarino/InvestitureCaptainsRegentAprilTest.php new file mode 100644 index 000000000..c5a287f42 --- /dev/null +++ b/tests/SanMarino/InvestitureCaptainsRegentAprilTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Investiture of the Captains Regent (April) in San Marino. + * + * Observed on 1 April, this holiday marks the formal investiture of the two Captains Regent, + * the heads of state of San Marino, elected every six months. + * + * @see https://en.wikipedia.org/wiki/Captain_Regent + */ +class InvestitureCaptainsRegentAprilTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'investitureCaptainsRegentApril'; + + /** + * Tests the Investiture of the Captains Regent (April). + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(4, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the Investiture of the Captains Regent (April). + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Investitura dei Capitani Reggenti'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/InvestitureCaptainsRegentOctoberTest.php b/tests/SanMarino/InvestitureCaptainsRegentOctoberTest.php new file mode 100644 index 000000000..25459cf1a --- /dev/null +++ b/tests/SanMarino/InvestitureCaptainsRegentOctoberTest.php @@ -0,0 +1,86 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for the Investiture of the Captains Regent (October) in San Marino. + * + * Observed on 1 October, this holiday marks the formal investiture of the two Captains Regent, + * the heads of state of San Marino, elected every six months. + * + * @see https://en.wikipedia.org/wiki/Captain_Regent + */ +class InvestitureCaptainsRegentOctoberTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'investitureCaptainsRegentOctober'; + + /** + * Tests the Investiture of the Captains Regent (October). + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(10, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the Investiture of the Captains Regent (October). + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Investitura dei Capitani Reggenti'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/NewYearsDayTest.php b/tests/SanMarino/NewYearsDayTest.php new file mode 100644 index 000000000..805d4870d --- /dev/null +++ b/tests/SanMarino/NewYearsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for New Year's Day in San Marino. + */ +class NewYearsDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests New Year's Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of New Year's Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Capodanno'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/SanMarino/SanMarinoBaseTestCase.php b/tests/SanMarino/SanMarinoBaseTestCase.php new file mode 100644 index 000000000..3c40bd9f2 --- /dev/null +++ b/tests/SanMarino/SanMarinoBaseTestCase.php @@ -0,0 +1,38 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the San Marino holiday provider. + */ +abstract class SanMarinoBaseTestCase extends TestCase +{ + use YasumiBase; + + /** Name of the region (e.g. country / state) to be tested. */ + public const REGION = 'SanMarino'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Europe/San_Marino'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'it_SM'; +} diff --git a/tests/SanMarino/SanMarinoTest.php b/tests/SanMarino/SanMarinoTest.php new file mode 100644 index 000000000..39c647864 --- /dev/null +++ b/tests/SanMarino/SanMarinoTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\Provider\SanMarino; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in San Marino. + */ +class SanMarinoTest extends SanMarinoBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(SanMarino::FALL_OF_FASCISM_YEAR); + } + + /** + * Tests if all official holidays in San Marino are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $this->assertDefinedHolidays([ + 'newYearsDay', + 'epiphany', + 'feastOfSaintAgatha', + 'anniversaryOfArengo', + 'easter', + 'easterMonday', + 'investitureCaptainsRegentApril', + 'internationalWorkersDay', + 'corpusChristi', + 'fallOfFascism', + 'assumptionOfMary', + 'foundationDay', + 'investitureCaptainsRegentOctober', + 'allSaintsDay', + 'commemorationOfTheFallen', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in San Marino are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in San Marino are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in San Marino are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in San Marino are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/SanMarino/StStephensDayTest.php b/tests/SanMarino/StStephensDayTest.php new file mode 100644 index 000000000..94e6960ce --- /dev/null +++ b/tests/SanMarino/StStephensDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\SanMarino; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for St. Stephen's Day in San Marino. + */ +class StStephensDayTest extends SanMarinoBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'stStephensDay'; + + /** + * Tests St. Stephen's Day. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 26, self::TIMEZONE); + } + + /** + * Tests the translated name of St. Stephen's Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Santo Stefano'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovakia/AllSaintsDayTest.php b/tests/Slovakia/AllSaintsDayTest.php index 8e06550ec..f399e312d 100644 --- a/tests/Slovakia/AllSaintsDayTest.php +++ b/tests/Slovakia/AllSaintsDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class AllSaintsDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sviatok Všetkých svätých'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/ChristmasDayTest.php b/tests/Slovakia/ChristmasDayTest.php index 43f457d4e..098e9eaee 100644 --- a/tests/Slovakia/ChristmasDayTest.php +++ b/tests/Slovakia/ChristmasDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas day in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class ChristmasDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; - /** * Tests Christmas Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } - /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Prvý sviatok vianočný'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/ChristmasEveTest.php b/tests/Slovakia/ChristmasEveTest.php index c0962e8b4..ff577766c 100644 --- a/tests/Slovakia/ChristmasEveTest.php +++ b/tests/Slovakia/ChristmasEveTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas eve in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class ChristmasEveTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasEve'; - /** * Tests Christmas Eve. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasEve($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testChristmasEve(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } - /** * Tests translated name of Christmas Eve. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Štedrý deň'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/DeclarationOfTheSlovakNationTest.php b/tests/Slovakia/DeclarationOfTheSlovakNationTest.php new file mode 100644 index 000000000..f3c5b18bb --- /dev/null +++ b/tests/Slovakia/DeclarationOfTheSlovakNationTest.php @@ -0,0 +1,87 @@ + + */ + +namespace Yasumi\tests\Slovakia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing an official holiday in Slovakia. + * + * @author Jan Hamrak + */ +class DeclarationOfTheSlovakNationTest extends SlovakiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'declarationOfTheSlovakNation'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + if (2018 === $year) { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } else { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(10, 30, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + 2018, + [self::LOCALE => 'Výročie Deklarácie slovenského národa'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, 2018, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovakia/EasterMondayTest.php b/tests/Slovakia/EasterMondayTest.php index 51db336c9..1e4775c7b 100644 --- a/tests/Slovakia/EasterMondayTest.php +++ b/tests/Slovakia/EasterMondayTest.php @@ -1,101 +1,94 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class EasterMondayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of test dates used for assertion of the holiday defined in this test + * Returns a list of test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $timezone = self::TIMEZONE; return [ - [1788, new DateTime('1788-3-24', new DateTimeZone($timezone))], - [1876, new DateTime('1876-4-17', new DateTimeZone($timezone))], - [2016, new DateTime('2016-3-28', new DateTimeZone($timezone))], - [2017, new DateTime('2017-4-17', new DateTimeZone($timezone))], - [2018, new DateTime('2018-4-2', new DateTimeZone($timezone))], - [2019, new DateTime('2019-4-22', new DateTimeZone($timezone))], - [2020, new DateTime('2020-4-13', new DateTimeZone($timezone))], - [2050, new DateTime('2050-4-11', new DateTimeZone($timezone))], + [1788, new \DateTime('1788-3-24', new \DateTimeZone($timezone))], + [1876, new \DateTime('1876-4-17', new \DateTimeZone($timezone))], + [2016, new \DateTime('2016-3-28', new \DateTimeZone($timezone))], + [2017, new \DateTime('2017-4-17', new \DateTimeZone($timezone))], + [2018, new \DateTime('2018-4-2', new \DateTimeZone($timezone))], + [2019, new \DateTime('2019-4-22', new \DateTimeZone($timezone))], + [2020, new \DateTime('2020-4-13', new \DateTimeZone($timezone))], + [2050, new \DateTime('2050-4-11', new \DateTimeZone($timezone))], ]; } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Veľkonočný pondelok'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/EpiphanyTest.php b/tests/Slovakia/EpiphanyTest.php index 6564460e4..c2c6b1d74 100644 --- a/tests/Slovakia/EpiphanyTest.php +++ b/tests/Slovakia/EpiphanyTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class EpiphanyTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Zjavenie Pána / Traja králi'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/GoodFridayTest.php b/tests/Slovakia/GoodFridayTest.php index d294f9e60..7b51c4487 100644 --- a/tests/Slovakia/GoodFridayTest.php +++ b/tests/Slovakia/GoodFridayTest.php @@ -1,101 +1,94 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class GoodFridayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'goodFriday'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of test dates used for assertion of the holiday defined in this test + * Returns a list of test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $timezone = self::TIMEZONE; return [ - [1788, new DateTime('1788-3-21', new DateTimeZone($timezone))], - [1876, new DateTime('1876-4-14', new DateTimeZone($timezone))], - [2016, new DateTime('2016-3-25', new DateTimeZone($timezone))], - [2017, new DateTime('2017-4-14', new DateTimeZone($timezone))], - [2018, new DateTime('2018-3-30', new DateTimeZone($timezone))], - [2019, new DateTime('2019-4-19', new DateTimeZone($timezone))], - [2020, new DateTime('2020-4-10', new DateTimeZone($timezone))], - [2050, new DateTime('2050-4-8', new DateTimeZone($timezone))], + [1788, new \DateTime('1788-3-21', new \DateTimeZone($timezone))], + [1876, new \DateTime('1876-4-14', new \DateTimeZone($timezone))], + [2016, new \DateTime('2016-3-25', new \DateTimeZone($timezone))], + [2017, new \DateTime('2017-4-14', new \DateTimeZone($timezone))], + [2018, new \DateTime('2018-3-30', new \DateTimeZone($timezone))], + [2019, new \DateTime('2019-4-19', new \DateTimeZone($timezone))], + [2020, new \DateTime('2020-4-10', new \DateTimeZone($timezone))], + [2050, new \DateTime('2050-4-8', new \DateTimeZone($timezone))], ]; } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Veľký piatok'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/InternationalWorkersDayTest.php b/tests/Slovakia/InternationalWorkersDayTest.php index c67e7730b..30e2b8d42 100644 --- a/tests/Slovakia/InternationalWorkersDayTest.php +++ b/tests/Slovakia/InternationalWorkersDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class InternationalWorkersDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sviatok práce'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/OurLadyOfSorrowsDayTest.php b/tests/Slovakia/OurLadyOfSorrowsDayTest.php index 641a6eecd..2f8f2b292 100644 --- a/tests/Slovakia/OurLadyOfSorrowsDayTest.php +++ b/tests/Slovakia/OurLadyOfSorrowsDayTest.php @@ -1,89 +1,100 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing a holiday in Slovakia. + * Class for testing the Our Lady of Sorrows holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class OurLadyOfSorrowsDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class OurLadyOfSorrowsDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday - */ public const HOLIDAY = 'ourLadyOfSorrowsDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which this holiday needs to be tested + * @param string $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, $expected): void { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(9, 15, self::TIMEZONE); - } + return static::generateRandomDatesWithModifier(9, 15, function ($year, \DateTime $date): ?bool { + // Our Lady of Sorrows Day is not observed in 2025 and 2026 + if (in_array($year, [2025, 2026])) { + return false; + } + return null; + }, 5, 1000, self::TIMEZONE); + } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { + // Our Lady of Sorrows Day is not observed in 2025 and 2026 + $validYears = array_merge(range(1993, 2024), range(2027, 2100)); + $year = static::randomYearFromArray($validYears); + $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + $year, [self::LOCALE => 'Sviatok Sedembolestnej Panny Márie'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + // Our Lady of Sorrows Day is not observed in 2025 and 2026 + $validYears = array_merge(range(1993, 2024), range(2027, 2100)); + $year = static::randomYearFromArray($validYears); + + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/SaintsCyrilAndMethodiusDayTest.php b/tests/Slovakia/SaintsCyrilAndMethodiusDayTest.php index 977e0ecf9..c69f57e66 100644 --- a/tests/Slovakia/SaintsCyrilAndMethodiusDayTest.php +++ b/tests/Slovakia/SaintsCyrilAndMethodiusDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing a official holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class SaintsCyrilAndMethodiusDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class SaintsCyrilAndMethodiusDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'saintsCyrilAndMethodiusDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(7, 5, self::TIMEZONE); + return static::generateRandomDates(7, 5, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sviatok svätého Cyrila a Metoda'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Slovakia/SecondChristmasDayTest.php b/tests/Slovakia/SecondChristmasDayTest.php index da0fcc14c..634f6c386 100644 --- a/tests/Slovakia/SecondChristmasDayTest.php +++ b/tests/Slovakia/SecondChristmasDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Second Christmas day in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class SecondChristmasDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } - /** * Tests translated name of Second Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Druhý sviatok vianočný'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/Slovakia/SlovakConstitutionDayTest.php b/tests/Slovakia/SlovakConstitutionDayTest.php index 438ddb289..01b93c2c9 100644 --- a/tests/Slovakia/SlovakConstitutionDayTest.php +++ b/tests/Slovakia/SlovakConstitutionDayTest.php @@ -1,88 +1,87 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing an official holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class SlovakConstitutionDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class SlovakConstitutionDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'slovakConstitutionDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + if ($year < 2024) { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } else { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(9, 1, self::TIMEZONE); + return static::generateRandomDates(9, 1, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(null, 2013), [self::LOCALE => 'Deň Ústavy Slovenskej republiky'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(null, 2013), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Slovakia/SlovakIndependeceDayTest.php b/tests/Slovakia/SlovakIndependeceDayTest.php deleted file mode 100644 index bfe589928..000000000 --- a/tests/Slovakia/SlovakIndependeceDayTest.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ - - -namespace Yasumi\tests\Slovakia; - -use DateTime; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Slovak independence day in Slovakia. - * - * - * @package Yasumi\tests\Slovakia - * @author Andrej Rypak (dakujem) - * @author Jan Langer - */ -class SlovakIndependeceDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday to be tested - */ - public const HOLIDAY = 'slovakIndependenceDay'; - - - /** - * Tests the holiday defined in this test. - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); - } - - - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - return $this->generateRandomDates(1, 1, self::TIMEZONE); - } - - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Deň vzniku Slovenskej republiky'] - ); - } - - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); - } -} diff --git a/tests/Slovakia/SlovakIndependenceDayTest.php b/tests/Slovakia/SlovakIndependenceDayTest.php new file mode 100644 index 000000000..8a838343e --- /dev/null +++ b/tests/Slovakia/SlovakIndependenceDayTest.php @@ -0,0 +1,84 @@ + + */ + +namespace Yasumi\tests\Slovakia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Slovak independence day in Slovakia. + * + * @author Andrej Rypak (dakujem) + * @author Jan Langer + */ +class SlovakIndependenceDayTest extends SlovakiaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'slovakIndependenceDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Deň vzniku Slovenskej republiky'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovakia/SlovakNationalUprisingDayTest.php b/tests/Slovakia/SlovakNationalUprisingDayTest.php index 858ac5fd6..c503f30a6 100644 --- a/tests/Slovakia/SlovakNationalUprisingDayTest.php +++ b/tests/Slovakia/SlovakNationalUprisingDayTest.php @@ -1,89 +1,83 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing an official holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class SlovakNationalUprisingDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class SlovakNationalUprisingDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'slovakNationalUprisingDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 29, self::TIMEZONE); + return static::generateRandomDates(8, 29, self::TIMEZONE); } - /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Výročie Slovenského národného povstania'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Slovakia/SlovakiaBaseTestCase.php b/tests/Slovakia/SlovakiaBaseTestCase.php index a2149af32..d3a239ce6 100644 --- a/tests/Slovakia/SlovakiaBaseTestCase.php +++ b/tests/Slovakia/SlovakiaBaseTestCase.php @@ -1,17 +1,20 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; use PHPUnit\Framework\TestCase; @@ -20,26 +23,18 @@ /** * Base class for test cases of the Slovakia holiday provider. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ abstract class SlovakiaBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Slovakia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Bratislava'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'sk_SK'; } diff --git a/tests/Slovakia/SlovakiaTest.php b/tests/Slovakia/SlovakiaTest.php index dc40b2a75..5e9a340d1 100644 --- a/tests/Slovakia/SlovakiaTest.php +++ b/tests/Slovakia/SlovakiaTest.php @@ -1,64 +1,90 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class SlovakiaTest extends SlovakiaBaseTestCase +class SlovakiaTest extends SlovakiaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + /** + * @var int year of Slovakia's consolidation + */ + protected int $yearOfConsolidation; + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + // NOTE: 1993 is the year Slovakia was founded as an independent state + $this->year = static::generateRandomYear(1993, 2100); + $this->yearOfConsolidation = static::generateRandomYear(1993, 2024); + } /** - * Tests if all official holidays in Slovakia are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Slovakia are defined by the provider class. */ public function testOfficialHolidays(): void { + $this->assertDefinedHolidays([ + 'struggleForFreedomAndDemocracyDay', + ], self::REGION, $this->yearOfConsolidation, Holiday::TYPE_OFFICIAL); + $this->assertDefinedHolidays([ 'slovakIndependenceDay', - 'slovakConstitutionDay', 'slovakNationalUprisingDay', 'saintsCyrilAndMethodiusDay', - 'struggleForFreedomAndDemocracyDay', ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); - } + $this->assertDefinedHolidays([ + 'slovakConstitutionDay', + ], self::REGION, 2013, Holiday::TYPE_OFFICIAL); + + $this->assertDefinedHolidays([ + 'declarationOfTheSlovakNation', + ], self::REGION, 2018, Holiday::TYPE_OFFICIAL); + } /** - * Tests if all bank holidays in Slovakia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Slovakia are defined by the provider class. */ public function testBankHolidays(): void { $this->assertDefinedHolidays([ - 'epiphany', - 'internationalWorkersDay', 'victoryInEuropeDay', 'ourLadyOfSorrowsDay', + ], self::REGION, $this->yearOfConsolidation, Holiday::TYPE_BANK); + + $this->assertDefinedHolidays([ + 'epiphany', + 'internationalWorkersDay', 'allSaintsDay', 'christmasEve', 'christmasDay', @@ -68,43 +94,36 @@ public function testBankHolidays(): void ], self::REGION, $this->year, Holiday::TYPE_BANK); } - /** - * Tests if all observed holidays in Slovakia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Slovakia are defined by the provider class. */ public function testObservedHolidays(): void { $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } - /** - * Tests if all seasonal holidays in Slovakia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Slovakia are defined by the provider class. */ public function testSeasonalHolidays(): void { $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); } - /** - * Tests if all other holidays in Slovakia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Slovakia are defined by the provider class. */ public function testOtherHolidays(): void { $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); } - /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - // NOTE: 1993 is the year Slovakia was founded as an independent state - $this->year = $this->generateRandomYear(1993, 2100); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Slovakia/StruggleForFreedomAndDemocracyDayTest.php b/tests/Slovakia/StruggleForFreedomAndDemocracyDayTest.php index 54f55a56f..3bcee77d0 100644 --- a/tests/Slovakia/StruggleForFreedomAndDemocracyDayTest.php +++ b/tests/Slovakia/StruggleForFreedomAndDemocracyDayTest.php @@ -1,89 +1,94 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing an official holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class StruggleForFreedomAndDemocracyDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class StruggleForFreedomAndDemocracyDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'struggleForFreedomAndDemocracyDay'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 17, self::TIMEZONE); - } + // Only use years between 1993 and 2024 + $years = range(1993, 2024); + $dates = []; + shuffle($years); + foreach (array_slice($years, 0, 10) as $year) { + $dates[] = [ + $year, + new \DateTime("{$year}-11-17", new \DateTimeZone(self::TIMEZONE)), + ]; + } + return $dates; + } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(1993, 2024), [self::LOCALE => 'Deň boja za slobodu a demokraciu'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1993, 2024), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Slovakia/VictoryInEuropeDayTest.php b/tests/Slovakia/VictoryInEuropeDayTest.php index ea7b03f46..d364c1923 100644 --- a/tests/Slovakia/VictoryInEuropeDayTest.php +++ b/tests/Slovakia/VictoryInEuropeDayTest.php @@ -1,89 +1,103 @@ - + * @author Sacha Telgenhof */ - namespace Yasumi\tests\Slovakia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing a holiday in Slovakia. + * Class for testing Victory in Europe holiday in Slovakia. * - * - * @package Yasumi\tests\Slovakia * @author Andrej Rypak (dakujem) */ -class VictoryInEuropeDayTest extends SlovakiaBaseTestCase implements YasumiTestCaseInterface +class VictoryInEuropeDayTest extends SlovakiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'victoryInEuropeDay'; - /** * Tests Christmas Day. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which this holiday needs to be tested + * @param string $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); } - /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 8, self::TIMEZONE); - } + return static::generateRandomDatesWithModifier(5, 8, function ($year, \DateTime $date): ?bool { + // Victory in Europe Day is not observed in 2025 and 2026 + if (in_array($year, [2025, 2026])) { + return false; + } + return null; + }, 5, 1000, self::TIMEZONE); + } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { + // Victory in Europe Day is not observed in 2025 and 2026 + $validYears = array_merge(range(1993, 2024), range(2027, 2100)); + $year = static::randomYearFromArray($validYears); + $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + $year, [self::LOCALE => 'Deň víťazstva nad fašizmom'] ); } - /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + // Victory in Europe Day is not observed in 2025 and 2026 + $validYears = array_merge(range(1993, 2024), range(2027, 2100)); + $year = static::randomYearFromArray($validYears); + + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_BANK); } } diff --git a/tests/Slovenia/AssumptionOfMaryTest.php b/tests/Slovenia/AssumptionOfMaryTest.php new file mode 100644 index 000000000..2a8055661 --- /dev/null +++ b/tests/Slovenia/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Assumption of Mary in Slovenia. + */ +class AssumptionOfMaryTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Marijino vnebovzetje'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/ChristmasDayTest.php b/tests/Slovenia/ChristmasDayTest.php new file mode 100644 index 000000000..21770cde3 --- /dev/null +++ b/tests/Slovenia/ChristmasDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas Day in Slovenia. + */ +class ChristmasDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'christmasDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 25, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Božič'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/EasterMondayTest.php b/tests/Slovenia/EasterMondayTest.php new file mode 100644 index 000000000..774fe5309 --- /dev/null +++ b/tests/Slovenia/EasterMondayTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter Monday in Slovenia. + */ +class EasterMondayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'easterMonday'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Velikonočni ponedeljek'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/EasterTest.php b/tests/Slovenia/EasterTest.php new file mode 100644 index 000000000..6249dc4d1 --- /dev/null +++ b/tests/Slovenia/EasterTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter in Slovenia. + */ +class EasterTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-3-31", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Velika noč'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/IndependenceDayTest.php b/tests/Slovenia/IndependenceDayTest.php new file mode 100644 index 000000000..bf36a57f4 --- /dev/null +++ b/tests/Slovenia/IndependenceDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Independence and Unity Day in Slovenia. + */ +class IndependenceDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'independenceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1991; + + /** + * Tests Independence Day. + * + * @throws \Exception + */ + public function testIndependenceDay(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Independence Day before 1991. + * + * @throws \Exception + */ + public function testIndependenceDayBefore1991(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Independence Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dan samostojnosti in enotnosti'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Slovenia/InternationalWorkersDayTest.php b/tests/Slovenia/InternationalWorkersDayTest.php new file mode 100644 index 000000000..ff6211abd --- /dev/null +++ b/tests/Slovenia/InternationalWorkersDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing International Workers' Day in Slovenia. + */ +class InternationalWorkersDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'internationalWorkersDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Praznik dela'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/LabourDayTest.php b/tests/Slovenia/LabourDayTest.php new file mode 100644 index 000000000..4e67ca574 --- /dev/null +++ b/tests/Slovenia/LabourDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Labour Day (May 2) in Slovenia. + */ +class LabourDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'labourDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 2, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Praznik dela (2. dan)'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/NewYearsDayTest.php b/tests/Slovenia/NewYearsDayTest.php new file mode 100644 index 000000000..506797eb6 --- /dev/null +++ b/tests/Slovenia/NewYearsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Year's Day in Slovenia. + */ +class NewYearsDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'newYearsDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Novo leto'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/PentecostTest.php b/tests/Slovenia/PentecostTest.php new file mode 100644 index 000000000..d584faba6 --- /dev/null +++ b/tests/Slovenia/PentecostTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Pentecost in Slovenia. + */ +class PentecostTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'pentecost'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2024; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-19", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Binkoštna nedelja'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/PreserenDayTest.php b/tests/Slovenia/PreserenDayTest.php new file mode 100644 index 000000000..e50fff0cc --- /dev/null +++ b/tests/Slovenia/PreserenDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Prešeren Day in Slovenia. + */ +class PreserenDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'preserenDay'; + + /** + * The year in which the holiday became work-free. + */ + public const ESTABLISHMENT_YEAR = 1991; + + /** + * Tests Prešeren Day. + * + * @throws \Exception + */ + public function testPreserenDay(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-2-8", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Prešeren Day before 1991. + * + * @throws \Exception + */ + public function testPreserenDayBefore1991(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Prešeren Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Prešernov dan, slovenski kulturni praznik'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Slovenia/ReformationDayTest.php b/tests/Slovenia/ReformationDayTest.php new file mode 100644 index 000000000..1015a9af2 --- /dev/null +++ b/tests/Slovenia/ReformationDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Reformation Day in Slovenia. + */ +class ReformationDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'reformationDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1992; + + /** + * Tests Reformation Day. + * + * @throws \Exception + */ + public function testReformationDay(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Reformation Day before 1992. + * + * @throws \Exception + */ + public function testReformationDayBefore1992(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Reformation Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dan reformacije'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Slovenia/RemembranceDayTest.php b/tests/Slovenia/RemembranceDayTest.php new file mode 100644 index 000000000..799a72717 --- /dev/null +++ b/tests/Slovenia/RemembranceDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Remembrance Day for the Dead in Slovenia. + */ +class RemembranceDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'remembranceDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Dan spomina na mrtve'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/SecondNewYearsDayTest.php b/tests/Slovenia/SecondNewYearsDayTest.php new file mode 100644 index 000000000..8f834ace5 --- /dev/null +++ b/tests/Slovenia/SecondNewYearsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Second New Year's Day in Slovenia. + */ +class SecondNewYearsDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'secondNewYearsDay'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 2, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Novo leto (2. dan)'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Slovenia/SloveniaBaseTestCase.php b/tests/Slovenia/SloveniaBaseTestCase.php new file mode 100644 index 000000000..183bbd877 --- /dev/null +++ b/tests/Slovenia/SloveniaBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Base class for test cases of the Slovenia holiday provider. + */ +abstract class SloveniaBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Slovenia'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'Europe/Ljubljana'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'sl_SI'; +} diff --git a/tests/Slovenia/SloveniaTest.php b/tests/Slovenia/SloveniaTest.php new file mode 100644 index 000000000..5c564b6dd --- /dev/null +++ b/tests/Slovenia/SloveniaTest.php @@ -0,0 +1,118 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Slovenia. + */ +class SloveniaTest extends SloveniaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1992); + } + + /** + * Tests if all official holidays in Slovenia are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'secondNewYearsDay', + 'internationalWorkersDay', + 'labourDay', + 'easter', + 'easterMonday', + 'pentecost', + 'assumptionOfMary', + 'christmasDay', + 'remembranceDay', + ]; + + if ($this->year >= 1991) { + $holidays[] = 'preserenDay'; + $holidays[] = 'statehoodDay'; + $holidays[] = 'independenceDay'; + } + + if ($this->year >= 1945) { + $holidays[] = 'uprisingAgainstOccupation'; + } + + if ($this->year >= 1992) { + $holidays[] = 'reformationDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Slovenia are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Slovenia are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Slovenia are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Slovenia are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Slovenia/StatehoodDayTest.php b/tests/Slovenia/StatehoodDayTest.php new file mode 100644 index 000000000..764dfd7b5 --- /dev/null +++ b/tests/Slovenia/StatehoodDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Statehood Day in Slovenia. + */ +class StatehoodDayTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'statehoodDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1991; + + /** + * Tests Statehood Day. + * + * @throws \Exception + */ + public function testStatehoodDay(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-25", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Statehood Day before 1991. + * + * @throws \Exception + */ + public function testStatehoodDayBefore1991(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Statehood Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dan državnosti'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Slovenia/UprisingAgainstOccupationTest.php b/tests/Slovenia/UprisingAgainstOccupationTest.php new file mode 100644 index 000000000..d481e5633 --- /dev/null +++ b/tests/Slovenia/UprisingAgainstOccupationTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Slovenia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Day of Uprising Against Occupation in Slovenia. + */ +class UprisingAgainstOccupationTest extends SloveniaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'uprisingAgainstOccupation'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1945; + + /** + * Tests Uprising Against Occupation Day. + * + * @throws \Exception + */ + public function testUprisingAgainstOccupation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-27", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Uprising Against Occupation Day before 1945. + * + * @throws \Exception + */ + public function testUprisingAgainstOccupationBefore1945(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of Uprising Against Occupation Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dan upora proti okupatorju'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/SouthAfrica/ChristmasDayTest.php b/tests/SouthAfrica/ChristmasDayTest.php index 4aef86f62..d068c1d0d 100644 --- a/tests/SouthAfrica/ChristmasDayTest.php +++ b/tests/SouthAfrica/ChristmasDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class ChristmasDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/FamilyDayTest.php b/tests/SouthAfrica/FamilyDayTest.php index 10d3408cf..6f3d96e03 100644 --- a/tests/SouthAfrica/FamilyDayTest.php +++ b/tests/SouthAfrica/FamilyDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Family Friday in South Africa. @@ -27,53 +27,52 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class FamilyDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class FamilyDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'familyDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -82,41 +81,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Family Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/FreedomDayTest.php b/tests/SouthAfrica/FreedomDayTest.php index 46d522ab4..c182defed 100644 --- a/tests/SouthAfrica/FreedomDayTest.php +++ b/tests/SouthAfrica/FreedomDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Freedom Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class FreedomDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class FreedomDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'freedomDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-4-27", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-4-27", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Freedom Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/GoodFridayTest.php b/tests/SouthAfrica/GoodFridayTest.php index 47f462576..6904730e2 100644 --- a/tests/SouthAfrica/GoodFridayTest.php +++ b/tests/SouthAfrica/GoodFridayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Good Friday in South Africa. @@ -27,53 +27,52 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class GoodFridayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->sub(new DateInterval('P2D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P2D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -82,41 +81,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/HeritageDayTest.php b/tests/SouthAfrica/HeritageDayTest.php index 4000e150c..690c19235 100644 --- a/tests/SouthAfrica/HeritageDayTest.php +++ b/tests/SouthAfrica/HeritageDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Heritage Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class HeritageDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class HeritageDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'heritageDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-9-24", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-9-24", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Heritage Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/HumanRightsDayTest.php b/tests/SouthAfrica/HumanRightsDayTest.php index f2320d4b5..3bfbc6f9d 100644 --- a/tests/SouthAfrica/HumanRightsDayTest.php +++ b/tests/SouthAfrica/HumanRightsDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Human Rights Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class HumanRightsDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class HumanRightsDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'humanRightsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Human Rights Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/MunicipalElections2016DayTest.php b/tests/SouthAfrica/MunicipalElections2016DayTest.php index d20c3181a..f88db38b8 100644 --- a/tests/SouthAfrica/MunicipalElections2016DayTest.php +++ b/tests/SouthAfrica/MunicipalElections2016DayTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the public holiday in respect of the 2016 Municipal Elections in South Africa (August 3rd, 2016). @@ -26,79 +27,83 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class MunicipalElections2016DayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class MunicipalElections2016DayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = '2016MunicipalElectionsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2016; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR, - new DateTime(self::ESTABLISHMENT_YEAR . '-8-3', new DateTimeZone(self::TIMEZONE)) + new \DateTime(self::ESTABLISHMENT_YEAR . '-8-3', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the holiday defined in this test after completion. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayDayAfterCompletion() + public function testHolidayDayAfterCompletion(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), [self::LOCALE => '2016 Municipal Elections Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/NationalWomensDayTest.php b/tests/SouthAfrica/NationalWomensDayTest.php index 6c329670d..bfd0f7dd9 100644 --- a/tests/SouthAfrica/NationalWomensDayTest.php +++ b/tests/SouthAfrica/NationalWomensDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing National Women's Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class NationalWomensDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class NationalWomensDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalWomensDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-8-9", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-8-9", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'National Women\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'National Women’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/NewYearsDayTest.php b/tests/SouthAfrica/NewYearsDayTest.php index 533368247..87c65a80d 100644 --- a/tests/SouthAfrica/NewYearsDayTest.php +++ b/tests/SouthAfrica/NewYearsDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class NewYearsDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/ReconciliationDayTest.php b/tests/SouthAfrica/ReconciliationDayTest.php index d3c24c855..0ba83c970 100644 --- a/tests/SouthAfrica/ReconciliationDayTest.php +++ b/tests/SouthAfrica/ReconciliationDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Day of Reconciliation in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class ReconciliationDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class ReconciliationDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'reconciliationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-12-16", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-12-16", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Day of Reconciliation'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/SecondChristmasDayTest.php b/tests/SouthAfrica/SecondChristmasDayTest.php index ab6815767..4569e3b92 100644 --- a/tests/SouthAfrica/SecondChristmasDayTest.php +++ b/tests/SouthAfrica/SecondChristmasDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Day of Goodwill in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class SecondChristmasDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Day of Goodwill'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/SouthAfricaBaseTestCase.php b/tests/SouthAfrica/SouthAfricaBaseTestCase.php index 9000a6b9b..4ccd74342 100644 --- a/tests/SouthAfrica/SouthAfricaBaseTestCase.php +++ b/tests/SouthAfrica/SouthAfricaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; @@ -19,25 +23,18 @@ /** * Base class for test cases of the South Africa holiday provider. * - * @package Yasumi\tests\SouthAfrica - * @author Sacha Telgenhof + * @author Sacha Telgenhof */ abstract class SouthAfricaBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'SouthAfrica'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Africa/Johannesburg'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_ZA'; } diff --git a/tests/SouthAfrica/SouthAfricaTest.php b/tests/SouthAfrica/SouthAfricaTest.php index 76c2985f1..4b189eb4a 100644 --- a/tests/SouthAfrica/SouthAfricaTest.php +++ b/tests/SouthAfrica/SouthAfricaTest.php @@ -1,37 +1,49 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in South Africa. * - * @package Yasumi\tests\SouthAfrica - * @author Sacha Telgenhof + * @author Sacha Telgenhof */ -class SouthAfricaTest extends SouthAfricaBaseTestCase +class SouthAfricaTest extends SouthAfricaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in SouthAfrica are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1994); + } + + /** + * Tests if all official holidays in SouthAfrica are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -59,8 +71,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all bank holidays in South Africa are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in South Africa are defined by the provider class. */ public function testBankHolidays(): void { @@ -68,8 +79,7 @@ public function testBankHolidays(): void } /** - * Tests if all observed holidays in South Africa are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in South Africa are defined by the provider class. */ public function testObservedHolidays(): void { @@ -77,8 +87,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in South Africa are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in South Africa are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -86,8 +95,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all other holidays in South Africa are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in South Africa are defined by the provider class. */ public function testOtherHolidays(): void { @@ -95,10 +103,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1994); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/SouthAfrica/SubstituteDayOfGoodwillTest.php b/tests/SouthAfrica/SubstituteDayOfGoodwillTest.php index 40dadeb46..c63fa619a 100644 --- a/tests/SouthAfrica/SubstituteDayOfGoodwillTest.php +++ b/tests/SouthAfrica/SubstituteDayOfGoodwillTest.php @@ -1,23 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the 2016 Substitute Day of Goodwill in South Africa. @@ -26,79 +27,83 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class SubstituteDayOfGoodwillTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class SubstituteDayOfGoodwillTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'substituteDayOfGoodwill'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2016; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR, - new DateTime(self::ESTABLISHMENT_YEAR . '-12-27', new DateTimeZone(self::TIMEZONE)) + new \DateTime(self::ESTABLISHMENT_YEAR . '-12-27', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the holiday defined in this test after completion. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayDayAfterCompletion() + public function testHolidayDayAfterCompletion(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR + 1)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Day of Goodwill observed'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/WorkersDayTest.php b/tests/SouthAfrica/WorkersDayTest.php index 7868b2d0d..7c75f6657 100644 --- a/tests/SouthAfrica/WorkersDayTest.php +++ b/tests/SouthAfrica/WorkersDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class WorkersDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Workers\' Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Workers’ Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthAfrica/YouthDayTest.php b/tests/SouthAfrica/YouthDayTest.php index 42ac762e7..df2d5992c 100644 --- a/tests/SouthAfrica/YouthDayTest.php +++ b/tests/SouthAfrica/YouthDayTest.php @@ -1,24 +1,24 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthAfrica; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Youth Day in South Africa. @@ -27,54 +27,53 @@ * determines whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. * Yasumi currently implements all South African holidays based on this act. */ -class YouthDayTest extends SouthAfricaBaseTestCase implements YasumiTestCaseInterface +class YouthDayTest extends SouthAfricaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'youthDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1994; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); // Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday. - if (0 === (int)$date->format('w')) { - $date->add(new DateInterval('P1D')); + if (0 === (int) $date->format('w')) { + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-6-16", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-6-16", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -83,41 +82,44 @@ public function HolidayDataProvider(): array /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Youth Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/ArborDayTest.php b/tests/SouthKorea/ArborDayTest.php index ccce9260c..4c42d67e2 100644 --- a/tests/SouthKorea/ArborDayTest.php +++ b/tests/SouthKorea/ArborDayTest.php @@ -1,136 +1,128 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing day after Arbor Day in South Korea. */ -class ArborDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ArborDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The year in which the holiday was removed. */ - private const HOLIDAY = 'arborDay'; + public const REMOVED_YEAR = 2005; /** - * The year in which the holiday was first established + * The year the date was temporarily changed. */ - private const ESTABLISHMENT_YEAR = 1949; - + public const TEMPORARY_CHANGED_YEAR = 1960; /** - * The year in which the holiday was removed + * The name of the holiday. */ - public const REMOVED_YEAR = 2005; + private const HOLIDAY = 'arborDay'; /** - * The year in which the holiday was not celebrated + * The year in which the holiday was first established. */ - public const YEAR_NOT_CELEBRATED = 1960; + private const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); - if (self::YEAR_NOT_CELEBRATED === $year) { - $this->assertNotHoliday( - self::REGION, - self::HOLIDAY, - $year - ); - } else { - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime("$year-4-5", new DateTimeZone(self::TIMEZONE)) - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $date = (self::TEMPORARY_CHANGED_YEAR === $year) + ? new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) + : new \DateTime("{$year}-4-5", new \DateTimeZone(self::TIMEZONE)); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + $date + ); } /** * Tests the holiday defined in this test after removal. * - * @throws ReflectionException + * @throws \Exception */ - public function testHolidayAfterRemoval() + public function testHolidayAfterRemoval(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::REMOVED_YEAR + 1) + static::generateRandomYear(self::REMOVED_YEAR + 1) ); } /** * Tests the holiday defined in this test before establishment. * - * @throws ReflectionException + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); - if (self::YEAR_NOT_CELEBRATED !== $year) { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $year, - [self::LOCALE => '식목일'] - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $translation = (self::TEMPORARY_CHANGED_YEAR === $year) ? '사방의 날' : '식목일'; + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => $translation] + ); } /** * Tests type of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); - if (self::YEAR_NOT_CELEBRATED !== $year) { - $this->assertHolidayType( - self::REGION, - self::HOLIDAY, - $year, - Holiday::TYPE_OFFICIAL - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $year, + Holiday::TYPE_OFFICIAL + ); } } diff --git a/tests/SouthKorea/ArmedForcesDayTest.php b/tests/SouthKorea/ArmedForcesDayTest.php index 8e6f48ce7..c94c8d96f 100644 --- a/tests/SouthKorea/ArmedForcesDayTest.php +++ b/tests/SouthKorea/ArmedForcesDayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing day after Armed Forces Day in South Korea. */ -class ArmedForcesDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ArmedForcesDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'armedForcesDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ - public const ESTABLISHMENT_YEAR = 1956; + public const ESTABLISHMENT_YEAR = 1976; /** - * The year in which the holiday was removed + * The year in which the holiday was removed. */ public const REMOVED_YEAR = 1990; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test after removal. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayAfterRemoval() + public function testHolidayAfterRemoval(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::REMOVED_YEAR + 1) + static::generateRandomYear(self::REMOVED_YEAR + 1) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), [self::LOCALE => '국군의 날'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/BuddhasBirthdayTest.php b/tests/SouthKorea/BuddhasBirthdayTest.php index 67d84551b..8f205defc 100644 --- a/tests/SouthKorea/BuddhasBirthdayTest.php +++ b/tests/SouthKorea/BuddhasBirthdayTest.php @@ -1,103 +1,158 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\SouthKorea; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Buddha's Birthday in South Korea. */ -class BuddhasBirthdayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class BuddhasBirthdayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'buddhasBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1975; + /** + * The year of upper limit for tests of lunar date. + */ + public const LUNAR_TEST_LIMIT = 2050; + /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $this->assertHoliday( + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime(self::LUNAR_HOLIDAY[self::HOLIDAY][$year], new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests substitute holidays. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param ?string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('SubstituteHolidayDataProvider')] + public function testSubstituteHoliday(int $year, ?string $expected): void + { + if ($expected) { + $this->assertSubstituteHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year], new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } else { + $this->assertNotSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year ); } } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $year, - [self::LOCALE => '부처님오신날'] - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => '부처님오신날'] + ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $this->assertHolidayType( - self::REGION, - self::HOLIDAY, - $year, - Holiday::TYPE_OFFICIAL - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $year, + Holiday::TYPE_OFFICIAL + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function SubstituteHolidayDataProvider(): array + { + return [ + [1975, null], + [2005, null], + [2020, null], + [2021, null], + [2022, null], + [2023, '2023-05-29'], + [2024, null], + [2025, '2025-05-06'], + [2026, '2026-05-25'], + [2027, null], + [2028, null], + [2029, '2029-05-21'], + [2030, null], + [2031, null], + [2032, '2032-05-17'], + [2036, '2036-05-06'], + ]; } } diff --git a/tests/SouthKorea/ChildrensDayTest.php b/tests/SouthKorea/ChildrensDayTest.php index e49e1877e..0d9d184e9 100644 --- a/tests/SouthKorea/ChildrensDayTest.php +++ b/tests/SouthKorea/ChildrensDayTest.php @@ -1,142 +1,157 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Children's Day in South Korea. */ -class ChildrensDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ChildrensDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'childrensDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ - public const ESTABLISHMENT_YEAR = 1970; + public const ESTABLISHMENT_YEAR = 1975; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMainHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-5", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the substitute holiday defined in this test (conflict with Buddha's Birthday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testSubstituteHolidayByBuddhasBirthday() + public function testSubstituteHolidayByBuddhasBirthday(): void { + $tz = new \DateTimeZone(self::TIMEZONE); + foreach ([2025, 2044] as $year) { $this->assertHoliday( self::REGION, - 'substituteHoliday:childrensDay', + 'buddhasBirthday', $year, - new DateTime("$year-5-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-5", $tz) + ); + + $this->assertSubstituteHoliday( + self::REGION, + 'buddhasBirthday', + $year, + new \DateTime("{$year}-5-6", $tz) ); } } /** - * Tests the substitute holiday defined in this test (conflict with Saturday). - * @throws Exception - * @throws ReflectionException + * Tests the substitute holiday defined in this test. + * + * @throws \Exception */ - public function testSubstituteHolidayBySaturday() + public function testSubstituteHoliday(): void { - $year = 2029; - $this->assertHoliday( + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2013); + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:childrensDay', - $year, - new DateTime("$year-5-7", new DateTimeZone(self::TIMEZONE)) + self::HOLIDAY, + 2019, + new \DateTime('2019-5-6', $tz) ); - } - /** - * Tests the substitute holiday defined in this test (conflict with Sunday). - * @throws Exception - * @throws ReflectionException - */ - public function testSubstituteHolidayBySunday() - { - $year = 2019; - $this->assertHoliday( + // By saturday + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:childrensDay', - $year, - new DateTime("$year-5-6", new DateTimeZone(self::TIMEZONE)) + self::HOLIDAY, + 2029, + new \DateTime('2029-5-7', $tz) + ); + + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2024, + new \DateTime('2024-5-6', $tz) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '어린이날'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/ChristmasDayTest.php b/tests/SouthKorea/ChristmasDayTest.php index 8e596fb3e..3f3c231cc 100644 --- a/tests/SouthKorea/ChristmasDayTest.php +++ b/tests/SouthKorea/ChristmasDayTest.php @@ -1,94 +1,161 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in South Korea. */ -class ChristmasDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) ); } + /** + * Tests substitute holidays. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param ?string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('SubstituteHolidayDataProvider')] + public function testSubstituteHoliday(int $year, ?string $expected): void + { + if ($expected) { + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } else { + $this->assertNotSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year + ); + } + } + /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '기독탄신일'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function SubstituteHolidayDataProvider(): array + { + return [ + [1949, null], + [1950, null], + [1959, null], + [1960, '1960-12-26'], + [1965, null], + [2020, null], + [2021, null], + [2022, null], + [2023, null], + [2024, null], + [2025, null], + [2026, null], + [2027, '2027-12-27'], + [2028, null], + [2029, null], + [2030, null], + [2031, null], + [2032, '2032-12-27'], + [2033, '2033-12-26'], + [2034, null], + [2035, null], + [2036, null], + [2037, null], + [2038, '2038-12-27'], + [2039, '2039-12-26'], + [2040, null], + ]; + } } diff --git a/tests/SouthKorea/ChuseokTest.php b/tests/SouthKorea/ChuseokTest.php index 1bbb1b744..fbc6b71a3 100644 --- a/tests/SouthKorea/ChuseokTest.php +++ b/tests/SouthKorea/ChuseokTest.php @@ -1,209 +1,242 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\SouthKorea; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Chuseok in South Korea. */ -class ChuseokTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ChuseokTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'chuseok'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; + /** + * The year of upper limit for tests of lunar date. + */ + public const LUNAR_TEST_LIMIT = 2050; + /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $date = new DateTime(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year], new DateTimeZone(self::TIMEZONE)); - - // Chuseok - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - - // Day after Chuseok - if ($year >= 1986) { - $this->assertHoliday( - self::REGION, - 'dayAfterChuseok', - $year, - (clone $date)->add(new DateInterval('P1D')) - ); - } - - // Day before Chuseok - if ($year >= 1989) { - $this->assertHoliday( - self::REGION, - 'dayBeforeChuseok', - $year, - (clone $date)->sub(new DateInterval('P1D')) - ); - } + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + $date = new \DateTime(self::LUNAR_HOLIDAY[self::HOLIDAY][$year], new \DateTimeZone(self::TIMEZONE)); + + // Chuseok + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); + + // Day after Chuseok + if ($year >= 1986) { + $this->assertHoliday( + self::REGION, + 'dayAfterChuseok', + $year, + (clone $date)->add(new \DateInterval('P1D')) + ); + } + + // Day before Chuseok + if ($year >= 1989) { + $this->assertHoliday( + self::REGION, + 'dayBeforeChuseok', + $year, + (clone $date)->sub(new \DateInterval('P1D')) + ); } } /** * Tests the substitute holiday defined in this test (conflict with Gaecheonjeol). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testSubstituteHolidayByGaecheonjeol() + public function testSubstituteHolidayByGaecheonjeol(): void { - $this->assertHoliday( + $tz = new \DateTimeZone(self::TIMEZONE); + + foreach ([2017, 2028, 2036, 2039] as $year) { + $this->assertHoliday( + self::REGION, + 'nationalFoundationDay', + $year, + new \DateTime("{$year}-10-3", $tz) + ); + } + + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayBeforeChuseok', + 'dayBeforeChuseok', 2017, - new DateTime('2017-10-6', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2017-10-6', $tz) ); - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:chuseok', + 'chuseok', 2028, - new DateTime('2028-10-5', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2028-10-5', $tz) + ); + $this->assertSubstituteHoliday( + self::REGION, + 'dayBeforeChuseok', + 2036, + new \DateTime('2036-10-6', $tz) ); - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayAfterChuseok', + 'dayAfterChuseok', 2039, - new DateTime('2039-10-5', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2039-10-5', $tz) ); } /** * Tests the substitute holiday defined in this test (conflict with Sunday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testSubstituteHolidayBySunday() + public function testSubstituteHoliday(): void { - $this->assertHoliday( + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayBeforeChuseok', + 'dayBeforeChuseok', 2014, - new DateTime('2014-9-10', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2014-9-10', $tz) ); - $this->assertHoliday( + + // By sunday + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:chuseok', - 2039, - new DateTime('2039-10-4', new DateTimeZone(self::TIMEZONE)) + 'dayBeforeChuseok', + 2025, + new \DateTime('2025-10-8', $tz) ); - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayAfterChuseok', - 2022, - new DateTime('2022-9-12', new DateTimeZone(self::TIMEZONE)) + 'chuseok', + 2032, + new \DateTime('2032-9-21', $tz) + ); + $this->assertSubstituteHoliday( + self::REGION, + 'dayAfterChuseok', + 2036, + new \DateTime('2036-10-7', $tz) ); } - /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => '추석'] + ); + + if ($year >= 1986) { + $this->assertTranslatedHolidayName( + self::REGION, + 'dayAfterChuseok', + $year, + [self::LOCALE => '추석 연휴'] + ); + } + + if ($year >= 1989) { $this->assertTranslatedHolidayName( self::REGION, - self::HOLIDAY, + 'dayBeforeChuseok', $year, - [self::LOCALE => '추석'] + [self::LOCALE => '추석 연휴'] ); - if ($year >= 1986) { - $this->assertTranslatedHolidayName( - self::REGION, - 'dayAfterChuseok', - $year, - [self::LOCALE => '추석 연휴'] - ); - } - if ($year >= 1989) { - $this->assertTranslatedHolidayName( - self::REGION, - 'dayBeforeChuseok', - $year, - [self::LOCALE => '추석 연휴'] - ); - } } } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $year, + Holiday::TYPE_OFFICIAL + ); + + if ($year >= 1986) { + $this->assertHolidayType( + self::REGION, + 'dayAfterChuseok', + $year, + Holiday::TYPE_OFFICIAL + ); + } + + if ($year >= 1989) { $this->assertHolidayType( self::REGION, - self::HOLIDAY, + 'dayBeforeChuseok', $year, Holiday::TYPE_OFFICIAL ); - if ($year >= 1986) { - $this->assertHolidayType( - self::REGION, - 'dayAfterChuseok', - $year, - Holiday::TYPE_OFFICIAL - ); - } - if ($year >= 1989) { - $this->assertHolidayType( - self::REGION, - 'dayBeforeChuseok', - $year, - Holiday::TYPE_OFFICIAL - ); - } } } } diff --git a/tests/SouthKorea/ConstitutionDayTest.php b/tests/SouthKorea/ConstitutionDayTest.php index a0b45af47..a5422706c 100644 --- a/tests/SouthKorea/ConstitutionDayTest.php +++ b/tests/SouthKorea/ConstitutionDayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing day after Constitution Day in South Korea. */ -class ConstitutionDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'constitutionDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** - * The year in which the holiday was removed + * The year in which the holiday was removed. */ public const REMOVED_YEAR = 2007; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test after removal. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayAfterRemoval() + public function testHolidayAfterRemoval(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::REMOVED_YEAR + 1) + static::generateRandomYear(self::REMOVED_YEAR + 1) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), [self::LOCALE => '제헌절'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/GaecheonjeolTest.php b/tests/SouthKorea/GaecheonjeolTest.php index 95ebe719c..87fd0c1b5 100644 --- a/tests/SouthKorea/GaecheonjeolTest.php +++ b/tests/SouthKorea/GaecheonjeolTest.php @@ -1,93 +1,158 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Gaecheonjeol (National Foundation Day) in South Korea. */ -class GaecheonjeolTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class GaecheonjeolTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'nationalFoundationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-3", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the substitute holiday defined in this test (conflict with Chuseok). + * + * @throws \Exception + */ + public function testSubstituteByChuseok(): void + { + $tz = new \DateTimeZone(self::TIMEZONE); + + $this->assertHoliday( + self::REGION, + 'chuseok', + 2028, + new \DateTime('2028-10-3', $tz) + ); + $this->assertHoliday( + self::REGION, + 'dayBeforeChuseok', + 2036, + new \DateTime('2036-10-3', $tz) + ); + // Chuseok will be substitute instead of Gaecheonjeol. + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2028); + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2036); + } + + /** + * Tests the substitute holiday defined in this test. + * + * @throws \Exception + */ + public function testSubstituteHoliday(): void + { + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2015); + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2020); + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2021, + new \DateTime('2021-10-4', $tz) + ); + + // By saturday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2026, + new \DateTime('2026-10-5', $tz) + ); + + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2032, + new \DateTime('2032-10-4', $tz) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '개천절'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/HangulDayTest.php b/tests/SouthKorea/HangulDayTest.php index e18a14206..866b166af 100644 --- a/tests/SouthKorea/HangulDayTest.php +++ b/tests/SouthKorea/HangulDayTest.php @@ -1,48 +1,48 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Hangul Day in South Korea. */ -class HangulDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class HangulDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'hangulDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); if ($year > 1990 && $year <= 2012) { $this->assertNotHoliday( self::REGION, @@ -54,55 +54,87 @@ public function testHoliday() self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-9", new \DateTimeZone(self::TIMEZONE)) ); } } + /** + * Tests the substitute holiday defined in this test. + * + * @throws \Exception + */ + public function testSubstituteHoliday(): void + { + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2016); + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2021, + new \DateTime('2021-10-11', $tz) + ); + + // By saturday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2027, + new \DateTime('2027-10-11', $tz) + ); + + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2022, + new \DateTime('2022-10-10', $tz) + ); + } + /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - if ($year <= 1990 || $year > 2012) { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $year, - [self::LOCALE => '한글날'] - ); - } + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(2013), + [self::LOCALE => '한글날'] + ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - if ($year <= 1990 || $year > 2012) { - $this->assertHolidayType( - self::REGION, - self::HOLIDAY, - $year, - Holiday::TYPE_OFFICIAL - ); - } + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(2013), + Holiday::TYPE_OFFICIAL + ); } } diff --git a/tests/SouthKorea/IndependenceMovementDayTest.php b/tests/SouthKorea/IndependenceMovementDayTest.php index 2b119df0d..2e5727041 100644 --- a/tests/SouthKorea/IndependenceMovementDayTest.php +++ b/tests/SouthKorea/IndependenceMovementDayTest.php @@ -1,93 +1,138 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Independence Movement Day in South Korea. */ -class IndependenceMovementDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class IndependenceMovementDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceMovementDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-1", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the substitute holiday defined in this test. + * + * @throws \Exception + */ + public function testSubstituteHoliday(): void + { + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2020); + + // By saturday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2025, + new \DateTime('2025-3-3', $tz) + ); + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2031, + new \DateTime('2031-3-3', $tz) + ); + + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2026, + new \DateTime('2026-3-2', $tz) + ); + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2037, + new \DateTime('2037-3-2', $tz) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '삼일절'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/LiberationDayTest.php b/tests/SouthKorea/LiberationDayTest.php index 711151f3b..b66b87e30 100644 --- a/tests/SouthKorea/LiberationDayTest.php +++ b/tests/SouthKorea/LiberationDayTest.php @@ -1,93 +1,133 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Independence Movement Day in South Korea. */ -class LiberationDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class LiberationDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'liberationDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1949; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-15", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-15", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the substitute holiday defined in this test. + * + * @throws \Exception + */ + public function testSubstituteHoliday(): void + { + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertNotSubstituteHoliday(self::REGION, self::HOLIDAY, 2020); + + // Year 2021 + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2021, + new \DateTime('2021-8-16', $tz) + ); + + // By saturday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2037, + new \DateTime('2037-8-17', $tz) + ); + + // By sunday + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + 2027, + new \DateTime('2027-8-16', $tz) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '광복절'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/MemorialDayTest.php b/tests/SouthKorea/MemorialDayTest.php index 61fa8dd46..e46d9ddc4 100644 --- a/tests/SouthKorea/MemorialDayTest.php +++ b/tests/SouthKorea/MemorialDayTest.php @@ -1,93 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Memorial Day in South Korea. */ -class MemorialDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class MemorialDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'memorialDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ - public const ESTABLISHMENT_YEAR = 1966; + public const ESTABLISHMENT_YEAR = 1956; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-6", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '현충일'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/NewYearsDayTest.php b/tests/SouthKorea/NewYearsDayTest.php index b53da96ca..64961930f 100644 --- a/tests/SouthKorea/NewYearsDayTest.php +++ b/tests/SouthKorea/NewYearsDayTest.php @@ -1,50 +1,49 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Year's Day in South Korea. */ -class NewYearsDayTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1950; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)); // New Year's Day $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); @@ -55,100 +54,104 @@ public function testHoliday() self::REGION, 'dayAfterNewYearsDay', $year, - (clone $date)->add(new DateInterval('P1D')) + (clone $date)->add(new \DateInterval('P1D')) ); } // Two days later New Year's Day - if ($year <= 1990) { + if ($year <= 1989) { $this->assertHoliday( self::REGION, 'twoDaysLaterNewYearsDay', $year, - (clone $date)->add(new DateInterval('P2D')) + (clone $date)->add(new \DateInterval('P2D')) ); } } /** * Tests the holiday defined in this test after removal. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayAfterRemoval() + public function testHolidayAfterRemoval(): void { $this->assertNotHoliday( self::REGION, 'dayAfterNewYearsDay', - $this->generateRandomYear(1999) + static::generateRandomYear(1999) ); $this->assertNotHoliday( self::REGION, 'twoDaysLaterNewYearsDay', - $this->generateRandomYear(1991) + static::generateRandomYear(1990) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '새해'] ); $this->assertTranslatedHolidayName( self::REGION, 'dayAfterNewYearsDay', - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1998), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1998), [self::LOCALE => '새해 연휴'] ); $this->assertTranslatedHolidayName( self::REGION, 'twoDaysLaterNewYearsDay', - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1990), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1989), [self::LOCALE => '새해 연휴'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); $this->assertHolidayType( self::REGION, 'dayAfterNewYearsDay', - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1998), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1998), Holiday::TYPE_OFFICIAL ); $this->assertHolidayType( self::REGION, 'twoDaysLaterNewYearsDay', - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1990), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1989), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/SouthKorea/SeollalTest.php b/tests/SouthKorea/SeollalTest.php index 5c5d556dd..c0c081bb4 100644 --- a/tests/SouthKorea/SeollalTest.php +++ b/tests/SouthKorea/SeollalTest.php @@ -1,175 +1,192 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\Provider\SouthKorea; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Seollal (Korean New Year's Day) in South Korea. */ -class SeollalTest extends SouthKoreaBaseTestCase implements YasumiTestCaseInterface +class SeollalTest extends SouthKoreaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'seollal'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1985; + /** + * The year of upper limit for tests of lunar date. + */ + public const LUNAR_TEST_LIMIT = 2050; + /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $date = new DateTime(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year], new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + $date = new \DateTime(self::LUNAR_HOLIDAY[self::HOLIDAY][$year], new \DateTimeZone(self::TIMEZONE)); + if ($year >= 1985) { // Seollal $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); + } - if ($year >= 1990) { - // Day before Seollal - $this->assertHoliday( - self::REGION, - 'dayBeforeSeollal', - $year, - (clone $date)->sub(new DateInterval('P1D')) - ); - - // Day after Seollal - $this->assertHoliday( - self::REGION, - 'dayAfterSeollal', - $year, - (clone $date)->add(new DateInterval('P1D')) - ); - } + if ($year >= 1989) { + // Day before Seollal + $this->assertHoliday( + self::REGION, + 'dayBeforeSeollal', + $year, + (clone $date)->sub(new \DateInterval('P1D')) + ); + // Day after Seollal + $this->assertHoliday( + self::REGION, + 'dayAfterSeollal', + $year, + (clone $date)->add(new \DateInterval('P1D')) + ); } } /** * Tests the substitute holiday defined in this test (conflict with Sunday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testSubstituteHolidayBySunday() + public function testSubstituteHoliday(): void { - $this->assertHoliday( + $tz = new \DateTimeZone(self::TIMEZONE); + + // Before 2022 + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayBeforeSeollal', + 'dayBeforeSeollal', 2016, - new DateTime('2016-2-10', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2016-2-10', $tz) ); - $this->assertHoliday( + $this->assertNotSubstituteHoliday(self::REGION, 'dayAfterSeollal', 2021); + + // By sunday + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:seollal', + 'dayBeforeSeollal', + 2033, + new \DateTime('2033-2-2', $tz) + ); + $this->assertSubstituteHoliday( + self::REGION, + 'seollal', 2034, - new DateTime('2034-2-21', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2034-2-21', $tz) ); - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:dayAfterSeollal', + 'dayAfterSeollal', 2024, - new DateTime('2024-2-12', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2024-2-12', $tz) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { - $this->assertTranslatedHolidayName( + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => '설날'] + ); + + if ($year >= 1990) { + $this->assertHolidayType( + self::REGION, + 'dayBeforeSeollal', + $year, + Holiday::TYPE_OFFICIAL + ); + $this->assertHolidayType( self::REGION, - self::HOLIDAY, + 'dayAfterSeollal', $year, - [self::LOCALE => '설날'] + Holiday::TYPE_OFFICIAL ); - if ($year >= 1990) { - $this->assertHolidayType( - self::REGION, - 'dayBeforeSeollal', - $year, - Holiday::TYPE_OFFICIAL - ); - $this->assertHolidayType( - self::REGION, - 'dayAfterSeollal', - $year, - Holiday::TYPE_OFFICIAL - ); - } } } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 2050); - if (isset(SouthKorea::LUNAR_HOLIDAY[self::HOLIDAY][$year])) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::LUNAR_TEST_LIMIT); + + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $year, + Holiday::TYPE_OFFICIAL + ); + + if ($year >= 1990) { + $this->assertHolidayType( + self::REGION, + 'dayBeforeSeollal', + $year, + Holiday::TYPE_OFFICIAL + ); $this->assertHolidayType( self::REGION, - self::HOLIDAY, + 'dayAfterSeollal', $year, Holiday::TYPE_OFFICIAL ); - if ($year >= 1990) { - $this->assertHolidayType( - self::REGION, - 'dayBeforeSeollal', - $year, - Holiday::TYPE_OFFICIAL - ); - $this->assertHolidayType( - self::REGION, - 'dayAfterSeollal', - $year, - Holiday::TYPE_OFFICIAL - ); - } } } } diff --git a/tests/SouthKorea/SouthKoreaBaseTestCase.php b/tests/SouthKorea/SouthKoreaBaseTestCase.php index 95aadfa97..6a0fe61fe 100644 --- a/tests/SouthKorea/SouthKoreaBaseTestCase.php +++ b/tests/SouthKorea/SouthKoreaBaseTestCase.php @@ -1,14 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; @@ -23,18 +27,85 @@ abstract class SouthKoreaBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'SouthKorea'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Asia/Seoul'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'ko_KR'; + + /** Lunar dates for lunar holidays */ + public const LUNAR_HOLIDAY = [ + 'seollal' => [ + '1949' => '1949-01-29', '1950' => '1950-02-17', '1951' => '1951-02-06', '1952' => '1952-01-27', '1953' => '1953-02-14', + '1954' => '1954-02-04', '1955' => '1955-01-24', '1956' => '1956-02-12', '1957' => '1957-01-31', '1958' => '1958-02-19', + '1959' => '1959-02-08', '1960' => '1960-01-28', '1961' => '1961-02-15', '1962' => '1962-02-05', '1963' => '1963-01-25', + '1964' => '1964-02-13', '1965' => '1965-02-02', '1966' => '1966-01-22', '1967' => '1967-02-09', '1968' => '1968-01-30', + '1969' => '1969-02-17', '1970' => '1970-02-06', '1971' => '1971-01-27', '1972' => '1972-02-15', '1973' => '1973-02-03', + '1974' => '1974-01-23', '1975' => '1975-02-11', '1976' => '1976-01-31', '1977' => '1977-02-18', '1978' => '1978-02-07', + '1979' => '1979-01-28', '1980' => '1980-02-16', '1981' => '1981-02-05', '1982' => '1982-01-25', '1983' => '1983-02-13', + '1984' => '1984-02-02', '1985' => '1985-02-20', '1986' => '1986-02-09', '1987' => '1987-01-29', '1988' => '1988-02-18', + '1989' => '1989-02-06', '1990' => '1990-01-27', '1991' => '1991-02-15', '1992' => '1992-02-04', '1993' => '1993-01-23', + '1994' => '1994-02-10', '1995' => '1995-01-31', '1996' => '1996-02-19', '1997' => '1997-02-08', '1998' => '1998-01-28', + '1999' => '1999-02-16', '2000' => '2000-02-05', '2001' => '2001-01-24', '2002' => '2002-02-12', '2003' => '2003-02-01', + '2004' => '2004-01-22', '2005' => '2005-02-09', '2006' => '2006-01-29', '2007' => '2007-02-18', '2008' => '2008-02-07', + '2009' => '2009-01-26', '2010' => '2010-02-14', '2011' => '2011-02-03', '2012' => '2012-01-23', '2013' => '2013-02-10', + '2014' => '2014-01-31', '2015' => '2015-02-19', '2016' => '2016-02-08', '2017' => '2017-01-28', '2018' => '2018-02-16', + '2019' => '2019-02-05', '2020' => '2020-01-25', '2021' => '2021-02-12', '2022' => '2022-02-01', '2023' => '2023-01-22', + '2024' => '2024-02-10', '2025' => '2025-01-29', '2026' => '2026-02-17', '2027' => '2027-02-07', '2028' => '2028-01-27', + '2029' => '2029-02-13', '2030' => '2030-02-03', '2031' => '2031-01-23', '2032' => '2032-02-11', '2033' => '2033-01-31', + '2034' => '2034-02-19', '2035' => '2035-02-08', '2036' => '2036-01-28', '2037' => '2037-02-15', '2038' => '2038-02-04', + '2039' => '2039-01-24', '2040' => '2040-02-12', '2041' => '2041-02-01', '2042' => '2042-01-22', '2043' => '2043-02-10', + '2044' => '2044-01-30', '2045' => '2045-02-17', '2046' => '2046-02-06', '2047' => '2047-01-26', '2048' => '2048-02-14', + '2049' => '2049-02-02', '2050' => '2050-01-23', + ], + 'buddhasBirthday' => [ + '1949' => '1949-05-05', '1950' => '1950-05-24', '1951' => '1951-05-13', '1952' => '1952-05-01', '1953' => '1953-05-20', + '1954' => '1954-05-10', '1955' => '1955-05-29', '1956' => '1956-05-17', '1957' => '1957-05-07', '1958' => '1958-05-26', + '1959' => '1959-05-15', '1960' => '1960-05-03', '1961' => '1961-05-22', '1962' => '1962-05-11', '1963' => '1963-05-01', + '1964' => '1964-05-19', '1965' => '1965-05-08', '1966' => '1966-05-27', '1967' => '1967-05-16', '1968' => '1968-05-05', + '1969' => '1969-05-23', '1970' => '1970-05-12', '1971' => '1971-05-02', '1972' => '1972-05-20', '1973' => '1973-05-10', + '1974' => '1974-04-29', '1975' => '1975-05-18', '1976' => '1976-05-06', '1977' => '1977-05-25', '1978' => '1978-05-14', + '1979' => '1979-05-03', '1980' => '1980-05-21', '1981' => '1981-05-11', '1982' => '1982-05-01', '1983' => '1983-05-20', + '1984' => '1984-05-08', '1985' => '1985-05-27', '1986' => '1986-05-16', '1987' => '1987-05-05', '1988' => '1988-05-23', + '1989' => '1989-05-12', '1990' => '1990-05-02', '1991' => '1991-05-21', '1992' => '1992-05-10', '1993' => '1993-05-28', + '1994' => '1994-05-18', '1995' => '1995-05-07', '1996' => '1996-05-24', '1997' => '1997-05-14', '1998' => '1998-05-03', + '1999' => '1999-05-22', '2000' => '2000-05-11', '2001' => '2001-05-01', '2002' => '2002-05-19', '2003' => '2003-05-08', + '2004' => '2004-05-26', '2005' => '2005-05-15', '2006' => '2006-05-05', '2007' => '2007-05-24', '2008' => '2008-05-12', + '2009' => '2009-05-02', '2010' => '2010-05-21', '2011' => '2011-05-10', '2012' => '2012-05-28', '2013' => '2013-05-17', + '2014' => '2014-05-06', '2015' => '2015-05-25', '2016' => '2016-05-14', '2017' => '2017-05-03', '2018' => '2018-05-22', + '2019' => '2019-05-12', '2020' => '2020-04-30', '2021' => '2021-05-19', '2022' => '2022-05-08', '2023' => '2023-05-27', + '2024' => '2024-05-15', '2025' => '2025-05-05', '2026' => '2026-05-24', '2027' => '2027-05-13', '2028' => '2028-05-02', + '2029' => '2029-05-20', '2030' => '2030-05-09', '2031' => '2031-05-28', '2032' => '2032-05-16', '2033' => '2033-05-06', + '2034' => '2034-05-25', '2035' => '2035-05-15', '2036' => '2036-05-03', '2037' => '2037-05-22', '2038' => '2038-05-11', + '2039' => '2039-04-30', '2040' => '2040-05-18', '2041' => '2041-05-07', '2042' => '2042-05-26', '2043' => '2043-05-16', + '2044' => '2044-05-05', '2045' => '2045-05-24', '2046' => '2046-05-13', '2047' => '2047-05-02', '2048' => '2048-05-20', + '2049' => '2049-05-09', '2050' => '2050-05-28', + ], + 'chuseok' => [ + '1949' => '1949-10-06', '1950' => '1950-09-26', '1951' => '1951-09-15', '1952' => '1952-10-03', '1953' => '1953-09-22', + '1954' => '1954-09-11', '1955' => '1955-09-30', '1956' => '1956-09-19', '1957' => '1957-09-08', '1958' => '1958-09-27', + '1959' => '1959-09-17', '1960' => '1960-10-05', '1961' => '1961-09-24', '1962' => '1962-09-13', '1963' => '1963-10-02', + '1964' => '1964-09-20', '1965' => '1965-09-10', '1966' => '1966-09-29', '1967' => '1967-09-18', '1968' => '1968-10-06', + '1969' => '1969-09-26', '1970' => '1970-09-15', '1971' => '1971-10-03', '1972' => '1972-09-22', '1973' => '1973-09-11', + '1974' => '1974-09-30', '1975' => '1975-09-20', '1976' => '1976-09-08', '1977' => '1977-09-27', '1978' => '1978-09-17', + '1979' => '1979-10-05', '1980' => '1980-09-23', '1981' => '1981-09-12', '1982' => '1982-10-01', '1983' => '1983-09-21', + '1984' => '1984-09-10', '1985' => '1985-09-29', '1986' => '1986-09-18', '1987' => '1987-10-07', '1988' => '1988-09-25', + '1989' => '1989-09-14', '1990' => '1990-10-03', '1991' => '1991-09-22', '1992' => '1992-09-11', '1993' => '1993-09-30', + '1994' => '1994-09-20', '1995' => '1995-09-09', '1996' => '1996-09-27', '1997' => '1997-09-16', '1998' => '1998-10-05', + '1999' => '1999-09-24', '2000' => '2000-09-12', '2001' => '2001-10-01', '2002' => '2002-09-21', '2003' => '2003-09-11', + '2004' => '2004-09-28', '2005' => '2005-09-18', '2006' => '2006-10-06', '2007' => '2007-09-25', '2008' => '2008-09-14', + '2009' => '2009-10-03', '2010' => '2010-09-22', '2011' => '2011-09-12', '2012' => '2012-09-30', '2013' => '2013-09-19', + '2014' => '2014-09-08', '2015' => '2015-09-27', '2016' => '2016-09-15', '2017' => '2017-10-04', '2018' => '2018-09-24', + '2019' => '2019-09-13', '2020' => '2020-10-01', '2021' => '2021-09-21', '2022' => '2022-09-10', '2023' => '2023-09-29', + '2024' => '2024-09-17', '2025' => '2025-10-06', '2026' => '2026-09-25', '2027' => '2027-09-15', '2028' => '2028-10-03', + '2029' => '2029-09-22', '2030' => '2030-09-12', '2031' => '2031-10-01', '2032' => '2032-09-19', '2033' => '2033-09-08', + '2034' => '2034-09-27', '2035' => '2035-09-16', '2036' => '2036-10-04', '2037' => '2037-09-24', '2038' => '2038-09-13', + '2039' => '2039-10-02', '2040' => '2040-09-21', '2041' => '2041-09-10', '2042' => '2042-09-28', '2043' => '2043-09-17', + '2044' => '2044-10-05', '2045' => '2045-09-25', '2046' => '2046-09-15', '2047' => '2047-10-04', '2048' => '2048-09-22', + '2049' => '2049-09-11', '2050' => '2050-09-30', + ], + ]; } diff --git a/tests/SouthKorea/SouthKoreaTest.php b/tests/SouthKorea/SouthKoreaTest.php index b177e8b89..b1d0195fa 100644 --- a/tests/SouthKorea/SouthKoreaTest.php +++ b/tests/SouthKorea/SouthKoreaTest.php @@ -1,97 +1,124 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\SouthKorea; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\SouthKorea; +use Yasumi\tests\ProviderTestCase; +use Yasumi\Yasumi; /** * Class for testing holidays in South Korea. */ -class SouthKoreaTest extends SouthKoreaBaseTestCase +class SouthKoreaTest extends SouthKoreaBaseTestCase implements ProviderTestCase { + /** + * @var int the year of upper limit for tests of lunar date + */ + public const LUNAR_TEST_LIMIT = 2050; + /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1949, self::LUNAR_TEST_LIMIT); + } /** - * Tests if all official holidays in South Korea are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in South Korea are defined by the provider class. */ public function testOfficialHolidays(): void { $officialHolidays = []; + if ($this->year >= 1949) { $officialHolidays[] = 'independenceMovementDay'; $officialHolidays[] = 'liberationDay'; $officialHolidays[] = 'nationalFoundationDay'; + $officialHolidays[] = 'newYearsDay'; + $officialHolidays[] = 'chuseok'; $officialHolidays[] = 'christmasDay'; - if ($this->year !== ArborDayTest::YEAR_NOT_CELEBRATED && $this->year < ArborDayTest::REMOVED_YEAR + 1) { - $officialHolidays[] = 'arborDay'; + + if ($this->year >= 1950 && $this->year < 1976) { + $officialHolidays[] = 'unitedNationsDay'; } - if ($this->year <= 1990 || $this->year > 2012) { - $officialHolidays[] = 'hangulDay'; + + if ($this->year >= 1956) { + $officialHolidays[] = 'memorialDay'; } - if ($this->year < 2008) { - $officialHolidays[] = 'constitutionDay'; + + if ($this->year >= 1975) { + $officialHolidays[] = 'childrensDay'; + $officialHolidays[] = 'buddhasBirthday'; } - } - if ($this->year >= 1950) { - $officialHolidays[] = 'newYearsDay'; - if ($this->year <= 1990) { - $officialHolidays[] = 'twoDaysLaterNewYearsDay'; + + if ($this->year >= 1976 && $this->year <= 1990) { + $officialHolidays[] = 'armedForcesDay'; } - if ($this->year <= 1998) { - $officialHolidays[] = 'dayAfterNewYearsDay'; + + if ($this->year >= 1985) { + $officialHolidays[] = 'seollal'; } - } - if ($this->year >= 1956 && $this->year <= 1990) { - $officialHolidays[] = 'armedForcesDay'; - } - if ($this->year >= 1966) { - $officialHolidays[] = 'memorialDay'; - } - // specific cases (Seollal, Buddha's Birthday and Chuseok) - if ($this->year >= 1949 && isset(SouthKorea::LUNAR_HOLIDAY['chuseok'][$this->year])) { - $officialHolidays[] = 'chuseok'; if ($this->year >= 1986) { $officialHolidays[] = 'dayAfterChuseok'; } + if ($this->year >= 1989) { $officialHolidays[] = 'dayBeforeChuseok'; - } - } - if ($this->year >= 1975 && isset(SouthKorea::LUNAR_HOLIDAY['buddhasBirthday'][$this->year])) { - $officialHolidays[] = 'buddhasBirthday'; - } - if ($this->year >= 1985 && isset(SouthKorea::LUNAR_HOLIDAY['seollal'][$this->year])) { - $officialHolidays[] = 'seollal'; - if ($this->year > 1989) { $officialHolidays[] = 'dayBeforeSeollal'; $officialHolidays[] = 'dayAfterSeollal'; } + + if ($this->year <= 1989) { + $officialHolidays[] = 'twoDaysLaterNewYearsDay'; + } + + if ($this->year <= 1990 || $this->year > 2012) { + $officialHolidays[] = 'hangulDay'; + } + + if ($this->year <= 1998) { + $officialHolidays[] = 'dayAfterNewYearsDay'; + } + + if ($this->year <= 2005) { + $officialHolidays[] = 'arborDay'; + } + + if ($this->year < 2008) { + $officialHolidays[] = 'constitutionDay'; + } } $this->assertDefinedHolidays($officialHolidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in South Korea are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in South Korea are defined by the provider class. */ public function testObservedHolidays(): void { @@ -99,8 +126,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in South Korea are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in South Korea are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -108,8 +134,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in South Korea are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in South Korea are defined by the provider class. */ public function testBankHolidays(): void { @@ -117,8 +142,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in South Korea are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in South Korea are defined by the provider class. */ public function testOtherHolidays(): void { @@ -126,10 +150,24 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1949, 2050); + $this->assertSources(self::REGION, 3); + } + + /** + * Tests if all generation methods is exists in provider. + */ + public function testGenerationMethods(): void + { + $holidayProvider = Yasumi::create(self::REGION, $this->year); + + $this->assertIsArray(SouthKorea::HOLIDAY_NAMES, 'Yasumi\Provider\SouthKorea::HOLIDAY_NAMES is not array'); + foreach (array_keys(SouthKorea::HOLIDAY_NAMES) as $key) { + $this->assertTrue(method_exists($holidayProvider, $key), sprintf('Generation method `%s` is not declared in provider `%s`', $key, self::REGION)); + } } } diff --git a/tests/SouthKorea/UnitedNationsDayTest.php b/tests/SouthKorea/UnitedNationsDayTest.php new file mode 100644 index 000000000..79fc9b5bd --- /dev/null +++ b/tests/SouthKorea/UnitedNationsDayTest.php @@ -0,0 +1,116 @@ + + */ + +namespace Yasumi\tests\SouthKorea; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing United Nations Day in South Korea. + */ +class UnitedNationsDayTest extends SouthKoreaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'unitedNationsDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1950; + + /** + * The year in which the holiday was removed. + */ + public const REMOVED_YEAR = 1975; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test after removal. + * + * @throws \Exception + */ + public function testHolidayAfterRemoval(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::REMOVED_YEAR + 1) + ); + } + + /** + * Tests the holiday defined in this test before establishment. + * + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + [self::LOCALE => '유엔의 날'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::REMOVED_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Spain/AllSaintsDayTest.php b/tests/Spain/AllSaintsDayTest.php index 54b0293a6..a888992e9 100644 --- a/tests/Spain/AllSaintsDayTest.php +++ b/tests/Spain/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Spain. */ -class AllSaintsDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Día de todos los Santos'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/Andalusia/AndalusiaBaseTestCase.php b/tests/Spain/Andalusia/AndalusiaBaseTestCase.php index 08f188cd5..e60b0c073 100644 --- a/tests/Spain/Andalusia/AndalusiaBaseTestCase.php +++ b/tests/Spain/Andalusia/AndalusiaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Andalusia; @@ -22,13 +27,9 @@ abstract class AndalusiaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Andalusia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Andalusia/AndalusiaDayTest.php b/tests/Spain/Andalusia/AndalusiaDayTest.php index 20e3a9095..cd80d8e02 100644 --- a/tests/Spain/Andalusia/AndalusiaDayTest.php +++ b/tests/Spain/Andalusia/AndalusiaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Andalusia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Andalusia Day in Andalusia (Spain). */ -class AndalusiaDayTest extends AndalusiaBaseTestCase implements YasumiTestCaseInterface +class AndalusiaDayTest extends AndalusiaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'andalusiaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1980; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Andalucía'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Andalusia/AndalusiaTest.php b/tests/Spain/Andalusia/AndalusiaTest.php index 71be400f8..adb91d8b5 100644 --- a/tests/Spain/Andalusia/AndalusiaTest.php +++ b/tests/Spain/Andalusia/AndalusiaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Andalusia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Andalusia (Spain). */ -class AndalusiaTest extends AndalusiaBaseTestCase +class AndalusiaTest extends AndalusiaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Andalusia (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Andalusia (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Andalusia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Andalusia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Andalusia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Andalusia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Andalusia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Andalusia are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Andalusia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Andalusia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Aragon/AragonBaseTestCase.php b/tests/Spain/Aragon/AragonBaseTestCase.php index 1b0f684b4..0bc46075d 100644 --- a/tests/Spain/Aragon/AragonBaseTestCase.php +++ b/tests/Spain/Aragon/AragonBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Aragon; @@ -22,13 +27,9 @@ abstract class AragonBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Aragon'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Aragon/AragonTest.php b/tests/Spain/Aragon/AragonTest.php index 25fa90d5d..907b8b6ee 100644 --- a/tests/Spain/Aragon/AragonTest.php +++ b/tests/Spain/Aragon/AragonTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Aragon; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Aragon (Spain). */ -class AragonTest extends AragonBaseTestCase +class AragonTest extends AragonBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Aragon (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Aragon (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -46,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Aragon are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Aragon are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Aragon are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Aragon are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Aragon are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Aragon are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Aragon are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Aragon are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Aragon/StGeorgesDayTest.php b/tests/Spain/Aragon/StGeorgesDayTest.php index ccd266284..8699312df 100644 --- a/tests/Spain/Aragon/StGeorgesDayTest.php +++ b/tests/Spain/Aragon/StGeorgesDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Aragon; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. George's Day in Aragon (Spain). */ -class StGeorgesDayTest extends AragonBaseTestCase implements YasumiTestCaseInterface +class StGeorgesDayTest extends AragonBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stGeorgesDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'San Jorge'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Spain/AssumptionOfMaryTest.php b/tests/Spain/AssumptionOfMaryTest.php index 948dd4b95..f09e2900b 100644 --- a/tests/Spain/AssumptionOfMaryTest.php +++ b/tests/Spain/AssumptionOfMaryTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Spain. */ -class AssumptionOfMaryTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Asunción de la Virgen María'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/Asturias/AsturiasBaseTestCase.php b/tests/Spain/Asturias/AsturiasBaseTestCase.php index b2a5642a9..cb87af2db 100644 --- a/tests/Spain/Asturias/AsturiasBaseTestCase.php +++ b/tests/Spain/Asturias/AsturiasBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Asturias; @@ -22,13 +27,9 @@ abstract class AsturiasBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Asturias'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Asturias/AsturiasDayTest.php b/tests/Spain/Asturias/AsturiasDayTest.php index dd80c6475..4f4f04d81 100644 --- a/tests/Spain/Asturias/AsturiasDayTest.php +++ b/tests/Spain/Asturias/AsturiasDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Asturias; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Asturias Day in Asturias (Spain). */ -class AsturiasDayTest extends AsturiasBaseTestCase implements YasumiTestCaseInterface +class AsturiasDayTest extends AsturiasBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'asturiasDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1984; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Asturias'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Asturias/AsturiasTest.php b/tests/Spain/Asturias/AsturiasTest.php index ab84f2b65..0727ebb59 100644 --- a/tests/Spain/Asturias/AsturiasTest.php +++ b/tests/Spain/Asturias/AsturiasTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Asturias; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Asturias (Spain). */ -class AsturiasTest extends AsturiasBaseTestCase +class AsturiasTest extends AsturiasBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1984); + } /** - * Tests if all official holidays in Asturias (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Asturias (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Asturias are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Asturias are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Asturias are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Asturias are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Asturias are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Asturias are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Asturias are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Asturias are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1984); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/BalearicIslands/BalearicIslandsBaseTestCase.php b/tests/Spain/BalearicIslands/BalearicIslandsBaseTestCase.php index 1e6fe0339..07573a154 100644 --- a/tests/Spain/BalearicIslands/BalearicIslandsBaseTestCase.php +++ b/tests/Spain/BalearicIslands/BalearicIslandsBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BalearicIslands; @@ -22,13 +27,9 @@ abstract class BalearicIslandsBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/BalearicIslands'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/BalearicIslands/BalearicIslandsDayTest.php b/tests/Spain/BalearicIslands/BalearicIslandsDayTest.php index 23db2daeb..ea0e917fb 100644 --- a/tests/Spain/BalearicIslands/BalearicIslandsDayTest.php +++ b/tests/Spain/BalearicIslands/BalearicIslandsDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BalearicIslands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Day of the Balearic Islands in the Balearic Islands (Spain). */ -class BalearicIslandsDayTest extends BalearicIslandsBaseTestCase implements YasumiTestCaseInterface +class BalearicIslandsDayTest extends BalearicIslandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'balearicIslandsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1983; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de les Illes Balears'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/BalearicIslands/BalearicIslandsTest.php b/tests/Spain/BalearicIslands/BalearicIslandsTest.php index cc6c97d30..8a139765d 100644 --- a/tests/Spain/BalearicIslands/BalearicIslandsTest.php +++ b/tests/Spain/BalearicIslands/BalearicIslandsTest.php @@ -1,40 +1,53 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BalearicIslands; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Balearic Islands (Spain). */ -class BalearicIslandsTest extends BalearicIslandsBaseTestCase +class BalearicIslandsTest extends BalearicIslandsBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in the Balearic Islands (Spain) are defined by the provider class - * @throws ReflectionException + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } + + /** + * Tests if all official holidays in the Balearic Islands (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $holidays = [ 'newYearsDay', 'epiphany', - 'balearicIslandsDay', 'goodFriday', 'internationalWorkersDay', 'assumptionOfMary', @@ -43,12 +56,17 @@ public function testOfficialHolidays(): void 'constitutionDay', 'immaculateConception', 'christmasDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if ($this->year >= 1983) { + $holidays[] = 'balearicIslandsDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in the Balearic Islands are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Balearic Islands are defined by the provider class. */ public function testObservedHolidays(): void { @@ -62,8 +80,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the Balearic Islands are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Balearic Islands are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -71,8 +88,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Balearic Islands are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Balearic Islands are defined by the provider class. */ public function testBankHolidays(): void { @@ -80,8 +96,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Balearic Islands are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Balearic Islands are defined by the provider class. */ public function testOtherHolidays(): void { @@ -89,10 +104,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/BasqueCountry/BasqueCountryBaseTestCase.php b/tests/Spain/BasqueCountry/BasqueCountryBaseTestCase.php index b6f1f9099..381e13754 100644 --- a/tests/Spain/BasqueCountry/BasqueCountryBaseTestCase.php +++ b/tests/Spain/BasqueCountry/BasqueCountryBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BasqueCountry; @@ -22,13 +27,9 @@ abstract class BasqueCountryBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/BasqueCountry'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/BasqueCountry/BasqueCountryDayTest.php b/tests/Spain/BasqueCountry/BasqueCountryDayTest.php index ce86f198a..7749e6de6 100644 --- a/tests/Spain/BasqueCountry/BasqueCountryDayTest.php +++ b/tests/Spain/BasqueCountry/BasqueCountryDayTest.php @@ -1,106 +1,111 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BasqueCountry; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Basque Country Day in Basque Country (Spain). */ -class BasqueCountryDayTest extends BasqueCountryBaseTestCase implements YasumiTestCaseInterface +class BasqueCountryDayTest extends BasqueCountryBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'basqueCountryDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2011; /** - * The year in which the holiday was abolished + * The year in which the holiday was abolished. */ public const ABOLISHMENT_YEAR = 2013; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the holiday defined in this test after abolishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayDayAfterAbolishment() + public function testHolidayDayAfterAbolishment(): void { - $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ABOLISHMENT_YEAR + 1)); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ABOLISHMENT_YEAR + 1)); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR), [self::LOCALE => 'Euskadi Eguna'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ABOLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/BasqueCountry/BasqueCountryTest.php b/tests/Spain/BasqueCountry/BasqueCountryTest.php index 928074d9f..78faad925 100644 --- a/tests/Spain/BasqueCountry/BasqueCountryTest.php +++ b/tests/Spain/BasqueCountry/BasqueCountryTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\BasqueCountry; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Basque Country (Spain). */ -class BasqueCountryTest extends BasqueCountryBaseTestCase +class BasqueCountryTest extends BasqueCountryBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2011, 2013); + } /** - * Tests if all official holidays in Basque Country (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Basque Country (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Basque Country are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Basque Country are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Basque Country are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Basque Country are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Basque Country are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Basque Country are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Basque Country are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Basque Country are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2011, 2013); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/CanaryIslands/CanaryIslandsBaseTestCase.php b/tests/Spain/CanaryIslands/CanaryIslandsBaseTestCase.php index 5372b33df..2f23af9ef 100644 --- a/tests/Spain/CanaryIslands/CanaryIslandsBaseTestCase.php +++ b/tests/Spain/CanaryIslands/CanaryIslandsBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CanaryIslands; @@ -22,13 +27,9 @@ abstract class CanaryIslandsBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/CanaryIslands'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Atlantic/Canary'; } diff --git a/tests/Spain/CanaryIslands/CanaryIslandsDayTest.php b/tests/Spain/CanaryIslands/CanaryIslandsDayTest.php index aaa7bd532..647309602 100644 --- a/tests/Spain/CanaryIslands/CanaryIslandsDayTest.php +++ b/tests/Spain/CanaryIslands/CanaryIslandsDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CanaryIslands; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Canary Islands Day in the Canary Islands (Spain). */ -class CanaryIslandsDayTest extends CanaryIslandsBaseTestCase implements YasumiTestCaseInterface +class CanaryIslandsDayTest extends CanaryIslandsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'canaryIslandsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1984; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de las Canarias'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/CanaryIslands/CanaryIslandsTest.php b/tests/Spain/CanaryIslands/CanaryIslandsTest.php index 462c6ae2f..0be6630ae 100644 --- a/tests/Spain/CanaryIslands/CanaryIslandsTest.php +++ b/tests/Spain/CanaryIslands/CanaryIslandsTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CanaryIslands; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Canary Islands (Spain). */ -class CanaryIslandsTest extends CanaryIslandsBaseTestCase +class CanaryIslandsTest extends CanaryIslandsBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1984); + } /** - * Tests if all official holidays in the Canary Islands (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the Canary Islands (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the Canary Islands are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Canary Islands are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the Canary Islands are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Canary Islands are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Canary Islands are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Canary Islands are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Canary Islands are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Canary Islands are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1984); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Cantabria/CantabriaBaseTestCase.php b/tests/Spain/Cantabria/CantabriaBaseTestCase.php index e42f2255b..76891f296 100644 --- a/tests/Spain/Cantabria/CantabriaBaseTestCase.php +++ b/tests/Spain/Cantabria/CantabriaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Cantabria; @@ -22,13 +27,9 @@ abstract class CantabriaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Cantabria'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Cantabria/CantabriaDayTest.php b/tests/Spain/Cantabria/CantabriaDayTest.php index e7d5db5f1..78d21c730 100644 --- a/tests/Spain/Cantabria/CantabriaDayTest.php +++ b/tests/Spain/Cantabria/CantabriaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Cantabria; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Cantabria Day in Cantabria (Spain). */ -class CantabriaDayTest extends CantabriaBaseTestCase implements YasumiTestCaseInterface +class CantabriaDayTest extends CantabriaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'cantabriaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1967; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("second sunday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("second sunday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Cantabria'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Cantabria/CantabriaTest.php b/tests/Spain/Cantabria/CantabriaTest.php index 29081edfe..0f93c62e9 100644 --- a/tests/Spain/Cantabria/CantabriaTest.php +++ b/tests/Spain/Cantabria/CantabriaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Cantabria; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Cantabria (Spain). */ -class CantabriaTest extends CantabriaBaseTestCase +class CantabriaTest extends CantabriaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Cantabria (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Cantabria (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Cantabria are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Cantabria are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Cantabria are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Cantabria are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Cantabria are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Cantabria are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Cantabria are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Cantabria are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/CastileAndLeon/CastileAndLeonBaseTestCase.php b/tests/Spain/CastileAndLeon/CastileAndLeonBaseTestCase.php index bac8f0583..57dd23bf9 100644 --- a/tests/Spain/CastileAndLeon/CastileAndLeonBaseTestCase.php +++ b/tests/Spain/CastileAndLeon/CastileAndLeonBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastileAndLeon; @@ -22,13 +27,9 @@ abstract class CastileAndLeonBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/CastileAndLeon'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/CastileAndLeon/CastileAndLeonDayTest.php b/tests/Spain/CastileAndLeon/CastileAndLeonDayTest.php index ecab9b16d..58aca932c 100644 --- a/tests/Spain/CastileAndLeon/CastileAndLeonDayTest.php +++ b/tests/Spain/CastileAndLeon/CastileAndLeonDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastileAndLeon; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Castile and León Day in Castile and León (Spain). */ -class CastileAndLeonDayTest extends CastileAndLeonBaseTestCase implements YasumiTestCaseInterface +class CastileAndLeonDayTest extends CastileAndLeonBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'castileAndLeonDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1976; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Castilla y León'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/CastileAndLeon/CastileAndLeonTest.php b/tests/Spain/CastileAndLeon/CastileAndLeonTest.php index 28cb06e5c..4acb64e55 100644 --- a/tests/Spain/CastileAndLeon/CastileAndLeonTest.php +++ b/tests/Spain/CastileAndLeon/CastileAndLeonTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastileAndLeon; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Castile And Leon (Spain). */ -class CastileAndLeonTest extends CastileAndLeonBaseTestCase +class CastileAndLeonTest extends CastileAndLeonBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Castile And Leon (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Castile And Leon (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Castile And Leon are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Castile And Leon are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Castile And Leon are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Castile And Leon are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Castile And Leon are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Castile And Leon are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Castile And Leon are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Castile And Leon are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/CastillaLaMancha/CastillaLaManchaBaseTestCase.php b/tests/Spain/CastillaLaMancha/CastillaLaManchaBaseTestCase.php index 30d9657e5..3c33a6dcc 100644 --- a/tests/Spain/CastillaLaMancha/CastillaLaManchaBaseTestCase.php +++ b/tests/Spain/CastillaLaMancha/CastillaLaManchaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastillaLaMancha; @@ -22,13 +27,9 @@ abstract class CastillaLaManchaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/CastillaLaMancha'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/CastillaLaMancha/CastillaLaManchaDayTest.php b/tests/Spain/CastillaLaMancha/CastillaLaManchaDayTest.php index 23934d0e9..3f3d4eaa2 100644 --- a/tests/Spain/CastillaLaMancha/CastillaLaManchaDayTest.php +++ b/tests/Spain/CastillaLaMancha/CastillaLaManchaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastillaLaMancha; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Castilla-La Mancha Day in Castilla-La Mancha (Spain). */ -class CastillaLaManchaDayTest extends CastillaLaManchaBaseTestCase implements YasumiTestCaseInterface +class CastillaLaManchaDayTest extends CastillaLaManchaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'castillaLaManchaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1984; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-31", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-31", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de la Región Castilla-La Mancha'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/CastillaLaMancha/CastillaLaManchaTest.php b/tests/Spain/CastillaLaMancha/CastillaLaManchaTest.php index 7c708ce4b..4b08d940a 100644 --- a/tests/Spain/CastillaLaMancha/CastillaLaManchaTest.php +++ b/tests/Spain/CastillaLaMancha/CastillaLaManchaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CastillaLaMancha; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Castilla-La Mancha (Spain). */ -class CastillaLaManchaTest extends CastillaLaManchaBaseTestCase +class CastillaLaManchaTest extends CastillaLaManchaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1984); + } /** - * Tests if all official holidays in Castilla-La Mancha (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Castilla-La Mancha (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Castilla-La Mancha are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Castilla-La Mancha are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Castilla-La Mancha are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Castilla-La Mancha are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Castilla-La Mancha are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Castilla-La Mancha are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Castilla-La Mancha are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Castilla-La Mancha are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1984); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Catalonia/CataloniaBaseTestCase.php b/tests/Spain/Catalonia/CataloniaBaseTestCase.php index fbf24dbc9..5f90e9ead 100644 --- a/tests/Spain/Catalonia/CataloniaBaseTestCase.php +++ b/tests/Spain/Catalonia/CataloniaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Catalonia; @@ -22,13 +27,9 @@ abstract class CataloniaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Catalonia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Catalonia/CataloniaTest.php b/tests/Spain/Catalonia/CataloniaTest.php index 44ca20e70..58e126091 100644 --- a/tests/Spain/Catalonia/CataloniaTest.php +++ b/tests/Spain/Catalonia/CataloniaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Catalonia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Catalonia (Spain). */ -class CataloniaTest extends CataloniaBaseTestCase +class CataloniaTest extends CataloniaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Catalonia (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Catalonia (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Catalonia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Catalonia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -61,8 +74,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Catalonia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Catalonia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -70,8 +82,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Catalonia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Catalonia are defined by the provider class. */ public function testBankHolidays(): void { @@ -79,8 +90,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Catalonia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Catalonia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -88,10 +98,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Catalonia/nationalCataloniaDayTest.php b/tests/Spain/Catalonia/nationalCataloniaDayTest.php index a04a09da2..dc787feba 100644 --- a/tests/Spain/Catalonia/nationalCataloniaDayTest.php +++ b/tests/Spain/Catalonia/nationalCataloniaDayTest.php @@ -1,92 +1,99 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Catalonia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Catalonia in Catalonia (Spain). */ -class nationalCataloniaDayTest extends CataloniaBaseTestCase implements YasumiTestCaseInterface +class nationalCataloniaDayTest extends CataloniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalCataloniaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1886; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-11", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Diada Nacional de Catalunya'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + 'es' => 'Diada Nacional de Cataluña', + 'ca' => 'Diada Nacional de Catalunya', + ] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Catalonia/stJohnsDayTest.php b/tests/Spain/Catalonia/stJohnsDayTest.php index 1d795a6e9..62dfd41f5 100644 --- a/tests/Spain/Catalonia/stJohnsDayTest.php +++ b/tests/Spain/Catalonia/stJohnsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Catalonia; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. John's Day in Catalonia (Spain). */ -class stJohnsDayTest extends CataloniaBaseTestCase implements YasumiTestCaseInterface +class stJohnsDayTest extends CataloniaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(6, 24, self::TIMEZONE); + return static::generateRandomDates(6, 24, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Sant Joan'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Spain/Ceuta/CeutaBaseTestCase.php b/tests/Spain/Ceuta/CeutaBaseTestCase.php index 75603c751..aa9b046c0 100644 --- a/tests/Spain/Ceuta/CeutaBaseTestCase.php +++ b/tests/Spain/Ceuta/CeutaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Ceuta; @@ -22,13 +27,9 @@ abstract class CeutaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Ceuta'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Ceuta/CeutaTest.php b/tests/Spain/Ceuta/CeutaTest.php index fa1258216..01598897f 100644 --- a/tests/Spain/Ceuta/CeutaTest.php +++ b/tests/Spain/Ceuta/CeutaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Ceuta; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Ceuta (Spain). */ -class CeutaTest extends CeutaBaseTestCase +class CeutaTest extends CeutaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Ceuta (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Ceuta (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Ceuta are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Ceuta are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Ceuta are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Ceuta are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Ceuta are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Ceuta are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Ceuta are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Ceuta are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Ceuta/ceutaDayTest.php b/tests/Spain/Ceuta/ceutaDayTest.php index 074524b90..f38baa957 100644 --- a/tests/Spain/Ceuta/ceutaDayTest.php +++ b/tests/Spain/Ceuta/ceutaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Ceuta; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Ceuta Day in Ceuta (Spain). */ -class ceutaDayTest extends CeutaBaseTestCase implements YasumiTestCaseInterface +class ceutaDayTest extends CeutaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ceutaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1416; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Ceuta'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/ChristmasTest.php b/tests/Spain/ChristmasTest.php index de5b8b2e9..d3d95b9c4 100644 --- a/tests/Spain/ChristmasTest.php +++ b/tests/Spain/ChristmasTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Spain. */ -class ChristmasTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class ChristmasTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Navidad'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/CommunityOfMadrid/CommunityOfMadridBaseTestCase.php b/tests/Spain/CommunityOfMadrid/CommunityOfMadridBaseTestCase.php index e358273da..2d3cf8dc4 100644 --- a/tests/Spain/CommunityOfMadrid/CommunityOfMadridBaseTestCase.php +++ b/tests/Spain/CommunityOfMadrid/CommunityOfMadridBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CommunityOfMadrid; @@ -22,13 +27,9 @@ abstract class CommunityOfMadridBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/CommunityOfMadrid'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/CommunityOfMadrid/CommunityOfMadridTest.php b/tests/Spain/CommunityOfMadrid/CommunityOfMadridTest.php index 8bb8bcae1..ecc27265f 100644 --- a/tests/Spain/CommunityOfMadrid/CommunityOfMadridTest.php +++ b/tests/Spain/CommunityOfMadrid/CommunityOfMadridTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CommunityOfMadrid; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Community of Madrid (Spain). */ -class CommunityOfMadridTest extends CommunityOfMadridBaseTestCase +class CommunityOfMadridTest extends CommunityOfMadridBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in the Community of Madrid (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the Community of Madrid (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the Community of Madrid are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Community of Madrid are defined by the provider class. */ public function testObservedHolidays(): void { @@ -61,8 +74,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the Community of Madrid are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Community of Madrid are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -70,8 +82,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Community of Madrid are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Community of Madrid are defined by the provider class. */ public function testBankHolidays(): void { @@ -79,8 +90,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Community of Madrid are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Community of Madrid are defined by the provider class. */ public function testOtherHolidays(): void { @@ -88,10 +98,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/CommunityOfMadrid/DosdeMayoUprisingDayTest.php b/tests/Spain/CommunityOfMadrid/DosdeMayoUprisingDayTest.php index c0e083e97..520e3e572 100644 --- a/tests/Spain/CommunityOfMadrid/DosdeMayoUprisingDayTest.php +++ b/tests/Spain/CommunityOfMadrid/DosdeMayoUprisingDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\CommunityOfMadrid; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for the day of Dos de Mayo Uprising in the Community of Madrid (Spain). */ -class DosdeMayoUprisingDayTest extends CommunityOfMadridBaseTestCase implements YasumiTestCaseInterface +class DosdeMayoUprisingDayTest extends CommunityOfMadridBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'dosdeMayoUprisingDay'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fiesta de la Comunidad de Madrid'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/ConstitutionDayTest.php b/tests/Spain/ConstitutionDayTest.php index 708da0a09..18836afe4 100644 --- a/tests/Spain/ConstitutionDayTest.php +++ b/tests/Spain/ConstitutionDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Day of the Constitution in Spain. */ -class ConstitutionDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constitutionDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-6", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de la Constitución'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/EasterMondayTest.php b/tests/Spain/EasterMondayTest.php index af7bf8dab..b787e48d1 100644 --- a/tests/Spain/EasterMondayTest.php +++ b/tests/Spain/EasterMondayTest.php @@ -1,31 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Spain. */ -class EasterMondayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; @@ -37,40 +38,42 @@ class EasterMondayTest extends SpainBaseTestCase implements YasumiTestCaseInterf /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2216; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lunes de Pascua'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Spain/EpiphanyTest.php b/tests/Spain/EpiphanyTest.php index c52080925..c75024883 100644 --- a/tests/Spain/EpiphanyTest.php +++ b/tests/Spain/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Spain. */ -class EpiphanyTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Día de Reyes'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/Extremadura/ExtremaduraBaseTestCase.php b/tests/Spain/Extremadura/ExtremaduraBaseTestCase.php index 513b3e897..bb53acce1 100644 --- a/tests/Spain/Extremadura/ExtremaduraBaseTestCase.php +++ b/tests/Spain/Extremadura/ExtremaduraBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Extremadura; @@ -22,13 +27,9 @@ abstract class ExtremaduraBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Extremadura'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Extremadura/ExtremaduraDayTest.php b/tests/Spain/Extremadura/ExtremaduraDayTest.php index 95e35a2b2..55e9c472c 100644 --- a/tests/Spain/Extremadura/ExtremaduraDayTest.php +++ b/tests/Spain/Extremadura/ExtremaduraDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Extremadura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Extremadura Day in Extremadura (Spain). */ -class ExtremaduraDayTest extends ExtremaduraBaseTestCase implements YasumiTestCaseInterface +class ExtremaduraDayTest extends ExtremaduraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'extremaduraDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1985; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-9-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-9-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de Extremadura'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Extremadura/ExtremaduraTest.php b/tests/Spain/Extremadura/ExtremaduraTest.php index f80dbeb61..19d92c339 100644 --- a/tests/Spain/Extremadura/ExtremaduraTest.php +++ b/tests/Spain/Extremadura/ExtremaduraTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Extremadura; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Extremadura (Spain). */ -class ExtremaduraTest extends ExtremaduraBaseTestCase +class ExtremaduraTest extends ExtremaduraBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1985); + } /** - * Tests if all official holidays in Extremadura (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Extremadura (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Extremadura are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Extremadura are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Extremadura are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Extremadura are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Extremadura are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Extremadura are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Extremadura are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Extremadura are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1984); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Galicia/GaliciaBaseTestCase.php b/tests/Spain/Galicia/GaliciaBaseTestCase.php index 2672db84e..eab9e9c52 100644 --- a/tests/Spain/Galicia/GaliciaBaseTestCase.php +++ b/tests/Spain/Galicia/GaliciaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Galicia; @@ -22,13 +27,9 @@ abstract class GaliciaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Galicia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/Galicia/GaliciaTest.php b/tests/Spain/Galicia/GaliciaTest.php index 22164492d..52a237518 100644 --- a/tests/Spain/Galicia/GaliciaTest.php +++ b/tests/Spain/Galicia/GaliciaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Galicia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Galicia (Spain). */ -class GaliciaTest extends GaliciaBaseTestCase +class GaliciaTest extends GaliciaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2000); + } /** - * Tests if all official holidays in Galicia (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Galicia (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -48,8 +62,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Galicia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Galicia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -61,8 +74,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Galicia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Galicia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -70,8 +82,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Galicia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Galicia are defined by the provider class. */ public function testBankHolidays(): void { @@ -79,8 +90,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Galicia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Galicia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -88,10 +98,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2000); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/Galicia/GalicianLiteratureDayTest.php b/tests/Spain/Galicia/GalicianLiteratureDayTest.php index d7eeb1025..4d0217fd0 100644 --- a/tests/Spain/Galicia/GalicianLiteratureDayTest.php +++ b/tests/Spain/Galicia/GalicianLiteratureDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Galicia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Galician Literature Day in Galicia (Spain). */ -class GalicianLiteratureDayTest extends GaliciaBaseTestCase implements YasumiTestCaseInterface +class GalicianLiteratureDayTest extends GaliciaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'galicianLiteratureDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1991; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de las Letras Gallegas'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Galicia/stJamesDayTest.php b/tests/Spain/Galicia/stJamesDayTest.php index 1859d35d3..67a179ec9 100644 --- a/tests/Spain/Galicia/stJamesDayTest.php +++ b/tests/Spain/Galicia/stJamesDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Galicia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. James Day in Galicia (Spain). */ -class stJamesDayTest extends GaliciaBaseTestCase implements YasumiTestCaseInterface +class stJamesDayTest extends GaliciaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJamesDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2000; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Santiago Apostol'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/GoodFridayTest.php b/tests/Spain/GoodFridayTest.php index 33ed82f4e..f0cd1c83c 100644 --- a/tests/Spain/GoodFridayTest.php +++ b/tests/Spain/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Spain. */ -class GoodFridayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2066; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Viernes Santo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/ImmaculateConceptionTest.php b/tests/Spain/ImmaculateConceptionTest.php index 523b9d407..cef91a431 100644 --- a/tests/Spain/ImmaculateConceptionTest.php +++ b/tests/Spain/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Spain. */ -class ImmaculateConceptionTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Inmaculada Concepción'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/InternationalWorkersDayTest.php b/tests/Spain/InternationalWorkersDayTest.php index d04571e8e..69ca4aa13 100644 --- a/tests/Spain/InternationalWorkersDayTest.php +++ b/tests/Spain/InternationalWorkersDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Spain. */ -class InternationalWorkersDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Día del Trabajador'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/LaRioja/LaRiojaBaseTestCase.php b/tests/Spain/LaRioja/LaRiojaBaseTestCase.php index 5f1f16687..0b0bd6737 100644 --- a/tests/Spain/LaRioja/LaRiojaBaseTestCase.php +++ b/tests/Spain/LaRioja/LaRiojaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\LaRioja; @@ -22,13 +27,9 @@ abstract class LaRiojaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/LaRioja'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/LaRioja/LaRiojaDayTest.php b/tests/Spain/LaRioja/LaRiojaDayTest.php index 3b7789828..e3cb38c83 100644 --- a/tests/Spain/LaRioja/LaRiojaDayTest.php +++ b/tests/Spain/LaRioja/LaRiojaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\LaRioja; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing La Rioja Day in La Rioja (Spain). */ -class LaRiojaDayTest extends LaRiojaBaseTestCase implements YasumiTestCaseInterface +class LaRiojaDayTest extends LaRiojaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'laRiojaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1983; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de La Rioja'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/LaRioja/LaRiojaTest.php b/tests/Spain/LaRioja/LaRiojaTest.php index 29ffdc795..357860fdf 100644 --- a/tests/Spain/LaRioja/LaRiojaTest.php +++ b/tests/Spain/LaRioja/LaRiojaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\LaRioja; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in La Rioja (Spain). */ -class LaRiojaTest extends LaRiojaBaseTestCase +class LaRiojaTest extends LaRiojaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1983); + } /** - * Tests if all official holidays in La Rioja (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in La Rioja (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in La Rioja are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in La Rioja are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in La Rioja are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in La Rioja are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in La Rioja are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in La Rioja are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in La Rioja are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in La Rioja are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1983); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/MaundyThursdayTest.php b/tests/Spain/MaundyThursdayTest.php index fbb9724a3..4be064822 100644 --- a/tests/Spain/MaundyThursdayTest.php +++ b/tests/Spain/MaundyThursdayTest.php @@ -1,31 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Maundy Thursday in Spain. */ -class MaundyThursdayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class MaundyThursdayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'maundyThursday'; @@ -37,40 +38,42 @@ class MaundyThursdayTest extends SpainBaseTestCase implements YasumiTestCaseInte /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-7", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-7", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jueves Santo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Spain/Melilla/MelillaBaseTestCase.php b/tests/Spain/Melilla/MelillaBaseTestCase.php index 6c9b72535..c47387b06 100644 --- a/tests/Spain/Melilla/MelillaBaseTestCase.php +++ b/tests/Spain/Melilla/MelillaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Melilla; @@ -22,8 +27,6 @@ abstract class MelillaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Melilla'; } diff --git a/tests/Spain/Melilla/MelillaTest.php b/tests/Spain/Melilla/MelillaTest.php index e6b682221..3261bf19b 100644 --- a/tests/Spain/Melilla/MelillaTest.php +++ b/tests/Spain/Melilla/MelillaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Melilla; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Melilla (Spain). */ -class MelillaTest extends MelillaBaseTestCase +class MelillaTest extends MelillaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Melilla (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Melilla (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -46,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Melilla are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Melilla are defined by the provider class. */ public function testObservedHolidays(): void { @@ -59,8 +72,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Melilla are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Melilla are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -68,8 +80,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Melilla are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Melilla are defined by the provider class. */ public function testBankHolidays(): void { @@ -77,8 +88,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Melilla are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Melilla are defined by the provider class. */ public function testOtherHolidays(): void { @@ -86,10 +96,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/NationalDayTest.php b/tests/Spain/NationalDayTest.php index 7d0e79659..8cfe8b244 100644 --- a/tests/Spain/NationalDayTest.php +++ b/tests/Spain/NationalDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Spain. */ -class NationalDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class NationalDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'nationalDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1981; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Fiesta Nacional de España'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/Navarre/NavarreBaseTestCase.php b/tests/Spain/Navarre/NavarreBaseTestCase.php index 0140ccf67..21685f234 100644 --- a/tests/Spain/Navarre/NavarreBaseTestCase.php +++ b/tests/Spain/Navarre/NavarreBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Navarre; @@ -22,8 +27,6 @@ abstract class NavarreBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/Navarre'; } diff --git a/tests/Spain/Navarre/NavarreTest.php b/tests/Spain/Navarre/NavarreTest.php index b4be42db1..72c34cb50 100644 --- a/tests/Spain/Navarre/NavarreTest.php +++ b/tests/Spain/Navarre/NavarreTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\Navarre; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Navarre (Spain). */ -class NavarreTest extends NavarreBaseTestCase +class NavarreTest extends NavarreBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in Navarre (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Navarre (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -46,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Navarre are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Navarre are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Navarre are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Navarre are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Navarre are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Navarre are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Navarre are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Navarre are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/NewYearsDayTest.php b/tests/Spain/NewYearsDayTest.php index ce5eb802b..981c58dff 100644 --- a/tests/Spain/NewYearsDayTest.php +++ b/tests/Spain/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Spain. */ -class NewYearsDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Año Nuevo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Spain/RegionOfMurcia/RegionOfMurciaBaseTestCase.php b/tests/Spain/RegionOfMurcia/RegionOfMurciaBaseTestCase.php index 368298865..a92c1013e 100644 --- a/tests/Spain/RegionOfMurcia/RegionOfMurciaBaseTestCase.php +++ b/tests/Spain/RegionOfMurcia/RegionOfMurciaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\RegionOfMurcia; @@ -22,13 +27,9 @@ abstract class RegionOfMurciaBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/RegionOfMurcia'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/RegionOfMurcia/RegionOfMurciaDayTest.php b/tests/Spain/RegionOfMurcia/RegionOfMurciaDayTest.php index ba1cee474..a2eb20b42 100644 --- a/tests/Spain/RegionOfMurcia/RegionOfMurciaDayTest.php +++ b/tests/Spain/RegionOfMurcia/RegionOfMurciaDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\RegionOfMurcia; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Murcia Day in the Region of Murcia (Spain). */ -class RegionOfMurciaDayTest extends RegionOfMurciaBaseTestCase implements YasumiTestCaseInterface +class RegionOfMurciaDayTest extends RegionOfMurciaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'murciaDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1983; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de la Región de Murcia'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/RegionOfMurcia/RegionOfMurciaTest.php b/tests/Spain/RegionOfMurcia/RegionOfMurciaTest.php index d2155a520..50be527f8 100644 --- a/tests/Spain/RegionOfMurcia/RegionOfMurciaTest.php +++ b/tests/Spain/RegionOfMurcia/RegionOfMurciaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\RegionOfMurcia; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Region of Murcia (Spain). */ -class RegionOfMurciaTest extends RegionOfMurciaBaseTestCase +class RegionOfMurciaTest extends RegionOfMurciaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1983); + } /** - * Tests if all official holidays in the Region of Murcia (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the Region of Murcia (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the Region of Murcia are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Region of Murcia are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the Region of Murcia are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Region of Murcia are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Region of Murcia are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Region of Murcia are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Region of Murcia are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Region of Murcia are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/SpainBaseTestCase.php b/tests/Spain/SpainBaseTestCase.php index 9ead6b6df..8ab7b39d4 100644 --- a/tests/Spain/SpainBaseTestCase.php +++ b/tests/Spain/SpainBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; @@ -22,19 +27,12 @@ abstract class SpainBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; - - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'es_ES'; } diff --git a/tests/Spain/SpainTest.php b/tests/Spain/SpainTest.php index 41a392158..95aa25aae 100644 --- a/tests/Spain/SpainTest.php +++ b/tests/Spain/SpainTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Spain. */ -class SpainTest extends SpainBaseTestCase +class SpainTest extends SpainBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2000); + } /** - * Tests if all official holidays in Spain are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Spain are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -46,8 +60,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Spain are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Spain are defined by the provider class. */ public function testObservedHolidays(): void { @@ -55,8 +68,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Spain are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Spain are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -64,8 +76,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Spain are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Spain are defined by the provider class. */ public function testBankHolidays(): void { @@ -73,8 +84,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Spain are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Spain are defined by the provider class. */ public function testOtherHolidays(): void { @@ -82,10 +92,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2000); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/ValencianCommunity/ValencianCommunityBaseTestCase.php b/tests/Spain/ValencianCommunity/ValencianCommunityBaseTestCase.php index e0d53df52..7ea5f8ea0 100644 --- a/tests/Spain/ValencianCommunity/ValencianCommunityBaseTestCase.php +++ b/tests/Spain/ValencianCommunity/ValencianCommunityBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\ValencianCommunity; @@ -22,13 +27,9 @@ abstract class ValencianCommunityBaseTestCase extends SpainBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Spain/ValencianCommunity'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Madrid'; } diff --git a/tests/Spain/ValencianCommunity/ValencianCommunityDayTest.php b/tests/Spain/ValencianCommunity/ValencianCommunityDayTest.php index 0c583ca59..6e75fcb43 100644 --- a/tests/Spain/ValencianCommunity/ValencianCommunityDayTest.php +++ b/tests/Spain/ValencianCommunity/ValencianCommunityDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\ValencianCommunity; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Valencian Community Day in the Valencian Community (Spain). */ -class ValencianCommunityDayTest extends ValencianCommunityBaseTestCase implements YasumiTestCaseInterface +class ValencianCommunityDayTest extends ValencianCommunityBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'valencianCommunityDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1239; // Not entirely sure about this year /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-9", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-9", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Día de la Comunidad Valenciana'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Spain/ValencianCommunity/ValencianCommunityTest.php b/tests/Spain/ValencianCommunity/ValencianCommunityTest.php index 83c198ffd..b33d6490a 100644 --- a/tests/Spain/ValencianCommunity/ValencianCommunityTest.php +++ b/tests/Spain/ValencianCommunity/ValencianCommunityTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain\ValencianCommunity; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the Valencian Community (Spain). */ -class ValencianCommunityTest extends ValencianCommunityBaseTestCase +class ValencianCommunityTest extends ValencianCommunityBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1981); + } /** - * Tests if all official holidays in the Valencian Community (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the Valencian Community (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -47,8 +61,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the Valencian Community are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the Valencian Community are defined by the provider class. */ public function testObservedHolidays(): void { @@ -60,8 +73,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the Valencian Community are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the Valencian Community are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -69,8 +81,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the Valencian Community are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the Valencian Community are defined by the provider class. */ public function testBankHolidays(): void { @@ -78,8 +89,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the Valencian Community are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the Valencian Community are defined by the provider class. */ public function testOtherHolidays(): void { @@ -87,10 +97,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1981); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Spain/ValentinesDayTest.php b/tests/Spain/ValentinesDayTest.php index 010f9f3ff..d7fb68b52 100644 --- a/tests/Spain/ValentinesDayTest.php +++ b/tests/Spain/ValentinesDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Valentines Day in the Spain. */ -class ValentinesDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class ValentinesDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'valentinesDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(2, 14, self::TIMEZONE); + return static::generateRandomDates(2, 14, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'San Valentín'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Spain/stJosephsDayTest.php b/tests/Spain/stJosephsDayTest.php index e93053029..1fa7d635d 100644 --- a/tests/Spain/stJosephsDayTest.php +++ b/tests/Spain/stJosephsDayTest.php @@ -1,30 +1,32 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Spain; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class for testing St. Joseph's Day in Spain + * Class for testing St. Joseph's Day in Spain. */ -class stJosephsDayTest extends SpainBaseTestCase implements YasumiTestCaseInterface +class stJosephsDayTest extends SpainBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJosephsDay'; @@ -37,49 +39,49 @@ class stJosephsDayTest extends SpainBaseTestCase implements YasumiTestCaseInterf /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'San José'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/AllSaintsDayTest.php b/tests/Sweden/AllSaintsDayTest.php index 5dc9ba06b..1e78af8f6 100644 --- a/tests/Sweden/AllSaintsDayTest.php +++ b/tests/Sweden/AllSaintsDayTest.php @@ -1,63 +1,61 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Sweden. */ -class AllSaintsDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-10-31", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-10-31", new \DateTimeZone(self::TIMEZONE)); // Check between 31 October and 6th of November the day that is a Saturday for ($d = 0; $d <= 7; ++$d) { @@ -65,7 +63,7 @@ public function HolidayDataProvider(): array $data[] = [$year, $date]; break; } - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); } } @@ -74,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'alla helgons dag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/AllSaintsEveTest.php b/tests/Sweden/AllSaintsEveTest.php index da1ac438c..8c7b571d9 100644 --- a/tests/Sweden/AllSaintsEveTest.php +++ b/tests/Sweden/AllSaintsEveTest.php @@ -1,63 +1,61 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Eve in Sweden. */ -class AllSaintsEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'allSaintsEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-10-30", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-10-30", new \DateTimeZone(self::TIMEZONE)); // Check between 30 October and 5th of November the day that is a Friday for ($d = 0; $d <= 7; ++$d) { @@ -65,7 +63,7 @@ public function HolidayDataProvider(): array $data[] = [$year, $date]; break; } - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); } } @@ -74,24 +72,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'alla helgons afton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/AscensionDayTest.php b/tests/Sweden/AscensionDayTest.php index bd06533d3..6c5c5d44d 100644 --- a/tests/Sweden/AscensionDayTest.php +++ b/tests/Sweden/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Sweden. */ -class AscensionDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1588; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests translated name of Ascension Day - * @throws ReflectionException + * Tests translated name of Ascension Day. + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Kristi himmelsfärdsdag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/ChristmasDayTest.php b/tests/Sweden/ChristmasDayTest.php index 3087ce744..e9e531c3e 100644 --- a/tests/Sweden/ChristmasDayTest.php +++ b/tests/Sweden/ChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Sweden. */ -class ChristmasDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'juldagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/ChristmasEveTest.php b/tests/Sweden/ChristmasEveTest.php index 17963fd5c..9d38a469f 100644 --- a/tests/Sweden/ChristmasEveTest.php +++ b/tests/Sweden/ChristmasEveTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Eve in Sweden. */ -class ChristmasEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class ChristmasEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'christmasEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 24, self::TIMEZONE); + return static::generateRandomDates(12, 24, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'julafton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/EasterMondayTest.php b/tests/Sweden/EasterMondayTest.php index be7159045..4bbe84030 100644 --- a/tests/Sweden/EasterMondayTest.php +++ b/tests/Sweden/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Sweden. */ -class EasterMondayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easterMonday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-8", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-8", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'annandag påsk'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/EasterTest.php b/tests/Sweden/EasterTest.php index c93ef318c..0772dd902 100644 --- a/tests/Sweden/EasterTest.php +++ b/tests/Sweden/EasterTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter in Sweden. */ -class EasterTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1847; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-4-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-4-4", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'påskdagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/EpiphanyEveTest.php b/tests/Sweden/EpiphanyEveTest.php index d7ee0c983..c72be25e3 100644 --- a/tests/Sweden/EpiphanyEveTest.php +++ b/tests/Sweden/EpiphanyEveTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany Eve in Sweden. */ -class EpiphanyEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class EpiphanyEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphanyEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 5, self::TIMEZONE); + return static::generateRandomDates(1, 5, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'trettondagsafton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/EpiphanyTest.php b/tests/Sweden/EpiphanyTest.php index c66bdfb05..4cce84f13 100644 --- a/tests/Sweden/EpiphanyTest.php +++ b/tests/Sweden/EpiphanyTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Sweden. */ -class EpiphanyTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'trettondedag jul'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/GoodFridayTest.php b/tests/Sweden/GoodFridayTest.php index 24e10c1e6..9e74a8441 100644 --- a/tests/Sweden/GoodFridayTest.php +++ b/tests/Sweden/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Sweden. */ -class GoodFridayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2005; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'långfredagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/InternationalWorkersDayTest.php b/tests/Sweden/InternationalWorkersDayTest.php index 500e0b633..2c8951b39 100644 --- a/tests/Sweden/InternationalWorkersDayTest.php +++ b/tests/Sweden/InternationalWorkersDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for International Workers' Day (i.e. Labour Day) in Sweden. */ -class InternationalWorkersDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Första maj'] + static::generateRandomYear(), + [self::LOCALE => 'första maj'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Sweden/NationalDayTest.php b/tests/Sweden/NationalDayTest.php index d4a8c243f..14b8ca95d 100644 --- a/tests/Sweden/NationalDayTest.php +++ b/tests/Sweden/NationalDayTest.php @@ -1,106 +1,111 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the National Day of Sweden in Sweden. */ -class NationalDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class NationalDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1916; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'nationalDay'; /** * Tests the holiday defined in this test on or after establishment. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayOnAfterEstablishment() + public function testHolidayOnAfterEstablishment(): void { $year = 2022; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-6-6", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-6-6", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test on or after establishment. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1982), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1982), [self::LOCALE => 'Svenska flaggans dag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } /** * Tests the translated name of the holiday defined in this test on or after establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testTranslationOnAfterNameChange() + public function testTranslationOnAfterNameChange(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1983), + static::generateRandomYear(1983), [self::LOCALE => 'Sveriges nationaldag'] ); } diff --git a/tests/Sweden/NewYearsDayTest.php b/tests/Sweden/NewYearsDayTest.php index 0573d1445..a2561ac02 100644 --- a/tests/Sweden/NewYearsDayTest.php +++ b/tests/Sweden/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Sweden. */ -class NewYearsDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'nyårsdagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/NewYearsEveTest.php b/tests/Sweden/NewYearsEveTest.php index b0cdee3a2..eee880798 100644 --- a/tests/Sweden/NewYearsEveTest.php +++ b/tests/Sweden/NewYearsEveTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Year's Eve in Sweden. */ -class NewYearsEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class NewYearsEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 31, self::TIMEZONE); + return static::generateRandomDates(12, 31, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'nyårsafton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/PentecostTest.php b/tests/Sweden/PentecostTest.php index 755e27a36..3360df4ae 100644 --- a/tests/Sweden/PentecostTest.php +++ b/tests/Sweden/PentecostTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Sweden. */ -class PentecostTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 4009; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-05-17", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-05-17", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Pingstdagen'] + static::generateRandomYear(), + [self::LOCALE => 'pingstdagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/SecondChristmasDayTest.php b/tests/Sweden/SecondChristmasDayTest.php index 2c908a0fa..7ae9ca5bf 100644 --- a/tests/Sweden/SecondChristmasDayTest.php +++ b/tests/Sweden/SecondChristmasDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Second Christmas Day in Sweden. */ -class SecondChristmasDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class SecondChristmasDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'annandag jul'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/StJohnsDayTest.php b/tests/Sweden/StJohnsDayTest.php index 6e68e55e3..7ac8f16d0 100644 --- a/tests/Sweden/StJohnsDayTest.php +++ b/tests/Sweden/StJohnsDayTest.php @@ -1,76 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; use Yasumi\Yasumi; /** * Class for testing St. John's Day / Midsummer's Day in Sweden. */ -class StJohnsDayTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class StJohnsDayTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsDay'; /** * Tests the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $holidays = Yasumi::create(self::REGION, $year); $holiday = $holidays->getHoliday(self::HOLIDAY); // Some basic assertions - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', self::REGION), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); + self::assertInstanceOf(Holiday::class, $holiday); // Holiday specific assertions - $this->assertEquals('Saturday', $holiday->format('l')); - $this->assertGreaterThanOrEqual(20, $holiday->format('j')); - $this->assertLessThanOrEqual(26, $holiday->format('j')); + self::assertEquals('Saturday', $holiday->format('l')); + self::assertGreaterThanOrEqual(20, $holiday->format('j')); + self::assertLessThanOrEqual(26, $holiday->format('j')); unset($holiday, $holidays); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'midsommardagen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Sweden/StJohnsEveTest.php b/tests/Sweden/StJohnsEveTest.php index 9279cdec7..452dbf9b8 100644 --- a/tests/Sweden/StJohnsEveTest.php +++ b/tests/Sweden/StJohnsEveTest.php @@ -1,76 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; use Yasumi\Yasumi; /** * Class for testing St. John's Eve / Midsummer's Eve in Sweden. */ -class StJohnsEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class StJohnsEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stJohnsEve'; /** * Tests the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(); + $year = static::generateRandomYear(); $holidays = Yasumi::create(self::REGION, $year); $holiday = $holidays->getHoliday(self::HOLIDAY); // Some basic assertions - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', self::REGION), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); + self::assertInstanceOf(Holiday::class, $holiday); // Holiday specific assertions - $this->assertEquals('Friday', $holiday->format('l')); - $this->assertGreaterThanOrEqual(19, $holiday->format('j')); - $this->assertLessThanOrEqual(25, $holiday->format('j')); + self::assertEquals('Friday', $holiday->format('l')); + self::assertGreaterThanOrEqual(19, $holiday->format('j')); + self::assertLessThanOrEqual(25, $holiday->format('j')); unset($holiday, $holidays); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'midsommarafton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Sweden/SwedenBaseTestCase.php b/tests/Sweden/SwedenBaseTestCase.php index d5b84f586..534f4b13b 100644 --- a/tests/Sweden/SwedenBaseTestCase.php +++ b/tests/Sweden/SwedenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; @@ -22,18 +27,12 @@ abstract class SwedenBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Sweden'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Stockholm'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'sv_SE'; } diff --git a/tests/Sweden/SwedenTest.php b/tests/Sweden/SwedenTest.php index 2a7974eef..89ea1a41b 100644 --- a/tests/Sweden/SwedenTest.php +++ b/tests/Sweden/SwedenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Sweden. */ -class SwedenTest extends SwedenBaseTestCase +class SwedenTest extends SwedenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1916); + } /** - * Tests if all official holidays in Sweden (Spain) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Sweden (Spain) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -49,8 +63,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Sweden are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Sweden are defined by the provider class. */ public function testObservedHolidays(): void { @@ -65,8 +78,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Sweden are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Sweden are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -74,8 +86,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Sweden are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Sweden are defined by the provider class. */ public function testBankHolidays(): void { @@ -83,8 +94,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Sweden are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Sweden are defined by the provider class. */ public function testOtherHolidays(): void { @@ -92,10 +102,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1916); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/Sweden/WalpurgisEveTest.php b/tests/Sweden/WalpurgisEveTest.php index 69226149b..9bdeabf59 100644 --- a/tests/Sweden/WalpurgisEveTest.php +++ b/tests/Sweden/WalpurgisEveTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Sweden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Walpurgis Night in Sweden. */ -class WalpurgisEveTest extends SwedenBaseTestCase implements YasumiTestCaseInterface +class WalpurgisEveTest extends SwedenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'walpurgisEve'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(4, 30, self::TIMEZONE); + return static::generateRandomDates(4, 30, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'valborgsmässoafton'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OBSERVANCE); } } diff --git a/tests/Switzerland/Aargau/AargauBaseTestCase.php b/tests/Switzerland/Aargau/AargauBaseTestCase.php index fd4c1dd41..1f65cadad 100644 --- a/tests/Switzerland/Aargau/AargauBaseTestCase.php +++ b/tests/Switzerland/Aargau/AargauBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; @@ -22,18 +27,12 @@ abstract class AargauBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Aargau'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Aargau/AargauTest.php b/tests/Switzerland/Aargau/AargauTest.php index 962f8d6aa..112474547 100644 --- a/tests/Switzerland/Aargau/AargauTest.php +++ b/tests/Switzerland/Aargau/AargauTest.php @@ -1,34 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Aargau (Switzerland). */ -class AargauTest extends AargauBaseTestCase +class AargauTest extends AargauBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; /** - * Tests if all official holidays in Aargau (Switzerland) are defined by the provider class + * Initial setup of this Test Case. * - * @throws ReflectionException + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } + + /** + * Tests if all official holidays in Aargau (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -40,9 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all official holidays in Aargau (Switzerland) are defined by the provider class - * - * @throws ReflectionException + * Tests if all official holidays in Aargau (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -55,14 +66,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Aargau (Switzerland) are defined by the provider class - * - * @throws ReflectionException + * Tests if all observed holidays in Aargau (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -70,9 +79,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Aargau (Switzerland) are defined by the provider class - * - * @throws ReflectionException + * Tests if all seasonal holidays in Aargau (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,9 +87,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Aargau (Switzerland) are defined by the provider class - * - * @throws ReflectionException + * Tests if all bank holidays in Aargau (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -90,20 +95,29 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Aargau (Switzerland) are defined by the provider class - * - * @throws ReflectionException + * Tests if all other holidays in Aargau (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'ascensionDay', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Aargau/AscensionDayTest.php b/tests/Switzerland/Aargau/AscensionDayTest.php index d56d49b4c..346cbd1c3 100644 --- a/tests/Switzerland/Aargau/AscensionDayTest.php +++ b/tests/Switzerland/Aargau/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Aargau (Switzerland). */ -class AscensionDayTest extends AargauBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends AargauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Aargau/ChristmasDayTest.php b/tests/Switzerland/Aargau/ChristmasDayTest.php index c0af064a5..9aeca4d90 100644 --- a/tests/Switzerland/Aargau/ChristmasDayTest.php +++ b/tests/Switzerland/Aargau/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Aargau (Switzerland). */ -class ChristmasDayTest extends AargauBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends AargauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Aargau/GoodFridayTest.php b/tests/Switzerland/Aargau/GoodFridayTest.php index 146c5cf20..ecb67a7b9 100644 --- a/tests/Switzerland/Aargau/GoodFridayTest.php +++ b/tests/Switzerland/Aargau/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Aargau (Switzerland). */ -class GoodFridayTest extends AargauBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends AargauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Aargau/NewYearsDayTest.php b/tests/Switzerland/Aargau/NewYearsDayTest.php index b4ff87369..8f13009b2 100644 --- a/tests/Switzerland/Aargau/NewYearsDayTest.php +++ b/tests/Switzerland/Aargau/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Aargau; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Aargau (Switzerland). */ -class NewYearsDayTest extends AargauBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends AargauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenBaseTestCase.php b/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenBaseTestCase.php index fe5ccfed8..f6616128a 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenBaseTestCase.php +++ b/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; @@ -22,18 +27,12 @@ abstract class AppenzellAusserrhodenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/AppenzellAusserrhoden'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenTest.php b/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenTest.php index 3f3989248..a28813631 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/AppenzellAusserrhodenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Appenzell Ausserrhoden (Switzerland). */ -class AppenzellAusserrhodenTest extends AppenzellAusserrhodenBaseTestCase +class AppenzellAusserrhodenTest extends AppenzellAusserrhodenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -56,13 +69,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -70,8 +82,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -79,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -88,19 +98,32 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Appenzell Ausserrhoden (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/AscensionDayTest.php b/tests/Switzerland/AppenzellAusserrhoden/AscensionDayTest.php index 5697a3c43..e91534b35 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/AscensionDayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Appenzell Ausserrhoden (Switzerland). */ -class AscensionDayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/ChristmasDayTest.php b/tests/Switzerland/AppenzellAusserrhoden/ChristmasDayTest.php index bfb4521b0..9144cd269 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/ChristmasDayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Appenzell Ausserrhoden (Switzerland). */ -class ChristmasDayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/EasterMondayTest.php b/tests/Switzerland/AppenzellAusserrhoden/EasterMondayTest.php index c771ff6bd..430110d29 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/EasterMondayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Appenzell Ausserrhoden (Switzerland). */ -class EasterMondayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/GoodFridayTest.php b/tests/Switzerland/AppenzellAusserrhoden/GoodFridayTest.php index cbe33ff89..3d635e2fc 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/GoodFridayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Appenzell Ausserrhoden (Switzerland). */ -class GoodFridayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/NewYearsDayTest.php b/tests/Switzerland/AppenzellAusserrhoden/NewYearsDayTest.php index f3193ca45..9ced14de4 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/NewYearsDayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Appenzell Ausserrhoden (Switzerland). */ -class NewYearsDayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/PentecostMondayTest.php b/tests/Switzerland/AppenzellAusserrhoden/PentecostMondayTest.php index 69a140087..049087da8 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/PentecostMondayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Appenzell Ausserrhoden (Switzerland). */ -class PentecostMondayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellAusserrhoden/StStephensDayTest.php b/tests/Switzerland/AppenzellAusserrhoden/StStephensDayTest.php index c64f71847..870bf6ccb 100644 --- a/tests/Switzerland/AppenzellAusserrhoden/StStephensDayTest.php +++ b/tests/Switzerland/AppenzellAusserrhoden/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellAusserrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Appenzell Ausserrhoden (Switzerland). */ -class StStephensDayTest extends AppenzellAusserrhodenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends AppenzellAusserrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/AllSaintsDayTest.php b/tests/Switzerland/AppenzellInnerrhoden/AllSaintsDayTest.php index a7648a9bf..27e631e00 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/AllSaintsDayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Appenzell Innerrhoden (Switzerland). */ -class AllSaintsDayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenBaseTestCase.php b/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenBaseTestCase.php index 833be4dc3..3162efcb2 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenBaseTestCase.php +++ b/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; @@ -22,18 +27,12 @@ abstract class AppenzellInnerrhodenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/AppenzellInnerrhoden'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenTest.php b/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenTest.php index c7aae43a1..0bba64d83 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/AppenzellInnerrhodenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Appenzell Innerrhoden (Switzerland). */ -class AppenzellInnerrhodenTest extends AppenzellInnerrhodenBaseTestCase +class AppenzellInnerrhodenTest extends AppenzellInnerrhodenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -60,13 +73,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -74,8 +86,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -83,8 +94,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -92,19 +102,36 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Appenzell Innerrhoden (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/AscensionDayTest.php b/tests/Switzerland/AppenzellInnerrhoden/AscensionDayTest.php index 6b14c6adc..17baf69f9 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/AscensionDayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Appenzell Innerrhoden (Switzerland). */ -class AscensionDayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/AssumptionOfMaryTest.php b/tests/Switzerland/AppenzellInnerrhoden/AssumptionOfMaryTest.php index e24653c1a..aefba491b 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/AssumptionOfMaryTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Appenzell Innerrhoden (Switzerland). */ -class AssumptionOfMaryTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/ChristmasDayTest.php b/tests/Switzerland/AppenzellInnerrhoden/ChristmasDayTest.php index fc6307190..bc56c35f8 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/ChristmasDayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Appenzell Innerrhoden (Switzerland). */ -class ChristmasDayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/CorpusChristiTest.php b/tests/Switzerland/AppenzellInnerrhoden/CorpusChristiTest.php index f64e6ebd6..89290d205 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/CorpusChristiTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Appenzell Innerrhoden (Switzerland). */ -class CorpusChristiTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/EasterMondayTest.php b/tests/Switzerland/AppenzellInnerrhoden/EasterMondayTest.php index b042e1909..cafa46df1 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/EasterMondayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Appenzell Innerrhoden (Switzerland). */ -class EasterMondayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/GoodFridayTest.php b/tests/Switzerland/AppenzellInnerrhoden/GoodFridayTest.php index ae20dc42b..9aaeb96a6 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/GoodFridayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Appenzell Innerrhoden (Switzerland). */ -class GoodFridayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/ImmaculateConceptionTest.php b/tests/Switzerland/AppenzellInnerrhoden/ImmaculateConceptionTest.php index f6dab1baa..2f49bb43c 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/ImmaculateConceptionTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Appenzell Innerrhoden (Switzerland). */ -class ImmaculateConceptionTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/NewYearsDayTest.php b/tests/Switzerland/AppenzellInnerrhoden/NewYearsDayTest.php index 47c8062ef..25ca12d26 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/NewYearsDayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Appenzell Innerrhoden (Switzerland). */ -class NewYearsDayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/PentecostMondayTest.php b/tests/Switzerland/AppenzellInnerrhoden/PentecostMondayTest.php index 368c83e86..bffa47487 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/PentecostMondayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Appenzell Innerrhoden (Switzerland). */ -class PentecostMondayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/AppenzellInnerrhoden/StStephensDayTest.php b/tests/Switzerland/AppenzellInnerrhoden/StStephensDayTest.php index 7320769ac..a30553698 100644 --- a/tests/Switzerland/AppenzellInnerrhoden/StStephensDayTest.php +++ b/tests/Switzerland/AppenzellInnerrhoden/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\AppenzellInnerrhoden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Appenzell Innerrhoden (Switzerland). */ -class StStephensDayTest extends AppenzellInnerrhodenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends AppenzellInnerrhodenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/AscensionDayTest.php b/tests/Switzerland/BaselLandschaft/AscensionDayTest.php index dbb70c314..65e680924 100644 --- a/tests/Switzerland/BaselLandschaft/AscensionDayTest.php +++ b/tests/Switzerland/BaselLandschaft/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Basel Landschaft (Switzerland). */ -class AscensionDayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/BaselLandschaftBaseTestCase.php b/tests/Switzerland/BaselLandschaft/BaselLandschaftBaseTestCase.php index 89422a582..fe5c9ab7c 100644 --- a/tests/Switzerland/BaselLandschaft/BaselLandschaftBaseTestCase.php +++ b/tests/Switzerland/BaselLandschaft/BaselLandschaftBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; @@ -22,18 +27,12 @@ abstract class BaselLandschaftBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/BaselLandschaft'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/BaselLandschaft/BaselLandschaftTest.php b/tests/Switzerland/BaselLandschaft/BaselLandschaftTest.php index b0d8d2dda..69865626d 100644 --- a/tests/Switzerland/BaselLandschaft/BaselLandschaftTest.php +++ b/tests/Switzerland/BaselLandschaft/BaselLandschaftTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Basel Landschaft (Switzerland). */ -class BaselLandschaftTest extends BaselLandschaftBaseTestCase +class BaselLandschaftTest extends BaselLandschaftBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in BaselLandschaft (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in BaselLandschaft (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/BaselLandschaft/ChristmasDayTest.php b/tests/Switzerland/BaselLandschaft/ChristmasDayTest.php index 24604fdca..439a3c0e3 100644 --- a/tests/Switzerland/BaselLandschaft/ChristmasDayTest.php +++ b/tests/Switzerland/BaselLandschaft/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Basel Landschaft (Switzerland). */ -class ChristmasDayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/EasterMondayTest.php b/tests/Switzerland/BaselLandschaft/EasterMondayTest.php index 9dd1c8b91..fac17c0b3 100644 --- a/tests/Switzerland/BaselLandschaft/EasterMondayTest.php +++ b/tests/Switzerland/BaselLandschaft/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Basel Landschaft (Switzerland). */ -class EasterMondayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/GoodFridayTest.php b/tests/Switzerland/BaselLandschaft/GoodFridayTest.php index 1e0979fd9..366d3258f 100644 --- a/tests/Switzerland/BaselLandschaft/GoodFridayTest.php +++ b/tests/Switzerland/BaselLandschaft/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Basel Landschaft (Switzerland). */ -class GoodFridayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/NewYearsDayTest.php b/tests/Switzerland/BaselLandschaft/NewYearsDayTest.php index da164573c..1c4feddbb 100644 --- a/tests/Switzerland/BaselLandschaft/NewYearsDayTest.php +++ b/tests/Switzerland/BaselLandschaft/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Basel Landschaft (Switzerland). */ -class NewYearsDayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/BaselLandschaft/PentecostMondayTest.php b/tests/Switzerland/BaselLandschaft/PentecostMondayTest.php index 28dcb9cc6..0962317a7 100644 --- a/tests/Switzerland/BaselLandschaft/PentecostMondayTest.php +++ b/tests/Switzerland/BaselLandschaft/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Basel Landschaft (Switzerland). */ -class PentecostMondayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/StStephensDayTest.php b/tests/Switzerland/BaselLandschaft/StStephensDayTest.php index 22804a351..4decd4f22 100644 --- a/tests/Switzerland/BaselLandschaft/StStephensDayTest.php +++ b/tests/Switzerland/BaselLandschaft/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Basel Landschaft (Switzerland). */ -class StStephensDayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselLandschaft/WorkersDayTest.php b/tests/Switzerland/BaselLandschaft/WorkersDayTest.php index 938e22363..9a0483faf 100644 --- a/tests/Switzerland/BaselLandschaft/WorkersDayTest.php +++ b/tests/Switzerland/BaselLandschaft/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselLandschaft; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in BaselLandschaft (Switzerland). */ -class WorkersDayTest extends BaselLandschaftBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends BaselLandschaftBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/AscensionDayTest.php b/tests/Switzerland/BaselStadt/AscensionDayTest.php index 64440e5b3..dde38535e 100644 --- a/tests/Switzerland/BaselStadt/AscensionDayTest.php +++ b/tests/Switzerland/BaselStadt/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Basel Stadt (Switzerland). */ -class AscensionDayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/BaselStadtBaseTestCase.php b/tests/Switzerland/BaselStadt/BaselStadtBaseTestCase.php index 74ab8c613..61ef731c8 100644 --- a/tests/Switzerland/BaselStadt/BaselStadtBaseTestCase.php +++ b/tests/Switzerland/BaselStadt/BaselStadtBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; @@ -22,18 +27,12 @@ abstract class BaselStadtBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/BaselStadt'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/BaselStadt/BaselStadtTest.php b/tests/Switzerland/BaselStadt/BaselStadtTest.php index 2c0357799..1cdf10930 100644 --- a/tests/Switzerland/BaselStadt/BaselStadtTest.php +++ b/tests/Switzerland/BaselStadt/BaselStadtTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Basel Stadt (Switzerland). */ -class BaselStadtTest extends BaselStadtBaseTestCase +class BaselStadtTest extends BaselStadtBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Basel Stadt (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Basel Stadt (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/BaselStadt/ChristmasDayTest.php b/tests/Switzerland/BaselStadt/ChristmasDayTest.php index 1b000b644..890c8c8dc 100644 --- a/tests/Switzerland/BaselStadt/ChristmasDayTest.php +++ b/tests/Switzerland/BaselStadt/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Basel Stadt (Switzerland). */ -class ChristmasDayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/EasterMondayTest.php b/tests/Switzerland/BaselStadt/EasterMondayTest.php index 28a3a3021..8ffc4fbc8 100644 --- a/tests/Switzerland/BaselStadt/EasterMondayTest.php +++ b/tests/Switzerland/BaselStadt/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Basel Stadt (Switzerland). */ -class EasterMondayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/GoodFridayTest.php b/tests/Switzerland/BaselStadt/GoodFridayTest.php index fc5b90aed..71b884b3c 100644 --- a/tests/Switzerland/BaselStadt/GoodFridayTest.php +++ b/tests/Switzerland/BaselStadt/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Basel Stadt (Switzerland). */ -class GoodFridayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/NewYearsDayTest.php b/tests/Switzerland/BaselStadt/NewYearsDayTest.php index 1ddffaef7..bcee90355 100644 --- a/tests/Switzerland/BaselStadt/NewYearsDayTest.php +++ b/tests/Switzerland/BaselStadt/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Basel Stadt (Switzerland). */ -class NewYearsDayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/BaselStadt/PentecostMondayTest.php b/tests/Switzerland/BaselStadt/PentecostMondayTest.php index 0b6447387..6fc7fe14d 100644 --- a/tests/Switzerland/BaselStadt/PentecostMondayTest.php +++ b/tests/Switzerland/BaselStadt/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Basel Stadt (Switzerland). */ -class PentecostMondayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/StStephensDayTest.php b/tests/Switzerland/BaselStadt/StStephensDayTest.php index de9a7edbc..38c5678b3 100644 --- a/tests/Switzerland/BaselStadt/StStephensDayTest.php +++ b/tests/Switzerland/BaselStadt/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Basel Stadt (Switzerland). */ -class StStephensDayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/BaselStadt/WorkersDayTest.php b/tests/Switzerland/BaselStadt/WorkersDayTest.php index c5494d7ef..27c1f2bcf 100644 --- a/tests/Switzerland/BaselStadt/WorkersDayTest.php +++ b/tests/Switzerland/BaselStadt/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\BaselStadt; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Basel Stadt (Switzerland). */ -class WorkersDayTest extends BaselStadtBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends BaselStadtBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/AscensionDayTest.php b/tests/Switzerland/Bern/AscensionDayTest.php index b54cd8c6a..709fe4fc7 100644 --- a/tests/Switzerland/Bern/AscensionDayTest.php +++ b/tests/Switzerland/Bern/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Bern (Switzerland). */ -class AscensionDayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/BerchtoldsTagTest.php b/tests/Switzerland/Bern/BerchtoldsTagTest.php index 5bc3f757d..1a2338ce0 100644 --- a/tests/Switzerland/Bern/BerchtoldsTagTest.php +++ b/tests/Switzerland/Bern/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Bern (Switzerland). */ -class BerchtoldsTagTest extends BernBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/BernBaseTestCase.php b/tests/Switzerland/Bern/BernBaseTestCase.php index d02ba7f57..68ab6b1fd 100644 --- a/tests/Switzerland/Bern/BernBaseTestCase.php +++ b/tests/Switzerland/Bern/BernBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; @@ -22,18 +27,12 @@ abstract class BernBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Bern'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Bern/BernTest.php b/tests/Switzerland/Bern/BernTest.php index 9916b59f2..919f458ad 100644 --- a/tests/Switzerland/Bern/BernTest.php +++ b/tests/Switzerland/Bern/BernTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Bern (Switzerland). */ -class BernTest extends BernBaseTestCase +class BernTest extends BernBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Bern (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Bern (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Bern (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Bern (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Bern (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Bern (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Bern (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Bern/ChristmasDayTest.php b/tests/Switzerland/Bern/ChristmasDayTest.php index 0ffda6983..bf66e8bbb 100644 --- a/tests/Switzerland/Bern/ChristmasDayTest.php +++ b/tests/Switzerland/Bern/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Bern (Switzerland). */ -class ChristmasDayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/EasterMondayTest.php b/tests/Switzerland/Bern/EasterMondayTest.php index 87df6acc9..4f78a864a 100644 --- a/tests/Switzerland/Bern/EasterMondayTest.php +++ b/tests/Switzerland/Bern/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Bern (Switzerland). */ -class EasterMondayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/GoodFridayTest.php b/tests/Switzerland/Bern/GoodFridayTest.php index 286eab721..c2aa8f2dd 100644 --- a/tests/Switzerland/Bern/GoodFridayTest.php +++ b/tests/Switzerland/Bern/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Bern (Switzerland). */ -class GoodFridayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/NewYearsDayTest.php b/tests/Switzerland/Bern/NewYearsDayTest.php index b8be1e1bc..f9e032c7e 100644 --- a/tests/Switzerland/Bern/NewYearsDayTest.php +++ b/tests/Switzerland/Bern/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Bern (Switzerland). */ -class NewYearsDayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Bern/PentecostMondayTest.php b/tests/Switzerland/Bern/PentecostMondayTest.php index fe51508df..4fd2f75d8 100644 --- a/tests/Switzerland/Bern/PentecostMondayTest.php +++ b/tests/Switzerland/Bern/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Bern (Switzerland). */ -class PentecostMondayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Bern/StStephensDayTest.php b/tests/Switzerland/Bern/StStephensDayTest.php index b63323ec0..4ab6c3454 100644 --- a/tests/Switzerland/Bern/StStephensDayTest.php +++ b/tests/Switzerland/Bern/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Bern; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Bern (Switzerland). */ -class StStephensDayTest extends BernBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends BernBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Fribourg/AllSaintsDayTest.php b/tests/Switzerland/Fribourg/AllSaintsDayTest.php new file mode 100644 index 000000000..b714fc497 --- /dev/null +++ b/tests/Switzerland/Fribourg/AllSaintsDayTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing All Saints' Day in Fribourg (Switzerland). + */ +class AllSaintsDayTest extends FribourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'allSaintsDay'; + + /** + * Tests All Saints' Day. + * + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests translated name of All Saints' Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Toussaint'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * Returns a list of random test dates used for assertion of All Saints' Day. + * + * @return array list of test dates for All Saints' Day + * + * @throws \Exception + */ + public static function AllSaintsDayDataProvider(): array + { + return static::generateRandomDates(11, 1, self::TIMEZONE); + } +} diff --git a/tests/Switzerland/Fribourg/AscensionDayTest.php b/tests/Switzerland/Fribourg/AscensionDayTest.php index f1a515ec8..505d26a10 100644 --- a/tests/Switzerland/Fribourg/AscensionDayTest.php +++ b/tests/Switzerland/Fribourg/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Fribourg (Switzerland). */ -class AscensionDayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Fribourg/AssumptionOfMaryTest.php b/tests/Switzerland/Fribourg/AssumptionOfMaryTest.php new file mode 100644 index 000000000..63a8aec15 --- /dev/null +++ b/tests/Switzerland/Fribourg/AssumptionOfMaryTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of the Assumption of Mary in Fribourg (Switzerland). + */ +class AssumptionOfMaryTest extends FribourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'assumptionOfMary'; + + /** + * Tests the day of the Assumption of Mary. + * + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests translated name of the day of the Assumption of Mary. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Assomption'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } + + /** + * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. + * + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception + */ + public static function AssumptionOfMaryDataProvider(): array + { + return static::generateRandomDates(8, 15, self::TIMEZONE); + } +} diff --git a/tests/Switzerland/Fribourg/BerchtoldsTagTest.php b/tests/Switzerland/Fribourg/BerchtoldsTagTest.php new file mode 100644 index 000000000..88a90874f --- /dev/null +++ b/tests/Switzerland/Fribourg/BerchtoldsTagTest.php @@ -0,0 +1,71 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing BerchtoldsTag in Fribourg (Switzerland). + */ +class BerchtoldsTagTest extends FribourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'berchtoldsTag'; + + /** + * Tests BerchtoldsTag. + * + * @throws \Exception + */ + public function testBerchtoldsTag(): void + { + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); + + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); + } + + /** + * Tests translated name of BerchtoldsTag. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Jour de la Saint-Berthold'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Fribourg/ChristmasDayTest.php b/tests/Switzerland/Fribourg/ChristmasDayTest.php index a912a9ad8..cb8a3ee55 100644 --- a/tests/Switzerland/Fribourg/ChristmasDayTest.php +++ b/tests/Switzerland/Fribourg/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Fribourg (Switzerland). */ -class ChristmasDayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Fribourg/CorpusChristiTest.php b/tests/Switzerland/Fribourg/CorpusChristiTest.php new file mode 100644 index 000000000..dc1ce015a --- /dev/null +++ b/tests/Switzerland/Fribourg/CorpusChristiTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Corpus Christi in Fribourg (Switzerland). + */ +class CorpusChristiTest extends FribourgBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'corpusChristi'; + + /** + * Tests Corpus Christi. + * + * @throws \Exception + */ + public function testCorpusChristi(): void + { + $year = 2016; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Fête-Dieu'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Fribourg/December26thTest.php b/tests/Switzerland/Fribourg/December26thTest.php new file mode 100644 index 000000000..bb1d655bb --- /dev/null +++ b/tests/Switzerland/Fribourg/December26thTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing December 26th in Fribourg (Switzerland). + */ +class December26thTest extends FribourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'december26th'; + + /** + * Tests December 26th. + * + * @throws \Exception + */ + public function testDecember26th(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests translated name of December 26th. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => '26 décembre'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Fribourg/EasterMondayTest.php b/tests/Switzerland/Fribourg/EasterMondayTest.php index 4bf52f23b..17728dd12 100644 --- a/tests/Switzerland/Fribourg/EasterMondayTest.php +++ b/tests/Switzerland/Fribourg/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Fribourg (Switzerland). */ -class EasterMondayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Fribourg/FribourgBaseTestCase.php b/tests/Switzerland/Fribourg/FribourgBaseTestCase.php index becf451e8..544b73900 100644 --- a/tests/Switzerland/Fribourg/FribourgBaseTestCase.php +++ b/tests/Switzerland/Fribourg/FribourgBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; @@ -22,18 +27,12 @@ abstract class FribourgBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Fribourg'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Fribourg/FribourgTest.php b/tests/Switzerland/Fribourg/FribourgTest.php index d4cdf155f..66fc345cb 100644 --- a/tests/Switzerland/Fribourg/FribourgTest.php +++ b/tests/Switzerland/Fribourg/FribourgTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Fribourg (Switzerland). */ -class FribourgTest extends FribourgBaseTestCase +class FribourgTest extends FribourgBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -51,17 +64,22 @@ public function testRegionalHolidays(): void 'ascensionDay', 'easterMonday', 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'berchtoldsTag', + 'december26th', ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Tests if all observed holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -69,8 +87,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -78,8 +95,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -87,19 +103,37 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Fribourg (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Fribourg (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'december26th', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Fribourg/GoodFridayTest.php b/tests/Switzerland/Fribourg/GoodFridayTest.php index 505719550..682643a99 100644 --- a/tests/Switzerland/Fribourg/GoodFridayTest.php +++ b/tests/Switzerland/Fribourg/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Fribourg (Switzerland). */ -class GoodFridayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Fribourg/ImmaculateConceptionTest.php b/tests/Switzerland/Fribourg/ImmaculateConceptionTest.php new file mode 100644 index 000000000..a7f317790 --- /dev/null +++ b/tests/Switzerland/Fribourg/ImmaculateConceptionTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\Switzerland\Fribourg; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the day of Immaculate Conception in Fribourg (Switzerland). + */ +class ImmaculateConceptionTest extends FribourgBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'immaculateConception'; + + /** + * Tests the holiday defined in this test. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(12, 8, self::TIMEZONE); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Immaculée Conception'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Fribourg/NewYearsDayTest.php b/tests/Switzerland/Fribourg/NewYearsDayTest.php index b12b7d4bf..faa9526a6 100644 --- a/tests/Switzerland/Fribourg/NewYearsDayTest.php +++ b/tests/Switzerland/Fribourg/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Fribourg (Switzerland). */ -class NewYearsDayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Fribourg/PentecostMondayTest.php b/tests/Switzerland/Fribourg/PentecostMondayTest.php index b0c82b68c..f2484da06 100644 --- a/tests/Switzerland/Fribourg/PentecostMondayTest.php +++ b/tests/Switzerland/Fribourg/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Fribourg; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Fribourg (Switzerland). */ -class PentecostMondayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends FribourgBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/AscensionDayTest.php b/tests/Switzerland/Geneva/AscensionDayTest.php index 5e814e4e4..011c3ae38 100644 --- a/tests/Switzerland/Geneva/AscensionDayTest.php +++ b/tests/Switzerland/Geneva/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Geneva (Switzerland). */ -class AscensionDayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/ChristmasDayTest.php b/tests/Switzerland/Geneva/ChristmasDayTest.php index e735671b0..20aa8d8b4 100644 --- a/tests/Switzerland/Geneva/ChristmasDayTest.php +++ b/tests/Switzerland/Geneva/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Geneva (Switzerland). */ -class ChristmasDayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/EasterMondayTest.php b/tests/Switzerland/Geneva/EasterMondayTest.php index 9b55b0857..4d98c0f15 100644 --- a/tests/Switzerland/Geneva/EasterMondayTest.php +++ b/tests/Switzerland/Geneva/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Geneva (Switzerland). */ -class EasterMondayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/GenevaBaseTestCase.php b/tests/Switzerland/Geneva/GenevaBaseTestCase.php index 15fea5703..b54de8812 100644 --- a/tests/Switzerland/Geneva/GenevaBaseTestCase.php +++ b/tests/Switzerland/Geneva/GenevaBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; @@ -22,18 +27,12 @@ abstract class GenevaBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Geneva'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Geneva/GenevaTest.php b/tests/Switzerland/Geneva/GenevaTest.php index dd0bdb1e5..45af127f2 100644 --- a/tests/Switzerland/Geneva/GenevaTest.php +++ b/tests/Switzerland/Geneva/GenevaTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Geneva (Switzerland). */ -class GenevaTest extends GenevaBaseTestCase +class GenevaTest extends GenevaBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Geneva (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Geneva (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -61,13 +74,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Geneva (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -79,8 +91,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Geneva (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -88,8 +99,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Geneva (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -97,8 +107,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Geneva (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Geneva (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { @@ -111,10 +120,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Geneva/GoodFridayTest.php b/tests/Switzerland/Geneva/GoodFridayTest.php index 27f76dc44..0cb2584ae 100644 --- a/tests/Switzerland/Geneva/GoodFridayTest.php +++ b/tests/Switzerland/Geneva/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Geneva (Switzerland). */ -class GoodFridayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/JeuneGenevoisTest.php b/tests/Switzerland/Geneva/JeuneGenevoisTest.php index 548844f3f..cf94fe5ae 100644 --- a/tests/Switzerland/Geneva/JeuneGenevoisTest.php +++ b/tests/Switzerland/Geneva/JeuneGenevoisTest.php @@ -1,119 +1,108 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\Provider\Switzerland\Geneva; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Jeune Genevois in Geneva (Switzerland). */ -class JeuneGenevoisTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class JeuneGenevoisTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'jeuneGenevois'; /** - * Tests Jeune Genevois on or after 1966 - * - * @throws ReflectionException - * @throws Exception - */ - public function testJeuneGenevoisOnAfter1966() - { - $year = $this->generateRandomYear(1966); - // Find first Sunday of September - $date = new DateTime('First Sunday of ' . $year . '-09', new DateTimeZone(self::TIMEZONE)); - // Go to next Thursday - $date->add(new DateInterval('P4D')); - - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); - } - - /** - * Tests Jeune Genevois between 1870 and 1965 + * Tests Jeune Genevois between 1870 and 1965. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testJeuneGenevoisBetween1870And1965() + public function testJeuneGenevoisBetween1870And1965(): void { - $year = $this->generateRandomYear(1870, 1965); + $year = static::generateRandomYear(1870, 1965); // Find first Sunday of September - $date = new DateTime('First Sunday of ' . $year . '-09', new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime('First Sunday of ' . $year . '-09', new \DateTimeZone(self::TIMEZONE)); // Go to next Thursday - $date->add(new DateInterval('P4D')); + $date->add(new \DateInterval('P4D')); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); } /** - * Tests Jeune Genevois between 1840 and 1869 + * Tests Jeune Genevois between 1840 and 1869. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testJeuneGenevoisBetween1840And1869() + public function testJeuneGenevoisBetween1840And1869(): void { - $year = $this->generateRandomYear(1840, 1869); + $year = static::generateRandomYear(Geneva::JEUNE_GENEVOIS_ESTABLISHMENT_YEAR, 1869); // Find first Sunday of September - $date = new DateTime('First Sunday of ' . $year . '-09', new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime('First Sunday of ' . $year . '-09', new \DateTimeZone(self::TIMEZONE)); // Go to next Thursday - $date->add(new DateInterval('P4D')); + $date->add(new \DateInterval('P4D')); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); } /** - * Tests Jeune Genevois before 1840 - * @throws ReflectionException + * Tests Jeune Genevois before 1840. + * + * @throws \Exception */ - public function testJeuneGenevoisBefore1840() + public function testJeuneGenevoisBefore1840(): void { - $year = $this->generateRandomYear(1000, 1839); + $year = static::generateRandomYear(1000, Geneva::JEUNE_GENEVOIS_ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Jeune Genevois. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1966), + static::generateRandomYear(1966), [self::LOCALE => 'Jeûne genevois'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1966), Holiday::TYPE_OTHER); + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1966), + Holiday::TYPE_OTHER + ); } } diff --git a/tests/Switzerland/Geneva/NewYearsDayTest.php b/tests/Switzerland/Geneva/NewYearsDayTest.php index 568fb5cce..f38688d8a 100644 --- a/tests/Switzerland/Geneva/NewYearsDayTest.php +++ b/tests/Switzerland/Geneva/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Geneva (Switzerland). */ -class NewYearsDayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Geneva/PentecostMondayTest.php b/tests/Switzerland/Geneva/PentecostMondayTest.php index d63299ec0..3cc909b6b 100644 --- a/tests/Switzerland/Geneva/PentecostMondayTest.php +++ b/tests/Switzerland/Geneva/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Geneva (Switzerland). */ -class PentecostMondayTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Geneva/RestaurationGenevoiseTest.php b/tests/Switzerland/Geneva/RestaurationGenevoiseTest.php index 82922cdeb..364f14ad7 100644 --- a/tests/Switzerland/Geneva/RestaurationGenevoiseTest.php +++ b/tests/Switzerland/Geneva/RestaurationGenevoiseTest.php @@ -1,71 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Geneva; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Restauration Genevoise in Geneva (Switzerland). */ -class RestaurationGenevoiseTest extends GenevaBaseTestCase implements YasumiTestCaseInterface +class RestaurationGenevoiseTest extends GenevaBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'restaurationGenevoise'; /** * Tests Restauration Genevoise. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testRestaurationGenevoiseAfter1813() + public function testRestaurationGenevoiseAfter1813(): void { - $year = $this->generateRandomYear(1814); + $year = static::generateRandomYear(1814); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($year . '-12-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime($year . '-12-31', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Restauration Genevoise. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1814), + static::generateRandomYear(1814), [self::LOCALE => 'Restauration de la République'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1814), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1814), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/AllSaintsDayTest.php b/tests/Switzerland/Glarus/AllSaintsDayTest.php index 394bf7fc1..41c4ff839 100644 --- a/tests/Switzerland/Glarus/AllSaintsDayTest.php +++ b/tests/Switzerland/Glarus/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Glarus (Switzerland). */ -class AllSaintsDayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Glarus/AscensionDayTest.php b/tests/Switzerland/Glarus/AscensionDayTest.php index 5d04de15a..6c1acb248 100644 --- a/tests/Switzerland/Glarus/AscensionDayTest.php +++ b/tests/Switzerland/Glarus/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Glarus (Switzerland). */ -class AscensionDayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/BerchtoldsTagTest.php b/tests/Switzerland/Glarus/BerchtoldsTagTest.php index cd9aab15b..217756196 100644 --- a/tests/Switzerland/Glarus/BerchtoldsTagTest.php +++ b/tests/Switzerland/Glarus/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Glarus (Switzerland). */ -class BerchtoldsTagTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/ChristmasDayTest.php b/tests/Switzerland/Glarus/ChristmasDayTest.php index 85b4e5ec5..4029e623a 100644 --- a/tests/Switzerland/Glarus/ChristmasDayTest.php +++ b/tests/Switzerland/Glarus/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Glarus (Switzerland). */ -class ChristmasDayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/EasterMondayTest.php b/tests/Switzerland/Glarus/EasterMondayTest.php index 25ed1dc37..10f29b0c9 100644 --- a/tests/Switzerland/Glarus/EasterMondayTest.php +++ b/tests/Switzerland/Glarus/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Glarus (Switzerland). */ -class EasterMondayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/GlarusBaseTestCase.php b/tests/Switzerland/Glarus/GlarusBaseTestCase.php index e5bbac7eb..a8a1c2baf 100644 --- a/tests/Switzerland/Glarus/GlarusBaseTestCase.php +++ b/tests/Switzerland/Glarus/GlarusBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; @@ -22,18 +27,12 @@ abstract class GlarusBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Glarus'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Glarus/GlarusTest.php b/tests/Switzerland/Glarus/GlarusTest.php index 564e6e5a9..76c0da5b1 100644 --- a/tests/Switzerland/Glarus/GlarusTest.php +++ b/tests/Switzerland/Glarus/GlarusTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Glarus (Switzerland). */ -class GlarusTest extends GlarusBaseTestCase +class GlarusTest extends GlarusBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Glarus (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Glarus (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -59,13 +72,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Glarus (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -73,8 +85,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Glarus (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -82,8 +93,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Glarus (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -91,19 +101,35 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Glarus (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Glarus (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'nafelserFahrt', + 'ascensionDay', + 'pentecostMonday', + 'allSaintsDay', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Glarus/GoodFridayTest.php b/tests/Switzerland/Glarus/GoodFridayTest.php index f6a27eeb3..893136274 100644 --- a/tests/Switzerland/Glarus/GoodFridayTest.php +++ b/tests/Switzerland/Glarus/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Glarus (Switzerland). */ -class GoodFridayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/NafelserFahrtTest.php b/tests/Switzerland/Glarus/NafelserFahrtTest.php index bd2f1b930..52701ab25 100644 --- a/tests/Switzerland/Glarus/NafelserFahrtTest.php +++ b/tests/Switzerland/Glarus/NafelserFahrtTest.php @@ -1,86 +1,90 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Näfelser Fahrt in Glarus (Switzerland). */ -class NafelserFahrtTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class NafelserFahrtTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'nafelserFahrt'; /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 1389; /** - * Tests Näfelser Fahrt on or after 1389 - * @throws ReflectionException - * @throws Exception + * Tests Näfelser Fahrt on or after 1389. + * + * @throws \Exception */ - public function testNafelserFahrtOnAfter1389() + public function testNafelserFahrtOnAfter1389(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime('First Thursday of ' . $year . '-04', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime('First Thursday of ' . $year . '-04', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Tests Näfelser Fahrt before 1389 - * @throws ReflectionException + * Tests Näfelser Fahrt before 1389. + * + * @throws \Exception */ - public function testNafelserFahrtBefore1389() + public function testNafelserFahrtBefore1389(): void { - $year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Näfelser Fahrt. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Näfelser Fahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OTHER ); } diff --git a/tests/Switzerland/Glarus/NewYearsDayTest.php b/tests/Switzerland/Glarus/NewYearsDayTest.php index 8474699ae..3a51f8201 100644 --- a/tests/Switzerland/Glarus/NewYearsDayTest.php +++ b/tests/Switzerland/Glarus/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Glarus (Switzerland). */ -class NewYearsDayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Glarus/PentecostMondayTest.php b/tests/Switzerland/Glarus/PentecostMondayTest.php index f6a5b00e7..912e6963a 100644 --- a/tests/Switzerland/Glarus/PentecostMondayTest.php +++ b/tests/Switzerland/Glarus/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Glarus (Switzerland). */ -class PentecostMondayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Glarus/StStephensDayTest.php b/tests/Switzerland/Glarus/StStephensDayTest.php index 6c522a033..a4af73624 100644 --- a/tests/Switzerland/Glarus/StStephensDayTest.php +++ b/tests/Switzerland/Glarus/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Glarus; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Glarus (Switzerland). */ -class StStephensDayTest extends GlarusBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends GlarusBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/AscensionDayTest.php b/tests/Switzerland/Grisons/AscensionDayTest.php index 1f6299b8f..b84512581 100644 --- a/tests/Switzerland/Grisons/AscensionDayTest.php +++ b/tests/Switzerland/Grisons/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Grisons (Switzerland). */ -class AscensionDayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/ChristmasDayTest.php b/tests/Switzerland/Grisons/ChristmasDayTest.php index 062cbef0b..eeb4eeb26 100644 --- a/tests/Switzerland/Grisons/ChristmasDayTest.php +++ b/tests/Switzerland/Grisons/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Grisons (Switzerland). */ -class ChristmasDayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/EasterMondayTest.php b/tests/Switzerland/Grisons/EasterMondayTest.php index 18299facd..e75a2f595 100644 --- a/tests/Switzerland/Grisons/EasterMondayTest.php +++ b/tests/Switzerland/Grisons/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Grisons (Switzerland). */ -class EasterMondayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/GoodFridayTest.php b/tests/Switzerland/Grisons/GoodFridayTest.php index 14424299c..409c68504 100644 --- a/tests/Switzerland/Grisons/GoodFridayTest.php +++ b/tests/Switzerland/Grisons/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Grisons (Switzerland). */ -class GoodFridayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/GrisonsBaseTestCase.php b/tests/Switzerland/Grisons/GrisonsBaseTestCase.php index 9a98ed919..ab44993e5 100644 --- a/tests/Switzerland/Grisons/GrisonsBaseTestCase.php +++ b/tests/Switzerland/Grisons/GrisonsBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; @@ -22,18 +27,12 @@ abstract class GrisonsBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Grisons'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Grisons/GrisonsTest.php b/tests/Switzerland/Grisons/GrisonsTest.php index aac1be88a..850a27b60 100644 --- a/tests/Switzerland/Grisons/GrisonsTest.php +++ b/tests/Switzerland/Grisons/GrisonsTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Grisons (Switzerland). */ -class GrisonsTest extends GrisonsBaseTestCase +class GrisonsTest extends GrisonsBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Grisons (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Grisons (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -56,13 +69,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Grisons (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -70,8 +82,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Grisons (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -79,8 +90,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Grisons (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -88,19 +98,32 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Grisons (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Grisons (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Grisons/NewYearsDayTest.php b/tests/Switzerland/Grisons/NewYearsDayTest.php index c88a8a7f0..e53049650 100644 --- a/tests/Switzerland/Grisons/NewYearsDayTest.php +++ b/tests/Switzerland/Grisons/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Grisons (Switzerland). */ -class NewYearsDayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Grisons/PentecostMondayTest.php b/tests/Switzerland/Grisons/PentecostMondayTest.php index 29232fd76..2e2213040 100644 --- a/tests/Switzerland/Grisons/PentecostMondayTest.php +++ b/tests/Switzerland/Grisons/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Grisons (Switzerland). */ -class PentecostMondayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Grisons/StStephensDayTest.php b/tests/Switzerland/Grisons/StStephensDayTest.php index 4f33d9711..13a8c9697 100644 --- a/tests/Switzerland/Grisons/StStephensDayTest.php +++ b/tests/Switzerland/Grisons/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Grisons; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Grisons (Switzerland). */ -class StStephensDayTest extends GrisonsBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends GrisonsBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/AllSaintsDayTest.php b/tests/Switzerland/Jura/AllSaintsDayTest.php index 9ce5a7af3..4916d1a6d 100644 --- a/tests/Switzerland/Jura/AllSaintsDayTest.php +++ b/tests/Switzerland/Jura/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Jura (Switzerland). */ -class AllSaintsDayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Toussaint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Jura/AscensionDayTest.php b/tests/Switzerland/Jura/AscensionDayTest.php index f0a592093..567749a57 100644 --- a/tests/Switzerland/Jura/AscensionDayTest.php +++ b/tests/Switzerland/Jura/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Jura (Switzerland). */ -class AscensionDayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/AssumptionOfMaryTest.php b/tests/Switzerland/Jura/AssumptionOfMaryTest.php index de43e22c9..49cff7116 100644 --- a/tests/Switzerland/Jura/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Jura/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Jura (Switzerland). */ -class AssumptionOfMaryTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assomption'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Jura/BerchtoldsTagTest.php b/tests/Switzerland/Jura/BerchtoldsTagTest.php index a86e46a16..bb8ace892 100644 --- a/tests/Switzerland/Jura/BerchtoldsTagTest.php +++ b/tests/Switzerland/Jura/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Jura (Switzerland). */ -class BerchtoldsTagTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jour de la Saint-Berthold'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/BettagsMontagTest.php b/tests/Switzerland/Jura/BettagsMontagTest.php new file mode 100644 index 000000000..4818d3171 --- /dev/null +++ b/tests/Switzerland/Jura/BettagsMontagTest.php @@ -0,0 +1,85 @@ + + */ + +namespace Yasumi\tests\Switzerland\Jura; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Bettags Montag in Jura (Switzerland). + */ +class BettagsMontagTest extends JuraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'bettagsMontag'; + + /** + * Tests Bettags Montag on or after 1832. + * + * @throws \Exception + */ + public function testBettagsMontagOnAfter1832(): void + { + $year = static::generateRandomYear(1832); + + // Find third Sunday of September + $date = new \DateTime('Third Sunday of ' . $year . '-09', new \DateTimeZone(self::TIMEZONE)); + // Go to next Thursday + $date->add(new \DateInterval('P1D')); + + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); + } + + /** + * Tests Bettags Montag before 1832. + * + * @throws \Exception + */ + public function testBettagsMontagBefore1832(): void + { + $year = static::generateRandomYear(1000, 1831); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests translated name of Bettags Montag. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1832), + [self::LOCALE => 'Jeûne fédéral'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1900), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Jura/ChristmasDayTest.php b/tests/Switzerland/Jura/ChristmasDayTest.php index 526111fa5..b4ffd4825 100644 --- a/tests/Switzerland/Jura/ChristmasDayTest.php +++ b/tests/Switzerland/Jura/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Jura (Switzerland). */ -class ChristmasDayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/CorpusChristiTest.php b/tests/Switzerland/Jura/CorpusChristiTest.php index 26f092718..e9565961d 100644 --- a/tests/Switzerland/Jura/CorpusChristiTest.php +++ b/tests/Switzerland/Jura/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Jura (Switzerland). */ -class CorpusChristiTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends JuraBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fête-Dieu'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/EasterMondayTest.php b/tests/Switzerland/Jura/EasterMondayTest.php index 8d1e4099c..7b55239d6 100644 --- a/tests/Switzerland/Jura/EasterMondayTest.php +++ b/tests/Switzerland/Jura/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Jura (Switzerland). */ -class EasterMondayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/EasterTest.php b/tests/Switzerland/Jura/EasterTest.php new file mode 100644 index 000000000..d695bdbad --- /dev/null +++ b/tests/Switzerland/Jura/EasterTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Switzerland\Jura; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class containing tests for Easter in Jura (Switzerland). + */ +class EasterTest extends JuraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday to be tested. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 2009; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-12", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Pâques'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Jura/GoodFridayTest.php b/tests/Switzerland/Jura/GoodFridayTest.php index 342d79165..67dff4339 100644 --- a/tests/Switzerland/Jura/GoodFridayTest.php +++ b/tests/Switzerland/Jura/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Jura (Switzerland). */ -class GoodFridayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/JuraBaseTestCase.php b/tests/Switzerland/Jura/JuraBaseTestCase.php index 6543fdd47..f8b281eb2 100644 --- a/tests/Switzerland/Jura/JuraBaseTestCase.php +++ b/tests/Switzerland/Jura/JuraBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; @@ -22,18 +27,12 @@ abstract class JuraBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Jura'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Jura/JuraTest.php b/tests/Switzerland/Jura/JuraTest.php index c9c924c40..619b7b300 100644 --- a/tests/Switzerland/Jura/JuraTest.php +++ b/tests/Switzerland/Jura/JuraTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Jura (Switzerland). */ -class JuraTest extends JuraBaseTestCase +class JuraTest extends JuraBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1975); + } /** - * Tests if all official holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Jura (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Jura (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -53,21 +66,23 @@ public function testRegionalHolidays(): void 'newYearsDay', 'christmasDay', 'ascensionDay', + 'easter', 'easterMonday', + 'pentecost', 'pentecostMonday', 'berchtoldsTag', 'plebisciteJurassien', + 'bettagsMontag', ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Tests if all observed holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Jura (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -75,8 +90,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Jura (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -84,8 +98,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Jura (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -93,19 +106,40 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Jura (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Jura (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easter', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecost', + 'pentecostMonday', + 'corpusChristi', + 'plebisciteJurassien', + 'assumptionOfMary', + 'bettagsMontag', + 'allSaintsDay', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1975); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Jura/NewYearsDayTest.php b/tests/Switzerland/Jura/NewYearsDayTest.php index 3962eee59..d61d3ac03 100644 --- a/tests/Switzerland/Jura/NewYearsDayTest.php +++ b/tests/Switzerland/Jura/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Jura (Switzerland). */ -class NewYearsDayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Jura/PentecostMondayTest.php b/tests/Switzerland/Jura/PentecostMondayTest.php index 6edf27404..8b96ade8c 100644 --- a/tests/Switzerland/Jura/PentecostMondayTest.php +++ b/tests/Switzerland/Jura/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Jura (Switzerland). */ -class PentecostMondayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Jura/PentecostTest.php b/tests/Switzerland/Jura/PentecostTest.php new file mode 100644 index 000000000..d9e1a30e8 --- /dev/null +++ b/tests/Switzerland/Jura/PentecostTest.php @@ -0,0 +1,73 @@ + + */ + +namespace Yasumi\tests\Switzerland\Jura; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Pentecost in Jura (Switzerland). + */ +class PentecostTest extends JuraBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'pentecost'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $year = 1344; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-23", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Pentecôte'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Jura/PlebisciteJurassienTest.php b/tests/Switzerland/Jura/PlebisciteJurassienTest.php index f02cc796a..d451a6fe6 100644 --- a/tests/Switzerland/Jura/PlebisciteJurassienTest.php +++ b/tests/Switzerland/Jura/PlebisciteJurassienTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Plébiscite jurassien in Jura (Switzerland). */ -class PlebisciteJurassienTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class PlebisciteJurassienTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'plebisciteJurassien'; /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 1975; /** * Tests Plébiscite jurassien on or after 1975. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testInstaurationRepubliqueOnAfter1975() + public function testInstaurationRepubliqueOnAfter1975(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-23", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-23", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Plébiscite jurassien before 1975. - * @throws ReflectionException + * + * @throws \Exception */ - public function testInstaurationRepubliqueBefore1975() + public function testInstaurationRepubliqueBefore1975(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Plébiscite jurassien. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Commémoration du plébiscite jurassien'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OTHER ); } diff --git a/tests/Switzerland/Jura/WorkersDayTest.php b/tests/Switzerland/Jura/WorkersDayTest.php index 4fb626a3a..fb614a9dd 100644 --- a/tests/Switzerland/Jura/WorkersDayTest.php +++ b/tests/Switzerland/Jura/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Jura; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Jura (Switzerland). */ -class WorkersDayTest extends JuraBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends JuraBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fête du Travail'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/AllSaintsDayTest.php b/tests/Switzerland/Lucerne/AllSaintsDayTest.php index 73a175807..f1e6c6331 100644 --- a/tests/Switzerland/Lucerne/AllSaintsDayTest.php +++ b/tests/Switzerland/Lucerne/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Lucerne (Switzerland). */ -class AllSaintsDayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Lucerne/AscensionDayTest.php b/tests/Switzerland/Lucerne/AscensionDayTest.php index 6b8e57a4f..1cea654d6 100644 --- a/tests/Switzerland/Lucerne/AscensionDayTest.php +++ b/tests/Switzerland/Lucerne/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Lucerne (Switzerland). */ -class AscensionDayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/AssumptionOfMaryTest.php b/tests/Switzerland/Lucerne/AssumptionOfMaryTest.php index a95cb784a..e9d7ec383 100644 --- a/tests/Switzerland/Lucerne/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Lucerne/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Lucerne (Switzerland). */ -class AssumptionOfMaryTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Lucerne/BerchtoldsTagTest.php b/tests/Switzerland/Lucerne/BerchtoldsTagTest.php index 43abf742f..8b34adbf2 100644 --- a/tests/Switzerland/Lucerne/BerchtoldsTagTest.php +++ b/tests/Switzerland/Lucerne/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Lucerne (Switzerland). */ -class BerchtoldsTagTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/ChristmasDayTest.php b/tests/Switzerland/Lucerne/ChristmasDayTest.php index e4e4a55aa..3013101eb 100644 --- a/tests/Switzerland/Lucerne/ChristmasDayTest.php +++ b/tests/Switzerland/Lucerne/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Lucerne (Switzerland). */ -class ChristmasDayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/CorpusChristiTest.php b/tests/Switzerland/Lucerne/CorpusChristiTest.php index a519cfb30..25edd2d2e 100644 --- a/tests/Switzerland/Lucerne/CorpusChristiTest.php +++ b/tests/Switzerland/Lucerne/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Lucerne (Switzerland). */ -class CorpusChristiTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends LucerneBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/EasterMondayTest.php b/tests/Switzerland/Lucerne/EasterMondayTest.php index 2de50ea5c..bdf05c44d 100644 --- a/tests/Switzerland/Lucerne/EasterMondayTest.php +++ b/tests/Switzerland/Lucerne/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Lucerne (Switzerland). */ -class EasterMondayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/GoodFridayTest.php b/tests/Switzerland/Lucerne/GoodFridayTest.php index d9e38cd10..9361c9994 100644 --- a/tests/Switzerland/Lucerne/GoodFridayTest.php +++ b/tests/Switzerland/Lucerne/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Lucerne (Switzerland). */ -class GoodFridayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/ImmaculateConceptionTest.php b/tests/Switzerland/Lucerne/ImmaculateConceptionTest.php index e50ecbfbf..7f9c609db 100644 --- a/tests/Switzerland/Lucerne/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Lucerne/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Lucerne (Switzerland). */ -class ImmaculateConceptionTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/LucerneBaseTestCase.php b/tests/Switzerland/Lucerne/LucerneBaseTestCase.php index bb5699569..92373e4dd 100644 --- a/tests/Switzerland/Lucerne/LucerneBaseTestCase.php +++ b/tests/Switzerland/Lucerne/LucerneBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; @@ -22,18 +27,12 @@ abstract class LucerneBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Lucerne'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Lucerne/LucerneTest.php b/tests/Switzerland/Lucerne/LucerneTest.php index a54963080..b49fde147 100644 --- a/tests/Switzerland/Lucerne/LucerneTest.php +++ b/tests/Switzerland/Lucerne/LucerneTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Lucerne (Switzerland). */ -class LucerneTest extends LucerneBaseTestCase +class LucerneTest extends LucerneBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -61,13 +74,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -75,8 +87,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -84,8 +95,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -93,19 +103,37 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Lucerne (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Lucerne (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Lucerne/NewYearsDayTest.php b/tests/Switzerland/Lucerne/NewYearsDayTest.php index 7a4b5c979..be1e5ab77 100644 --- a/tests/Switzerland/Lucerne/NewYearsDayTest.php +++ b/tests/Switzerland/Lucerne/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Lucerne (Switzerland). */ -class NewYearsDayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Lucerne/PentecostMondayTest.php b/tests/Switzerland/Lucerne/PentecostMondayTest.php index b70726c64..62e0e3924 100644 --- a/tests/Switzerland/Lucerne/PentecostMondayTest.php +++ b/tests/Switzerland/Lucerne/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Lucerne (Switzerland). */ -class PentecostMondayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Lucerne/StStephensDayTest.php b/tests/Switzerland/Lucerne/StStephensDayTest.php index 4a4ac6a09..5c33a610f 100644 --- a/tests/Switzerland/Lucerne/StStephensDayTest.php +++ b/tests/Switzerland/Lucerne/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Lucerne; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Lucerne (Switzerland). */ -class StStephensDayTest extends LucerneBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends LucerneBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/AscensionDayTest.php b/tests/Switzerland/Neuchatel/AscensionDayTest.php index 9081c0ffd..3f5ebefe5 100644 --- a/tests/Switzerland/Neuchatel/AscensionDayTest.php +++ b/tests/Switzerland/Neuchatel/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Neuchatel (Switzerland). */ -class AscensionDayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/BerchtoldsTagTest.php b/tests/Switzerland/Neuchatel/BerchtoldsTagTest.php deleted file mode 100644 index 94e605ae9..000000000 --- a/tests/Switzerland/Neuchatel/BerchtoldsTagTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ - -namespace Yasumi\tests\Switzerland\Neuchatel; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing BerchtoldsTag in Neuchatel (Switzerland). - */ -class BerchtoldsTagTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'berchtoldsTag'; - - /** - * Tests BerchtoldsTag - * - * @throws ReflectionException - * @throws Exception - */ - public function testBerchtoldsTag() - { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); - - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); - } - - /** - * Tests translated name of BerchtoldsTag. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Jour de la Saint-Berthold'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); - } -} diff --git a/tests/Switzerland/Neuchatel/BettagsMontagTest.php b/tests/Switzerland/Neuchatel/BettagsMontagTest.php index b1a330339..376558f47 100644 --- a/tests/Switzerland/Neuchatel/BettagsMontagTest.php +++ b/tests/Switzerland/Neuchatel/BettagsMontagTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Bettags Montag in Neuchatel (Switzerland). */ -class BettagsMontagTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class BettagsMontagTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bettagsMontag'; /** - * Tests Bettags Montag on or after 1832 + * Tests Bettags Montag on or after 1832. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBettagsMontagOnAfter1832() + public function testBettagsMontagOnAfter1832(): void { - $year = $this->generateRandomYear(1832); + $year = static::generateRandomYear(1832); // Find third Sunday of September - $date = new DateTime('Third Sunday of ' . $year . '-09', new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime('Third Sunday of ' . $year . '-09', new \DateTimeZone(self::TIMEZONE)); // Go to next Thursday - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Tests Bettags Montag before 1832 - * @throws ReflectionException + * Tests Bettags Montag before 1832. + * + * @throws \Exception */ - public function testBettagsMontagBefore1832() + public function testBettagsMontagBefore1832(): void { - $year = $this->generateRandomYear(1000, 1831); + $year = static::generateRandomYear(1000, 1831); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Bettags Montag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1832), + static::generateRandomYear(1832), [self::LOCALE => 'Jeûne fédéral'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1900), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1900), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/ChristmasDayTest.php b/tests/Switzerland/Neuchatel/ChristmasDayTest.php index 36c28cc7e..1037f4a6f 100644 --- a/tests/Switzerland/Neuchatel/ChristmasDayTest.php +++ b/tests/Switzerland/Neuchatel/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Neuchatel (Switzerland). */ -class ChristmasDayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/December26thTest.php b/tests/Switzerland/Neuchatel/December26thTest.php new file mode 100644 index 000000000..384eeca51 --- /dev/null +++ b/tests/Switzerland/Neuchatel/December26thTest.php @@ -0,0 +1,93 @@ + + */ + +namespace Yasumi\tests\Switzerland\Neuchatel; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing December 26th in Neuchatel (Switzerland). + */ +class December26thTest extends NeuchatelBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'december26th'; + + /** + * One of the year the holiday is observed. + */ + public const OBSERVANCE_YEAR = 2022; + + /** + * Tests December 26th. + * + * @throws \Exception + */ + public function testDecember26th(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::OBSERVANCE_YEAR, + new \DateTime(self::OBSERVANCE_YEAR . '-12-26', new \DateTimeZone(self::TIMEZONE)) + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2020 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2021 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2023 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2024 + ); + } + + /** + * Tests translated name of December 26th. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::OBSERVANCE_YEAR, + [self::LOCALE => '26 décembre'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, self::OBSERVANCE_YEAR, Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Neuchatel/EasterMondayTest.php b/tests/Switzerland/Neuchatel/EasterMondayTest.php index 39fc77be1..304a1ac63 100644 --- a/tests/Switzerland/Neuchatel/EasterMondayTest.php +++ b/tests/Switzerland/Neuchatel/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Neuchatel (Switzerland). */ -class EasterMondayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/GoodFridayTest.php b/tests/Switzerland/Neuchatel/GoodFridayTest.php index 7228d9926..7213ff589 100644 --- a/tests/Switzerland/Neuchatel/GoodFridayTest.php +++ b/tests/Switzerland/Neuchatel/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Neuchatel (Switzerland). */ -class GoodFridayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/InstaurationRepubliqueTest.php b/tests/Switzerland/Neuchatel/InstaurationRepubliqueTest.php index 2d8dd7221..94080d9a9 100644 --- a/tests/Switzerland/Neuchatel/InstaurationRepubliqueTest.php +++ b/tests/Switzerland/Neuchatel/InstaurationRepubliqueTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Instauration de la République in Neuchatel (Switzerland). */ -class InstaurationRepubliqueTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class InstaurationRepubliqueTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'instaurationRepublique'; /** - * The year in which the holiday was established + * The year in which the holiday was established. */ public const ESTABLISHMENT_YEAR = 1849; /** * Tests Instauration de la République on or after 1849. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testInstaurationRepubliqueOnAfter1849() + public function testInstaurationRepubliqueOnAfter1849(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-03-01", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-03-01", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Instauration de la République before 1849. - * @throws ReflectionException + * + * @throws \Exception */ - public function testInstaurationRepubliqueBefore1849() + public function testInstaurationRepubliqueBefore1849(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of Instauration de la République. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Instauration de la République'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OTHER ); } diff --git a/tests/Switzerland/Neuchatel/January2ndTest.php b/tests/Switzerland/Neuchatel/January2ndTest.php new file mode 100644 index 000000000..9313eac52 --- /dev/null +++ b/tests/Switzerland/Neuchatel/January2ndTest.php @@ -0,0 +1,93 @@ + + */ + +namespace Yasumi\tests\Switzerland\Neuchatel; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing January 2nd in Neuchatel (Switzerland). + */ +class January2ndTest extends NeuchatelBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'january2nd'; + + /** + * One of the year the holiday is observed. + */ + public const OBSERVANCE_YEAR = 2023; + + /** + * Tests January 2nd. + * + * @throws \Exception + */ + public function testJanuary2nd(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::OBSERVANCE_YEAR, + new \DateTime(self::OBSERVANCE_YEAR . '-1-02', new \DateTimeZone(self::TIMEZONE)) + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2020 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2021 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2022 + ); + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + 2024 + ); + } + + /** + * Tests translated name of January 2nd. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::OBSERVANCE_YEAR, + [self::LOCALE => '2 janvier'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, self::OBSERVANCE_YEAR, Holiday::TYPE_OTHER); + } +} diff --git a/tests/Switzerland/Neuchatel/NeuchatelBaseTestCase.php b/tests/Switzerland/Neuchatel/NeuchatelBaseTestCase.php index 394164ebb..a54f618bf 100644 --- a/tests/Switzerland/Neuchatel/NeuchatelBaseTestCase.php +++ b/tests/Switzerland/Neuchatel/NeuchatelBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; @@ -22,18 +27,12 @@ abstract class NeuchatelBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Neuchatel'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Neuchatel/NeuchatelTest.php b/tests/Switzerland/Neuchatel/NeuchatelTest.php index 7f9682a67..912a34bb6 100644 --- a/tests/Switzerland/Neuchatel/NeuchatelTest.php +++ b/tests/Switzerland/Neuchatel/NeuchatelTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Neuchatel (Switzerland). */ -class NeuchatelTest extends NeuchatelBaseTestCase +class NeuchatelTest extends NeuchatelBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -52,20 +65,18 @@ public function testRegionalHolidays(): void 'easterMonday', 'pentecostMonday', 'internationalWorkersDay', - 'berchtoldsTag', 'bettagsMontag', 'instaurationRepublique', ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Tests if all observed holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -73,8 +84,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -82,8 +92,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -91,19 +100,34 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Neuchatel (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Neuchatel (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'instaurationRepublique', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'bettagsMontag', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Neuchatel/NewYearsDayTest.php b/tests/Switzerland/Neuchatel/NewYearsDayTest.php index b10a229da..7058aa0ce 100644 --- a/tests/Switzerland/Neuchatel/NewYearsDayTest.php +++ b/tests/Switzerland/Neuchatel/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Neuchatel (Switzerland). */ -class NewYearsDayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Neuchatel/PentecostMondayTest.php b/tests/Switzerland/Neuchatel/PentecostMondayTest.php index 2d44d1a70..71b9431a8 100644 --- a/tests/Switzerland/Neuchatel/PentecostMondayTest.php +++ b/tests/Switzerland/Neuchatel/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Neuchatel (Switzerland). */ -class PentecostMondayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Neuchatel/WorkersDayTest.php b/tests/Switzerland/Neuchatel/WorkersDayTest.php index ec705e161..ba8c82cde 100644 --- a/tests/Switzerland/Neuchatel/WorkersDayTest.php +++ b/tests/Switzerland/Neuchatel/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Neuchatel; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Neuchatel (Switzerland). */ -class WorkersDayTest extends NeuchatelBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends NeuchatelBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fête du Travail'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/AllSaintsDayTest.php b/tests/Switzerland/Nidwalden/AllSaintsDayTest.php index 0c63e4e59..63bb2590f 100644 --- a/tests/Switzerland/Nidwalden/AllSaintsDayTest.php +++ b/tests/Switzerland/Nidwalden/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Nidwalden (Switzerland). */ -class AllSaintsDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Nidwalden/AscensionDayTest.php b/tests/Switzerland/Nidwalden/AscensionDayTest.php index 55d7e23f3..a4d06b017 100644 --- a/tests/Switzerland/Nidwalden/AscensionDayTest.php +++ b/tests/Switzerland/Nidwalden/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Nidwalden (Switzerland). */ -class AscensionDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/AssumptionOfMaryTest.php b/tests/Switzerland/Nidwalden/AssumptionOfMaryTest.php index f8ef07fcd..87adedac7 100644 --- a/tests/Switzerland/Nidwalden/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Nidwalden/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Nidwalden (Switzerland). */ -class AssumptionOfMaryTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Nidwalden/ChristmasDayTest.php b/tests/Switzerland/Nidwalden/ChristmasDayTest.php index a56367ab5..063d85bc3 100644 --- a/tests/Switzerland/Nidwalden/ChristmasDayTest.php +++ b/tests/Switzerland/Nidwalden/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Nidwalden (Switzerland). */ -class ChristmasDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/CorpusChristiTest.php b/tests/Switzerland/Nidwalden/CorpusChristiTest.php index 5e6abf8d0..f48fc8e61 100644 --- a/tests/Switzerland/Nidwalden/CorpusChristiTest.php +++ b/tests/Switzerland/Nidwalden/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Nidwalden (Switzerland). */ -class CorpusChristiTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends NidwaldenBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/EasterMondayTest.php b/tests/Switzerland/Nidwalden/EasterMondayTest.php index a1027f0a3..93ac66c8a 100644 --- a/tests/Switzerland/Nidwalden/EasterMondayTest.php +++ b/tests/Switzerland/Nidwalden/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Nidwalden (Switzerland). */ -class EasterMondayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/GoodFridayTest.php b/tests/Switzerland/Nidwalden/GoodFridayTest.php index 1eae695fb..8fe75839d 100644 --- a/tests/Switzerland/Nidwalden/GoodFridayTest.php +++ b/tests/Switzerland/Nidwalden/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Nidwalden (Switzerland). */ -class GoodFridayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/ImmaculateConceptionTest.php b/tests/Switzerland/Nidwalden/ImmaculateConceptionTest.php index c1a16fd4e..55ac472a8 100644 --- a/tests/Switzerland/Nidwalden/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Nidwalden/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Nidwalden (Switzerland). */ -class ImmaculateConceptionTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/NewYearsDayTest.php b/tests/Switzerland/Nidwalden/NewYearsDayTest.php index b01170b01..02ffe4389 100644 --- a/tests/Switzerland/Nidwalden/NewYearsDayTest.php +++ b/tests/Switzerland/Nidwalden/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Nidwalden (Switzerland). */ -class NewYearsDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Nidwalden/NidwaldenBaseTestCase.php b/tests/Switzerland/Nidwalden/NidwaldenBaseTestCase.php index ebe1a018a..4e47d7b02 100644 --- a/tests/Switzerland/Nidwalden/NidwaldenBaseTestCase.php +++ b/tests/Switzerland/Nidwalden/NidwaldenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; @@ -22,18 +27,12 @@ abstract class NidwaldenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Nidwalden'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Nidwalden/NidwaldenTest.php b/tests/Switzerland/Nidwalden/NidwaldenTest.php index 6adff25ca..61e19d611 100644 --- a/tests/Switzerland/Nidwalden/NidwaldenTest.php +++ b/tests/Switzerland/Nidwalden/NidwaldenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Nidwalden (Switzerland). */ -class NidwaldenTest extends NidwaldenBaseTestCase +class NidwaldenTest extends NidwaldenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -61,13 +74,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -75,8 +87,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -84,8 +95,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -93,19 +103,37 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Nidwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Nidwalden (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'stJosephsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Nidwalden/PentecostMondayTest.php b/tests/Switzerland/Nidwalden/PentecostMondayTest.php index ec55aef57..1c747498e 100644 --- a/tests/Switzerland/Nidwalden/PentecostMondayTest.php +++ b/tests/Switzerland/Nidwalden/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Nidwalden (Switzerland). */ -class PentecostMondayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/StJosephDayTest.php b/tests/Switzerland/Nidwalden/StJosephDayTest.php index 6952d4117..22dcb1396 100644 --- a/tests/Switzerland/Nidwalden/StJosephDayTest.php +++ b/tests/Switzerland/Nidwalden/StJosephDayTest.php @@ -1,47 +1,46 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Joseph's Day in Nidwalden (Switzerland). */ -class StJosephDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class StJosephDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stJosephsDay'; /** * Tests St. Joseph's Day. * - * @dataProvider StJosephDayDataProvider - * - * @param int $year the year for which St. Joseph's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Joseph's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testStJosephDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephDayDataProvider')] + public function testStJosephDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -49,34 +48,37 @@ public function testStJosephDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Joseph's Day. * - * @return array list of test dates for St. Joseph's Day - * @throws Exception + * @return array list of test dates for St. Joseph's Day + * + * @throws \Exception */ - public function StJosephDayDataProvider(): array + public static function StJosephDayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Josephstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Nidwalden/StStephensDayTest.php b/tests/Switzerland/Nidwalden/StStephensDayTest.php index e6751e536..dfd3e46ad 100644 --- a/tests/Switzerland/Nidwalden/StStephensDayTest.php +++ b/tests/Switzerland/Nidwalden/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Nidwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Nidwalden (Switzerland). */ -class StStephensDayTest extends NidwaldenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends NidwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/AllSaintsDayTest.php b/tests/Switzerland/Obwalden/AllSaintsDayTest.php index 7c3c34489..f8630f3cc 100644 --- a/tests/Switzerland/Obwalden/AllSaintsDayTest.php +++ b/tests/Switzerland/Obwalden/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Obwalden (Switzerland). */ -class AllSaintsDayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Obwalden/AscensionDayTest.php b/tests/Switzerland/Obwalden/AscensionDayTest.php index fb3968c33..9a0b233e7 100644 --- a/tests/Switzerland/Obwalden/AscensionDayTest.php +++ b/tests/Switzerland/Obwalden/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Obwalden (Switzerland). */ -class AscensionDayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/AssumptionOfMaryTest.php b/tests/Switzerland/Obwalden/AssumptionOfMaryTest.php index 5e1c4eed4..3dd55f851 100644 --- a/tests/Switzerland/Obwalden/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Obwalden/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Obwalden (Switzerland). */ -class AssumptionOfMaryTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Obwalden/BerchtoldsTagTest.php b/tests/Switzerland/Obwalden/BerchtoldsTagTest.php index ed6647ca6..671526f0b 100644 --- a/tests/Switzerland/Obwalden/BerchtoldsTagTest.php +++ b/tests/Switzerland/Obwalden/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Obwalden (Switzerland). */ -class BerchtoldsTagTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/BruderKlausenFestTest.php b/tests/Switzerland/Obwalden/BruderKlausenFestTest.php index afecbd18f..3d0633d37 100644 --- a/tests/Switzerland/Obwalden/BruderKlausenFestTest.php +++ b/tests/Switzerland/Obwalden/BruderKlausenFestTest.php @@ -1,94 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Bruder-Klausen-Fest in Obwalden (Switzerland). */ -class BruderKlausenFestTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class BruderKlausenFestTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bruderKlausenFest'; /** - * Tests Bruder-Klausen-Fest on or after 1947 + * Tests Bruder-Klausen-Fest on or after 1947. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBruderKlausenFestOnAfter1947() + public function testBruderKlausenFestOnAfter1947(): void { - $year = $this->generateRandomYear(1947); - $date = new DateTime($year . '-09-25', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(1947); + $date = new \DateTime($year . '-09-25', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); } /** - * Tests Bruder-Klausen-Fest between 1649 and 1946 + * Tests Bruder-Klausen-Fest between 1649 and 1946. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBruderKlausenFestBetween1649And1946() + public function testBruderKlausenFestBetween1649And1946(): void { - $year = $this->generateRandomYear(1649, 1946); - $date = new DateTime($year . '-09-21', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(1649, 1946); + $date = new \DateTime($year . '-09-21', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); } /** - * Tests Bruder-Klausen-Fest before 1648 - * @throws ReflectionException + * Tests Bruder-Klausen-Fest before 1648. + * + * @throws \Exception */ - public function testBruderKlausenFestBefore1648() + public function testBruderKlausenFestBefore1648(): void { - $year = $this->generateRandomYear(1000, 1648); + $year = static::generateRandomYear(1000, 1648); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Bruder-Klausen-Fest. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1947), + static::generateRandomYear(1947), [self::LOCALE => 'Bruder-Klausen-Fest'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1947), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1947), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/ChristmasDayTest.php b/tests/Switzerland/Obwalden/ChristmasDayTest.php index 414940426..94d566c2b 100644 --- a/tests/Switzerland/Obwalden/ChristmasDayTest.php +++ b/tests/Switzerland/Obwalden/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Obwalden (Switzerland). */ -class ChristmasDayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/CorpusChristiTest.php b/tests/Switzerland/Obwalden/CorpusChristiTest.php index 15f1234c4..247185fe1 100644 --- a/tests/Switzerland/Obwalden/CorpusChristiTest.php +++ b/tests/Switzerland/Obwalden/CorpusChristiTest.php @@ -1,72 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Obwalden (Switzerland). */ -class CorpusChristiTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends ObwaldenBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/EasterMondayTest.php b/tests/Switzerland/Obwalden/EasterMondayTest.php index 9e8cfd347..f0b8e55a5 100644 --- a/tests/Switzerland/Obwalden/EasterMondayTest.php +++ b/tests/Switzerland/Obwalden/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Obwalden (Switzerland). */ -class EasterMondayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/GoodFridayTest.php b/tests/Switzerland/Obwalden/GoodFridayTest.php index 2179d440a..b5ac0d96a 100644 --- a/tests/Switzerland/Obwalden/GoodFridayTest.php +++ b/tests/Switzerland/Obwalden/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Obwalden (Switzerland). */ -class GoodFridayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/ImmaculateConceptionTest.php b/tests/Switzerland/Obwalden/ImmaculateConceptionTest.php index 818af8db4..c83baba2e 100644 --- a/tests/Switzerland/Obwalden/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Obwalden/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Obwalden (Switzerland). */ -class ImmaculateConceptionTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/NewYearsDayTest.php b/tests/Switzerland/Obwalden/NewYearsDayTest.php index 40059d9f9..e2f5eb4e0 100644 --- a/tests/Switzerland/Obwalden/NewYearsDayTest.php +++ b/tests/Switzerland/Obwalden/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Obwalden (Switzerland). */ -class NewYearsDayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Obwalden/ObwaldenBaseTestCase.php b/tests/Switzerland/Obwalden/ObwaldenBaseTestCase.php index 41e6a4dd7..8cc1100bd 100644 --- a/tests/Switzerland/Obwalden/ObwaldenBaseTestCase.php +++ b/tests/Switzerland/Obwalden/ObwaldenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; @@ -22,18 +27,12 @@ abstract class ObwaldenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Obwalden'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Obwalden/ObwaldenTest.php b/tests/Switzerland/Obwalden/ObwaldenTest.php index 5dd21aec5..4019ca369 100644 --- a/tests/Switzerland/Obwalden/ObwaldenTest.php +++ b/tests/Switzerland/Obwalden/ObwaldenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Obwalden (Switzerland). */ -class ObwaldenTest extends ObwaldenBaseTestCase +class ObwaldenTest extends ObwaldenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -62,13 +75,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -76,8 +88,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -85,8 +96,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -94,19 +104,38 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Obwalden (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Obwalden (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'bruderKlausenFest', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Obwalden/PentecostMondayTest.php b/tests/Switzerland/Obwalden/PentecostMondayTest.php index d710a7aeb..6262f7bf6 100644 --- a/tests/Switzerland/Obwalden/PentecostMondayTest.php +++ b/tests/Switzerland/Obwalden/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Obwalden (Switzerland). */ -class PentecostMondayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Obwalden/StStephensDayTest.php b/tests/Switzerland/Obwalden/StStephensDayTest.php index 4be0a7046..849899936 100644 --- a/tests/Switzerland/Obwalden/StStephensDayTest.php +++ b/tests/Switzerland/Obwalden/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Obwalden; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Obwalden (Switzerland). */ -class StStephensDayTest extends ObwaldenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends ObwaldenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/AscensionDayTest.php b/tests/Switzerland/Schaffhausen/AscensionDayTest.php index 7780af046..2394fb019 100644 --- a/tests/Switzerland/Schaffhausen/AscensionDayTest.php +++ b/tests/Switzerland/Schaffhausen/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Schaffhausen (Switzerland). */ -class AscensionDayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/BerchtoldsTagTest.php b/tests/Switzerland/Schaffhausen/BerchtoldsTagTest.php index aa0128708..58417e6d0 100644 --- a/tests/Switzerland/Schaffhausen/BerchtoldsTagTest.php +++ b/tests/Switzerland/Schaffhausen/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Schaffhausen (Switzerland). */ -class BerchtoldsTagTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/ChristmasDayTest.php b/tests/Switzerland/Schaffhausen/ChristmasDayTest.php index f08fa0b66..6190e3b1c 100644 --- a/tests/Switzerland/Schaffhausen/ChristmasDayTest.php +++ b/tests/Switzerland/Schaffhausen/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Schaffhausen (Switzerland). */ -class ChristmasDayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/EasterMondayTest.php b/tests/Switzerland/Schaffhausen/EasterMondayTest.php index 510f16a94..cdb29bae0 100644 --- a/tests/Switzerland/Schaffhausen/EasterMondayTest.php +++ b/tests/Switzerland/Schaffhausen/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Schaffhausen (Switzerland). */ -class EasterMondayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/GoodFridayTest.php b/tests/Switzerland/Schaffhausen/GoodFridayTest.php index 8d251e219..88de4e1c0 100644 --- a/tests/Switzerland/Schaffhausen/GoodFridayTest.php +++ b/tests/Switzerland/Schaffhausen/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Schaffhausen (Switzerland). */ -class GoodFridayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/NewYearsDayTest.php b/tests/Switzerland/Schaffhausen/NewYearsDayTest.php index c4df03b57..6c39687dc 100644 --- a/tests/Switzerland/Schaffhausen/NewYearsDayTest.php +++ b/tests/Switzerland/Schaffhausen/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Schaffhausen (Switzerland). */ -class NewYearsDayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Schaffhausen/PentecostMondayTest.php b/tests/Switzerland/Schaffhausen/PentecostMondayTest.php index e8aa0e6ae..7efe7fd7e 100644 --- a/tests/Switzerland/Schaffhausen/PentecostMondayTest.php +++ b/tests/Switzerland/Schaffhausen/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Schaffhausen (Switzerland). */ -class PentecostMondayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/SchaffhausenBaseTestCase.php b/tests/Switzerland/Schaffhausen/SchaffhausenBaseTestCase.php index 506f62b4f..c77373778 100644 --- a/tests/Switzerland/Schaffhausen/SchaffhausenBaseTestCase.php +++ b/tests/Switzerland/Schaffhausen/SchaffhausenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; @@ -22,18 +27,12 @@ abstract class SchaffhausenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Schaffhausen'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Schaffhausen/SchaffhausenTest.php b/tests/Switzerland/Schaffhausen/SchaffhausenTest.php index 93c16bbe3..f002d742c 100644 --- a/tests/Switzerland/Schaffhausen/SchaffhausenTest.php +++ b/tests/Switzerland/Schaffhausen/SchaffhausenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Schaffhausen (Switzerland). */ -class SchaffhausenTest extends SchaffhausenBaseTestCase +class SchaffhausenTest extends SchaffhausenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -58,13 +71,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -72,8 +84,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -81,8 +92,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -90,19 +100,34 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Schaffhausen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Schaffhausen (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Schaffhausen/StStephensDayTest.php b/tests/Switzerland/Schaffhausen/StStephensDayTest.php index a3e2f2f40..402591271 100644 --- a/tests/Switzerland/Schaffhausen/StStephensDayTest.php +++ b/tests/Switzerland/Schaffhausen/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Schaffhausen (Switzerland). */ -class StStephensDayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schaffhausen/WorkersDayTest.php b/tests/Switzerland/Schaffhausen/WorkersDayTest.php index ac38bf4a1..2a28a0f48 100644 --- a/tests/Switzerland/Schaffhausen/WorkersDayTest.php +++ b/tests/Switzerland/Schaffhausen/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schaffhausen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Schaffhausen (Switzerland). */ -class WorkersDayTest extends SchaffhausenBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends SchaffhausenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/AllSaintsDayTest.php b/tests/Switzerland/Schwyz/AllSaintsDayTest.php index e62182f4e..688fddd5c 100644 --- a/tests/Switzerland/Schwyz/AllSaintsDayTest.php +++ b/tests/Switzerland/Schwyz/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Schwyz (Switzerland). */ -class AllSaintsDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Schwyz/AscensionDayTest.php b/tests/Switzerland/Schwyz/AscensionDayTest.php index 3156306d2..1fd0c8dd7 100644 --- a/tests/Switzerland/Schwyz/AscensionDayTest.php +++ b/tests/Switzerland/Schwyz/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Schwyz (Switzerland). */ -class AscensionDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/AssumptionOfMaryTest.php b/tests/Switzerland/Schwyz/AssumptionOfMaryTest.php index e5f45b786..3247d7f03 100644 --- a/tests/Switzerland/Schwyz/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Schwyz/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Schwyz (Switzerland). */ -class AssumptionOfMaryTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Schwyz/ChristmasDayTest.php b/tests/Switzerland/Schwyz/ChristmasDayTest.php index eb369d5e4..dced19bbf 100644 --- a/tests/Switzerland/Schwyz/ChristmasDayTest.php +++ b/tests/Switzerland/Schwyz/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Schwyz (Switzerland). */ -class ChristmasDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/CorpusChristiTest.php b/tests/Switzerland/Schwyz/CorpusChristiTest.php index dae5d0cb7..27e555d43 100644 --- a/tests/Switzerland/Schwyz/CorpusChristiTest.php +++ b/tests/Switzerland/Schwyz/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Schwyz (Switzerland). */ -class CorpusChristiTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends SchwyzBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/EasterMondayTest.php b/tests/Switzerland/Schwyz/EasterMondayTest.php index 0c53e7729..4eeca9c4d 100644 --- a/tests/Switzerland/Schwyz/EasterMondayTest.php +++ b/tests/Switzerland/Schwyz/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Schwyz (Switzerland). */ -class EasterMondayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/EpiphanyTest.php b/tests/Switzerland/Schwyz/EpiphanyTest.php index 1d8b0be01..4c231a15c 100644 --- a/tests/Switzerland/Schwyz/EpiphanyTest.php +++ b/tests/Switzerland/Schwyz/EpiphanyTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Schwyz (Switzerland). */ -class EpiphanyTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige Drei Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/GoodFridayTest.php b/tests/Switzerland/Schwyz/GoodFridayTest.php index a3f879166..8a4d032db 100644 --- a/tests/Switzerland/Schwyz/GoodFridayTest.php +++ b/tests/Switzerland/Schwyz/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Schwyz (Switzerland). */ -class GoodFridayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/ImmaculateConceptionTest.php b/tests/Switzerland/Schwyz/ImmaculateConceptionTest.php index 251b321ad..dd9b6b001 100644 --- a/tests/Switzerland/Schwyz/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Schwyz/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Schwyz (Switzerland). */ -class ImmaculateConceptionTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/NewYearsDayTest.php b/tests/Switzerland/Schwyz/NewYearsDayTest.php index 3e984e39f..e8595645e 100644 --- a/tests/Switzerland/Schwyz/NewYearsDayTest.php +++ b/tests/Switzerland/Schwyz/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Schwyz (Switzerland). */ -class NewYearsDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Schwyz/PentecostMondayTest.php b/tests/Switzerland/Schwyz/PentecostMondayTest.php index 5f789d8e6..3958008a2 100644 --- a/tests/Switzerland/Schwyz/PentecostMondayTest.php +++ b/tests/Switzerland/Schwyz/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Schwyz (Switzerland). */ -class PentecostMondayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/SchwyzBaseTestCase.php b/tests/Switzerland/Schwyz/SchwyzBaseTestCase.php index 99b6f4061..1a565bbe3 100644 --- a/tests/Switzerland/Schwyz/SchwyzBaseTestCase.php +++ b/tests/Switzerland/Schwyz/SchwyzBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; @@ -22,18 +27,12 @@ abstract class SchwyzBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Schwyz'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Schwyz/SchwyzTest.php b/tests/Switzerland/Schwyz/SchwyzTest.php index 9c89225c4..9b0d8c140 100644 --- a/tests/Switzerland/Schwyz/SchwyzTest.php +++ b/tests/Switzerland/Schwyz/SchwyzTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Schwyz (Switzerland). */ -class SchwyzTest extends SchwyzBaseTestCase +class SchwyzTest extends SchwyzBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -62,13 +75,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -76,8 +88,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -85,8 +96,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -94,19 +104,38 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Schwyz (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Schwyz (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'epiphany', + 'stJosephsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Schwyz/StJosephDayTest.php b/tests/Switzerland/Schwyz/StJosephDayTest.php index fdc98b49d..34ecdceba 100644 --- a/tests/Switzerland/Schwyz/StJosephDayTest.php +++ b/tests/Switzerland/Schwyz/StJosephDayTest.php @@ -1,47 +1,46 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Joseph's Day in Schwyz (Switzerland). */ -class StJosephDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class StJosephDayTest extends SchwyzBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stJosephsDay'; /** * Tests St. Joseph's Day. * - * @dataProvider StJosephDayDataProvider - * - * @param int $year the year for which St. Joseph's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Joseph's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testStJosephDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephDayDataProvider')] + public function testStJosephDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -49,34 +48,37 @@ public function testStJosephDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Joseph's Day. * - * @return array list of test dates for St. Joseph's Day - * @throws Exception + * @return array list of test dates for St. Joseph's Day + * + * @throws \Exception */ - public function StJosephDayDataProvider(): array + public static function StJosephDayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Josephstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Schwyz/StStephensDayTest.php b/tests/Switzerland/Schwyz/StStephensDayTest.php index 42ddcccb3..eff31c2e9 100644 --- a/tests/Switzerland/Schwyz/StStephensDayTest.php +++ b/tests/Switzerland/Schwyz/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Schwyz; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Schwyz (Switzerland). */ -class StStephensDayTest extends SchwyzBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends SchwyzBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Solothurn/AscensionDayTest.php b/tests/Switzerland/Solothurn/AscensionDayTest.php index 700a173ff..680f0b64d 100644 --- a/tests/Switzerland/Solothurn/AscensionDayTest.php +++ b/tests/Switzerland/Solothurn/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Solothurn (Switzerland). */ -class AscensionDayTest extends SolothurnBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends SolothurnBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Solothurn/BerchtoldsTagTest.php b/tests/Switzerland/Solothurn/BerchtoldsTagTest.php index a1589c860..956434d1a 100644 --- a/tests/Switzerland/Solothurn/BerchtoldsTagTest.php +++ b/tests/Switzerland/Solothurn/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Solothurn (Switzerland). */ -class BerchtoldsTagTest extends SolothurnBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends SolothurnBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Solothurn/ChristmasDayTest.php b/tests/Switzerland/Solothurn/ChristmasDayTest.php index 31207d23d..82bac1b0d 100644 --- a/tests/Switzerland/Solothurn/ChristmasDayTest.php +++ b/tests/Switzerland/Solothurn/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Solothurn (Switzerland). */ -class ChristmasDayTest extends SolothurnBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends SolothurnBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Solothurn/GoodFridayTest.php b/tests/Switzerland/Solothurn/GoodFridayTest.php index cec3b568d..eab8a71ed 100644 --- a/tests/Switzerland/Solothurn/GoodFridayTest.php +++ b/tests/Switzerland/Solothurn/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Solothurn (Switzerland). */ -class GoodFridayTest extends SolothurnBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends SolothurnBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Solothurn/NewYearsDayTest.php b/tests/Switzerland/Solothurn/NewYearsDayTest.php index 795b60089..356facaf2 100644 --- a/tests/Switzerland/Solothurn/NewYearsDayTest.php +++ b/tests/Switzerland/Solothurn/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Solothurn (Switzerland). */ -class NewYearsDayTest extends SolothurnBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends SolothurnBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Solothurn/SolothurnBaseTestCase.php b/tests/Switzerland/Solothurn/SolothurnBaseTestCase.php index 38273f7f7..b64c15444 100644 --- a/tests/Switzerland/Solothurn/SolothurnBaseTestCase.php +++ b/tests/Switzerland/Solothurn/SolothurnBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; @@ -22,18 +27,12 @@ abstract class SolothurnBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Solothurn'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Solothurn/SolothurnTest.php b/tests/Switzerland/Solothurn/SolothurnTest.php index 51f13f1a8..dc9063356 100644 --- a/tests/Switzerland/Solothurn/SolothurnTest.php +++ b/tests/Switzerland/Solothurn/SolothurnTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Solothurn; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Solothurn (Switzerland). */ -class SolothurnTest extends SolothurnBaseTestCase +class SolothurnTest extends SolothurnBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -40,8 +54,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -55,13 +68,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -69,8 +81,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -78,8 +89,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -87,19 +97,30 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Solothurn (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Solothurn (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'ascensionDay', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/StGallen/AllSaintsDayTest.php b/tests/Switzerland/StGallen/AllSaintsDayTest.php index 5a72db48a..a6214af67 100644 --- a/tests/Switzerland/StGallen/AllSaintsDayTest.php +++ b/tests/Switzerland/StGallen/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in St. Gallen (Switzerland). */ -class AllSaintsDayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/StGallen/AscensionDayTest.php b/tests/Switzerland/StGallen/AscensionDayTest.php index c27554a20..da238eba3 100644 --- a/tests/Switzerland/StGallen/AscensionDayTest.php +++ b/tests/Switzerland/StGallen/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in St. Gallen (Switzerland). */ -class AscensionDayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/StGallen/ChristmasDayTest.php b/tests/Switzerland/StGallen/ChristmasDayTest.php index 98b92ac90..08659bc8c 100644 --- a/tests/Switzerland/StGallen/ChristmasDayTest.php +++ b/tests/Switzerland/StGallen/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in St. Gallen (Switzerland). */ -class ChristmasDayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/StGallen/EasterMondayTest.php b/tests/Switzerland/StGallen/EasterMondayTest.php index f7b404b25..10e2e0fb9 100644 --- a/tests/Switzerland/StGallen/EasterMondayTest.php +++ b/tests/Switzerland/StGallen/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in St. Gallen (Switzerland). */ -class EasterMondayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/StGallen/GoodFridayTest.php b/tests/Switzerland/StGallen/GoodFridayTest.php index 22cbb85b1..75950e560 100644 --- a/tests/Switzerland/StGallen/GoodFridayTest.php +++ b/tests/Switzerland/StGallen/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in St. Gallen (Switzerland). */ -class GoodFridayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/StGallen/NewYearsDayTest.php b/tests/Switzerland/StGallen/NewYearsDayTest.php index 860330605..ee08d1e89 100644 --- a/tests/Switzerland/StGallen/NewYearsDayTest.php +++ b/tests/Switzerland/StGallen/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in St. Gallen (Switzerland). */ -class NewYearsDayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/StGallen/PentecostMondayTest.php b/tests/Switzerland/StGallen/PentecostMondayTest.php index 8a7961e72..b942a2d33 100644 --- a/tests/Switzerland/StGallen/PentecostMondayTest.php +++ b/tests/Switzerland/StGallen/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in St. Gallen (Switzerland). */ -class PentecostMondayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/StGallen/StGallenBaseTestCase.php b/tests/Switzerland/StGallen/StGallenBaseTestCase.php index 53751e055..9f9d93960 100644 --- a/tests/Switzerland/StGallen/StGallenBaseTestCase.php +++ b/tests/Switzerland/StGallen/StGallenBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; @@ -22,18 +27,12 @@ abstract class StGallenBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/StGallen'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/StGallen/StGallenTest.php b/tests/Switzerland/StGallen/StGallenTest.php index 25ef3f378..b6ac5a699 100644 --- a/tests/Switzerland/StGallen/StGallenTest.php +++ b/tests/Switzerland/StGallen/StGallenTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in St. Gallen (Switzerland). */ -class StGallenTest extends StGallenBaseTestCase +class StGallenTest extends StGallenBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in St. Gallen (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in St. Gallen (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'allSaintsDay', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/StGallen/StStephensDayTest.php b/tests/Switzerland/StGallen/StStephensDayTest.php index a708e135e..e3ea5f4ae 100644 --- a/tests/Switzerland/StGallen/StStephensDayTest.php +++ b/tests/Switzerland/StGallen/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\StGallen; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in St. Gallen (Switzerland). */ -class StStephensDayTest extends StGallenBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends StGallenBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/SwissNationalDayTest.php b/tests/Switzerland/SwissNationalDayTest.php index 01729417b..d306d2063 100644 --- a/tests/Switzerland/SwissNationalDayTest.php +++ b/tests/Switzerland/SwissNationalDayTest.php @@ -1,148 +1,151 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for National Day in Switzerland. */ -class SwissNationalDayTest extends SwitzerlandBaseTestCase implements YasumiTestCaseInterface +class SwissNationalDayTest extends SwitzerlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'swissNationalDay'; /** - * The year in which the holiday was established as national holiday + * The year in which the holiday was established as national holiday. */ public const NATIONAL_ESTABLISHMENT_YEAR = 1994; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const FIRST_ESTABLISHMENT_YEAR = 1899; /** - * The year in which the holiday was first observed + * The year in which the holiday was first observed. */ public const FIRST_OBSERVANCE_YEAR = 1891; /** * Tests National Day on or after 1994. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayOnAfter1994() + public function testNationalDayOnAfter1994(): void { - $year = $this->generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-01", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-01", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests National Day on or after 1899 and before 1994. - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayOnAfter1899() + public function testNationalDayOnAfter1899(): void { - $year = $this->generateRandomYear(self::FIRST_ESTABLISHMENT_YEAR, self::NATIONAL_ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(self::FIRST_ESTABLISHMENT_YEAR, self::NATIONAL_ESTABLISHMENT_YEAR - 1); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-01", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-01", new \DateTimeZone(self::TIMEZONE)) ); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); } /** - * Tests National Day on 1891 - * @throws ReflectionException - * @throws Exception - * @throws ReflectionException + * Tests National Day on 1891. + * + * @throws \Exception */ - public function testNationalDayOn1891() + public function testNationalDayOn1891(): void { $year = self::FIRST_OBSERVANCE_YEAR; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-8-01", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-8-01", new \DateTimeZone(self::TIMEZONE)) ); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE); } /** * Tests National Day before 1891. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayBefore1891() + public function testNationalDayBefore1891(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::FIRST_OBSERVANCE_YEAR - 1) + static::generateRandomYear(1000, self::FIRST_OBSERVANCE_YEAR - 1) ); } /** * Tests National Day between 1891 and 1899. - * @throws ReflectionException + * + * @throws \Exception */ - public function testNationalDayBetween1891And1899() + public function testNationalDayBetween1891And1899(): void { - $year = $this->generateRandomYear(self::FIRST_OBSERVANCE_YEAR + 1, self::FIRST_ESTABLISHMENT_YEAR - 1); + $year = static::generateRandomYear(self::FIRST_OBSERVANCE_YEAR + 1, self::FIRST_ESTABLISHMENT_YEAR - 1); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of National Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR), + static::generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR), [self::LOCALE => 'Bundesfeiertag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR), + static::generateRandomYear(self::NATIONAL_ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Switzerland/SwitzerlandBaseTestCase.php b/tests/Switzerland/SwitzerlandBaseTestCase.php index 24ffa87dd..21ba03b23 100644 --- a/tests/Switzerland/SwitzerlandBaseTestCase.php +++ b/tests/Switzerland/SwitzerlandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland; @@ -23,17 +28,13 @@ abstract class SwitzerlandBaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'Switzerland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/SwitzerlandTest.php b/tests/Switzerland/SwitzerlandTest.php index bb2b9d170..f9cbfbccd 100644 --- a/tests/Switzerland/SwitzerlandTest.php +++ b/tests/Switzerland/SwitzerlandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Switzerland. */ -class SwitzerlandTest extends SwitzerlandBaseTestCase +class SwitzerlandTest extends SwitzerlandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Switzerland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Switzerland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,13 +53,12 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Switzerland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Switzerland are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -53,8 +66,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Switzerland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Switzerland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -62,8 +74,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Switzerland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Switzerland are defined by the provider class. */ public function testBankHolidays(): void { @@ -71,8 +82,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Switzerland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Switzerland are defined by the provider class. */ public function testOtherHolidays(): void { @@ -80,10 +90,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Thurgau/AscensionDayTest.php b/tests/Switzerland/Thurgau/AscensionDayTest.php index 5684c6ace..353865f76 100644 --- a/tests/Switzerland/Thurgau/AscensionDayTest.php +++ b/tests/Switzerland/Thurgau/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Thurgau (Switzerland). */ -class AscensionDayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/BerchtoldsTagTest.php b/tests/Switzerland/Thurgau/BerchtoldsTagTest.php index b5f4efe15..a947a13a1 100644 --- a/tests/Switzerland/Thurgau/BerchtoldsTagTest.php +++ b/tests/Switzerland/Thurgau/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Thurgau (Switzerland). */ -class BerchtoldsTagTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/ChristmasDayTest.php b/tests/Switzerland/Thurgau/ChristmasDayTest.php index ee8ae604f..da918cadd 100644 --- a/tests/Switzerland/Thurgau/ChristmasDayTest.php +++ b/tests/Switzerland/Thurgau/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Thurgau (Switzerland). */ -class ChristmasDayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/EasterMondayTest.php b/tests/Switzerland/Thurgau/EasterMondayTest.php index 5a4cd9ecb..a836510fe 100644 --- a/tests/Switzerland/Thurgau/EasterMondayTest.php +++ b/tests/Switzerland/Thurgau/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Thurgau (Switzerland). */ -class EasterMondayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/GoodFridayTest.php b/tests/Switzerland/Thurgau/GoodFridayTest.php index bf100fbab..b32d65efc 100644 --- a/tests/Switzerland/Thurgau/GoodFridayTest.php +++ b/tests/Switzerland/Thurgau/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Thurgau (Switzerland). */ -class GoodFridayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/NewYearsDayTest.php b/tests/Switzerland/Thurgau/NewYearsDayTest.php index b6b82f4d5..fc7792dd6 100644 --- a/tests/Switzerland/Thurgau/NewYearsDayTest.php +++ b/tests/Switzerland/Thurgau/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Thurgau (Switzerland). */ -class NewYearsDayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Thurgau/PentecostMondayTest.php b/tests/Switzerland/Thurgau/PentecostMondayTest.php index 660b675fe..d9f3609c1 100644 --- a/tests/Switzerland/Thurgau/PentecostMondayTest.php +++ b/tests/Switzerland/Thurgau/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Thurgau (Switzerland). */ -class PentecostMondayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/StStephensDayTest.php b/tests/Switzerland/Thurgau/StStephensDayTest.php index 2f38d0d50..d6b6ce9cb 100644 --- a/tests/Switzerland/Thurgau/StStephensDayTest.php +++ b/tests/Switzerland/Thurgau/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Thurgau (Switzerland). */ -class StStephensDayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Thurgau/ThurgauBaseTestCase.php b/tests/Switzerland/Thurgau/ThurgauBaseTestCase.php index 87aa4f9f4..ca4cbdbb8 100644 --- a/tests/Switzerland/Thurgau/ThurgauBaseTestCase.php +++ b/tests/Switzerland/Thurgau/ThurgauBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; @@ -22,18 +27,12 @@ abstract class ThurgauBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Thurgau'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Thurgau/ThurgauTest.php b/tests/Switzerland/Thurgau/ThurgauTest.php index f214114dd..948ec16b7 100644 --- a/tests/Switzerland/Thurgau/ThurgauTest.php +++ b/tests/Switzerland/Thurgau/ThurgauTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Thurgau (Switzerland). */ -class ThurgauTest extends ThurgauBaseTestCase +class ThurgauTest extends ThurgauBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -58,13 +71,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -72,8 +84,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -81,8 +92,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -90,19 +100,34 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Thurgau (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Thurgau (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Thurgau/WorkersDayTest.php b/tests/Switzerland/Thurgau/WorkersDayTest.php index 9b7c71fad..e81fc28ff 100644 --- a/tests/Switzerland/Thurgau/WorkersDayTest.php +++ b/tests/Switzerland/Thurgau/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Thurgau; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Thurgau (Switzerland). */ -class WorkersDayTest extends ThurgauBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends ThurgauBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/AllSaintsDayTest.php b/tests/Switzerland/Ticino/AllSaintsDayTest.php index d8ac06566..fb780940d 100644 --- a/tests/Switzerland/Ticino/AllSaintsDayTest.php +++ b/tests/Switzerland/Ticino/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Ticino (Switzerland). */ -class AllSaintsDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ognissanti'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Ticino/AscensionDayTest.php b/tests/Switzerland/Ticino/AscensionDayTest.php index 302e97d6d..aea3c5600 100644 --- a/tests/Switzerland/Ticino/AscensionDayTest.php +++ b/tests/Switzerland/Ticino/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Ticino (Switzerland). */ -class AscensionDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascensione'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/AssumptionOfMaryTest.php b/tests/Switzerland/Ticino/AssumptionOfMaryTest.php index 7fbe3acfc..696213f2c 100644 --- a/tests/Switzerland/Ticino/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Ticino/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Ticino (Switzerland). */ -class AssumptionOfMaryTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assunzione'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Ticino/ChristmasDayTest.php b/tests/Switzerland/Ticino/ChristmasDayTest.php index e0b946bcf..917ff421d 100644 --- a/tests/Switzerland/Ticino/ChristmasDayTest.php +++ b/tests/Switzerland/Ticino/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Ticino (Switzerland). */ -class ChristmasDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Natale'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/CorpusChristiTest.php b/tests/Switzerland/Ticino/CorpusChristiTest.php index 6389a308f..12af645cf 100644 --- a/tests/Switzerland/Ticino/CorpusChristiTest.php +++ b/tests/Switzerland/Ticino/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Ticino (Switzerland). */ -class CorpusChristiTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends TicinoBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Corpus Domini'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/EasterMondayTest.php b/tests/Switzerland/Ticino/EasterMondayTest.php index 026f15d8b..b9be12cdc 100644 --- a/tests/Switzerland/Ticino/EasterMondayTest.php +++ b/tests/Switzerland/Ticino/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Ticino (Switzerland). */ -class EasterMondayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lunedi di Pasqua'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/EpiphanyTest.php b/tests/Switzerland/Ticino/EpiphanyTest.php index 4236b715d..3b9609881 100644 --- a/tests/Switzerland/Ticino/EpiphanyTest.php +++ b/tests/Switzerland/Ticino/EpiphanyTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Ticino (Switzerland). */ -class EpiphanyTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Epifania'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/ImmaculateConceptionTest.php b/tests/Switzerland/Ticino/ImmaculateConceptionTest.php index 450d5ff61..b4830d6d9 100644 --- a/tests/Switzerland/Ticino/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Ticino/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Ticino (Switzerland). */ -class ImmaculateConceptionTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Immacolata Concezione'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/NewYearsDayTest.php b/tests/Switzerland/Ticino/NewYearsDayTest.php index 8c3b688f2..5afdd249a 100644 --- a/tests/Switzerland/Ticino/NewYearsDayTest.php +++ b/tests/Switzerland/Ticino/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Ticino (Switzerland). */ -class NewYearsDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Capodanno'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Ticino/PentecostMondayTest.php b/tests/Switzerland/Ticino/PentecostMondayTest.php index f6fabd015..3346bd32a 100644 --- a/tests/Switzerland/Ticino/PentecostMondayTest.php +++ b/tests/Switzerland/Ticino/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Ticino (Switzerland). */ -class PentecostMondayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lunedi di Pentecoste'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/StJosephDayTest.php b/tests/Switzerland/Ticino/StJosephDayTest.php index c3ff8a5cb..37397f492 100644 --- a/tests/Switzerland/Ticino/StJosephDayTest.php +++ b/tests/Switzerland/Ticino/StJosephDayTest.php @@ -1,47 +1,46 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Joseph's Day in Ticino (Switzerland). */ -class StJosephDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class StJosephDayTest extends TicinoBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stJosephsDay'; /** * Tests St. Joseph's Day. * - * @dataProvider StJosephDayDataProvider - * - * @param int $year the year for which St. Joseph's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Joseph's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testStJosephDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephDayDataProvider')] + public function testStJosephDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -49,34 +48,37 @@ public function testStJosephDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Joseph's Day. * - * @return array list of test dates for St. Joseph's Day - * @throws Exception + * @return array list of test dates for St. Joseph's Day + * + * @throws \Exception */ - public function StJosephDayDataProvider(): array + public static function StJosephDayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'San Giuseppe'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/StPeterPaulTest.php b/tests/Switzerland/Ticino/StPeterPaulTest.php index ce9b43250..5d7ffae1d 100644 --- a/tests/Switzerland/Ticino/StPeterPaulTest.php +++ b/tests/Switzerland/Ticino/StPeterPaulTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Feast of Saints Peter and Paul in Ticino (Switzerland). */ -class StPeterPaulTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class StPeterPaulTest extends TicinoBaseTestCase implements HolidayTestCase { - /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stPeterPaul'; /** * Tests Feast of Saints Peter and Paul. * - * @dataProvider StPeterPaulDataProvider - * - * @param int $year the year for which Feast of Saints Peter and Paul needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Feast of Saints Peter and Paul needs to be tested + * @param \DateTime $expected the expected date */ - public function testStPeterPaul($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StPeterPaulDataProvider')] + public function testStPeterPaul(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function testStPeterPaul($year, $expected) /** * Returns a list of random test dates used for assertion of Feast of Saints Peter and Paul. * - * @return array list of test dates for Feast of Saints Peter and Paul - * @throws Exception + * @return array list of test dates for Feast of Saints Peter and Paul + * + * @throws \Exception */ - public function StPeterPaulDataProvider(): array + public static function StPeterPaulDataProvider(): array { - return $this->generateRandomDates(6, 29, self::TIMEZONE); + return static::generateRandomDates(6, 29, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Santi Pietro e Paolo'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/StStephensDayTest.php b/tests/Switzerland/Ticino/StStephensDayTest.php index e571a914d..8039fc51e 100644 --- a/tests/Switzerland/Ticino/StStephensDayTest.php +++ b/tests/Switzerland/Ticino/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Ticino (Switzerland). */ -class StStephensDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Santo Stefano'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Ticino/TicinoBaseTestCase.php b/tests/Switzerland/Ticino/TicinoBaseTestCase.php index 7dc3d7b40..89b6cb1f8 100644 --- a/tests/Switzerland/Ticino/TicinoBaseTestCase.php +++ b/tests/Switzerland/Ticino/TicinoBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; @@ -22,18 +27,12 @@ abstract class TicinoBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Ticino'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'it_CH'; } diff --git a/tests/Switzerland/Ticino/TicinoTest.php b/tests/Switzerland/Ticino/TicinoTest.php index bd2e521d6..92e449f99 100644 --- a/tests/Switzerland/Ticino/TicinoTest.php +++ b/tests/Switzerland/Ticino/TicinoTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Ticino (Switzerland). */ -class TicinoTest extends TicinoBaseTestCase +class TicinoTest extends TicinoBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Ticino (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Ticino (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -63,13 +76,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Ticino (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -77,8 +89,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Ticino (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -86,8 +97,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Ticino (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -95,19 +105,39 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Ticino (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Ticino (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'epiphany', + 'stJosephsDay', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'stPeterPaul', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Ticino/WorkersDayTest.php b/tests/Switzerland/Ticino/WorkersDayTest.php index 71101fdaa..ab935539c 100644 --- a/tests/Switzerland/Ticino/WorkersDayTest.php +++ b/tests/Switzerland/Ticino/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Ticino; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Ticino (Switzerland). */ -class WorkersDayTest extends TicinoBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends TicinoBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Festa dei lavoratori'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/AllSaintsDayTest.php b/tests/Switzerland/Uri/AllSaintsDayTest.php index 5daabb77c..28e281f4e 100644 --- a/tests/Switzerland/Uri/AllSaintsDayTest.php +++ b/tests/Switzerland/Uri/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Uri (Switzerland). */ -class AllSaintsDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Uri/AscensionDayTest.php b/tests/Switzerland/Uri/AscensionDayTest.php index b4ad563b2..ea93292be 100644 --- a/tests/Switzerland/Uri/AscensionDayTest.php +++ b/tests/Switzerland/Uri/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Uri (Switzerland). */ -class AscensionDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/AssumptionOfMaryTest.php b/tests/Switzerland/Uri/AssumptionOfMaryTest.php index bf183f0bd..9db396279 100644 --- a/tests/Switzerland/Uri/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Uri/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Uri (Switzerland). */ -class AssumptionOfMaryTest extends UriBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Uri/ChristmasDayTest.php b/tests/Switzerland/Uri/ChristmasDayTest.php index 81be39847..4d32bcdb9 100644 --- a/tests/Switzerland/Uri/ChristmasDayTest.php +++ b/tests/Switzerland/Uri/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Uri (Switzerland). */ -class ChristmasDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/CorpusChristiTest.php b/tests/Switzerland/Uri/CorpusChristiTest.php index 563606ba9..c3da48b4f 100644 --- a/tests/Switzerland/Uri/CorpusChristiTest.php +++ b/tests/Switzerland/Uri/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Uri (Switzerland). */ -class CorpusChristiTest extends UriBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends UriBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/EasterMondayTest.php b/tests/Switzerland/Uri/EasterMondayTest.php index cd4146c42..f77596a12 100644 --- a/tests/Switzerland/Uri/EasterMondayTest.php +++ b/tests/Switzerland/Uri/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Uri (Switzerland). */ -class EasterMondayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/EpiphanyTest.php b/tests/Switzerland/Uri/EpiphanyTest.php index 443ea02e1..acfb6910d 100644 --- a/tests/Switzerland/Uri/EpiphanyTest.php +++ b/tests/Switzerland/Uri/EpiphanyTest.php @@ -1,45 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Epiphany in Uri (Switzerland). */ -class EpiphanyTest extends UriBaseTestCase implements YasumiTestCaseInterface +class EpiphanyTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'epiphany'; - /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -47,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 6, self::TIMEZONE); + return static::generateRandomDates(1, 6, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Heilige Drei Könige'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/GoodFridayTest.php b/tests/Switzerland/Uri/GoodFridayTest.php index d5a9893b3..565ccd624 100644 --- a/tests/Switzerland/Uri/GoodFridayTest.php +++ b/tests/Switzerland/Uri/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Uri (Switzerland). */ -class GoodFridayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/ImmaculateConceptionTest.php b/tests/Switzerland/Uri/ImmaculateConceptionTest.php index 0b4214838..d67583e0d 100644 --- a/tests/Switzerland/Uri/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Uri/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Uri (Switzerland). */ -class ImmaculateConceptionTest extends UriBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/NewYearsDayTest.php b/tests/Switzerland/Uri/NewYearsDayTest.php index ca3af4eef..ae7c13132 100644 --- a/tests/Switzerland/Uri/NewYearsDayTest.php +++ b/tests/Switzerland/Uri/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Uri (Switzerland). */ -class NewYearsDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Uri/PentecostMondayTest.php b/tests/Switzerland/Uri/PentecostMondayTest.php index 0ec45cf50..9461ddd63 100644 --- a/tests/Switzerland/Uri/PentecostMondayTest.php +++ b/tests/Switzerland/Uri/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Uri (Switzerland). */ -class PentecostMondayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/StJosephDayTest.php b/tests/Switzerland/Uri/StJosephDayTest.php index 5485301b2..9afa9fab6 100644 --- a/tests/Switzerland/Uri/StJosephDayTest.php +++ b/tests/Switzerland/Uri/StJosephDayTest.php @@ -1,47 +1,46 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Joseph's Day in Uri (Switzerland). */ -class StJosephDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class StJosephDayTest extends UriBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stJosephsDay'; /** * Tests St. Joseph's Day. * - * @dataProvider StJosephDayDataProvider - * - * @param int $year the year for which St. Joseph's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Joseph's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testStJosephDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephDayDataProvider')] + public function testStJosephDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -49,34 +48,37 @@ public function testStJosephDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Joseph's Day. * - * @return array list of test dates for St. Joseph's Day - * @throws Exception + * @return array list of test dates for St. Joseph's Day + * + * @throws \Exception */ - public function StJosephDayDataProvider(): array + public static function StJosephDayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Josephstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/StStephensDayTest.php b/tests/Switzerland/Uri/StStephensDayTest.php index 4997103ba..10a62ac0f 100644 --- a/tests/Switzerland/Uri/StStephensDayTest.php +++ b/tests/Switzerland/Uri/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Uri (Switzerland). */ -class StStephensDayTest extends UriBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends UriBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Uri/UriBaseTestCase.php b/tests/Switzerland/Uri/UriBaseTestCase.php index 1cb912a7e..28b20d1e0 100644 --- a/tests/Switzerland/Uri/UriBaseTestCase.php +++ b/tests/Switzerland/Uri/UriBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; @@ -22,18 +27,12 @@ abstract class UriBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Uri'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Uri/UriTest.php b/tests/Switzerland/Uri/UriTest.php index 8d4095b64..61223abf7 100644 --- a/tests/Switzerland/Uri/UriTest.php +++ b/tests/Switzerland/Uri/UriTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Uri; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Uri (Switzerland). */ -class UriTest extends UriBaseTestCase +class UriTest extends UriBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Uri (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Uri (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -62,13 +75,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Uri (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -76,8 +88,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Uri (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -85,8 +96,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Uri (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -94,19 +104,38 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Uri (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Uri (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'epiphany', + 'stJosephsDay', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Valais/AllSaintsDayTest.php b/tests/Switzerland/Valais/AllSaintsDayTest.php index 959110522..558ffe05b 100644 --- a/tests/Switzerland/Valais/AllSaintsDayTest.php +++ b/tests/Switzerland/Valais/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Valais (Switzerland). */ -class AllSaintsDayTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Toussaint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Valais/AscensionDayTest.php b/tests/Switzerland/Valais/AscensionDayTest.php index 5098bb9e3..3f265ae6e 100644 --- a/tests/Switzerland/Valais/AscensionDayTest.php +++ b/tests/Switzerland/Valais/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Valais (Switzerland). */ -class AscensionDayTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Valais/AssumptionOfMaryTest.php b/tests/Switzerland/Valais/AssumptionOfMaryTest.php index 6f50d2132..7e0287513 100644 --- a/tests/Switzerland/Valais/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Valais/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Valais (Switzerland). */ -class AssumptionOfMaryTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Assomption'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Valais/ChristmasDayTest.php b/tests/Switzerland/Valais/ChristmasDayTest.php index f59c3b3f3..5cf57bb9f 100644 --- a/tests/Switzerland/Valais/ChristmasDayTest.php +++ b/tests/Switzerland/Valais/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Valais (Switzerland). */ -class ChristmasDayTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Valais/CorpusChristiTest.php b/tests/Switzerland/Valais/CorpusChristiTest.php index 5714a60a8..9d139e047 100644 --- a/tests/Switzerland/Valais/CorpusChristiTest.php +++ b/tests/Switzerland/Valais/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Valais (Switzerland). */ -class CorpusChristiTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends ValaisBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fête-Dieu'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Valais/ImmaculateConceptionTest.php b/tests/Switzerland/Valais/ImmaculateConceptionTest.php index 3ab4470e2..5ef326320 100644 --- a/tests/Switzerland/Valais/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Valais/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Valais (Switzerland). */ -class ImmaculateConceptionTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Immaculée Conception'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Valais/NewYearsDayTest.php b/tests/Switzerland/Valais/NewYearsDayTest.php index 07caa7ddb..9037da167 100644 --- a/tests/Switzerland/Valais/NewYearsDayTest.php +++ b/tests/Switzerland/Valais/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Valais (Switzerland). */ -class NewYearsDayTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ValaisBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Valais/StJosephDayTest.php b/tests/Switzerland/Valais/StJosephDayTest.php index 5c172ab53..77a84cc0e 100644 --- a/tests/Switzerland/Valais/StJosephDayTest.php +++ b/tests/Switzerland/Valais/StJosephDayTest.php @@ -1,47 +1,46 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Joseph's Day in Valais (Switzerland). */ -class StJosephDayTest extends ValaisBaseTestCase implements YasumiTestCaseInterface +class StJosephDayTest extends ValaisBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'stJosephsDay'; /** * Tests St. Joseph's Day. * - * @dataProvider StJosephDayDataProvider - * - * @param int $year the year for which St. Joseph's Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which St. Joseph's Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testStJosephDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('StJosephDayDataProvider')] + public function testStJosephDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -49,34 +48,37 @@ public function testStJosephDay($year, $expected) /** * Returns a list of random test dates used for assertion of St. Joseph's Day. * - * @return array list of test dates for St. Joseph's Day - * @throws Exception + * @return array list of test dates for St. Joseph's Day + * + * @throws \Exception */ - public function StJosephDayDataProvider(): array + public static function StJosephDayDataProvider(): array { - return $this->generateRandomDates(3, 19, self::TIMEZONE); + return static::generateRandomDates(3, 19, self::TIMEZONE); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Saint-Joseph'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Valais/ValaisBaseTestCase.php b/tests/Switzerland/Valais/ValaisBaseTestCase.php index 8315e5041..7bffc30b2 100644 --- a/tests/Switzerland/Valais/ValaisBaseTestCase.php +++ b/tests/Switzerland/Valais/ValaisBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; @@ -22,18 +27,12 @@ abstract class ValaisBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Valais'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Valais/ValaisTest.php b/tests/Switzerland/Valais/ValaisTest.php index 67500efb9..fd1b5ca80 100644 --- a/tests/Switzerland/Valais/ValaisTest.php +++ b/tests/Switzerland/Valais/ValaisTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Valais; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Valais (Switzerland). */ -class ValaisTest extends ValaisBaseTestCase +class ValaisTest extends ValaisBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Valais (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Valais (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Valais (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Valais (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Valais (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Valais (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Valais (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'stJosephsDay', + 'ascensionDay', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Vaud/AscensionDayTest.php b/tests/Switzerland/Vaud/AscensionDayTest.php index cd1c86ac2..fe45b7d2c 100644 --- a/tests/Switzerland/Vaud/AscensionDayTest.php +++ b/tests/Switzerland/Vaud/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Vaud (Switzerland). */ -class AscensionDayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ascension'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/BerchtoldsTagTest.php b/tests/Switzerland/Vaud/BerchtoldsTagTest.php index 13f3d8bb5..f8782f4b7 100644 --- a/tests/Switzerland/Vaud/BerchtoldsTagTest.php +++ b/tests/Switzerland/Vaud/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Vaud (Switzerland). */ -class BerchtoldsTagTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Jour de la Saint-Berthold'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/BettagsMontagTest.php b/tests/Switzerland/Vaud/BettagsMontagTest.php index 25968c5e7..50f21141a 100644 --- a/tests/Switzerland/Vaud/BettagsMontagTest.php +++ b/tests/Switzerland/Vaud/BettagsMontagTest.php @@ -1,83 +1,85 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Bettags Montag in Vaud (Switzerland). */ -class BettagsMontagTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class BettagsMontagTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'bettagsMontag'; /** - * Tests Bettags Montag on or after 1832 - * @throws ReflectionException + * Tests Bettags Montag on or after 1832. * - * @throws Exception + * @throws \Exception */ - public function testBettagsMontagOnAfter1832() + public function testBettagsMontagOnAfter1832(): void { - $year = $this->generateRandomYear(1832); + $year = static::generateRandomYear(1832); // Find third Sunday of September - $date = new DateTime('Third Sunday of ' . $year . '-09', new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime('Third Sunday of ' . $year . '-09', new \DateTimeZone(self::TIMEZONE)); // Go to next Thursday - $date->add(new DateInterval('P1D')); + $date->add(new \DateInterval('P1D')); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Tests Bettags Montag before 1832 - * @throws ReflectionException + * Tests Bettags Montag before 1832. + * + * @throws \Exception */ - public function testBettagsMontagBefore1832() + public function testBettagsMontagBefore1832(): void { - $year = $this->generateRandomYear(1000, 1831); + $year = static::generateRandomYear(1000, 1831); $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Bettags Montag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1832), + static::generateRandomYear(1832), [self::LOCALE => 'Jeûne fédéral'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(1900), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1900), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/ChristmasDayTest.php b/tests/Switzerland/Vaud/ChristmasDayTest.php index f3008b403..4544b24c5 100644 --- a/tests/Switzerland/Vaud/ChristmasDayTest.php +++ b/tests/Switzerland/Vaud/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Vaud (Switzerland). */ -class ChristmasDayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Noël'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/EasterMondayTest.php b/tests/Switzerland/Vaud/EasterMondayTest.php index 05fdade11..315854d5a 100644 --- a/tests/Switzerland/Vaud/EasterMondayTest.php +++ b/tests/Switzerland/Vaud/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Vaud (Switzerland). */ -class EasterMondayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pâques'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/GoodFridayTest.php b/tests/Switzerland/Vaud/GoodFridayTest.php index 2839636be..da34d7834 100644 --- a/tests/Switzerland/Vaud/GoodFridayTest.php +++ b/tests/Switzerland/Vaud/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Vaud (Switzerland). */ -class GoodFridayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Vendredi Saint'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/NewYearsDayTest.php b/tests/Switzerland/Vaud/NewYearsDayTest.php index 387a8ef34..e37a0b45e 100644 --- a/tests/Switzerland/Vaud/NewYearsDayTest.php +++ b/tests/Switzerland/Vaud/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Vaud (Switzerland). */ -class NewYearsDayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Nouvel An'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Vaud/PentecostMondayTest.php b/tests/Switzerland/Vaud/PentecostMondayTest.php index 289ee2867..76866875d 100644 --- a/tests/Switzerland/Vaud/PentecostMondayTest.php +++ b/tests/Switzerland/Vaud/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Vaud (Switzerland). */ -class PentecostMondayTest extends VaudBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends VaudBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Lundi de Pentecôte'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Vaud/VaudBaseTestCase.php b/tests/Switzerland/Vaud/VaudBaseTestCase.php index 235ffd005..4bde2d947 100644 --- a/tests/Switzerland/Vaud/VaudBaseTestCase.php +++ b/tests/Switzerland/Vaud/VaudBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; @@ -22,18 +27,12 @@ abstract class VaudBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Vaud'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'fr_CH'; } diff --git a/tests/Switzerland/Vaud/VaudTest.php b/tests/Switzerland/Vaud/VaudTest.php index 2ef4757c7..c2456f903 100644 --- a/tests/Switzerland/Vaud/VaudTest.php +++ b/tests/Switzerland/Vaud/VaudTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Vaud; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Vaud (Switzerland). */ -class VaudTest extends VaudBaseTestCase +class VaudTest extends VaudBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Vaud (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Vaud (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -57,13 +70,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Vaud (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -71,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Vaud (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -80,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Vaud (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -89,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Vaud (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Vaud (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'bettagsMontag', + 'christmasDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Zug/AllSaintsDayTest.php b/tests/Switzerland/Zug/AllSaintsDayTest.php index c1c954f2f..ef451414b 100644 --- a/tests/Switzerland/Zug/AllSaintsDayTest.php +++ b/tests/Switzerland/Zug/AllSaintsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing All Saints' Day in Zug (Switzerland). */ -class AllSaintsDayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class AllSaintsDayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'allSaintsDay'; /** * Tests All Saints' Day. * - * @dataProvider AllSaintsDayDataProvider - * - * @param int $year the year for which All Saints' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which All Saints' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testAllSaintsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AllSaintsDayDataProvider')] + public function testAllSaintsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of All Saints' Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Allerheiligen'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of All Saints' Day. * - * @return array list of test dates for All Saints' Day - * @throws Exception + * @return array list of test dates for All Saints' Day + * + * @throws \Exception */ - public function AllSaintsDayDataProvider(): array + public static function AllSaintsDayDataProvider(): array { - return $this->generateRandomDates(11, 1, self::TIMEZONE); + return static::generateRandomDates(11, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Zug/AscensionDayTest.php b/tests/Switzerland/Zug/AscensionDayTest.php index 9f145a543..94a260a5e 100644 --- a/tests/Switzerland/Zug/AscensionDayTest.php +++ b/tests/Switzerland/Zug/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Zug (Switzerland). */ -class AscensionDayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/AssumptionOfMaryTest.php b/tests/Switzerland/Zug/AssumptionOfMaryTest.php index f7fa6e966..f5d2d358c 100644 --- a/tests/Switzerland/Zug/AssumptionOfMaryTest.php +++ b/tests/Switzerland/Zug/AssumptionOfMaryTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of the Assumption of Mary in Zug (Switzerland). */ -class AssumptionOfMaryTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class AssumptionOfMaryTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'assumptionOfMary'; /** * Tests the day of the Assumption of Mary. * - * @dataProvider AssumptionOfMaryDataProvider - * - * @param int $year the year for which the day of the Assumption of Mary needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the day of the Assumption of Mary needs to be tested + * @param \DateTime $expected the expected date */ - public function testAssumptionOfMary($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('AssumptionOfMaryDataProvider')] + public function testAssumptionOfMary(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the day of the Assumption of Mary. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Himmelfahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of the day of the Assumption of Mary. * - * @return array list of test dates for the day of the Assumption of Mary - * @throws Exception + * @return array list of test dates for the day of the Assumption of Mary + * + * @throws \Exception */ - public function AssumptionOfMaryDataProvider(): array + public static function AssumptionOfMaryDataProvider(): array { - return $this->generateRandomDates(8, 15, self::TIMEZONE); + return static::generateRandomDates(8, 15, self::TIMEZONE); } } diff --git a/tests/Switzerland/Zug/BerchtoldsTagTest.php b/tests/Switzerland/Zug/BerchtoldsTagTest.php index 96ce451f8..1b5b69a88 100644 --- a/tests/Switzerland/Zug/BerchtoldsTagTest.php +++ b/tests/Switzerland/Zug/BerchtoldsTagTest.php @@ -1,44 +1,44 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing BerchtoldsTag in Zug (Switzerland). */ -class BerchtoldsTagTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class BerchtoldsTagTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'berchtoldsTag'; /** - * Tests BerchtoldsTag + * Tests BerchtoldsTag. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testBerchtoldsTag() + public function testBerchtoldsTag(): void { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); + $year = static::generateRandomYear(); + $date = new \DateTime($year . '-01-02', new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); @@ -46,24 +46,26 @@ public function testBerchtoldsTag() /** * Tests translated name of BerchtoldsTag. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Berchtoldstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/ChristmasDayTest.php b/tests/Switzerland/Zug/ChristmasDayTest.php index 6c827d68a..4a05226dc 100644 --- a/tests/Switzerland/Zug/ChristmasDayTest.php +++ b/tests/Switzerland/Zug/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Zug (Switzerland). */ -class ChristmasDayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/CorpusChristiTest.php b/tests/Switzerland/Zug/CorpusChristiTest.php index 5052521be..a0c648ee7 100644 --- a/tests/Switzerland/Zug/CorpusChristiTest.php +++ b/tests/Switzerland/Zug/CorpusChristiTest.php @@ -1,73 +1,76 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateInterval; -use Exception; -use ReflectionException; use Yasumi\Holiday; use Yasumi\Provider\ChristianHolidays; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Corpus Christi in Zug (Switzerland). */ -class CorpusChristiTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class CorpusChristiTest extends ZugBaseTestCase implements HolidayTestCase { use ChristianHolidays; /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'corpusChristi'; /** * Tests Corpus Christi. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testCorpusChristi() + public function testCorpusChristi(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - $this->calculateEaster($year, self::TIMEZONE)->add(new DateInterval('P60D')) + static::computeEaster($year, self::TIMEZONE)->add(new \DateInterval('P60D')) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Fronleichnam'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/EasterMondayTest.php b/tests/Switzerland/Zug/EasterMondayTest.php index 66d5a9eed..494e8ae41 100644 --- a/tests/Switzerland/Zug/EasterMondayTest.php +++ b/tests/Switzerland/Zug/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Zug (Switzerland). */ -class EasterMondayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/GoodFridayTest.php b/tests/Switzerland/Zug/GoodFridayTest.php index b8606c8f8..b4b5f8d1a 100644 --- a/tests/Switzerland/Zug/GoodFridayTest.php +++ b/tests/Switzerland/Zug/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Zug (Switzerland). */ -class GoodFridayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/ImmaculateConceptionTest.php b/tests/Switzerland/Zug/ImmaculateConceptionTest.php index 7bce420ce..e8a49be85 100644 --- a/tests/Switzerland/Zug/ImmaculateConceptionTest.php +++ b/tests/Switzerland/Zug/ImmaculateConceptionTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the day of Immaculate Conception in Zug (Switzerland). */ -class ImmaculateConceptionTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class ImmaculateConceptionTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'immaculateConception'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testHoliday($year, $expected) /** * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the day of the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 8, self::TIMEZONE); + return static::generateRandomDates(12, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Mariä Empfängnis'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/NewYearsDayTest.php b/tests/Switzerland/Zug/NewYearsDayTest.php index 2c4a762a8..f8fdb9014 100644 --- a/tests/Switzerland/Zug/NewYearsDayTest.php +++ b/tests/Switzerland/Zug/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Zug (Switzerland). */ -class NewYearsDayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Zug/PentecostMondayTest.php b/tests/Switzerland/Zug/PentecostMondayTest.php index 465a86e4a..277525ffc 100644 --- a/tests/Switzerland/Zug/PentecostMondayTest.php +++ b/tests/Switzerland/Zug/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Zug (Switzerland). */ -class PentecostMondayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/StStephensDayTest.php b/tests/Switzerland/Zug/StStephensDayTest.php index 5cc3bb571..d02d73979 100644 --- a/tests/Switzerland/Zug/StStephensDayTest.php +++ b/tests/Switzerland/Zug/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Zug (Switzerland). */ -class StStephensDayTest extends ZugBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends ZugBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zug/ZugBaseTestCase.php b/tests/Switzerland/Zug/ZugBaseTestCase.php index d4fde5dfc..c67d789c8 100644 --- a/tests/Switzerland/Zug/ZugBaseTestCase.php +++ b/tests/Switzerland/Zug/ZugBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; @@ -22,18 +27,12 @@ abstract class ZugBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Zug'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Zug/ZugTest.php b/tests/Switzerland/Zug/ZugTest.php index 21a5db80b..18cb177e5 100644 --- a/tests/Switzerland/Zug/ZugTest.php +++ b/tests/Switzerland/Zug/ZugTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zug; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Zug (Switzerland). */ -class ZugTest extends ZugBaseTestCase +class ZugTest extends ZugBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Zug (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Zug (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -61,13 +74,12 @@ public function testRegionalHolidays(): void } /** - * Tests if all observed holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Zug (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -75,8 +87,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Zug (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -84,8 +95,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Zug (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -93,19 +103,37 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Zug (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Zug (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'berchtoldsTag', + 'goodFriday', + 'easterMonday', + 'ascensionDay', + 'pentecostMonday', + 'corpusChristi', + 'assumptionOfMary', + 'allSaintsDay', + 'immaculateConception', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Switzerland/Zurich/AscensionDayTest.php b/tests/Switzerland/Zurich/AscensionDayTest.php index 7bee91426..1baaf7b7d 100644 --- a/tests/Switzerland/Zurich/AscensionDayTest.php +++ b/tests/Switzerland/Zurich/AscensionDayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Ascension Day in Zurich (Switzerland). */ -class AscensionDayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class AscensionDayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'ascensionDay'; /** * Tests Ascension Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testAscensionDay() + public function testAscensionDay(): void { $year = 1901; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-16", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-16", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Ascension Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Auffahrt'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/BerchtoldsTagTest.php b/tests/Switzerland/Zurich/BerchtoldsTagTest.php deleted file mode 100644 index 330b3e325..000000000 --- a/tests/Switzerland/Zurich/BerchtoldsTagTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ - -namespace Yasumi\tests\Switzerland\Zurich; - -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing BerchtoldsTag in Zurich (Switzerland). - */ -class BerchtoldsTagTest extends ZurichBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'berchtoldsTag'; - - /** - * Tests BerchtoldsTag - * - * @throws ReflectionException - * @throws Exception - */ - public function testBerchtoldsTag() - { - $year = $this->generateRandomYear(); - $date = new DateTime($year . '-01-02', new DateTimeZone(self::TIMEZONE)); - - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OTHER); - } - - /** - * Tests translated name of BerchtoldsTag. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Berchtoldstag'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); - } -} diff --git a/tests/Switzerland/Zurich/ChristmasDayTest.php b/tests/Switzerland/Zurich/ChristmasDayTest.php index 15b28bef4..24c4a3eee 100644 --- a/tests/Switzerland/Zurich/ChristmasDayTest.php +++ b/tests/Switzerland/Zurich/ChristmasDayTest.php @@ -1,44 +1,43 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas in Zurich (Switzerland). */ -class ChristmasDayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. * - * @dataProvider ChristmasDayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which Christmas Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testChristmasDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('ChristmasDayDataProvider')] + public function testChristmasDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } @@ -46,34 +45,37 @@ public function testChristmasDay($year, $expected) /** * Returns a list of random test dates used for assertion of Christmas Day. * - * @return array list of test dates for Christmas Day - * @throws Exception + * @return array list of test dates for Christmas Day + * + * @throws \Exception */ - public function ChristmasDayDataProvider(): array + public static function ChristmasDayDataProvider(): array { - return $this->generateRandomDates(12, 25, self::TIMEZONE); + return static::generateRandomDates(12, 25, self::TIMEZONE); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Weihnachtstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/EasterMondayTest.php b/tests/Switzerland/Zurich/EasterMondayTest.php index 42d18423c..14b76915c 100644 --- a/tests/Switzerland/Zurich/EasterMondayTest.php +++ b/tests/Switzerland/Zurich/EasterMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Easter Monday in Zurich (Switzerland). */ -class EasterMondayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** * Tests Easter Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testEasterMonday() + public function testEasterMonday(): void { $year = 2016; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-28", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Easter Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Ostermontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/GoodFridayTest.php b/tests/Switzerland/Zurich/GoodFridayTest.php index 8d2f89788..a38be3ed4 100644 --- a/tests/Switzerland/Zurich/GoodFridayTest.php +++ b/tests/Switzerland/Zurich/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Zurich (Switzerland). */ -class GoodFridayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2008; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-21", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-21", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Karfreitag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/NewYearsDayTest.php b/tests/Switzerland/Zurich/NewYearsDayTest.php index 08fb47f29..546aa6b47 100644 --- a/tests/Switzerland/Zurich/NewYearsDayTest.php +++ b/tests/Switzerland/Zurich/NewYearsDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for New Years Day in Zurich (Switzerland). */ -class NewYearsDayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. * - * @dataProvider NewYearsDayDataProvider - * - * @param int $year the year for which New Years Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which New Years Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testNewYearsDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('NewYearsDayDataProvider')] + public function testNewYearsDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of New Years Day. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Neujahr'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } /** * Returns a list of random test dates used for assertion of New Years Day. * - * @return array list of test dates for New Years Day - * @throws Exception + * @return array list of test dates for New Years Day + * + * @throws \Exception */ - public function NewYearsDayDataProvider(): array + public static function NewYearsDayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } } diff --git a/tests/Switzerland/Zurich/PentecostMondayTest.php b/tests/Switzerland/Zurich/PentecostMondayTest.php index 69c932475..8acf77c8e 100644 --- a/tests/Switzerland/Zurich/PentecostMondayTest.php +++ b/tests/Switzerland/Zurich/PentecostMondayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Pentecost Monday in Zurich (Switzerland). */ -class PentecostMondayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class PentecostMondayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecostMonday'; /** * Tests Pentecost Monday. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testPentecostMonday() + public function testPentecostMonday(): void { $year = 1977; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of Pentecost Monday. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Pfingstmontag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/StStephensDayTest.php b/tests/Switzerland/Zurich/StStephensDayTest.php index a98488f2f..c3a7d18a6 100644 --- a/tests/Switzerland/Zurich/StStephensDayTest.php +++ b/tests/Switzerland/Zurich/StStephensDayTest.php @@ -1,79 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Stephen's Day in Zurich (Switzerland). */ -class StStephensDayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class StStephensDayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stStephensDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(12, 26, self::TIMEZONE); + return static::generateRandomDates(12, 26, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Stephanstag'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/WorkersDayTest.php b/tests/Switzerland/Zurich/WorkersDayTest.php index c521dc96d..6a7e47716 100644 --- a/tests/Switzerland/Zurich/WorkersDayTest.php +++ b/tests/Switzerland/Zurich/WorkersDayTest.php @@ -1,64 +1,64 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Workers' Day in Zurich (Switzerland). */ -class WorkersDayTest extends ZurichBaseTestCase implements YasumiTestCaseInterface +class WorkersDayTest extends ZurichBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-5-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-5-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -67,24 +67,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Tag der Arbeit'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Switzerland/Zurich/ZurichBaseTestCase.php b/tests/Switzerland/Zurich/ZurichBaseTestCase.php index 7a97d7ab9..58268d469 100644 --- a/tests/Switzerland/Zurich/ZurichBaseTestCase.php +++ b/tests/Switzerland/Zurich/ZurichBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; @@ -22,18 +27,12 @@ abstract class ZurichBaseTestCase extends SwitzerlandBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Switzerland/Zurich'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Zurich'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'de_CH'; } diff --git a/tests/Switzerland/Zurich/ZurichTest.php b/tests/Switzerland/Zurich/ZurichTest.php index 730f6c7a1..4d3ffe526 100644 --- a/tests/Switzerland/Zurich/ZurichTest.php +++ b/tests/Switzerland/Zurich/ZurichTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Switzerland\Zurich; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Zurich (Switzerland). */ -class ZurichTest extends ZurichBaseTestCase +class ZurichTest extends ZurichBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1945); + } /** - * Tests if all official holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Zurich (Switzerland) are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -39,8 +53,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all regional holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all regional holidays in Zurich (Switzerland) are defined by the provider class. */ public function testRegionalHolidays(): void { @@ -53,18 +66,16 @@ public function testRegionalHolidays(): void 'ascensionDay', 'easterMonday', 'pentecostMonday', - 'berchtoldsTag', ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** - * Tests if all observed holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Zurich (Switzerland) are defined by the provider class. */ public function testObservedHolidays(): void { $observedHolidays = []; - if (($this->year >= 1899 && $this->year < 1994) || $this->year = 1891) { + if (($this->year >= 1899 && $this->year < 1994) || 1891 === $this->year) { $observedHolidays[] = 'swissNationalDay'; } @@ -72,8 +83,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Zurich (Switzerland) are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -81,8 +91,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Zurich (Switzerland) are defined by the provider class. */ public function testBankHolidays(): void { @@ -90,19 +99,33 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Zurich (Switzerland) are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Zurich (Switzerland) are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'newYearsDay', + 'goodFriday', + 'easterMonday', + 'internationalWorkersDay', + 'ascensionDay', + 'pentecostMonday', + 'christmasDay', + 'stStephensDay', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1945); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Turkey/CommemorationOfAtaturkTest.php b/tests/Turkey/CommemorationOfAtaturkTest.php new file mode 100644 index 000000000..394cc60a7 --- /dev/null +++ b/tests/Turkey/CommemorationOfAtaturkTest.php @@ -0,0 +1,76 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class CommemorationOfAtaturkTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'commemorationAtaturk'; + + public const ESTABLISHMENT_YEAR = 1920; + + /** + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testHolidayOnAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-5-19", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Atatürk’ü Anma, Gençlik ve Spor Bayramı'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Turkey/DemocracyDayTest.php b/tests/Turkey/DemocracyDayTest.php new file mode 100644 index 000000000..b60131bd6 --- /dev/null +++ b/tests/Turkey/DemocracyDayTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class DemocracyDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'democracyDay'; + + public const ESTABLISHMENT_YEAR = 2017; + + /** + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-7-15", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Demokrasi ve Millî Birlik Günü'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Turkey/LabourDayTest.php b/tests/Turkey/LabourDayTest.php new file mode 100644 index 000000000..ea52715c4 --- /dev/null +++ b/tests/Turkey/LabourDayTest.php @@ -0,0 +1,72 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class LabourDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'labourDay'; + + /** + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Emek ve Dayanışma Günü'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OFFICIAL + ); + } + + /** + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(5, 1, self::TIMEZONE); + } +} diff --git a/tests/Turkey/NationalSovereigntyDayTest.php b/tests/Turkey/NationalSovereigntyDayTest.php new file mode 100644 index 000000000..728efae56 --- /dev/null +++ b/tests/Turkey/NationalSovereigntyDayTest.php @@ -0,0 +1,93 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class NationalSovereigntyDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'nationalSovereigntyDay'; + + // National Sovereignty Day was declared a national holiday on May 1st, 1921, thus celebrating from 1922. + public const ESTABLISHMENT_YEAR = 1922; + + // In 1981 this day was officially named 'Ulusal Egemenlik ve Çocuk Bayramı' + public const NAME_CHANGED_YEAR = 1981; + + /** + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testHolidayOnAfterEstablishment(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-4-23", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::NAME_CHANGED_YEAR - 1), + [self::LOCALE => 'Ulusal Egemenlik Bayramı'] + ); + } + + /** + * @throws \Exception + */ + public function testTranslationOnAfterNameChange(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::NAME_CHANGED_YEAR), + [self::LOCALE => 'Ulusal Egemenlik ve Çocuk Bayramı'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Turkey/NewYearsDayTest.php b/tests/Turkey/NewYearsDayTest.php new file mode 100644 index 000000000..ce64006c1 --- /dev/null +++ b/tests/Turkey/NewYearsDayTest.php @@ -0,0 +1,67 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +class NewYearsDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'newYearsDay'; + + /** + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + return static::generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Yılbaşı'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Turkey/RepublicDayTest.php b/tests/Turkey/RepublicDayTest.php new file mode 100644 index 000000000..afdde07d8 --- /dev/null +++ b/tests/Turkey/RepublicDayTest.php @@ -0,0 +1,82 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class RepublicDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'republicDay'; + + public const ESTABLISHMENT_YEAR = 1924; + + /** + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-29", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testHolidayBeforeEstablishment(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Cumhuriyet Bayramı'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/Turkey/TurkeyBaseTestCase.php b/tests/Turkey/TurkeyBaseTestCase.php new file mode 100644 index 000000000..6fe0d69e8 --- /dev/null +++ b/tests/Turkey/TurkeyBaseTestCase.php @@ -0,0 +1,32 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +class TurkeyBaseTestCase extends TestCase +{ + use YasumiBase; + + public const REGION = 'Turkey'; + + public const TIMEZONE = 'Europe/Istanbul'; + + public const LOCALE = 'tr_TR'; +} diff --git a/tests/Turkey/TurkeyTest.php b/tests/Turkey/TurkeyTest.php new file mode 100644 index 000000000..83deafecd --- /dev/null +++ b/tests/Turkey/TurkeyTest.php @@ -0,0 +1,107 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +class TurkeyTest extends TurkeyBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } + + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'labourDay', + ]; + + /* + * Not sure if 1920 is the first year of celebration as above source mentions Law No. 3466 that "May 19" was + * made official June 20, 1938. + * @see: https://en.wikipedia.org/wiki/Commemoration_of_Atat%C3%BCrk,_Youth_and_Sports_Day + */ + if (1920 <= $this->year) { + $holidays[] = 'commemorationAtaturk'; + } + + if (1922 <= $this->year) { + $holidays[] = 'nationalSovereigntyDay'; + } + + if (2017 <= $this->year) { + $holidays[] = 'democracyDay'; + } + + if (1926 <= $this->year) { + $holidays[] = 'victoryDay'; + } + + if (1923 < $this->year) { + $holidays[] = 'republicDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + public function testObservedHolidays(): void + { + $holidays = []; + + if (1923 <= $this->year && 1926 > $this->year) { + $holidays[] = 'victoryDay'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 2); + } +} diff --git a/tests/Turkey/VictoryDayTest.php b/tests/Turkey/VictoryDayTest.php new file mode 100644 index 000000000..0e66d914f --- /dev/null +++ b/tests/Turkey/VictoryDayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Turkey; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +class VictoryDayTest extends TurkeyBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'victoryDay'; + + public const ESTABLISHMENT_YEAR = 1926; + + public const CELEBRATION_YEAR = 1923; + + /** + * @throws \Exception + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(self::CELEBRATION_YEAR); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-8-30", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @throws \Exception + */ + public function testHolidayBeforeCelebration(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::CELEBRATION_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::CELEBRATION_YEAR), + [self::LOCALE => 'Zafer Bayramı'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } + + /** + * @throws \Exception + */ + public function testHolidayTypeBeforeEstablishment(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::CELEBRATION_YEAR, self::ESTABLISHMENT_YEAR - 1), + Holiday::TYPE_OBSERVANCE + ); + } +} diff --git a/tests/USA/ChristmasDayTest.php b/tests/USA/ChristmasDayTest.php index b74a875f6..0e9341653 100644 --- a/tests/USA/ChristmasDayTest.php +++ b/tests/USA/ChristmasDayTest.php @@ -1,56 +1,57 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the USA. */ -class ChristmasDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. Christmas Day is celebrated on December 25th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testChristmasDay() + public function testChristmasDay(): void { $year = 2001; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Christmas Day substituted on Monday (when Christmas Day falls on Sunday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testChristmasDaySubstitutedMonday() + public function testChristmasDaySubstitutedMonday(): void { // Substituted Holiday on Monday (Christmas Day falls on Sunday) $year = 6101; @@ -58,16 +59,16 @@ public function testChristmasDaySubstitutedMonday() self::REGION, 'substituteHoliday:christmasDay', $year, - new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Christmas Day substituted on Monday (when Christmas Day falls on Saturday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testChristmasDaySubstitutedFriday() + public function testChristmasDaySubstitutedFriday(): void { // Substituted Holiday on Friday (Christmas Day falls on Saturday) $year = 2060; @@ -75,30 +76,32 @@ public function testChristmasDaySubstitutedFriday() self::REGION, 'substituteHoliday:christmasDay', $year, - new DateTime("$year-12-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-12-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/USA/ColumbusDayTest.php b/tests/USA/ColumbusDayTest.php index 4581a6da9..c548ae521 100644 --- a/tests/USA/ColumbusDayTest.php +++ b/tests/USA/ColumbusDayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Columbus Day in the USA. */ -class ColumbusDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class ColumbusDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'columbusDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1937; /** * Tests Columbus Day on or after 1970. Columbus Day was established in 1937 on October 12th, but has been fixed to * the second Monday in October since 1970. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testColumbusDayOnAfter1970() + public function testColumbusDayOnAfter1970(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("second monday of october $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("second monday of october {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Columbus Day between 1937 and 1969. Columbus Day was established in 1937 on October 12th, but has been * fixed to the second Monday in October since 1970. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testColumbusBetween1937And1969() + public function testColumbusBetween1937And1969(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1969); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1969); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-12", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Columbus Day before 1937. Columbus Day was established in 1937 on October 12th, but has been fixed to * the second Monday in October since 1970. - * @throws ReflectionException + * + * @throws \Exception */ - public function testColumbusDayBefore1937() + public function testColumbusDayBefore1937(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Columbus Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/IndependenceDayTest.php b/tests/USA/IndependenceDayTest.php index 5cc3c2712..fb203bcea 100644 --- a/tests/USA/IndependenceDayTest.php +++ b/tests/USA/IndependenceDayTest.php @@ -1,124 +1,128 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class to test Independence Day. */ -class IndependenceDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'independenceDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1776; /** * Tests Independence Day on or after 1776. Independence Day is celebrated since 1776 on July 4th. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayOnAfter1776() + public function testIndependenceDayOnAfter1776(): void { $year = 1955; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-7-4", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-4", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Independence Day on or after 1776 when substituted on Monday (when Independence Day falls on Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Independence Day on or after 1776 when substituted on Monday (when Independence Day falls on Sunday). + * + * @throws \Exception */ - public function testIndependenceDayOnAfter1776SubstitutedMonday() + public function testIndependenceDayOnAfter1776SubstitutedMonday(): void { $year = 3362; $this->assertHoliday( self::REGION, 'substituteHoliday:independenceDay', $year, - new DateTime("$year-7-5", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-5", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Independence Day on or after 1776 when substituted on Friday (when Independence Day falls on Saturday) - * @throws Exception - * @throws ReflectionException + * Tests Independence Day on or after 1776 when substituted on Friday (when Independence Day falls on Saturday). + * + * @throws \Exception */ - public function testIndependenceDayOnAfter1776SubstitutedFriday() + public function testIndependenceDayOnAfter1776SubstitutedFriday(): void { $year = 8291; $this->assertHoliday( self::REGION, 'substituteHoliday:independenceDay', $year, - new DateTime("$year-7-3", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-7-3", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Independence Day before 1776. Independence Day is celebrated since 1776 on July 4th. - * @throws ReflectionException + * + * @throws \Exception */ - public function testIndependenceDayBefore1776() + public function testIndependenceDayBefore1776(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Independence Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/JuneteenthTest.php b/tests/USA/JuneteenthTest.php new file mode 100644 index 000000000..a7f2e0997 --- /dev/null +++ b/tests/USA/JuneteenthTest.php @@ -0,0 +1,129 @@ + + */ + +namespace Yasumi\tests\USA; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class to test Juneteenth. + */ +class JuneteenthTest extends USABaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'juneteenth'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 2021; + + /** + * Tests Juneteenth on or after 2021. Juneteenth is celebrated since 2021 on June 19th. + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2021(): void + { + $year = 2023; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-19", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth on or after 2021 when substituted on Monday (when Juneteenth falls on Sunday). + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2021SubstitutedMonday(): void + { + $year = 2022; + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth on or after 2021 when substituted on Friday (when Juneteenth falls on Saturday). + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2021SubstitutedFriday(): void + { + $year = 2021; + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-18", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth before 2021. Juneteenth is celebrated since 2021 on June 19th. + * + * @throws \Exception + */ + public function testJuneteenthBefore2021(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Juneteenth'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +} diff --git a/tests/USA/LabourDayTest.php b/tests/USA/LabourDayTest.php index 5c420c24e..87f519f46 100644 --- a/tests/USA/LabourDayTest.php +++ b/tests/USA/LabourDayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Labour Day in the USA. */ -class LabourDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class LabourDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'labourDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1887; /** * Tests Labour Day on or after 1887. Labour Day was established since 1887 on the first Monday of September. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testLabourDayOnAfter1887() + public function testLabourDayOnAfter1887(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of september $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of september {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Labour Day before 1887. Labour Day was established since 1887 on the first Monday of September. - * @throws ReflectionException + * + * @throws \Exception */ - public function testLabourDayBefore1887() + public function testLabourDayBefore1887(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Labour Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Labor Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/MartinLutherKingDayTest.php b/tests/USA/MartinLutherKingDayTest.php index 3e65fb616..7791e013f 100644 --- a/tests/USA/MartinLutherKingDayTest.php +++ b/tests/USA/MartinLutherKingDayTest.php @@ -1,94 +1,98 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class to test Dr. Martin Luther King Day. */ -class MartinLutherKingDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class MartinLutherKingDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'martinLutherKingDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1986; /** * Tests Dr. Martin Luther King Day on or after 1986. Dr. Martin Luther King Day was established since 1986 on the * third Monday of January. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMartinLutherKingDayOnAfter1986() + public function testMartinLutherKingDayOnAfter1986(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third monday of january $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third monday of january {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Dr. Martin Luther King Day before 1986. Dr. Martin Luther King Day was established since 1996 on the third * Monday of January. - * @throws ReflectionException + * + * @throws \Exception */ - public function testMartinLutherKingDayBefore1986() + public function testMartinLutherKingDayBefore1986(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Dr. Martin Luther King Jr\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Dr. Martin Luther King Jr’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/MemorialDayTest.php b/tests/USA/MemorialDayTest.php index c301c5820..0f01420ea 100644 --- a/tests/USA/MemorialDayTest.php +++ b/tests/USA/MemorialDayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class to test Memorial Day. */ -class MemorialDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class MemorialDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'memorialDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1865; /** * Tests Memorial Day on or after 1968. Memorial Day was established since 1865 on May 30 and was changed in 1968 * to the last Monday in May. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMemorialDayOnAfter1968() + public function testMemorialDayOnAfter1968(): void { - $year = $this->generateRandomYear(1968); + $year = static::generateRandomYear(1968); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("last monday of may $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("last monday of may {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Memorial Day between 1865 and 1967. Memorial Day was established since 1865 on May 30 and was changed in * 1968 to the last Monday in May. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testMemorialDayBetween1865And1967() + public function testMemorialDayBetween1865And1967(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1967); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1967); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Memorial Day before 1865. Memorial Day was established since 1865 on May 30 and was changed in 1968 to the * last Monday in May. - * @throws ReflectionException + * + * @throws \Exception */ - public function testMemorialDayBefore1865() + public function testMemorialDayBefore1865(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Memorial Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/NYSE/CarterMourningTest.php b/tests/USA/NYSE/CarterMourningTest.php new file mode 100644 index 000000000..fa5bc37fd --- /dev/null +++ b/tests/USA/NYSE/CarterMourningTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test day of closure of NYSE due to Jimmy Carter mourning proclamation + * + * @author Art Kurbakov + */ +class CarterMourningTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2025; + + /** + * Tests day of closure on January 9th 2025 + * + * @throws \Exception + */ + public function testCarterMourning(): void + { + $this->assertHoliday( + self::REGION, + 'CarterMourning', + self::OBSERVED_YEAR, + new \DateTime('2025-01-09', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2025 + * + * @throws \Exception + */ + public function testCarterMourningBefore2025(): void + { + $this->assertNotHoliday( + self::REGION, + 'CarterMourning', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2025 + * + * @throws \Exception + */ + public function testCarterMourningAfter2025(): void + { + $this->assertNotHoliday( + self::REGION, + 'CarterMourning', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NYSE/GRFordMourningTest.php b/tests/USA/NYSE/GRFordMourningTest.php new file mode 100644 index 000000000..349be62cc --- /dev/null +++ b/tests/USA/NYSE/GRFordMourningTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test day of closure of NYSE due to G.R. Ford Mourning proclamation + * + * @author Art Kurbakov + */ +class GRFordMourningTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2007; + + /** + * Tests day of closure on January 2nd 2007 + * + * @throws \Exception + */ + public function testGRFordMourning(): void + { + $this->assertHoliday( + self::REGION, + 'GRFordMourning', + self::OBSERVED_YEAR, + new \DateTime('2007-01-02', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2007 + * + * @throws \Exception + */ + public function testGRFordMourningBefore2007(): void + { + $this->assertNotHoliday( + self::REGION, + 'GRFordMourning', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2007 + * + * @throws \Exception + */ + public function testGRFordMourningAfter2007(): void + { + $this->assertNotHoliday( + self::REGION, + 'GRFordMourning', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NYSE/GroundZeroTest.php b/tests/USA/NYSE/GroundZeroTest.php new file mode 100644 index 000000000..d46c181f6 --- /dev/null +++ b/tests/USA/NYSE/GroundZeroTest.php @@ -0,0 +1,138 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test 4 days of closure of NYSE due to September 11th attacks + * + * @author Art Kurbakov + */ +class GroundZeroTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2001; + + /** + * Tests 4 days of closure on September 11th 2001 + * + * @throws \Exception + */ + public function testGroundZero(): void + { + $this->assertHoliday( + self::REGION, + 'groundZero1', + self::OBSERVED_YEAR, + new \DateTime('2001-09-11', new \DateTimeZone(self::TIMEZONE)) + ); + + $this->assertHoliday( + self::REGION, + 'groundZero2', + self::OBSERVED_YEAR, + new \DateTime('2001-09-12', new \DateTimeZone(self::TIMEZONE)) + ); + + $this->assertHoliday( + self::REGION, + 'groundZero3', + self::OBSERVED_YEAR, + new \DateTime('2001-09-13', new \DateTimeZone(self::TIMEZONE)) + ); + + $this->assertHoliday( + self::REGION, + 'groundZero4', + self::OBSERVED_YEAR, + new \DateTime('2001-09-14', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2001 + * + * @throws \Exception + */ + public function testGroundZeroBefore2001(): void + { + $this->assertNotHoliday( + self::REGION, + 'groundZero1', + self::OBSERVED_YEAR - 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero2', + self::OBSERVED_YEAR - 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero3', + self::OBSERVED_YEAR - 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero4', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2001 + * + * @throws \Exception + */ + public function testGroundZeroAfter2001(): void + { + $this->assertNotHoliday( + self::REGION, + 'groundZero1', + self::OBSERVED_YEAR + 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero2', + self::OBSERVED_YEAR + 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero3', + self::OBSERVED_YEAR + 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'groundZero4', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NYSE/HWBushMourningTest.php b/tests/USA/NYSE/HWBushMourningTest.php new file mode 100644 index 000000000..6899a7659 --- /dev/null +++ b/tests/USA/NYSE/HWBushMourningTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test day of closure of NYSE due to H.W. Bush Mourning proclamation + * + * @author Art Kurbakov + */ +class HWBushMourningTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2018; + + /** + * Tests day of closure on December 5th 2018 + * + * @throws \Exception + */ + public function testHWBushMourning(): void + { + $this->assertHoliday( + self::REGION, + 'HWBushMourning', + self::OBSERVED_YEAR, + new \DateTime('2018-12-05', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2018 + * + * @throws \Exception + */ + public function testHWBushMourningBefore2018(): void + { + $this->assertNotHoliday( + self::REGION, + 'HWBushMourning', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2018 + * + * @throws \Exception + */ + public function testHWBushMourningAfter2018(): void + { + $this->assertNotHoliday( + self::REGION, + 'HWBushMourning', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NYSE/HurricaneSandyTest.php b/tests/USA/NYSE/HurricaneSandyTest.php new file mode 100644 index 000000000..a3800fe55 --- /dev/null +++ b/tests/USA/NYSE/HurricaneSandyTest.php @@ -0,0 +1,100 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test 2 days of closure of NYSE due to Hurricane Sandy + * + * @author Art Kurbakov + */ +class HurricaneSandyTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2012; + + /** + * Tests both days of closure of October 29-30th, 2012 + * + * @throws \Exception + */ + public function testHurricaneSandyDays(): void + { + $this->assertHoliday( + self::REGION, + 'hurricaneSandy1', + self::OBSERVED_YEAR, + new \DateTime('2012-10-29', new \DateTimeZone(self::TIMEZONE)) + ); + + $this->assertHoliday( + self::REGION, + 'hurricaneSandy2', + self::OBSERVED_YEAR, + new \DateTime('2012-10-30', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2012 + * + * @throws \Exception + */ + public function testHurricaneSandyBefore2012(): void + { + $this->assertNotHoliday( + self::REGION, + 'hurricaneSandy1', + self::OBSERVED_YEAR - 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'hurricaneSandy2', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2012 + * + * @throws \Exception + */ + public function testHurricaneSandyAfter2012(): void + { + $this->assertNotHoliday( + self::REGION, + 'hurricaneSandy1', + self::OBSERVED_YEAR + 1 + ); + + $this->assertNotHoliday( + self::REGION, + 'hurricaneSandy2', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NYSE/JuneteenthTest.php b/tests/USA/NYSE/JuneteenthTest.php new file mode 100644 index 000000000..4404131a2 --- /dev/null +++ b/tests/USA/NYSE/JuneteenthTest.php @@ -0,0 +1,106 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\Holiday; +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test Juneteenth holiday + * + * @author Art Kurbakov + */ +class JuneteenthTest extends USABaseTestCase +{ + /** + * Country (name) to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The name of the holiday. + */ + public const HOLIDAY = 'juneteenth'; + + /** + * The year in which the holiday was first established for NYSE. + */ + public const ESTABLISHMENT_YEAR = 2022; + + /** + * Tests Juneteenth on or after 2022. For NYSE Juneteenth is celebrated since 2022 on June 19th. + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2022(): void + { + $year = 2023; + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-19", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth on or after 2022 when substituted on Monday (when Juneteenth falls on Sunday). + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2022SubstitutedMonday(): void + { + $year = 2022; + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-20", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth on or after 2022 when substituted on Friday (when Juneteenth falls on Saturday). + * + * @throws \Exception + */ + public function testJuneteenthOnAfter2022SubstitutedFriday(): void + { + $year = 2027; + $this->assertSubstituteHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-6-18", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Juneteenth before 2022. For NYSE Juneteenth is celebrated since 2022 on June 19th. + * + * @throws \Exception + */ + public function testJuneteenthBefore2022(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + self::ESTABLISHMENT_YEAR - 1 + ); + } +} diff --git a/tests/USA/NYSE/NYSETest.php b/tests/USA/NYSE/NYSETest.php new file mode 100644 index 000000000..e222a9c1c --- /dev/null +++ b/tests/USA/NYSE/NYSETest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class for testing closure days for NYSE + * + * @author Art Kurbakov + */ +class NYSETest extends USABaseTestCase implements ProviderTestCase +{ + /** + * Country (name) to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(2000); + } + + /** + * Tests if all official holidays in the USA are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $holidays = [ + 'newYearsDay', + 'martinLutherKingDay', + 'washingtonsBirthday', + 'goodFriday', + 'memorialDay', + 'independenceDay', + 'labourDay', + 'thanksgivingDay', + 'christmasDay', + ]; + + if (2001 === $this->year) { + $holidays[] = 'groundZero1'; + $holidays[] = 'groundZero2'; + $holidays[] = 'groundZero3'; + $holidays[] = 'groundZero4'; + } + + if (2004 === $this->year) { + $holidays[] = 'ReaganMourning'; + } + + if (2007 === $this->year) { + $holidays[] = 'GRFordMourning'; + } + + if (2012 === $this->year) { + $holidays[] = 'hurricaneSandy1'; + $holidays[] = 'hurricaneSandy2'; + } + + if (2018 === $this->year) { + $holidays[] = 'HWBushMourning'; + } + + if (2021 < $this->year) { + $holidays[] = 'juneteenth'; + } + + if (2025 === $this->year) { + $holidays[] = 'CarterMourning'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 5); + } +} diff --git a/tests/USA/NYSE/ReaganMourningTest.php b/tests/USA/NYSE/ReaganMourningTest.php new file mode 100644 index 000000000..710603eb7 --- /dev/null +++ b/tests/USA/NYSE/ReaganMourningTest.php @@ -0,0 +1,81 @@ + + */ + +namespace Yasumi\tests\USA\NYSE; + +use Yasumi\tests\USA\USABaseTestCase; + +/** + * Class to test day of closure of NYSE due to Reagan Mourning proclamation + * + * @author Art Kurbakov + */ +class ReaganMourningTest extends USABaseTestCase +{ + /** + * Name of provider to be tested. + */ + public const REGION = 'USA/NYSE'; + + /** + * The year when the closure was observed. + */ + public const OBSERVED_YEAR = 2004; + + /** + * Tests day of closure on June 11th 2004 + * + * @throws \Exception + */ + public function testReaganMourning(): void + { + $this->assertHoliday( + self::REGION, + 'ReaganMourning', + self::OBSERVED_YEAR, + new \DateTime('2004-06-11', new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests years before 2004 + * + * @throws \Exception + */ + public function testReaganMourningBefore2004(): void + { + $this->assertNotHoliday( + self::REGION, + 'ReaganMourning', + self::OBSERVED_YEAR - 1 + ); + } + + /** + * Tests years after 2004 + * + * @throws \Exception + */ + public function testReaganMourningAfter2004(): void + { + $this->assertNotHoliday( + self::REGION, + 'ReaganMourning', + self::OBSERVED_YEAR + 1 + ); + } +} diff --git a/tests/USA/NewYearsDayTest.php b/tests/USA/NewYearsDayTest.php index 33908b64f..d6900631e 100644 --- a/tests/USA/NewYearsDayTest.php +++ b/tests/USA/NewYearsDayTest.php @@ -1,72 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the USA. */ -class NewYearsDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'newYearsDay'; /** * Tests New Years Day. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNewYearsDay() + public function testNewYearsDay(): void { $year = 1997; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests New Years Day when substituted on Monday (when New Years Day falls on Sunday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNewYearsDaySubstitutedMonday() + public function testNewYearsDaySubstitutedMonday(): void { $year = 2445; $this->assertHoliday( self::REGION, 'substituteHoliday:newYearsDay', $year, - new DateTime("$year-1-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-1-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests New Years Day when substituted on Friday (when New Years Day falls on Saturday). - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testNewYearsDaySubstitutedFriday() + public function testNewYearsDaySubstitutedFriday(): void { $year = 1938; $subYear = $year - 1; @@ -74,30 +75,32 @@ public function testNewYearsDaySubstitutedFriday() self::REGION, 'substituteHoliday:newYearsDay', $year, - new DateTime("$subYear-12-31", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$subYear}-12-31", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/USA/ThanksgivingDayTest.php b/tests/USA/ThanksgivingDayTest.php index 6c3d30f7a..5cb67c3d3 100644 --- a/tests/USA/ThanksgivingDayTest.php +++ b/tests/USA/ThanksgivingDayTest.php @@ -1,94 +1,98 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Thanksgiving Day in the USA. */ -class ThanksgivingDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class ThanksgivingDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'thanksgivingDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1863; /** * Tests Thanksgiving Day on or after 1863. Thanksgiving Day is celebrated since 1863 on the fourth Thursday * of November. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testThanksgivingDayOnAfter1863() + public function testThanksgivingDayOnAfter1863(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("fourth thursday of november $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("fourth thursday of november {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Thanksgiving Day before 1863. ThanksgivingDay Day is celebrated since 1863 on the fourth Thursday * of November. - * @throws ReflectionException + * + * @throws \Exception */ - public function testThanksgivingDayBefore1863() + public function testThanksgivingDayBefore1863(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Thanksgiving Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/USABaseTestCase.php b/tests/USA/USABaseTestCase.php index 6ce669cd9..a15c57748 100644 --- a/tests/USA/USABaseTestCase.php +++ b/tests/USA/USABaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; @@ -23,17 +28,13 @@ abstract class USABaseTestCase extends TestCase use YasumiBase; /** - * Country (name) to be tested + * Country (name) to be tested. */ public const REGION = 'USA'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'America/New_York'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_US'; } diff --git a/tests/USA/USATest.php b/tests/USA/USATest.php index 2b9008fcd..eb6e63bff 100644 --- a/tests/USA/USATest.php +++ b/tests/USA/USATest.php @@ -1,37 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the USA. */ -class USATest extends USABaseTestCase +class USATest extends USABaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1986); + } /** - * Tests if all official holidays in the USA are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the USA are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $holidays = [ 'newYearsDay', 'martinLutherKingDay', 'washingtonsBirthday', @@ -42,12 +56,17 @@ public function testOfficialHolidays(): void 'veteransDay', 'thanksgivingDay', 'christmasDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if (2021 <= $this->year) { + $holidays[] = 'juneteenth'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL); } /** - * Tests if all observed holidays in the USA are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the USA are defined by the provider class. */ public function testObservedHolidays(): void { @@ -55,8 +74,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the USA are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the USA are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -64,8 +82,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the USA are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the USA are defined by the provider class. */ public function testBankHolidays(): void { @@ -73,8 +90,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in the USA are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the USA are defined by the provider class. */ public function testOtherHolidays(): void { @@ -82,10 +98,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1986); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/USA/VeteransDayTest.php b/tests/USA/VeteransDayTest.php index e5a3564e9..24690804b 100644 --- a/tests/USA/VeteransDayTest.php +++ b/tests/USA/VeteransDayTest.php @@ -1,151 +1,166 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; +use Yasumi\Exception\MissingTranslationException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; use Yasumi\Yasumi; /** * Class for testing Veterans Day in the USA. */ -class VeteransDayTest extends USABaseTestCase implements YasumiTestCaseInterface +class VeteransDayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'veteransDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1919; /** * Tests Veterans Day on or after 1919. Veterans Day was established in 1919 on November 11. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testVeteransDayOnAfter1919() + public function testVeteransDayOnAfter1919(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-11-11", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-11", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Veterans Day on or after 1919 when substituted on Monday (when Veterans Day falls on Sunday) - * @throws Exception - * @throws ReflectionException + * Tests Veterans Day on or after 1919 when substituted on Monday (when Veterans Day falls on Sunday). + * + * @throws \Exception */ - public function testVeteransDayOnAfter1919SubstitutedMonday() + public function testVeteransDayOnAfter1919SubstitutedMonday(): void { $year = 2018; $this->assertHoliday( self::REGION, 'substituteHoliday:veteransDay', $year, - new DateTime("$year-11-12", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-12", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests Veterans Day on or after 1919 when substituted on Friday (when Veterans Day falls on Saturday) - * @throws Exception - * @throws ReflectionException + * Tests Veterans Day on or after 1919 when substituted on Friday (when Veterans Day falls on Saturday). + * + * @throws \Exception */ - public function testVeteransDayOnAfter1919SubstitutedFriday() + public function testVeteransDayOnAfter1919SubstitutedFriday(): void { $year = 2017; $this->assertHoliday( self::REGION, 'substituteHoliday:veteransDay', $year, - new DateTime("$year-11-10", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-11-10", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Veterans Day before 1919. Veterans Day was established in 1919 on November 11. - * @throws ReflectionException + * + * @throws \Exception */ - public function testVeteransDayBefore1919() + public function testVeteransDayBefore1919(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests name of Veterans Day before 1954. Veterans Day was named 'Armistice Day' before 1954. - * @throws ReflectionException + * + * @throws MissingTranslationException */ - public function testVeteransDayNameBefore1954() + public function testVeteransDayNameBefore1954(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1953); + try { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1953); - $holidays = Yasumi::create(self::REGION, $year); - $holiday = $holidays->getHoliday(self::HOLIDAY); - $this->assertEquals('Armistice Day', $holiday->getName()); + $holidays = Yasumi::create(self::REGION, $year); + $holiday = $holidays->getHoliday(self::HOLIDAY); + self::assertEquals('Armistice Day', $holiday->getName()); + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); + } } /** * Tests name of Veterans Day after 1954. Veterans Day was named 'Armistice Day' before 1954. - * @throws ReflectionException + * + * @throws MissingTranslationException */ - public function testVeteransDayNameAfter1954() + public function testVeteransDayNameAfter1954(): void { - $year = $this->generateRandomYear(1954); + try { + $year = static::generateRandomYear(1954); - $holidays = Yasumi::create(self::REGION, $year); - $holiday = $holidays->getHoliday(self::HOLIDAY); - $this->assertEquals('Veterans Day', $holiday->getName()); + $holidays = Yasumi::create(self::REGION, $year); + $holiday = $holidays->getHoliday(self::HOLIDAY); + self::assertEquals('Veterans Day', $holiday->getName()); + } catch (\Exception $e) { + throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); + } } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1954), + static::generateRandomYear(1954), [self::LOCALE => 'Veterans Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/USA/WashingtonsBirthdayTest.php b/tests/USA/WashingtonsBirthdayTest.php index 95cff15b0..e59fe3c46 100644 --- a/tests/USA/WashingtonsBirthdayTest.php +++ b/tests/USA/WashingtonsBirthdayTest.php @@ -1,111 +1,115 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\USA; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class to test Washington's Birthday. */ -class WashingtonsBirthdayTest extends USABaseTestCase implements YasumiTestCaseInterface +class WashingtonsBirthdayTest extends USABaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'washingtonsBirthday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1879; /** * Tests Washington's Birthday on or after 1968. Washington's Birthday was established since 1879 on February 22 * and was changed in 1968 to the third Monday in February. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testWashingtonsBirthdayOnAfter1968() + public function testWashingtonsBirthdayOnAfter1968(): void { - $year = $this->generateRandomYear(1968); + $year = static::generateRandomYear(1968); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("third monday of february $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("third monday of february {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Washington's Birthday between 1879 and 1967. Washington's Birthday was established since 1879 on February * 22 and was changed in 1968 to the third Monday in February. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testWashingtonsBirthdayBetween1879And1967() + public function testWashingtonsBirthdayBetween1879And1967(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1967); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1967); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-2-22", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-2-22", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests Washington's Birthday before 1879. Washington's Birthday was established since 1879 on February 22 and was * changed in 1968 to the third Monday in February. - * @throws ReflectionException + * + * @throws \Exception */ - public function testWashingtonsBirthdayBefore1879() + public function testWashingtonsBirthdayBefore1879(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'Washington\'s Birthday'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Washington’s Birthday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Ukraine/CatholicChristmasDayTest.php b/tests/Ukraine/CatholicChristmasDayTest.php new file mode 100644 index 000000000..4f8d8ad90 --- /dev/null +++ b/tests/Ukraine/CatholicChristmasDayTest.php @@ -0,0 +1,105 @@ + + */ + +namespace Yasumi\tests\Ukraine; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +/** + * Class CatholicChristmasDayTest. + */ +class CatholicChristmasDayTest extends UkraineBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'catholicChristmasDay'; + + /** + * Tests Catholic Christmas Day. + * + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date + */ + #[\PHPUnit\Framework\Attributes\DataProvider('CatholicChristmasDayDataProvider')] + public function testCatholicChristmasDay(int $year, \DateTimeInterface $expected): void + { + $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + } + + /** + * Tests Catholic Christmas Day before 2017. + * + * @throws \Exception + */ + public function testNoCatholicChristmasDayBefore2017(): void + { + $year = static::generateRandomYear(null, 2016); + $holidays = Yasumi::create(self::REGION, $year); + $holiday = $holidays->getHoliday(self::HOLIDAY); + + self::assertNull($holiday); + + unset($year, $holiday, $holidays); + } + + /** + * Tests translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(2017), + [self::LOCALE => 'Католицький день Різдва'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(2017), Holiday::TYPE_OFFICIAL); + } + + /** + * Returns a list of random test dates used for assertion of Catholic Christmas Day. + * + * @return array list of test dates for Catholic Christmas Day + * + * @throws \Exception + */ + public static function CatholicChristmasDayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 10; ++$y) { + $year = static::generateRandomYear(2017); + $data[] = [$year, new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; + } +} diff --git a/tests/Ukraine/ChristmasDayTest.php b/tests/Ukraine/ChristmasDayTest.php index addef44ba..46d1496e7 100644 --- a/tests/Ukraine/ChristmasDayTest.php +++ b/tests/Ukraine/ChristmasDayTest.php @@ -1,79 +1,80 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class ChristmasDayTest + * Class ChristmasDayTest. */ -class ChristmasDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends UkraineBaseTestCase implements HolidayTestCase { + public const ABOLISHMENT_YEAR = 2023; + /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests Christmas Day. - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which Christmas Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException */ - public function testChristmasDay($year, $expected) + public function testHoliday(): void { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + $year = static::generateRandomYear(1000, self::ABOLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-01-07", new \DateTimeZone(self::TIMEZONE)) + ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * Tests Christmas Day was abolished in 2023. */ - public function HolidayDataProvider(): array + public function testNotHolidayAfter2023(): void { - return $this->generateRandomDates(1, 7, self::TIMEZONE); + $year = static::generateRandomYear(self::ABOLISHMENT_YEAR + 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests translated name of Christmas Day. - * @throws ReflectionException */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(1000, 2023), [self::LOCALE => 'Різдво'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(1000, 2023), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ukraine/ConstitutionDayTest.php b/tests/Ukraine/ConstitutionDayTest.php index d529190c1..243515f20 100644 --- a/tests/Ukraine/ConstitutionDayTest.php +++ b/tests/Ukraine/ConstitutionDayTest.php @@ -1,53 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class ConstitutionDayTest - * @package Yasumi\tests\Ukraine + * Class ConstitutionDayTest. */ -class ConstitutionDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class ConstitutionDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'constitutionDay'; /** - * @throws ReflectionException - * @throws Exception + * Tests the holiday defined in this test. + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(2024); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-15", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test. */ - public function testHoliday() + public function testHolidayBefore2024(): void { - $year = 2020; + $year = static::generateRandomYear(1996, 2023); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-28", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-28", new \DateTimeZone(self::TIMEZONE)) ); } + /** + * Tests the holiday defined in this test. + */ + public function testNotHolidayBeforeEstablishment(): void + { + $year = static::generateRandomYear(1000, 1995); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -56,7 +77,6 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { diff --git a/tests/Ukraine/DefenderOfUkraineDayTest.php b/tests/Ukraine/DefenderOfUkraineDayTest.php index 7041f5007..809485d85 100644 --- a/tests/Ukraine/DefenderOfUkraineDayTest.php +++ b/tests/Ukraine/DefenderOfUkraineDayTest.php @@ -1,53 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class DefenderOfUkraineDayTest - * @package Yasumi\tests\Ukraine + * Class DefenderOfUkraineDayTest. */ -class DefenderOfUkraineDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class DefenderOfUkraineDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'defenderOfUkraineDay'; /** - * @throws ReflectionException - * @throws Exception + * Tests the holiday defined in this test. + */ + public function testHoliday(): void + { + $year = static::generateRandomYear(2023); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-01", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test. */ - public function testHoliday() + public function testHolidayBefore2023(): void { - $year = 2020; + $year = static::generateRandomYear(2015, 2022); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-10-14", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-10-14", new \DateTimeZone(self::TIMEZONE)) ); } + /** + * Tests the holiday defined in this test. + */ + public function testNotHolidayBeforeEstablishment(): void + { + $year = static::generateRandomYear(1000, 2014); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -61,7 +82,6 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { diff --git a/tests/Ukraine/EasterTest.php b/tests/Ukraine/EasterTest.php index fa233cd0e..d59ca93d5 100644 --- a/tests/Ukraine/EasterTest.php +++ b/tests/Ukraine/EasterTest.php @@ -1,71 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class EasterTest - * @package Yasumi\tests\Ukraine + * Class EasterTest. */ -class EasterTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class EasterTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'easter'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-04-19", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-04-19", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Великдень'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ukraine/IndependenceDayTest.php b/tests/Ukraine/IndependenceDayTest.php index 91d27f99f..949e93af7 100644 --- a/tests/Ukraine/IndependenceDayTest.php +++ b/tests/Ukraine/IndependenceDayTest.php @@ -1,53 +1,51 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class IndependenceDayTest - * @package Yasumi\tests\Ukraine + * Class IndependenceDayTest. */ -class IndependenceDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class IndependenceDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'independenceDay'; /** - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-08-24", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-08-24", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException */ public function testTranslation(): void { @@ -56,7 +54,6 @@ public function testTranslation(): void /** * Tests type of the holiday defined in this test. - * @throws ReflectionException */ public function testHolidayType(): void { diff --git a/tests/Ukraine/InternationalWomensDayTest.php b/tests/Ukraine/InternationalWomensDayTest.php index 2c05eed64..1cbb10b13 100644 --- a/tests/Ukraine/InternationalWomensDayTest.php +++ b/tests/Ukraine/InternationalWomensDayTest.php @@ -1,78 +1,75 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class InternationalWomensDayTest - * @package Yasumi\tests\Ukraine + * Class InternationalWomensDayTest. */ -class InternationalWomensDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class InternationalWomensDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'internationalWomensDay'; - /** - * @dataProvider HolidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException - */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(3, 8, self::TIMEZONE); + return static::generateRandomDates(3, 8, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Міжнародний жіночий день'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ukraine/InternationalWorkersDayTest.php b/tests/Ukraine/InternationalWorkersDayTest.php index aa07cbc24..fe84d1ce4 100644 --- a/tests/Ukraine/InternationalWorkersDayTest.php +++ b/tests/Ukraine/InternationalWorkersDayTest.php @@ -1,80 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class InternationalWorkersDayTest - * @package Yasumi\tests\Ukraine + * Class InternationalWorkersDayTest. */ -class InternationalWorkersDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class InternationalWorkersDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'internationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider InternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('InternationalWorkersDayDataProvider')] + public function testInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'День міжнародної солідарності трудящих'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function InternationalWorkersDayDataProvider(): array + public static function InternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 1, self::TIMEZONE); + return static::generateRandomDates(5, 1, self::TIMEZONE); } } diff --git a/tests/Ukraine/NewYearsDayTest.php b/tests/Ukraine/NewYearsDayTest.php index dd3f0907a..d28431801 100644 --- a/tests/Ukraine/NewYearsDayTest.php +++ b/tests/Ukraine/NewYearsDayTest.php @@ -1,80 +1,81 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class NewYearsDayTest - * @package Yasumi\tests\Ukraine + * Class NewYearsDayTest. */ -class NewYearsDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param \DateTime $expected the expected date */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDates(1, 1, self::TIMEZONE); + return static::generateRandomDates(1, 1, self::TIMEZONE); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Новий Рік'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ukraine/PentecostTest.php b/tests/Ukraine/PentecostTest.php index 63bf3e519..4da8fc0fc 100644 --- a/tests/Ukraine/PentecostTest.php +++ b/tests/Ukraine/PentecostTest.php @@ -1,71 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class PentecostTest - * @package Yasumi\tests\Ukraine + * Class PentecostTest. */ -class PentecostTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class PentecostTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'pentecost'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2020; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-06-07", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-06-07", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Трійця'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Ukraine/SecondInternationalWorkersDayTest.php b/tests/Ukraine/SecondInternationalWorkersDayTest.php index 0c6028643..8cfdd66f4 100644 --- a/tests/Ukraine/SecondInternationalWorkersDayTest.php +++ b/tests/Ukraine/SecondInternationalWorkersDayTest.php @@ -1,80 +1,110 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; /** - * Class SecondInternationalWorkersDayTest - * @package Yasumi\tests\Ukraine + * Class SecondInternationalWorkersDayTest. */ -class SecondInternationalWorkersDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class SecondInternationalWorkersDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondInternationalWorkersDay'; /** * Tests International Workers' Day. * - * @dataProvider SecondInternationalWorkersDayDataProvider - * - * @param int $year the year for which International Workers' Day needs to be tested - * @param DateTime $expected the expected date - * - * @throws ReflectionException + * @param int $year the year for which International Workers' Day needs to be tested + * @param \DateTime $expected the expected date */ - public function testSecondInternationalWorkersDay($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('SecondInternationalWorkersDayDataProvider')] + public function testSecondInternationalWorkersDay(int $year, \DateTimeInterface $expected): void { $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); } + /** + * Tests International Workers' Day since 2018. + * + * @throws \Exception + */ + public function testNoSecondInternationalWorkersDaySince2018(): void + { + $year = static::generateRandomYear(2018); + $holidays = Yasumi::create(self::REGION, $year); + $holiday = $holidays->getHoliday(self::HOLIDAY); + + self::assertNull($holiday); + + unset($year, $holiday, $holidays); + } + /** * Tests translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(null, 2017), [self::LOCALE => 'День міжнародної солідарності трудящих'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(null, 2017), + Holiday::TYPE_OFFICIAL + ); } /** * Returns a list of random test dates used for assertion of International Workers' Day. * - * @return array list of test dates for International Workers' Day - * @throws Exception + * @return array list of test dates for International Workers' Day + * + * @throws \Exception */ - public function SecondInternationalWorkersDayDataProvider(): array + public static function SecondInternationalWorkersDayDataProvider(): array { - return $this->generateRandomDates(5, 2, self::TIMEZONE); + $data = []; + + for ($y = 0; $y < 10; ++$y) { + $year = static::generateRandomYear(null, 2017); + $data[] = [$year, new \DateTime("{$year}-05-02", new \DateTimeZone(self::TIMEZONE))]; + } + + return $data; } } diff --git a/tests/Ukraine/SubstitutedHolidayTest.php b/tests/Ukraine/SubstitutedHolidayTest.php new file mode 100644 index 000000000..2d4b42044 --- /dev/null +++ b/tests/Ukraine/SubstitutedHolidayTest.php @@ -0,0 +1,179 @@ + + */ + +namespace Yasumi\tests\Ukraine; + +use Yasumi\Holiday; +use Yasumi\SubstituteHoliday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\Yasumi; + +/** + * Class SubstitutedHolidayTest. + */ +class SubstitutedHolidayTest extends UkraineBaseTestCase implements HolidayTestCase +{ + /** + * Tests the substitution of holidays on saturday (weekend). + * + * @throws \Exception + * @throws \ReflectionException + */ + public function testSaturdaySubstitution(): void + { + // 2020-05-09 victoryDay (День перемоги) + $year = 2020; + $holiday = 'victoryDay'; + + $this->assertHolidayWithSubstitution( + self::REGION, + $holiday, + $year, + new \DateTime("{$year}-05-09", new \DateTimeZone(self::TIMEZONE)), + new \DateTime("{$year}-05-11", new \DateTimeZone(self::TIMEZONE)) + ); + + unset($year, $holiday); + } + + /** + * Asserts that the expected date is indeed a holiday for that given year and name. + * + * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be tested + * @param string $key string the key of the holiday to be checked against + * @param int $year holiday calendar year + * @param \DateTimeInterface $expectedOfficial the official date to be checked against + * @param \DateTimeImmutable|null $expectedSubstitution the substituted date to be checked against + */ + public function assertHolidayWithSubstitution( + string $provider, + string $key, + int $year, + \DateTimeInterface $expectedOfficial, + ?\DateTimeInterface $expectedSubstitution = null, + ): void { + $holidays = Yasumi::create($provider, $year); + + $holidayOfficial = $holidays->getHoliday($key); + self::assertInstanceOf(Holiday::class, $holidayOfficial); + self::assertNotNull($holidayOfficial); + $this->assertDateTime($expectedOfficial, $holidayOfficial); + self::assertTrue($holidays->isHoliday($holidayOfficial)); + self::assertEquals(Holiday::TYPE_OFFICIAL, $holidayOfficial->getType()); + + $holidaySubstitution = $holidays->getHoliday('substituteHoliday:' . $holidayOfficial->getKey()); + + if (! $expectedSubstitution instanceof \DateTimeInterface) { + // without substitution + self::assertNull($holidaySubstitution); + } else { + // with substitution + self::assertNotNull($holidaySubstitution); + self::assertInstanceOf(SubstituteHoliday::class, $holidaySubstitution); + $this->assertDateTime($expectedSubstitution, $holidaySubstitution); + self::assertTrue($holidays->isHoliday($holidaySubstitution)); + self::assertEquals(Holiday::TYPE_OFFICIAL, $holidaySubstitution->getType()); + } + + unset($holidayOfficial, $holidaySubstitution, $holidays); + } + + /** + * Tests the substitution of holidays on sunday (weekend). + * + * @throws \Exception + * @throws \ReflectionException + */ + public function testSundaySubstitution(): void + { + // 2020-06-28 constitutionDay (День Конституції) + $year = 2020; + $holiday = 'constitutionDay'; + + $this->assertHolidayWithSubstitution( + self::REGION, + $holiday, + $year, + new \DateTime("{$year}-06-28", new \DateTimeZone(self::TIMEZONE)), + new \DateTime("{$year}-06-29", new \DateTimeZone(self::TIMEZONE)) + ); + + unset($year, $holiday); + } + + /** + * Tests the substitution of new year (1. January) on a weekend. + * Special: no substitution at new year (1. January) on a weekend. + * + * @throws \Exception + * @throws \ReflectionException + */ + public function testNewYearNoSubstitution(): void + { + // 2022-01-01 (Saturday) constitutionDay (Новий Рік) + $year = 2022; + $holiday = 'newYearsDay'; + + $this->assertHolidayWithSubstitution( + self::REGION, + $holiday, + $year, + new \DateTime("{$year}-01-01", new \DateTimeZone(self::TIMEZONE)) + ); + + unset($year, $holiday); + } + + /** + * Tests the substitution of Catholic Christmas Day (25. December) on a weekend. + * Special: no substitution at Catholic Christmas Day (25. December) on a weekend. + * + * @throws \Exception + * @throws \ReflectionException + */ + public function testCatholicChristmasDayNoSubstitution(): void + { + // 2022-12-25 (Sunday) catholicChristmasDay (Католицький день Різдва) + $year = 2022; + $holiday = 'catholicChristmasDay'; + + $this->assertHolidayWithSubstitution( + self::REGION, + $holiday, + $year, + new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)) + ); + + unset($year, $holiday); + } + + /** + * Dummy: Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + self::assertTrue(true); + } + + /** + * Dummy: Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + self::assertTrue(true); + } +} diff --git a/tests/Ukraine/UkraineBaseTestCase.php b/tests/Ukraine/UkraineBaseTestCase.php index f736e5169..df65c6757 100644 --- a/tests/Ukraine/UkraineBaseTestCase.php +++ b/tests/Ukraine/UkraineBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; @@ -16,25 +21,18 @@ use Yasumi\tests\YasumiBase; /** - * Class UkraineBaseTestCase - * @package Yasumi\tests\Ukraine + * Class UkraineBaseTestCase. */ class UkraineBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'Ukraine'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Kiev'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'uk_UA'; } diff --git a/tests/Ukraine/UkraineTest.php b/tests/Ukraine/UkraineTest.php index 880a99836..8ef788acc 100644 --- a/tests/Ukraine/UkraineTest.php +++ b/tests/Ukraine/UkraineTest.php @@ -1,55 +1,93 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** - * Class UkraineTest - * @package Yasumi\tests\Ukraine + * Class UkraineTest. */ -class UkraineTest extends UkraineBaseTestCase +class UkraineTest extends UkraineBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(); + } /** - * Tests if all official holidays in Ukraine are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Ukraine are defined by the provider class. */ public function testOfficialHolidays(): void { - $this->assertDefinedHolidays([ + $holidays = [ 'newYearsDay', 'internationalWorkersDay', - 'secondInternationalWorkersDay', - 'christmasDay', 'easter', 'pentecost', 'internationalWomensDay', - 'victoryDay', - 'constitutionDay', - 'independenceDay', - 'defenderOfUkraineDay', - ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + ]; + + if ($this->year >= 1996) { + $holidays[] = 'constitutionDay'; + } + + if ($this->year >= 1991) { + $holidays[] = 'independenceDay'; + } + + if ($this->year >= 2015) { + $holidays[] = 'victoryDay'; + $holidays[] = 'defenderOfUkraineDay'; + } + + if ($this->year < 2018) { + $holidays[] = 'secondInternationalWorkersDay'; + } + + if ($this->year >= 2017) { + $holidays[] = 'catholicChristmasDay'; + } + + if ($this->year <= 2023) { + $holidays[] = 'christmasDay'; + } + + $this->assertDefinedHolidays( + $holidays, + self::REGION, + $this->year, + Holiday::TYPE_OFFICIAL + ); } /** - * Tests if all observed holidays in Ukraine are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Ukraine are defined by the provider class. */ public function testObservedHolidays(): void { @@ -57,8 +95,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Ukraine are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Ukraine are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -66,8 +103,7 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Ukraine are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Ukraine are defined by the provider class. */ public function testBankHolidays(): void { @@ -75,8 +111,7 @@ public function testBankHolidays(): void } /** - * Tests if all other holidays in Ukraine are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Ukraine are defined by the provider class. */ public function testOtherHolidays(): void { @@ -84,10 +119,11 @@ public function testOtherHolidays(): void } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(2015, 2025); + $this->assertSources(self::REGION, 3); } } diff --git a/tests/Ukraine/VictoryDayTest.php b/tests/Ukraine/VictoryDayTest.php index b0f84fcd6..0b0959d89 100644 --- a/tests/Ukraine/VictoryDayTest.php +++ b/tests/Ukraine/VictoryDayTest.php @@ -1,78 +1,94 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\Ukraine; -use DateTime; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** - * Class VictoryDayTest - * @package Yasumi\tests\Ukraine + * Class VictoryDayTest. */ -class VictoryDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface +class VictoryDayTest extends UkraineBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'victoryDay'; /** - * @dataProvider HolidayDataProvider - * - * @param int $year - * @param DateTime $expected - * - * @throws ReflectionException + * Tests the holiday defined in this test. */ - public function testHoliday($year, $expected) + public function testHoliday(): void { - $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected); + $year = static::generateRandomYear(2024); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-08", new \DateTimeZone(self::TIMEZONE)) + ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * Tests the holiday defined in this test. */ - public function HolidayDataProvider(): array + public function testHolidayBefore2024(): void { - return $this->generateRandomDates(5, 9, self::TIMEZONE); + $year = static::generateRandomYear(2015, 2023); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-05-09", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test. + */ + public function testNotHolidayBeforeEstablishment(): void + { + $year = static::generateRandomYear(1000, 2014); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(2015), [self::LOCALE => 'День перемоги'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(2015), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/BoxingDayTest.php b/tests/UnitedKingdom/BoxingDayTest.php index d4b856a57..adfd6a2ad 100644 --- a/tests/UnitedKingdom/BoxingDayTest.php +++ b/tests/UnitedKingdom/BoxingDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in the United Kingdom. */ -class BoxingDayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/ChristmasDayTest.php b/tests/UnitedKingdom/ChristmasDayTest.php index b6cee7ae5..3e1060d15 100644 --- a/tests/UnitedKingdom/ChristmasDayTest.php +++ b/tests/UnitedKingdom/ChristmasDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in the United Kingdom. */ -class ChristmasDayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/EasterMondayTest.php b/tests/UnitedKingdom/EasterMondayTest.php deleted file mode 100644 index fbf376c1d..000000000 --- a/tests/UnitedKingdom/EasterMondayTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - -namespace Yasumi\tests\UnitedKingdom; - -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; -use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; - -/** - * Class for testing Easter Monday in the United Kingdom. - */ -class EasterMondayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface -{ - /** - * The name of the holiday - */ - public const HOLIDAY = 'easterMonday'; - - /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param string $expected the expected date - * - * @throws ReflectionException - * @throws Exception - */ - public function testHoliday($year, $expected) - { - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) - ); - } - - /** - * Returns a list of test dates - * - * @return array list of test dates for the holiday defined in this test - * @throws Exception - */ - public function HolidayDataProvider(): array - { - $data = []; - - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); - - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; - } - - /** - * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException - */ - public function testTranslation(): void - { - $this->assertTranslatedHolidayName( - self::REGION, - self::HOLIDAY, - $this->generateRandomYear(), - [self::LOCALE => 'Easter Monday'] - ); - } - - /** - * Tests type of the holiday defined in this test. - * @throws ReflectionException - */ - public function testHolidayType(): void - { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); - } -} diff --git a/tests/UnitedKingdom/England/BoxingDayTest.php b/tests/UnitedKingdom/England/BoxingDayTest.php index bf689d0d7..cc5436672 100644 --- a/tests/UnitedKingdom/England/BoxingDayTest.php +++ b/tests/UnitedKingdom/England/BoxingDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in England. */ -class BoxingDayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/England/ChristmasDayTest.php b/tests/UnitedKingdom/England/ChristmasDayTest.php index c416252e1..cf08a4d75 100644 --- a/tests/UnitedKingdom/England/ChristmasDayTest.php +++ b/tests/UnitedKingdom/England/ChristmasDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in England. */ -class ChristmasDayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/England/EasterMondayTest.php b/tests/UnitedKingdom/England/EasterMondayTest.php index 4c0570255..6f8a5ee17 100644 --- a/tests/UnitedKingdom/England/EasterMondayTest.php +++ b/tests/UnitedKingdom/England/EasterMondayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Monday in England. */ -class EasterMondayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider + * Tests Easter Monday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,24 +73,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/England/EnglandBaseTestCase.php b/tests/UnitedKingdom/England/EnglandBaseTestCase.php index bb600ae66..d623887ab 100644 --- a/tests/UnitedKingdom/England/EnglandBaseTestCase.php +++ b/tests/UnitedKingdom/England/EnglandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; @@ -22,23 +27,17 @@ abstract class EnglandBaseTestCase extends UnitedKingdomBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'UnitedKingdom\England'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/London'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_GB'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/UnitedKingdom/England/EnglandTest.php b/tests/UnitedKingdom/England/EnglandTest.php index 35366f83e..33e28336b 100644 --- a/tests/UnitedKingdom/England/EnglandTest.php +++ b/tests/UnitedKingdom/England/EnglandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in England. */ -class EnglandTest extends EnglandBaseTestCase +class EnglandTest extends EnglandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } /** - * Tests if all official holidays in England are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in England are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -38,8 +52,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in England are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in England are defined by the provider class. */ public function testObservedHolidays(): void { @@ -47,8 +60,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in England are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in England are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -56,34 +68,61 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in England are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in England are defined by the provider class. */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', + $holidays = [ 'easterMonday', - 'mayDayBankHoliday', - 'springBankHoliday', 'secondChristmasDay', - ], self::REGION, $this->year, Holiday::TYPE_BANK); + ]; + + $year = static::generateRandomYear(); + + if (1965 <= $year) { + $holidays[] = 'springBankHoliday'; + } + + if (1974 <= $year) { + $holidays[] = 'newYearsDay'; + } + + if (1978 <= $year) { + $holidays[] = 'mayDayBankHoliday'; + } + + if (2022 === $year) { + $holidays[] = 'queenElizabethFuneralBankHoliday'; + } + + if (2023 === $year) { + $holidays[] = 'kingCharlesCoronationBankHoliday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_BANK); } /** - * Tests if all other holidays in England are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in England are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'motheringSunday', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1978); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/UnitedKingdom/England/GoodFridayTest.php b/tests/UnitedKingdom/England/GoodFridayTest.php index ca21008bf..dd530353d 100644 --- a/tests/UnitedKingdom/England/GoodFridayTest.php +++ b/tests/UnitedKingdom/England/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in England. */ -class GoodFridayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/England/MayDayBankHolidayTest.php b/tests/UnitedKingdom/England/MayDayBankHolidayTest.php index 3ced29d35..4b1b85075 100644 --- a/tests/UnitedKingdom/England/MayDayBankHolidayTest.php +++ b/tests/UnitedKingdom/England/MayDayBankHolidayTest.php @@ -1,116 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the May Day Bank Holiday in England. */ -class MayDayBankHolidayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class MayDayBankHolidayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDayBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2101; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 1995 and 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayExceptions() + public function testHolidayExceptions(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1995, - new DateTime('1995-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1995-5-8', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2020, - new DateTime('2020-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2020-5-8', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/England/NewYearsDayTest.php b/tests/UnitedKingdom/England/NewYearsDayTest.php index 6149c5162..6cb0db022 100644 --- a/tests/UnitedKingdom/England/NewYearsDayTest.php +++ b/tests/UnitedKingdom/England/NewYearsDayTest.php @@ -1,127 +1,131 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in England. */ -class NewYearsDayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); + return static::generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/England/SpringBankHolidayTest.php b/tests/UnitedKingdom/England/SpringBankHolidayTest.php index 560b3fe6a..c46763feb 100644 --- a/tests/UnitedKingdom/England/SpringBankHolidayTest.php +++ b/tests/UnitedKingdom/England/SpringBankHolidayTest.php @@ -1,116 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Spring Bank Holiday in England. */ -class SpringBankHolidayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class SpringBankHolidayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'springBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1965; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exceptions in 2002 and 2012. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayException() + public function testHolidayException(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 2002, - new DateTime('2002-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2002-6-4', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2012, - new DateTime('2012-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2012-6-4', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Spring Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/England/SummerBankHolidayTest.php b/tests/UnitedKingdom/England/SummerBankHolidayTest.php index 888deb764..1a11de9c1 100644 --- a/tests/UnitedKingdom/England/SummerBankHolidayTest.php +++ b/tests/UnitedKingdom/England/SummerBankHolidayTest.php @@ -1,34 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\England; -use DateTime; -use DateTimeZone; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Summer Bank Holiday England. */ -class SummerBankHolidayTest extends EnglandBaseTestCase implements YasumiTestCaseInterface +class SummerBankHolidayTest extends EnglandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'summerBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; @@ -39,17 +42,17 @@ class SummerBankHolidayTest extends EnglandBaseTestCase implements YasumiTestCas /** * Tests the holiday defined in this test. + * * @throws \Exception - * @throws \ReflectionException */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("last monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("last monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } @@ -57,116 +60,118 @@ public function testHoliday() * Tests the holiday exception in 2020. * * @throws \Exception - * @throws \ReflectionException */ - public function testHolidayBefore1965() + public function testHolidayBefore1965(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday during trial period in 1965-1970. * - * @throws \ReflectionException * @throws \Exception */ - public function testHolidayTrialPeriod() + public function testHolidayTrialPeriod(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1965, - new DateTime('1965-8-30', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1965-8-30', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1966, - new DateTime('1966-8-29', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1966-8-29', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1967, - new DateTime('1967-8-28', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1967-8-28', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1968, - new DateTime('1968-9-2', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1968-9-2', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1969, - new DateTime('1969-9-1', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1969-9-1', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1970, - new DateTime('1970-8-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1970-8-31', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws \ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws \ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::RENAME_YEAR), + static::generateRandomYear(self::RENAME_YEAR), [self::LOCALE => 'Summer Bank Holiday'] ); } /** * Tests the translated name of the holiday defined in this test. - * @throws \ReflectionException + * + * @throws \Exception */ public function testTranslationBeforeRename(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), [self::LOCALE => 'August Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws \ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/GoodFridayTest.php b/tests/UnitedKingdom/GoodFridayTest.php index 2221ffd76..72987520f 100644 --- a/tests/UnitedKingdom/GoodFridayTest.php +++ b/tests/UnitedKingdom/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in the United Kingdom. */ -class GoodFridayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/KingCharlesCoronationBankHolidayTest.php b/tests/UnitedKingdom/KingCharlesCoronationBankHolidayTest.php new file mode 100644 index 000000000..3b02184dd --- /dev/null +++ b/tests/UnitedKingdom/KingCharlesCoronationBankHolidayTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\UnitedKingdom; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the King Charle's Coronation Bank Holiday in the United Kingdom. + */ +class KingCharlesCoronationBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'kingCharlesCoronationBankHoliday'; + + /** + * The year in which the holiday occurred. + */ + public const ACTIVE_YEAR = 2023; + + /** + * The date on which the holiday occurred. + */ + public const ACTIVE_DATE = '2023-5-8'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + new \DateTime(self::ACTIVE_DATE, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test before the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayBeforeActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ACTIVE_YEAR - 1) + ); + } + + /** + * Tests the holiday defined in this test after the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayAfterActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ACTIVE_YEAR + 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + [self::LOCALE => 'King Charles III’s Coronation Bank Holiday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + Holiday::TYPE_BANK + ); + } +} diff --git a/tests/UnitedKingdom/MayDayBankHolidayTest.php b/tests/UnitedKingdom/MayDayBankHolidayTest.php index d6d12e122..3746a1537 100644 --- a/tests/UnitedKingdom/MayDayBankHolidayTest.php +++ b/tests/UnitedKingdom/MayDayBankHolidayTest.php @@ -1,114 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the May Day Bank Holiday in the United Kingdom. */ -class MayDayBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class MayDayBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDayBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2101; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 1995 and 2020. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayExceptions() + public function testHolidayExceptions(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1995, - new DateTime('1995-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1995-5-8', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2020, - new DateTime('2020-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2020-5-8', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/MotheringSundayTest.php b/tests/UnitedKingdom/MotheringSundayTest.php new file mode 100644 index 000000000..4ae81d075 --- /dev/null +++ b/tests/UnitedKingdom/MotheringSundayTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\UnitedKingdom; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; +use Yasumi\tests\UnitedKingdom\England\EnglandBaseTestCase; + +class MotheringSundayTest extends EnglandBaseTestCase implements HolidayTestCase +{ + public const HOLIDAY = 'motheringSunday'; + + /** + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P3W')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + // some extra random dates + $data[] = [2016, '2016-03-06']; + $data[] = [2022, '2022-03-27']; + + return $data; + } + + /** + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Mothering Sunday'] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(), + Holiday::TYPE_OTHER + ); + } +} diff --git a/tests/UnitedKingdom/NewYearsDayTest.php b/tests/UnitedKingdom/NewYearsDayTest.php index a44cc17bf..1efe44830 100644 --- a/tests/UnitedKingdom/NewYearsDayTest.php +++ b/tests/UnitedKingdom/NewYearsDayTest.php @@ -1,127 +1,131 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in the United Kingdom. */ -class NewYearsDayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested + * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); + return static::generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/BattleOfTheBoyneTest.php b/tests/UnitedKingdom/NorthernIreland/BattleOfTheBoyneTest.php index 766d6bd15..446f86a00 100644 --- a/tests/UnitedKingdom/NorthernIreland/BattleOfTheBoyneTest.php +++ b/tests/UnitedKingdom/NorthernIreland/BattleOfTheBoyneTest.php @@ -1,56 +1,55 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Batthe of the Boyne in Northern Ireland. */ -class BattleOfTheBoyneTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class BattleOfTheBoyneTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'battleOfTheBoyne'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1926; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param \DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } @@ -58,30 +57,32 @@ public function testHoliday($year, $expected) /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-7-12", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-7-12", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -91,28 +92,29 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Battle of the Boyne'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/BoxingDayTest.php b/tests/UnitedKingdom/NorthernIreland/BoxingDayTest.php index 42b4101ce..fc56f8669 100644 --- a/tests/UnitedKingdom/NorthernIreland/BoxingDayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/BoxingDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in Northern Ireland. */ -class BoxingDayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/NorthernIreland/ChristmasDayTest.php b/tests/UnitedKingdom/NorthernIreland/ChristmasDayTest.php index d5d393f71..31f69a4dd 100644 --- a/tests/UnitedKingdom/NorthernIreland/ChristmasDayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/ChristmasDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Northern Ireland. */ -class ChristmasDayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/NorthernIreland/EasterMondayTest.php b/tests/UnitedKingdom/NorthernIreland/EasterMondayTest.php index 39c215e4f..9ce46db08 100644 --- a/tests/UnitedKingdom/NorthernIreland/EasterMondayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/EasterMondayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Monday in Northern Ireland. */ -class EasterMondayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider + * Tests Easter Monday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,24 +73,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/NorthernIreland/GoodFridayTest.php b/tests/UnitedKingdom/NorthernIreland/GoodFridayTest.php index 9c9722fd6..d72435185 100644 --- a/tests/UnitedKingdom/NorthernIreland/GoodFridayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Northern Ireland. */ -class GoodFridayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/NorthernIreland/MayDayBankHolidayTest.php b/tests/UnitedKingdom/NorthernIreland/MayDayBankHolidayTest.php index 08b38cc73..985d45051 100644 --- a/tests/UnitedKingdom/NorthernIreland/MayDayBankHolidayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/MayDayBankHolidayTest.php @@ -1,115 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the May Day Bank Holiday in Northern Ireland. */ -class MayDayBankHolidayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class MayDayBankHolidayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDayBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2101; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 1995 and 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayExceptions() + public function testHolidayExceptions(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1995, - new DateTime('1995-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1995-5-8', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2020, - new DateTime('2020-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2020-5-8', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/NewYearsDayTest.php b/tests/UnitedKingdom/NorthernIreland/NewYearsDayTest.php index b46bd36dc..009c85ab0 100644 --- a/tests/UnitedKingdom/NorthernIreland/NewYearsDayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/NewYearsDayTest.php @@ -1,127 +1,131 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Northern Ireland. */ -class NewYearsDayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); + return static::generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/NorthernIrelandBaseTestCase.php b/tests/UnitedKingdom/NorthernIreland/NorthernIrelandBaseTestCase.php index 01d690060..1e7db5833 100644 --- a/tests/UnitedKingdom/NorthernIreland/NorthernIrelandBaseTestCase.php +++ b/tests/UnitedKingdom/NorthernIreland/NorthernIrelandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; @@ -22,23 +27,17 @@ abstract class NorthernIrelandBaseTestCase extends UnitedKingdomBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'UnitedKingdom\NorthernIreland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/Belfast'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_GB'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/UnitedKingdom/NorthernIreland/NorthernIrelandTest.php b/tests/UnitedKingdom/NorthernIreland/NorthernIrelandTest.php index fb84414c1..1c60072de 100644 --- a/tests/UnitedKingdom/NorthernIreland/NorthernIrelandTest.php +++ b/tests/UnitedKingdom/NorthernIreland/NorthernIrelandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Northern Ireland. */ -class NorthernIrelandTest extends NorthernIrelandBaseTestCase +class NorthernIrelandTest extends NorthernIrelandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } /** - * Tests if all official holidays in Northern Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Northern Ireland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -38,8 +52,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Northern Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Northern Ireland are defined by the provider class. */ public function testObservedHolidays(): void { @@ -47,8 +60,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Northern Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Northern Ireland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -56,35 +68,65 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Northern Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Northern Ireland are defined by the provider class. */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', + $holidays = [ 'easterMonday', - 'mayDayBankHoliday', - 'springBankHoliday', - 'battleOfTheBoyne', 'secondChristmasDay', - ], self::REGION, $this->year, Holiday::TYPE_BANK); + ]; + + $year = static::generateRandomYear(); + + if (1926 <= $year) { + $holidays[] = 'battleOfTheBoyne'; + } + + if (1965 <= $year) { + $holidays[] = 'springBankHoliday'; + } + + if (1974 <= $year) { + $holidays[] = 'newYearsDay'; + } + + if (1978 <= $year) { + $holidays[] = 'mayDayBankHoliday'; + } + + if (2022 === $year) { + $holidays[] = 'queenElizabethFuneralBankHoliday'; + } + + if (2023 === $year) { + $holidays[] = 'kingCharlesCoronationBankHoliday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Northern Ireland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Northern Ireland are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'motheringSunday', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1978); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/UnitedKingdom/NorthernIreland/SpringBankHolidayTest.php b/tests/UnitedKingdom/NorthernIreland/SpringBankHolidayTest.php index 73aa13ef1..25eabf06e 100644 --- a/tests/UnitedKingdom/NorthernIreland/SpringBankHolidayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/SpringBankHolidayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Spring Bank Holiday in Northern Ireland. */ -class SpringBankHolidayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class SpringBankHolidayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'springBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1965; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Spring Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/StPatricksDayTest.php b/tests/UnitedKingdom/NorthernIreland/StPatricksDayTest.php index 835014044..ceb153c7b 100644 --- a/tests/UnitedKingdom/NorthernIreland/StPatricksDayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/StPatricksDayTest.php @@ -1,56 +1,55 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Patrick's Day in Northern Ireland. */ -class StPatricksDayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class StPatricksDayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stPatricksDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1971; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param \DateTime $expected the expected date + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } @@ -58,30 +57,32 @@ public function testHoliday($year, $expected) /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-3-17", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-3-17", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -91,28 +92,29 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'St. Patrick\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'St. Patrick’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/NorthernIreland/SummerBankHolidayTest.php b/tests/UnitedKingdom/NorthernIreland/SummerBankHolidayTest.php index eb5d93073..6c19d2115 100644 --- a/tests/UnitedKingdom/NorthernIreland/SummerBankHolidayTest.php +++ b/tests/UnitedKingdom/NorthernIreland/SummerBankHolidayTest.php @@ -1,36 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\NorthernIreland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Summer Bank Holiday in Northern Ireland. */ -class SummerBankHolidayTest extends NorthernIrelandBaseTestCase implements YasumiTestCaseInterface +class SummerBankHolidayTest extends NorthernIrelandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'summerBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; @@ -41,133 +42,136 @@ class SummerBankHolidayTest extends NorthernIrelandBaseTestCase implements Yasum /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("last monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("last monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayBefore1965() + public function testHolidayBefore1965(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday during trial period in 1965-1970. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayTrialPeriod() + public function testHolidayTrialPeriod(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1965, - new DateTime('1965-8-30', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1965-8-30', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1966, - new DateTime('1966-8-29', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1966-8-29', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1967, - new DateTime('1967-8-28', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1967-8-28', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1968, - new DateTime('1968-9-2', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1968-9-2', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1969, - new DateTime('1969-9-1', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1969-9-1', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1970, - new DateTime('1970-8-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1970-8-31', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::RENAME_YEAR), + static::generateRandomYear(self::RENAME_YEAR), [self::LOCALE => 'Summer Bank Holiday'] ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslationBeforeRename(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), [self::LOCALE => 'August Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/PlatinumJubileeBankHolidayTest.php b/tests/UnitedKingdom/PlatinumJubileeBankHolidayTest.php new file mode 100644 index 000000000..347047441 --- /dev/null +++ b/tests/UnitedKingdom/PlatinumJubileeBankHolidayTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\UnitedKingdom; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the Platinum Jubilee Bank Holiday in the United Kingdom. + */ +class PlatinumJubileeBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'platinumJubileeBankHoliday'; + + /** + * The year in which the holiday occurred. + */ + public const ACTIVE_YEAR = 2022; + + /** + * The date on which the holiday occurred. + */ + public const ACTIVE_DATE = '2022-6-3'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + new \DateTime(self::ACTIVE_DATE, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test before the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayBeforeActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ACTIVE_YEAR - 1) + ); + } + + /** + * Tests the holiday defined in this test after the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayAfterActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ACTIVE_YEAR + 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + [self::LOCALE => 'Platinum Jubilee Bank Holiday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + Holiday::TYPE_BANK + ); + } +} diff --git a/tests/UnitedKingdom/QueenElizabethFuneralBankHolidayTest.php b/tests/UnitedKingdom/QueenElizabethFuneralBankHolidayTest.php new file mode 100644 index 000000000..fd2e42870 --- /dev/null +++ b/tests/UnitedKingdom/QueenElizabethFuneralBankHolidayTest.php @@ -0,0 +1,111 @@ + + */ + +namespace Yasumi\tests\UnitedKingdom; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing the Queen Elizabeth's Funeral Bank Holiday in the United Kingdom. + */ +class QueenElizabethFuneralBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'queenElizabethFuneralBankHoliday'; + + /** + * The year in which the holiday occurred. + */ + public const ACTIVE_YEAR = 2022; + + /** + * The date on which the holiday occurred. + */ + public const ACTIVE_DATE = '2022-9-19'; + + /** + * Tests the holiday defined in this test. + * + * @throws \Exception + */ + public function testHoliday(): void + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + new \DateTime(self::ACTIVE_DATE, new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the holiday defined in this test before the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayBeforeActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(1000, self::ACTIVE_YEAR - 1) + ); + } + + /** + * Tests the holiday defined in this test after the year in which it occurred. + * + * @throws \Exception + */ + public function testHolidayAfterActive(): void + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + static::generateRandomYear(self::ACTIVE_YEAR + 1) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + [self::LOCALE => 'Queen Elizabeth II’s State Funeral Bank Holiday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + self::ACTIVE_YEAR, + Holiday::TYPE_BANK + ); + } +} diff --git a/tests/UnitedKingdom/Scotland/BoxingDayTest.php b/tests/UnitedKingdom/Scotland/BoxingDayTest.php index b81708d4e..da0edd5af 100644 --- a/tests/UnitedKingdom/Scotland/BoxingDayTest.php +++ b/tests/UnitedKingdom/Scotland/BoxingDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in Scotland. */ -class BoxingDayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/Scotland/ChristmasDayTest.php b/tests/UnitedKingdom/Scotland/ChristmasDayTest.php index b9e829841..bc9c2ed4c 100644 --- a/tests/UnitedKingdom/Scotland/ChristmasDayTest.php +++ b/tests/UnitedKingdom/Scotland/ChristmasDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Scotland. */ -class ChristmasDayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/Scotland/GoodFridayTest.php b/tests/UnitedKingdom/Scotland/GoodFridayTest.php index 066bdd63b..e6c510238 100644 --- a/tests/UnitedKingdom/Scotland/GoodFridayTest.php +++ b/tests/UnitedKingdom/Scotland/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Scotland. */ -class GoodFridayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/Scotland/MayDayBankHolidayTest.php b/tests/UnitedKingdom/Scotland/MayDayBankHolidayTest.php index e3659fcf5..a17d73882 100644 --- a/tests/UnitedKingdom/Scotland/MayDayBankHolidayTest.php +++ b/tests/UnitedKingdom/Scotland/MayDayBankHolidayTest.php @@ -1,116 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the May Day Bank Holiday in Scotland. */ -class MayDayBankHolidayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class MayDayBankHolidayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDayBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2101; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 1995 and 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayExceptions() + public function testHolidayExceptions(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1995, - new DateTime('1995-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1995-5-8', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2020, - new DateTime('2020-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2020-5-8', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Scotland/NewYearsDayTest.php b/tests/UnitedKingdom/Scotland/NewYearsDayTest.php index 96ac0792f..b2cc54c42 100644 --- a/tests/UnitedKingdom/Scotland/NewYearsDayTest.php +++ b/tests/UnitedKingdom/Scotland/NewYearsDayTest.php @@ -1,107 +1,108 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Scotland. */ -class NewYearsDayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-1-1", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-1-1", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -110,28 +111,30 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Scotland/ScotlandBaseTestCase.php b/tests/UnitedKingdom/Scotland/ScotlandBaseTestCase.php index e59c806ff..e57fe5c36 100644 --- a/tests/UnitedKingdom/Scotland/ScotlandBaseTestCase.php +++ b/tests/UnitedKingdom/Scotland/ScotlandBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; @@ -22,23 +27,17 @@ abstract class ScotlandBaseTestCase extends UnitedKingdomBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'UnitedKingdom\Scotland'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/London'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_GB'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/UnitedKingdom/Scotland/ScotlandTest.php b/tests/UnitedKingdom/Scotland/ScotlandTest.php index 495d790fd..27262ae00 100644 --- a/tests/UnitedKingdom/Scotland/ScotlandTest.php +++ b/tests/UnitedKingdom/Scotland/ScotlandTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Scotland. */ -class ScotlandTest extends ScotlandBaseTestCase +class ScotlandTest extends ScotlandBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } /** - * Tests if all official holidays in Scotland are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Scotland are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -36,8 +50,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Scotland are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Scotland are defined by the provider class. */ public function testObservedHolidays(): void { @@ -45,8 +58,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Scotland are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Scotland are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -54,35 +66,62 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Scotland are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Scotland are defined by the provider class. */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([ - 'goodFriday', - 'mayDayBankHoliday', - 'springBankHoliday', + $holidays = [ 'christmasDay', + 'goodFriday', 'secondChristmasDay', - 'newYearsDay', - ], self::REGION, $this->year, Holiday::TYPE_BANK); + ]; + + $year = static::generateRandomYear(); + + if (1965 <= $year) { + $holidays[] = 'springBankHoliday'; + } + + if (1974 <= $year) { + $holidays[] = 'newYearsDay'; + } + + if (1978 <= $year) { + $holidays[] = 'mayDayBankHoliday'; + } + + if (2022 === $year) { + $holidays[] = 'queenElizabethFuneralBankHoliday'; + } + + if (2023 === $year) { + $holidays[] = 'kingCharlesCoronationBankHoliday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Scotland are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Scotland are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'motheringSunday', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1978); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/UnitedKingdom/Scotland/SecondNewYearsDayTest.php b/tests/UnitedKingdom/Scotland/SecondNewYearsDayTest.php index d2aaefed6..1eb70f4b0 100644 --- a/tests/UnitedKingdom/Scotland/SecondNewYearsDayTest.php +++ b/tests/UnitedKingdom/Scotland/SecondNewYearsDayTest.php @@ -1,107 +1,108 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Scotland. */ -class SecondNewYearsDayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class SecondNewYearsDayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'secondNewYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-1-2", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-1-2", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -110,28 +111,30 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => '2nd January'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Scotland/SpringBankHolidayTest.php b/tests/UnitedKingdom/Scotland/SpringBankHolidayTest.php index 014d6e97c..11b683a35 100644 --- a/tests/UnitedKingdom/Scotland/SpringBankHolidayTest.php +++ b/tests/UnitedKingdom/Scotland/SpringBankHolidayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Spring Bank Holiday in Scotland. */ -class SpringBankHolidayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class SpringBankHolidayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'springBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1965; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Spring Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Scotland/StAndrewsDayTest.php b/tests/UnitedKingdom/Scotland/StAndrewsDayTest.php index 151485d38..d4d4e507d 100644 --- a/tests/UnitedKingdom/Scotland/StAndrewsDayTest.php +++ b/tests/UnitedKingdom/Scotland/StAndrewsDayTest.php @@ -1,74 +1,74 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing St. Patrick's Day in Scotland. */ -class StAndrewsDayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class StAndrewsDayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'stAndrewsDay'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 2007; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date * - * @param int $year the year for which the holiday defined in this test needs to be tested - * @param \DateTime $expected the expected date - * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { + if (\in_array((int) $date->format('w'), [0, 6], true)) { $date->modify('next monday'); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); } } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); - $date = new DateTime("$year-11-30", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $date = new \DateTime("{$year}-11-30", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -78,28 +78,29 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. * - * @throws ReflectionException + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'St. Andrew\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'St. Andrew’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Scotland/SummerBankHolidayTest.php b/tests/UnitedKingdom/Scotland/SummerBankHolidayTest.php index 783106888..745855fca 100644 --- a/tests/UnitedKingdom/Scotland/SummerBankHolidayTest.php +++ b/tests/UnitedKingdom/Scotland/SummerBankHolidayTest.php @@ -1,92 +1,96 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Scotland; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the August Bank Holiday in Scotland. */ -class SummerBankHolidayTest extends ScotlandBaseTestCase implements YasumiTestCaseInterface +class SummerBankHolidayTest extends ScotlandBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'summerBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'August Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/SpringBankHolidayTest.php b/tests/UnitedKingdom/SpringBankHolidayTest.php index 348b5b7a1..7053009ca 100644 --- a/tests/UnitedKingdom/SpringBankHolidayTest.php +++ b/tests/UnitedKingdom/SpringBankHolidayTest.php @@ -1,114 +1,125 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Spring Bank Holiday in the United Kingdom. */ -class SpringBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class SpringBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'springBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1965; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** - * Tests the holiday exceptions in 2002 and 2012. - * @throws ReflectionException - * @throws Exception + * Tests the holiday exceptions in 2002, 2012 and 2022. + * + * @throws \Exception */ - public function testHolidayException() + public function testHolidayException(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 2002, - new DateTime('2002-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2002-6-4', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2012, - new DateTime('2012-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2012-6-4', new \DateTimeZone(self::TIMEZONE)) + ); + + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + 2022, + new \DateTime('2022-6-2', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Spring Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/SummerBankHolidayTest.php b/tests/UnitedKingdom/SummerBankHolidayTest.php index fe591a8c4..a7a2b54ba 100644 --- a/tests/UnitedKingdom/SummerBankHolidayTest.php +++ b/tests/UnitedKingdom/SummerBankHolidayTest.php @@ -1,36 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Summer Bank Holiday in the United Kingdom. */ -class SummerBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiTestCaseInterface +class SummerBankHolidayTest extends UnitedKingdomBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'summerBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; @@ -41,132 +42,136 @@ class SummerBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiT /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("last monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("last monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 2020. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayBefore1965() + public function testHolidayBefore1965(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday during trial period in 1965-1970. - * @throws ReflectionException - * @throws Exception + * + * @throws \Exception */ - public function testHolidayTrialPeriod() + public function testHolidayTrialPeriod(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1965, - new DateTime('1965-8-30', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1965-8-30', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1966, - new DateTime('1966-8-29', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1966-8-29', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1967, - new DateTime('1967-8-28', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1967-8-28', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1968, - new DateTime('1968-9-2', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1968-9-2', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1969, - new DateTime('1969-9-1', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1969-9-1', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1970, - new DateTime('1970-8-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1970-8-31', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::RENAME_YEAR), + static::generateRandomYear(self::RENAME_YEAR), [self::LOCALE => 'Summer Bank Holiday'] ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslationBeforeRename(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), [self::LOCALE => 'August Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/UnitedKingdomBaseTestCase.php b/tests/UnitedKingdom/UnitedKingdomBaseTestCase.php index fcc0013be..d0eaa0514 100644 --- a/tests/UnitedKingdom/UnitedKingdomBaseTestCase.php +++ b/tests/UnitedKingdom/UnitedKingdomBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; @@ -22,23 +27,17 @@ abstract class UnitedKingdomBaseTestCase extends TestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'UnitedKingdom'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/London'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_GB'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/UnitedKingdom/UnitedKingdomTest.php b/tests/UnitedKingdom/UnitedKingdomTest.php index fd9ecf93b..682d1368e 100644 --- a/tests/UnitedKingdom/UnitedKingdomTest.php +++ b/tests/UnitedKingdom/UnitedKingdomTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in the United Kingdom. */ -class UnitedKingdomTest extends UnitedKingdomBaseTestCase +class UnitedKingdomTest extends UnitedKingdomBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } /** - * Tests if all official holidays in the United Kingdom are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in the United Kingdom are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -38,8 +52,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in the United Kingdom are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in the United Kingdom are defined by the provider class. */ public function testObservedHolidays(): void { @@ -47,8 +60,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in the United Kingdom are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in the United Kingdom are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -56,34 +68,60 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in the United Kingdom are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in the United Kingdom are defined by the provider class. */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', - 'easterMonday', - 'mayDayBankHoliday', - 'springBankHoliday', + $holidays = [ 'secondChristmasDay', - ], self::REGION, $this->year, Holiday::TYPE_BANK); + ]; + + $year = static::generateRandomYear(); + + if (1965 <= $year) { + $holidays[] = 'springBankHoliday'; + } + + if (1974 <= $year) { + $holidays[] = 'newYearsDay'; + } + + if (1978 <= $year) { + $holidays[] = 'mayDayBankHoliday'; + } + + if (2022 === $year) { + $holidays[] = 'queenElizabethFuneralBankHoliday'; + } + + if (2023 === $year) { + $holidays[] = 'kingCharlesCoronationBankHoliday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_BANK); } /** - * Tests if all other holidays in the United Kingdom are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in the United Kingdom are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'motheringSunday', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1978); + $this->assertSources(self::REGION, 2); } } diff --git a/tests/UnitedKingdom/Wales/BoxingDayTest.php b/tests/UnitedKingdom/Wales/BoxingDayTest.php index eee71a3cb..339918d74 100644 --- a/tests/UnitedKingdom/Wales/BoxingDayTest.php +++ b/tests/UnitedKingdom/Wales/BoxingDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Boxing Day in Wales. */ -class BoxingDayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class BoxingDayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'secondChristmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-26", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-26", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Boxing Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/Wales/ChristmasDayTest.php b/tests/UnitedKingdom/Wales/ChristmasDayTest.php index b32321bc1..913d8334e 100644 --- a/tests/UnitedKingdom/Wales/ChristmasDayTest.php +++ b/tests/UnitedKingdom/Wales/ChristmasDayTest.php @@ -1,71 +1,70 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Christmas Day in Wales. */ -class ChristmasDayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class ChristmasDayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'christmasDay'; /** * Tests the holiday defined in this test. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { - $date = new DateTime($expected, new DateTimeZone(self::TIMEZONE)); + $date = new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)); $this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date); - if (\in_array((int)$date->format('w'), [0, 6], true)) { - $date->add(new DateInterval('P2D')); + if (\in_array((int) $date->format('w'), [0, 6], true)) { + $date->add(new \DateInterval('P2D')); $this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date); $this->assertHolidayType(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, Holiday::TYPE_BANK); } } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < self::TEST_ITERATIONS; $y++) { - $year = $this->generateRandomYear(); - $date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE)); + for ($y = 0; $y < self::TEST_ITERATIONS; ++$y) { + $year = static::generateRandomYear(); + $date = new \DateTime("{$year}-12-25", new \DateTimeZone(self::TIMEZONE)); $data[] = [$year, $date->format('Y-m-d')]; } @@ -75,24 +74,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Christmas Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/Wales/EasterMondayTest.php b/tests/UnitedKingdom/Wales/EasterMondayTest.php index 03910b78e..017d1bddc 100644 --- a/tests/UnitedKingdom/Wales/EasterMondayTest.php +++ b/tests/UnitedKingdom/Wales/EasterMondayTest.php @@ -1,70 +1,69 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateInterval; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing Easter Monday in Wales. */ -class EasterMondayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class EasterMondayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'easterMonday'; /** - * Tests Easter Monday - * - * @dataProvider HolidayDataProvider + * Tests Easter Monday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHoliday($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** - * Returns a list of test dates + * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { $data = []; - for ($y = 0; $y < 50; $y++) { - $year = $this->generateRandomYear(); - $date = $this->calculateEaster($year, self::TIMEZONE); - $date->add(new DateInterval('P1D')); + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->add(new \DateInterval('P1D')); $data[] = [$year, $date->format('Y-m-d')]; } @@ -74,24 +73,26 @@ public function HolidayDataProvider(): array /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Easter Monday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_BANK); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_BANK); } } diff --git a/tests/UnitedKingdom/Wales/GoodFridayTest.php b/tests/UnitedKingdom/Wales/GoodFridayTest.php index d4ec2a195..011c65395 100644 --- a/tests/UnitedKingdom/Wales/GoodFridayTest.php +++ b/tests/UnitedKingdom/Wales/GoodFridayTest.php @@ -1,70 +1,73 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class containing tests for Good Friday in Wales. */ -class GoodFridayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class GoodFridayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'goodFriday'; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1866; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-3-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-3-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + static::generateRandomYear(), [self::LOCALE => 'Good Friday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/UnitedKingdom/Wales/MayDayBankHolidayTest.php b/tests/UnitedKingdom/Wales/MayDayBankHolidayTest.php index b8d710000..d5aa4b817 100644 --- a/tests/UnitedKingdom/Wales/MayDayBankHolidayTest.php +++ b/tests/UnitedKingdom/Wales/MayDayBankHolidayTest.php @@ -1,116 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the May Day Bank Holiday in Wales. */ -class MayDayBankHolidayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class MayDayBankHolidayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'mayDayBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1978; /** * Tests the holiday defined in this test. * - * @throws Exception - * @throws ReflectionException + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 2101; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-2", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-2", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 1995 and 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayExceptions() + public function testHolidayExceptions(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1995, - new DateTime('1995-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1995-5-8', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2020, - new DateTime('2020-5-8', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2020-5-8', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'May Day Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Wales/NewYearsDayTest.php b/tests/UnitedKingdom/Wales/NewYearsDayTest.php index eb0c293a9..4a4644650 100644 --- a/tests/UnitedKingdom/Wales/NewYearsDayTest.php +++ b/tests/UnitedKingdom/Wales/NewYearsDayTest.php @@ -1,127 +1,131 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing New Years Day in Wales. */ -class NewYearsDayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class NewYearsDayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; /** - * The year in which the holiday was adjusted + * The year in which the holiday was adjusted. */ public const ADJUSTMENT_YEAR = 1974; /** - * The name of the holiday to be tested + * The name of the holiday to be tested. */ public const HOLIDAY = 'newYearsDay'; /** * Tests the holiday defined in this test on or after establishment. * - * @dataProvider HolidayDataProvider - * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayOnAfterEstablishment($year, $expected) + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHolidayOnAfterEstablishment(int $year, string $expected): void { $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime($expected, new DateTimeZone(self::TIMEZONE)) + new \DateTime($expected, new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests that the holiday defined in this test is of the type 'observance' before the year it was changed. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayIsObservedTypeBeforeChange() + public function testHolidayIsObservedTypeBeforeChange(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::ADJUSTMENT_YEAR - 1), Holiday::TYPE_OBSERVANCE ); } /** - * Returns a list of random test dates used for assertion of the holiday defined in this test + * Returns a list of random test dates used for assertion of the holiday defined in this test. + * + * @return array list of test dates for the holiday defined in this test * - * @return array list of test dates for the holiday defined in this test - * @throws Exception + * @throws \Exception */ - public function HolidayDataProvider(): array + public static function HolidayDataProvider(): array { - return $this->generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); + return static::generateRandomDatesWithHolidayMovedToMonday(01, 01, self::TIMEZONE, 10, self::ESTABLISHMENT_YEAR); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), - [self::LOCALE => 'New Year\'s Day'] + static::generateRandomYear(self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'New Year’s Day'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ADJUSTMENT_YEAR + 1), + static::generateRandomYear(self::ADJUSTMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Wales/SpringBankHolidayTest.php b/tests/UnitedKingdom/Wales/SpringBankHolidayTest.php index d9b7a577a..03954edfa 100644 --- a/tests/UnitedKingdom/Wales/SpringBankHolidayTest.php +++ b/tests/UnitedKingdom/Wales/SpringBankHolidayTest.php @@ -1,115 +1,118 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Spring Bank Holiday in Wales. */ -class SpringBankHolidayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class SpringBankHolidayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'springBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1965; /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { $year = 1988; $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("$year-5-30", new DateTimeZone(self::TIMEZONE)) + new \DateTime("{$year}-5-30", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exceptions in 2002 and 2012. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayException() + public function testHolidayException(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 2002, - new DateTime('2002-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2002-6-4', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 2012, - new DateTime('2012-6-4', new DateTimeZone(self::TIMEZONE)) + new \DateTime('2012-6-4', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), [self::LOCALE => 'Spring Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Wales/SummerBankHolidayTest.php b/tests/UnitedKingdom/Wales/SummerBankHolidayTest.php index ca69ded05..3c0d9d532 100644 --- a/tests/UnitedKingdom/Wales/SummerBankHolidayTest.php +++ b/tests/UnitedKingdom/Wales/SummerBankHolidayTest.php @@ -1,36 +1,37 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use DateTime; -use DateTimeZone; -use Exception; -use ReflectionException; use Yasumi\Holiday; -use Yasumi\tests\YasumiTestCaseInterface; +use Yasumi\tests\HolidayTestCase; /** * Class for testing the Summer Bank Holiday in Wales. */ -class SummerBankHolidayTest extends WalesBaseTestCase implements YasumiTestCaseInterface +class SummerBankHolidayTest extends WalesBaseTestCase implements HolidayTestCase { /** - * The name of the holiday + * The name of the holiday. */ public const HOLIDAY = 'summerBankHoliday'; /** - * The year in which the holiday was first established + * The year in which the holiday was first established. */ public const ESTABLISHMENT_YEAR = 1871; @@ -41,134 +42,136 @@ class SummerBankHolidayTest extends WalesBaseTestCase implements YasumiTestCaseI /** * Tests the holiday defined in this test. - * @throws Exception - * @throws ReflectionException + * + * @throws \Exception */ - public function testHoliday() + public function testHoliday(): void { - $year = $this->generateRandomYear(1970); + $year = static::generateRandomYear(1970); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("last monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("last monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday exception in 2020. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayBefore1965() + public function testHolidayBefore1965(): void { - $year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR, 1964); $this->assertHoliday( self::REGION, self::HOLIDAY, $year, - new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE)) + new \DateTime("first monday of august {$year}", new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday during trial period in 1965-1970. * - * @throws ReflectionException - * @throws Exception + * @throws \Exception */ - public function testHolidayTrialPeriod() + public function testHolidayTrialPeriod(): void { $this->assertHoliday( self::REGION, self::HOLIDAY, 1965, - new DateTime('1965-8-30', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1965-8-30', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1966, - new DateTime('1966-8-29', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1966-8-29', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1967, - new DateTime('1967-8-28', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1967-8-28', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1968, - new DateTime('1968-9-2', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1968-9-2', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1969, - new DateTime('1969-9-1', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1969-9-1', new \DateTimeZone(self::TIMEZONE)) ); $this->assertHoliday( self::REGION, self::HOLIDAY, 1970, - new DateTime('1970-8-31', new DateTimeZone(self::TIMEZONE)) + new \DateTime('1970-8-31', new \DateTimeZone(self::TIMEZONE)) ); } /** * Tests the holiday defined in this test before establishment. - * @throws ReflectionException + * + * @throws \Exception */ - public function testHolidayBeforeEstablishment() + public function testHolidayBeforeEstablishment(): void { $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslation(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::RENAME_YEAR), + static::generateRandomYear(self::RENAME_YEAR), [self::LOCALE => 'Summer Bank Holiday'] ); } /** * Tests the translated name of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testTranslationBeforeRename(): void { $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, self::RENAME_YEAR - 1), [self::LOCALE => 'August Bank Holiday'] ); } /** * Tests type of the holiday defined in this test. - * @throws ReflectionException + * + * @throws \Exception */ public function testHolidayType(): void { $this->assertHolidayType( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_BANK ); } diff --git a/tests/UnitedKingdom/Wales/WalesBaseTestCase.php b/tests/UnitedKingdom/Wales/WalesBaseTestCase.php index 27d3e1836..892b8d9a9 100644 --- a/tests/UnitedKingdom/Wales/WalesBaseTestCase.php +++ b/tests/UnitedKingdom/Wales/WalesBaseTestCase.php @@ -1,13 +1,18 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; @@ -22,23 +27,17 @@ abstract class WalesBaseTestCase extends UnitedKingdomBaseTestCase { use YasumiBase; - /** - * Name of the region (e.g. country / state) to be tested - */ + /** Name of the region (e.g. country / state) to be tested. */ public const REGION = 'UnitedKingdom\Wales'; - /** - * Timezone in which this provider has holidays defined - */ + /** Timezone in which this provider has holidays defined. */ public const TIMEZONE = 'Europe/London'; - /** - * Locale that is considered common for this provider - */ + /** Locale that is considered common for this provider. */ public const LOCALE = 'en_GB'; /** - * Number of iterations to be used for the various unit tests of this provider + * Number of iterations to be used for the various unit tests of this provider. */ public const TEST_ITERATIONS = 50; } diff --git a/tests/UnitedKingdom/Wales/WalesTest.php b/tests/UnitedKingdom/Wales/WalesTest.php index 279b5dc01..533ece322 100644 --- a/tests/UnitedKingdom/Wales/WalesTest.php +++ b/tests/UnitedKingdom/Wales/WalesTest.php @@ -1,33 +1,47 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests\UnitedKingdom\Wales; -use ReflectionException; use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; /** * Class for testing holidays in Wales. */ -class WalesTest extends WalesBaseTestCase +class WalesTest extends WalesBaseTestCase implements ProviderTestCase { /** * @var int year random year number used for all tests in this Test Case */ - protected $year; + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1978); + } /** - * Tests if all official holidays in Wales are defined by the provider class - * @throws ReflectionException + * Tests if all official holidays in Wales are defined by the provider class. */ public function testOfficialHolidays(): void { @@ -38,8 +52,7 @@ public function testOfficialHolidays(): void } /** - * Tests if all observed holidays in Wales are defined by the provider class - * @throws ReflectionException + * Tests if all observed holidays in Wales are defined by the provider class. */ public function testObservedHolidays(): void { @@ -47,8 +60,7 @@ public function testObservedHolidays(): void } /** - * Tests if all seasonal holidays in Wales are defined by the provider class - * @throws ReflectionException + * Tests if all seasonal holidays in Wales are defined by the provider class. */ public function testSeasonalHolidays(): void { @@ -56,34 +68,61 @@ public function testSeasonalHolidays(): void } /** - * Tests if all bank holidays in Wales are defined by the provider class - * @throws ReflectionException + * Tests if all bank holidays in Wales are defined by the provider class. */ public function testBankHolidays(): void { - $this->assertDefinedHolidays([ - 'newYearsDay', + $holidays = [ 'easterMonday', - 'mayDayBankHoliday', - 'springBankHoliday', 'secondChristmasDay', - ], self::REGION, $this->year, Holiday::TYPE_BANK); + ]; + + $year = static::generateRandomYear(); + + if (1965 <= $year) { + $holidays[] = 'springBankHoliday'; + } + + if (1974 <= $year) { + $holidays[] = 'newYearsDay'; + } + + if (1978 <= $year) { + $holidays[] = 'mayDayBankHoliday'; + } + + if (2022 === $year) { + $holidays[] = 'queenElizabethFuneralBankHoliday'; + } + + if (2023 === $year) { + $holidays[] = 'kingCharlesCoronationBankHoliday'; + } + + $this->assertDefinedHolidays($holidays, self::REGION, $year, Holiday::TYPE_BANK); } /** - * Tests if all other holidays in Wales are defined by the provider class - * @throws ReflectionException + * Tests if all other holidays in Wales are defined by the provider class. */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays( + [ + 'motheringSunday', + ], + self::REGION, + $this->year, + Holiday::TYPE_OTHER + ); } /** - * Initial setup of this Test Case + * @throws \ReflectionException + * @throws \Exception */ - protected function setUp(): void + public function testSources(): void { - $this->year = $this->generateRandomYear(1978); + $this->assertSources(self::REGION, 1); } } diff --git a/tests/Venezuela/BattleOfCaraboboTest.php b/tests/Venezuela/BattleOfCaraboboTest.php new file mode 100644 index 000000000..5885f39bd --- /dev/null +++ b/tests/Venezuela/BattleOfCaraboboTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Battle of Carabobo in Venezuela. + */ +class BattleOfCaraboboTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'battleOfCarabobo'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1821; + + /** + * Tests Battle of Carabobo on or after 1821. + * + * @throws \Exception + */ + public function testBattleOfCaraboboAfter1821(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-06-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Battle of Carabobo before 1821. + * + * @throws \Exception + */ + public function testBattleOfCaraboboBefore1821(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Batalla de Carabobo'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/CarnavalTest.php b/tests/Venezuela/CarnavalTest.php new file mode 100644 index 000000000..fd2e5e0d4 --- /dev/null +++ b/tests/Venezuela/CarnavalTest.php @@ -0,0 +1,129 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\Provider\ChristianHolidays; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Carnival holidays in Venezuela. + */ +class CarnavalTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + use ChristianHolidays; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1700; + + /** + * Tests Carnival Monday on or after 1700. + * + * @throws \Exception + */ + public function testCarnavalMondayAfter1700(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $easter = $this->calculateEaster($year, self::TIMEZONE); + $expected = (clone $easter)->sub(new \DateInterval('P48D')); + + $this->assertHoliday( + self::REGION, + 'carnavalMonday', + $year, + $expected + ); + } + + /** + * Tests Carnival Tuesday on or after 1700. + * + * @throws \Exception + */ + public function testCarnavalTuesdayAfter1700(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $easter = $this->calculateEaster($year, self::TIMEZONE); + $expected = (clone $easter)->sub(new \DateInterval('P47D')); + + $this->assertHoliday( + self::REGION, + 'carnavalTuesday', + $year, + $expected + ); + } + + /** + * Tests Carnival Monday before 1700. + * + * @throws \Exception + */ + public function testCarnavalMondayBefore1700(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, 'carnavalMonday', $year); + } + + /** + * Tests Carnival Tuesday before 1700. + * + * @throws \Exception + */ + public function testCarnavalTuesdayBefore1700(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, 'carnavalTuesday', $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + 'carnavalMonday', + $year, + [self::LOCALE => 'Lunes de Carnaval'] + ); + $this->assertTranslatedHolidayName( + self::REGION, + 'carnavalTuesday', + $year, + [self::LOCALE => 'Martes de Carnaval'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, 'carnavalMonday', $year, Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, 'carnavalTuesday', $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/ChristmasEveTest.php b/tests/Venezuela/ChristmasEveTest.php new file mode 100644 index 000000000..4392e4a42 --- /dev/null +++ b/tests/Venezuela/ChristmasEveTest.php @@ -0,0 +1,75 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Christmas Eve in Venezuela. + */ +class ChristmasEveTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'christmasEve'; + + /** + * Tests Christmas Eve. + * + * @throws \Exception + */ + public function testChristmasEve(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Nochebuena'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/DayOfIndigenousResistanceTest.php b/tests/Venezuela/DayOfIndigenousResistanceTest.php new file mode 100644 index 000000000..1b2e05c90 --- /dev/null +++ b/tests/Venezuela/DayOfIndigenousResistanceTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Day of Indigenous Resistance in Venezuela. + */ +class DayOfIndigenousResistanceTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'dayOfIndigenousResistance'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1921; + + /** + * Tests Day of Indigenous Resistance on or after 1921. + * + * @throws \Exception + */ + public function testDayOfIndigenousResistanceAfter1921(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-10-12", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Day of Indigenous Resistance before 1921. + * + * @throws \Exception + */ + public function testDayOfIndigenousResistanceBefore1921(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Día de la Resistencia Indígena'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/DeclarationOfIndependenceTest.php b/tests/Venezuela/DeclarationOfIndependenceTest.php new file mode 100644 index 000000000..479ce7209 --- /dev/null +++ b/tests/Venezuela/DeclarationOfIndependenceTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Declaration of Independence in Venezuela. + */ +class DeclarationOfIndependenceTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'declarationOfIndependence'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1810; + + /** + * Tests Declaration of Independence on or after 1810. + * + * @throws \Exception + */ + public function testDeclarationOfIndependenceAfter1810(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-04-19", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Declaration of Independence before 1810. + * + * @throws \Exception + */ + public function testDeclarationOfIndependenceBefore1810(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Declaración de la Independencia'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/IndependenceDayTest.php b/tests/Venezuela/IndependenceDayTest.php new file mode 100644 index 000000000..5ac2aea25 --- /dev/null +++ b/tests/Venezuela/IndependenceDayTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Independence Day in Venezuela. + */ +class IndependenceDayTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'independenceDay'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1811; + + /** + * Tests Independence Day on or after 1811. + * + * @throws \Exception + */ + public function testIndependenceDayAfter1811(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-05", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Independence Day before 1811. + * + * @throws \Exception + */ + public function testIndependenceDayBefore1811(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Día de la Independencia'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/NewYearsEveTest.php b/tests/Venezuela/NewYearsEveTest.php new file mode 100644 index 000000000..1670a9082 --- /dev/null +++ b/tests/Venezuela/NewYearsEveTest.php @@ -0,0 +1,75 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing New Year's Eve in Venezuela. + */ +class NewYearsEveTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'newYearsEve'; + + /** + * Tests New Year's Eve. + * + * @throws \Exception + */ + public function testNewYearsEve(): void + { + $year = static::generateRandomYear(); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-12-31", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Nochevieja'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/SimonBolivarBirthdayTest.php b/tests/Venezuela/SimonBolivarBirthdayTest.php new file mode 100644 index 000000000..129217560 --- /dev/null +++ b/tests/Venezuela/SimonBolivarBirthdayTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Simon Bolivar's Birthday in Venezuela. + */ +class SimonBolivarBirthdayTest extends VenezuelaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'simonBolivarBirthday'; + + /** + * The year in which the holiday was first established. + */ + public const ESTABLISHMENT_YEAR = 1783; + + /** + * Tests Simon Bolivar's Birthday on or after 1783. + * + * @throws \Exception + */ + public function testSimonBolivarBirthdayAfter1783(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime("{$year}-07-24", new \DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Tests Simon Bolivar's Birthday before 1783. + * + * @throws \Exception + */ + public function testSimonBolivarBirthdayBefore1783(): void + { + $year = static::generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1); + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $year); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $year, + [self::LOCALE => 'Natalicio del Libertador'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $year = static::generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Venezuela/VenezuelaBaseTestCase.php b/tests/Venezuela/VenezuelaBaseTestCase.php new file mode 100644 index 000000000..5d2083399 --- /dev/null +++ b/tests/Venezuela/VenezuelaBaseTestCase.php @@ -0,0 +1,40 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use PHPUnit\Framework\TestCase; +use Yasumi\tests\YasumiBase; + +/** + * Class VenezuelaBaseTestCase. + */ +abstract class VenezuelaBaseTestCase extends TestCase +{ + use YasumiBase; + + /** + * Country (name) to be tested. + */ + public const REGION = 'Venezuela'; + + /** Timezone in which this provider has holidays defined. */ + public const TIMEZONE = 'America/Caracas'; + + /** Locale that is considered common for this provider. */ + public const LOCALE = 'es_VE'; +} diff --git a/tests/Venezuela/VenezuelaTest.php b/tests/Venezuela/VenezuelaTest.php new file mode 100644 index 000000000..a8aee6127 --- /dev/null +++ b/tests/Venezuela/VenezuelaTest.php @@ -0,0 +1,106 @@ + + */ + +namespace Yasumi\tests\Venezuela; + +use Yasumi\Holiday; +use Yasumi\tests\ProviderTestCase; + +/** + * Class for testing holidays in Venezuela. + */ +class VenezuelaTest extends VenezuelaBaseTestCase implements ProviderTestCase +{ + /** + * @var int year random year number used for all tests in this Test Case + */ + protected int $year; + + /** + * Initial setup of this Test Case. + * + * @throws \Exception + */ + protected function setUp(): void + { + $this->year = static::generateRandomYear(1921); + } + + /** + * Tests if all official holidays in Venezuela are defined by the provider class. + */ + public function testOfficialHolidays(): void + { + $this->assertDefinedHolidays([ + 'newYearsDay', + 'carnavalMonday', + 'carnavalTuesday', + 'maundyThursday', + 'goodFriday', + 'declarationOfIndependence', + 'internationalWorkersDay', + 'battleOfCarabobo', + 'independenceDay', + 'simonBolivarBirthday', + 'dayOfIndigenousResistance', + 'christmasEve', + 'christmasDay', + 'newYearsEve', + ], self::REGION, $this->year, Holiday::TYPE_OFFICIAL); + } + + /** + * Tests if all observed holidays in Venezuela are defined by the provider class. + */ + public function testObservedHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + } + + /** + * Tests if all seasonal holidays in Venezuela are defined by the provider class. + */ + public function testSeasonalHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + } + + /** + * Tests if all bank holidays in Venezuela are defined by the provider class. + */ + public function testBankHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK); + } + + /** + * Tests if all other holidays in Venezuela are defined by the provider class. + */ + public function testOtherHolidays(): void + { + $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + } + + /** + * @throws \ReflectionException + * @throws \Exception + */ + public function testSources(): void + { + $this->assertSources(self::REGION, 3); + } +} diff --git a/tests/YasumiBase.php b/tests/YasumiBase.php index 8677c9116..3b04b9b5d 100644 --- a/tests/YasumiBase.php +++ b/tests/YasumiBase.php @@ -1,28 +1,23 @@ - + * @author Sacha Telgenhof */ namespace Yasumi\tests; -use DateInterval; -use DateTime; -use DateTimeInterface; -use DateTimeZone; -use Exception; -use Faker\Factory as Faker; -use InvalidArgumentException; use PHPUnit\Framework\AssertionFailedError; -use ReflectionException; -use RuntimeException; -use Yasumi\Exception\InvalidDateException; use Yasumi\Exception\UnknownLocaleException; use Yasumi\Filters\BankHolidaysFilter; use Yasumi\Filters\ObservedHolidaysFilter; @@ -30,32 +25,36 @@ use Yasumi\Filters\OtherHolidaysFilter; use Yasumi\Filters\SeasonalHolidaysFilter; use Yasumi\Holiday; +use Yasumi\SubstituteHoliday; use Yasumi\Yasumi; /** - * Trait YasumiBase. - * - * Trait containing some base function for testing Yasumi. + * Trait containing useful functions for the various unit tests. */ trait YasumiBase { + use Randomizer; + /** - * Asserts that the expected holidays are indeed a holiday for the given provider and year + * Asserts the expected holidays are a holidays for the given provider and year. * - * @param array $expectedHolidays list of all known holidays of the given provider - * @param string $provider the holiday provider (i.e. country/state) for which the holidays need to be - * tested - * @param int $year holiday calendar year - * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, - * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. + * @param array $expectedHolidays list of all known holidays of the given provider + * @param string $provider holiday provider (i.e. country/state) for which the holidays need to be + * tested. + * @param int $year holiday calendar year + * @param string $type type of holiday. Use the following constants: TYPE_OFFICIAL, + * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. * - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException */ - public function assertDefinedHolidays($expectedHolidays, $provider, $year, $type): void - { + public function assertDefinedHolidays( + array $expectedHolidays, + string $provider, + int $year, + string $type, + ): void { $holidays = Yasumi::create($provider, $year); switch ($type) { @@ -76,475 +75,252 @@ public function assertDefinedHolidays($expectedHolidays, $provider, $year, $type break; } - // Loop through all known holidays and assert they are defined by the provider class - foreach ($expectedHolidays as $holiday) { - $this->assertArrayHasKey($holiday, \iterator_to_array($holidays)); + $holidayList = iterator_to_array($holidays); + + if ([] === $expectedHolidays) { + // No holidays to assert; increment count to avoid PHPUnit "no assertions" warning. + $this->addToAssertionCount(1); + + return; } - unset($holidays); + // Loop through all known holidays and assert they are defined by the provider class. + foreach ($expectedHolidays as $holiday) { + self::assertArrayHasKey($holiday, $holidayList, sprintf('`%s` should exist for year `%u` in the `%s` holiday list for `%s`', $holiday, $year, $type, $provider)); + } } /** - * Asserts that the expected date is indeed a holiday for that given year and name + * Asserts expected date is a holiday for the given year and name. * - * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be tested - * @param string $shortName string the short name of the holiday to be checked against - * @param int $year holiday calendar year - * @param DateTime $expected the date to be checked against + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the holiday to be checked against + * @param int $year holiday calendar year + * @param \DateTime $expected date to be checked against * * @throws UnknownLocaleException - * @throws InvalidDateException - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws AssertionFailedError - * @throws ReflectionException */ - public function assertHoliday($provider, $shortName, $year, $expected): void - { + public function assertHoliday( + string $provider, + string $key, + int $year, + \DateTimeInterface $expected, + ): void { $holidays = Yasumi::create($provider, $year); - $holiday = $holidays->getHoliday($shortName); + $holiday = $holidays->getHoliday($key); - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', $provider), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); - $this->assertEquals($expected, $holiday); - $this->assertTrue($holidays->isHoliday($holiday)); - - unset($holiday, $holidays); + self::assertInstanceOf(Holiday::class, $holiday, sprintf('No instance holiday for `%s` in year `%u`', $key, $year)); + $this->assertDateTime($expected, $holiday); + self::assertTrue($holidays->isHoliday($holiday), sprintf('Holiday `%s` not recognised as holiday for year `%u`', $key, $year)); } /** - * Asserts that the given holiday for that given year does not exist. + * Asserts the expected date is a substitute holiday for that given year and name. * - * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be tested - * @param string $shortName the short name of the holiday to be checked against - * @param int $year holiday calendar year + * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the substituted holiday to be checked against + * @param int $year holiday calendar year + * @param \DateTime $expected date to be checked against * - * @throws InvalidArgumentException - * @throws RuntimeException * @throws UnknownLocaleException - * @throws InvalidDateException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws AssertionFailedError - * @throws ReflectionException */ - public function assertNotHoliday($provider, $shortName, $year): void - { + public function assertSubstituteHoliday( + string $provider, + string $key, + int $year, + \DateTimeInterface $expected, + ): void { $holidays = Yasumi::create($provider, $year); - $holiday = $holidays->getHoliday($shortName); + $holiday = $holidays->getHoliday('substituteHoliday:' . $key); - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', $provider), $holidays); - $this->assertNull($holiday); - - unset($holiday, $holidays); + self::assertInstanceOf(SubstituteHoliday::class, $holiday, sprintf('No substitute holiday for `%s` in year `%u`', $key, $year)); + $this->assertDateTime($expected, $holiday); + self::assertTrue($holidays->isHoliday($holiday)); } /** - * Asserts that the expected name is indeed provided as a translated holiday name for that given year and name + * Asserts the given substitute holiday for a given year does not exist. * - * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be tested - * @param string $shortName string the short name of the holiday to be checked against - * @param int $year holiday calendar year - * @param array $translations the translations to be checked against + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the substituted holiday to be checked against + * @param int $year holiday calendar year * - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException * @throws AssertionFailedError - * @throws ReflectionException */ - public function assertTranslatedHolidayName($provider, $shortName, $year, $translations): void - { - $holidays = Yasumi::create($provider, $year); - $holiday = $holidays->getHoliday($shortName); - - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', $provider), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); - $this->assertTrue($holidays->isHoliday($holiday)); - - if (\is_array($translations) && !empty($translations)) { - foreach ($translations as $locale => $name) { - $locales = [$locale]; - $parts = \explode('_', $locale); - while (\array_pop($parts) && $parts) { - $locales[] = \implode('_', $parts); - } - - $translation = null; - foreach ($locales as $l) { - if (isset($holiday->translations[$l])) { - $translation = $holiday->translations[$l]; - break; - } - } - - $this->assertTrue(isset($translation)); - $this->assertEquals($name, $translation); - } - } - - unset($holiday, $holidays); + public function assertNotSubstituteHoliday( + string $provider, + string $key, + int $year, + ): void { + $this->assertNotHoliday( + $provider, + 'substituteHoliday:' . $key, + $year + ); } /** - * Asserts that the expected type is indeed the associated type of the given holiday + * Asserts the given holiday for a given year does not exist. * - * @param string $provider the holiday provider (i.e. country/region) for which the holiday need to be tested - * @param string $shortName string the short name of the holiday to be checked against - * @param int $year holiday calendar year - * @param string $type the type to be checked against + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the holiday to be checked against + * @param int $year holiday calendar year * - * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AssertionFailedError + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws AssertionFailedError */ - public function assertHolidayType($provider, $shortName, $year, $type): void - { + public function assertNotHoliday( + string $provider, + string $key, + int $year, + ): void { $holidays = Yasumi::create($provider, $year); - $holiday = $holidays->getHoliday($shortName); - - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', $provider), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); - $this->assertEquals($type, $holiday->getType()); + $holiday = $holidays->getHoliday($key); - unset($holiday, $holidays); + self::assertNull($holiday, sprintf('Holiday `%s` should not exist for year `%u`', $key, $year)); } /** - * Asserts that the expected week day is indeed the week day for the given holiday and year + * Asserts the expected name is provided as a translated holiday name for that given year and name. * - * @param string $provider the holiday provider (i.e. country/state) for which the holiday need to be - * tested - * @param string $shortName string the short name of the holiday to be checked against - * @param int $year holiday calendar year - * @param string $expectedDayOfWeek the expected week day (i.e. "Saturday", "Sunday", etc.) + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the holiday to be checked against + * @param int $year holiday calendar year + * @param array $translations translations to be checked against * - * @throws AssertionFailedError - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \RuntimeException * @throws UnknownLocaleException - * @throws ReflectionException + * @throws AssertionFailedError */ - public function assertDayOfWeek($provider, $shortName, $year, $expectedDayOfWeek): void - { + public function assertTranslatedHolidayName( + string $provider, + string $key, + int $year, + array $translations, + ): void { $holidays = Yasumi::create($provider, $year); - $holiday = $holidays->getHoliday($shortName); - - $this->assertInstanceOf('Yasumi\Provider\\' . \str_replace('/', '\\', $provider), $holidays); - $this->assertInstanceOf(Holiday::class, $holiday); - $this->assertNotNull($holiday); - $this->assertTrue($holidays->isHoliday($holiday)); - $this->assertEquals($expectedDayOfWeek, $holiday->format('l')); - - unset($holiday, $holidays); - } - - /** - * Returns a list of random test dates used for assertion of holidays. - * - * @param int $month month (number) for which the test date needs to be generated - * @param int $day day (number) for which the test date needs to be generated - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) - * - * @return array list of random test dates used for assertion of holidays. - * @throws Exception - */ - public function generateRandomDates($month, $day, $timezone = null, $iterations = null, $range = null): array - { - $data = []; - $range = $range ?? 1000; - for ($y = 1; $y <= ($iterations ?? 10); $y++) { - $year = (int)Faker::create()->dateTimeBetween("-$range years", "+$range years")->format('Y'); - $data[] = [$year, new DateTime("$year-$month-$day", new DateTimeZone($timezone ?? 'UTC'))]; - } - - return $data; - } - - /** - * Returns a list of random easter test dates used for assertion of holidays. - * - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) - * - * @return array list of random easter test dates used for assertion of holidays. - * @throws Exception - */ - public function generateRandomEasterDates($timezone = null, $iterations = null, $range = null): array - { - $data = []; - $range = $range ?? 1000; - - for ($i = 1; $i <= ($iterations ?? 10); ++$i) { - $year = (int)Faker::create()->dateTimeBetween("-$range years", "+$range years")->format('Y'); - $date = $this->calculateEaster($year, $timezone ?? 'UTC'); + $holiday = $holidays->getHoliday($key); - $data[] = [$year, $date->format('Y-m-d')]; - } + self::assertInstanceOf(Holiday::class, $holiday, sprintf('No holiday instance for `%s` in year `%u`', $key, $year)); + self::assertTrue($holidays->isHoliday($holiday), sprintf('Holiday `%s` not recognized as holiday for year `%u`', $key, $year)); - return $data; - } - - /** - * Calculates the date for Easter. - * - * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated - * on a date based on a certain number of days after March 21st. - * - * This function uses the standard PHP 'easter_days' function if the calendar extension is enabled. In case the - * calendar function is not enabled, a fallback calculation has been implemented that is based on the same - * 'easter_days' c function. - * - * Note: In calendrical calculations, frequently operations called integer division are used. - * - * @param int $year the year for which Easter needs to be calculated - * @param string $timezone the timezone in which Easter is celebrated - * - * @return DateTime date of Easter - * @throws Exception - * @see easter_days - * - * @link https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/ext/calendar/easter.c - * @link http://www.gmarts.org/index.php?go=415#EasterMallen - * @link http://www.tondering.dk/claus/cal/easter.php - * - */ - protected function calculateEaster(int $year, string $timezone): DateTime - { - if (\extension_loaded('calendar')) { - $easter_days = \easter_days($year); - } else { - $golden = (($year % 19) + 1); // The Golden Number - - // The Julian calendar applies to the original method from 326AD. The Gregorian calendar was first - // introduced in October 1582 in Italy. Easter algorithms using the Gregorian calendar apply to years - // 1583 AD to 4099 (A day adjustment is required in or shortly after 4100 AD). - // After 1752, most western churches have adopted the current algorithm. - if ($year <= 1752) { - $dom = ($year + (int)($year / 4) + 5) % 7; // The 'Dominical number' - finding a Sunday - if ($dom < 0) { - $dom += 7; - } - - $pfm = (3 - (11 * $golden) - 7) % 30; // Uncorrected date of the Paschal full moon - if ($pfm < 0) { - $pfm += 30; - } - } else { - $dom = ($year + (int)($year / 4) - (int)($year / 100) + (int)($year / 400)) % 7; // The 'Dominical number' - finding a Sunday - if ($dom < 0) { - $dom += 7; - } - - $solar = (int)(($year - 1600) / 100) - (int)(($year - 1600) / 400); // The solar correction - $lunar = (int)(((int)(($year - 1400) / 100) * 8) / 25); // The lunar correction - - $pfm = (3 - (11 * $golden) + $solar - $lunar) % 30; // Uncorrected date of the Paschal full moon - if ($pfm < 0) { - $pfm += 30; - } + foreach ($translations as $locale => $name) { + $locales = [$locale]; + $parts = explode('_', $locale); + while (array_pop($parts) && $parts) { + $locales[] = implode('_', $parts); } - // Corrected date of the Paschal full moon, - days after 21st March - if ((29 === $pfm) || (28 === $pfm && $golden > 11)) { - --$pfm; - } - - $tmp = (4 - $pfm - $dom) % 7; - if ($tmp < 0) { - $tmp += 7; + $translation = null; + foreach ($locales as $l) { + if (isset($holiday->translations[$l])) { + $translation = $holiday->translations[$l]; + break; + } } - $easter_days = ($pfm + $tmp + 1); // Easter as the number of days after 21st March + self::assertTrue(isset($translation)); + self::assertEquals($name, $translation); } - - $easter = new DateTime("$year-3-21", new DateTimeZone($timezone)); - $easter->add(new DateInterval('P' . $easter_days . 'D')); - - return $easter; } /** - * Returns a list of random Easter Monday test dates used for assertion of holidays. + * Asserts the expected type is the associated type for the given holiday. * - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) + * @param string $provider holiday provider (i.e. country/region) for which the holiday need to be tested. + * @param string $key the key of the holiday to be checked against + * @param int $year holiday calendar year + * @param string $type type to be checked against * - * @return array list of random Easter Monday test dates used for assertion of holidays. - * - * @throws Exception - */ - public function generateRandomEasterMondayDates($timezone = null, $iterations = null, $range = null): array - { - $range = $range ?? 1000; - return $this->generateRandomModifiedEasterDates(static function (DateTime $date) { - $date->add(new DateInterval('P1D')); - }, $timezone ?? 'UTC', $iterations ?? 10, $range); - } - - /** - * Returns a list of random modified Easter day test dates for assertion of holidays. - * - * @param callable $cb callback(DateTime $date) to modify $date by custom rules - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) - * - * @return array list of random modified Easter day test dates for assertion of holidays. - * @throws Exception + * @throws \InvalidArgumentException + * @throws \RuntimeException + * @throws AssertionFailedError + * @throws UnknownLocaleException */ - public function generateRandomModifiedEasterDates( - callable $cb, - $timezone = null, - $iterations = null, - $range = null - ): array { - $data = []; - $range = $range ?? 1000; - for ($i = 1; $i <= ($iterations ?? 10); ++$i) { - $year = (int)Faker::create()->dateTimeBetween("-$range years", "+$range years")->format('Y'); - $date = $this->calculateEaster($year, $timezone ?? 'UTC'); - - $cb($date); - - $data[] = [$year, $date->format('Y-m-d')]; - } + public function assertHolidayType( + string $provider, + string $key, + int $year, + string $type, + ): void { + $holidays = Yasumi::create($provider, $year); + $holiday = $holidays->getHoliday($key); - return $data; + self::assertInstanceOf(Holiday::class, $holiday, sprintf('No holiday instance for `%s` in year `%u`', $key, $year)); + self::assertEquals($type, $holiday->getType(), sprintf('Expected type `%s`, got `%s` for year `%u`', $type, $holiday->getType(), $year)); } /** - * Returns a list of random Good Friday test dates used for assertion of holidays. - * - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) + * Asserts the expected week day is the week day for the given holiday and year. * - * @return array list of random Good Friday test dates used for assertion of holidays. + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param string $key key of the holiday to be checked against + * @param int $year holiday calendar year + * @param string $expectedDayOfWeek expected week day (i.e. "Saturday", "Sunday", etc.). * - * @throws Exception + * @throws AssertionFailedError + * @throws \InvalidArgumentException + * @throws \RuntimeException + * @throws UnknownLocaleException */ - public function generateRandomGoodFridayDates($timezone = null, $iterations = null, $range = null): array - { - $range = $range ?? 1000; + public function assertDayOfWeek( + string $provider, + string $key, + int $year, + string $expectedDayOfWeek, + ): void { + $holidays = Yasumi::create($provider, $year); + $holiday = $holidays->getHoliday($key); - return $this->generateRandomModifiedEasterDates(static function (DateTime $date) { - $date->sub(new DateInterval('P2D')); - }, $timezone ?? 'UTC', $iterations ?? 10, $range); + self::assertInstanceOf(Holiday::class, $holiday, sprintf('No holiday instance for key `%s` in year `%us`', $key, $year)); + self::assertTrue($holidays->isHoliday($holiday), sprintf('Holiday `%s` not recognized as holiday for year `%u`', $key, $year)); + self::assertEquals($expectedDayOfWeek, $holiday->format('l'), sprintf('Wrong day of week for `%s` in year `%u`', $key, $year)); } /** - * Returns a list of random Pentecost test dates used for assertion of holidays. + * Asserts the holiday provider has the expected sources number. * - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) + * @param string $provider holiday provider (i.e. country/state) for which the holiday need to be tested. + * @param int $expectedSourceCount expected sources number * - * @return array list of random Pentecost test dates used for assertion of holidays. - * - * @throws Exception + * @throws \Exception */ - public function generateRandomPentecostDates($timezone = null, $iterations = null, $range = null): array + public function assertSources(string $provider, int $expectedSourceCount): void { - $range = $range ?? 1000; - - return $this->generateRandomModifiedEasterDates(static function (DateTime $date) { - $date->add(new DateInterval('P49D')); - }, $timezone ?? 'UTC', $iterations ?? 10, $range); - } - - /** - * Returns a list of random test dates used for assertion of holidays. If the date falls in a weekend, random - * holiday day is moved to to Monday. - * - * @param int $month month (number) for which the test date needs to be generated - * @param int $day day (number) for which the test date needs to be generated - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) - * - * @return array list of random test dates used for assertion of holidays. - * @throws Exception - */ - public function generateRandomDatesWithHolidayMovedToMonday( - $month, - $day, - $timezone = null, - $iterations = null, - $range = null - ): array { - return $this->generateRandomDatesWithModifier($month, $day, function ($range, DateTime $date) { - if ($this->isWeekend($date)) { - $date->modify('next monday'); - } - }, $timezone ?? 'UTC', $iterations ?? 10, $range); - } - - /** - * Returns a list of random test dates used for assertion of holidays with applied callback. - * - * @param int $month month (number) for which the test date needs to be generated - * @param int $day day (number) for which the test date needs to be generated - * @param callable $callback callback(int $year, \DateTime $dateTime) to modify $dateTime by custom rules - * @param string $timezone name of the timezone for which the dates need to be generated - * @param int $iterations number of iterations (i.e. samples) that need to be generated (default: 10) - * @param int $range year range from which dates will be generated (default: 1000) - * - * @return array list of random test dates used for assertion of holidays with applied callback. - * @throws Exception - */ - public function generateRandomDatesWithModifier( - $month, - $day, - callable $callback, - $timezone = null, - $iterations, - $range - ): array { - $data = []; - - for ($i = 1; $i <= $iterations; ++$i) { - $year = $this->generateRandomYear($range); - $date = new DateTime("{$year}-{$month}-{$day}", new DateTimeZone($timezone ?? 'UTC')); - - $callback($year, $date); + $holidayProvider = Yasumi::create($provider, static::generateRandomYear()); - $data[] = [$year, $date->format('Y-m-d')]; - } - - return $data; + self::assertCount($expectedSourceCount, $holidayProvider->getSources()); } /** - * Generates a random year (number). + * Asserts that a DateTime object is canonically equal to an expected DateTime object. * - * @param int $lowerLimit the lower limit for generating a year number (default: 1000) - * @param int $upperLimit the upper limit for generating a year number (default: 9999) + * This helper method employs the 'assertEqualsWithDelta' method to allow for variations + * in precision between DateTime objects. The default object comparator will report some + * DateTime object pairs as not equal even if they are canonically equal because the + * object comparator looks at exact object field values. * - * @return int a year number - */ - public function generateRandomYear($lowerLimit = null, $upperLimit = null): int - { - return (int)Faker::create()->numberBetween($lowerLimit ?? 1000, $upperLimit ?? 9999); - } - - /** - * Checks if given $dateTime is a weekend. + * Variations have been seen between different versions of PHP and OS distributions. + * Likely this is caused by different editions of the tz database used in those releases. * - * @param DateTimeInterface $dateTime date for which weekend will be checked. - * @param array $weekendDays weekend days. Saturday and Sunday are used by default. + * The chosen delta is somewhat arbitrary and seems to solve the experienced issues. * - * @return bool true if $dateTime is a weekend, false otherwise + * @throws \ExpectationFailedException */ - public function isWeekend(DateTimeInterface $dateTime, array $weekendDays = [0, 6]): bool + public function assertDateTime(\DateTimeInterface $expected, \DateTimeInterface $actual): void { - return \in_array((int)$dateTime->format('w'), $weekendDays, true); + self::assertEqualsWithDelta($expected, $actual, 1800); } }