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 index 48ad3efde..9f11f3917 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest] - php-versions: ["8.0", "8.1", "8.2", "8.3"] + php-versions: ["8.0", "8.1", "8.2", "8.3", "8.4"] steps: - name: Set git to use LF @@ -21,7 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,7 +35,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 93f0cd096..6bb1de147 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -15,7 +15,7 @@ jobs: steps: - name: "Prune stale issues and pull requests" - uses: "actions/stale@v3.0.14" + uses: "actions/stale@v9.0.0" with: repo-token: "${{ secrets.GITHUB_TOKEN }}" days-before-close: "${{ env.DAYS_BEFORE_CLOSE }}" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 96b1f49e8..849895b78 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest] - php-versions: ["8.0", "8.1", "8.2", "8.3"] + php-versions: ["8.0", "8.1", "8.2", "8.3", "8.4"] steps: - name: Set git to use LF @@ -21,7 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,7 +35,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 1cec88931..c0cd0b684 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest] - php-versions: ["8.0", "8.1", "8.2", "8.3"] + php-versions: ["8.0", "8.1", "8.2", "8.3", "8.4"] steps: - name: Set git to use LF @@ -21,7 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,7 +35,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.gitignore b/.gitignore index 00cc7cd98..10ea067ab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .idea/ .php-cs-fixer.cache .php_cs.cache +.phpactor.json .phpunit.result.cache bin/_* composer.lock diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..f7cee6dd0 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,121 @@ +# 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] + +# changelog header +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 +""" + +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version -%} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else -%} + ## [Unreleased] +{% endif -%} + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}({{ commit.scope | upper_first }}) {% endif%}{{ commit.message | split(pat="\n") | first | split(pat=": ") | last | trim | upper_first }}\ + {% endfor %} +{% endfor %} + +{%- 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 +""" + +# template for the changelog footer +footer = """ +{% for release in releases -%} + {% if release.version -%} + {% if release.previous.version -%} + [{{ release.version | trim_start_matches(pat="v") }}]: \ + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..{{ release.version }} + {% endif -%} + {% else -%} + [unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..HEAD + {% endif -%} +{% endfor %} +""" + +# remove the leading and trailing whitespace from the templates +trim = true + +[git] + +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true + +# filter out the commits that are not conventional +filter_unconventional = true + +# process each line of a commit as an individual commit +split_commits = false + +# preprocessors for manipulating the commit messages before parsing/grouping them +commit_preprocessors = [ + { pattern = "\\(#([0-9]+)\\)", replace = "([#${1}](https://github.com/azuyalabs/yasumi/issues/${1}))"} +] + +# regex for parsing and grouping commits +commit_parsers = [ + { 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" }, + + # skip merge commits + { message = "^[Mm]erge", skip = true }, +] + +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false + +# filter out the commits that are not matched by commit parsers +filter_commits = true + +# regex for matching git tags +tag_pattern = "[0-9].*" + +# regex for skipping tags +skip_tags = "beta|alpha" + +# regex for ignoring tags +ignore_tags = "" + +# sort the tags topologically +topo_order = true + +# sort the commits inside sections by oldest/newest order +sort_commits = "newest" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fcf8aea40..62403f3bd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,6 +18,10 @@ verbose="true" > + + + + ./src/Yasumi diff --git a/src/Yasumi/Filters/BetweenFilter.php b/src/Yasumi/Filters/BetweenFilter.php index 48e9ba949..e2d9431bb 100644 --- a/src/Yasumi/Filters/BetweenFilter.php +++ b/src/Yasumi/Filters/BetweenFilter.php @@ -50,7 +50,7 @@ public function __construct( \Iterator $iterator, \DateTimeInterface $startDate, \DateTimeInterface $endDate, - private bool $equal = true + private bool $equal = true, ) { parent::__construct($iterator); $this->startDate = $startDate->format(self::DATE_FORMAT); diff --git a/src/Yasumi/Filters/OnFilter.php b/src/Yasumi/Filters/OnFilter.php index 6bdc258fc..3d8d182b7 100644 --- a/src/Yasumi/Filters/OnFilter.php +++ b/src/Yasumi/Filters/OnFilter.php @@ -41,7 +41,7 @@ class OnFilter extends AbstractFilter */ public function __construct( \Iterator $iterator, - \DateTimeInterface $date + \DateTimeInterface $date, ) { parent::__construct($iterator); $this->date = $date->format(self::DATE_FORMAT); diff --git a/src/Yasumi/Holiday.php b/src/Yasumi/Holiday.php index 622cd82f5..a6f99c005 100644 --- a/src/Yasumi/Holiday.php +++ b/src/Yasumi/Holiday.php @@ -99,7 +99,7 @@ public function __construct( public array $translations, \DateTimeInterface $date, string $displayLocale = self::DEFAULT_LOCALE, - protected string $type = self::TYPE_OFFICIAL + protected string $type = self::TYPE_OFFICIAL, ) { // Validate if key is not empty if ('' === $key) { diff --git a/src/Yasumi/Provider/AbstractProvider.php b/src/Yasumi/Provider/AbstractProvider.php index aec92c9fd..35cc36b47 100644 --- a/src/Yasumi/Provider/AbstractProvider.php +++ b/src/Yasumi/Provider/AbstractProvider.php @@ -97,7 +97,7 @@ abstract class AbstractProvider implements \Countable, ProviderInterface, \Itera public function __construct( int $year, ?string $locale = null, - private ?TranslationsInterface $globalTranslations = null + private ?TranslationsInterface $globalTranslations = null, ) { $this->clearHolidays(); @@ -217,7 +217,7 @@ public function previous(string $key): ?Holiday public function between( \DateTimeInterface $startDate, \DateTimeInterface $endDate, - ?bool $equals = null + ?bool $equals = null, ): BetweenFilter { if ($startDate > $endDate) { throw new \InvalidArgumentException('Start date must be a date before the end date.'); diff --git a/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php index e14dabe78..a4956abfd 100644 --- a/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php +++ b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php @@ -75,7 +75,7 @@ protected function easterSunday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { return new Holiday( 'easter', @@ -107,7 +107,7 @@ protected function easterSaturday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Australia/NewSouthWales.php b/src/Yasumi/Provider/Australia/NewSouthWales.php index eb72ded0a..9e9490b88 100644 --- a/src/Yasumi/Provider/Australia/NewSouthWales.php +++ b/src/Yasumi/Provider/Australia/NewSouthWales.php @@ -74,7 +74,7 @@ protected function easterSaturday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Australia/NorthernTerritory.php b/src/Yasumi/Provider/Australia/NorthernTerritory.php index b9c88d4c0..6e01ff139 100644 --- a/src/Yasumi/Provider/Australia/NorthernTerritory.php +++ b/src/Yasumi/Provider/Australia/NorthernTerritory.php @@ -73,7 +73,7 @@ protected function easterSaturday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Australia/SouthAustralia.php b/src/Yasumi/Provider/Australia/SouthAustralia.php index d27e69f33..11266ca00 100644 --- a/src/Yasumi/Provider/Australia/SouthAustralia.php +++ b/src/Yasumi/Provider/Australia/SouthAustralia.php @@ -81,7 +81,7 @@ protected function easterSaturday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Australia/Victoria.php b/src/Yasumi/Provider/Australia/Victoria.php index 1757a0a85..4c52e627c 100644 --- a/src/Yasumi/Provider/Australia/Victoria.php +++ b/src/Yasumi/Provider/Australia/Victoria.php @@ -75,7 +75,7 @@ protected function easterSunday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { return new Holiday( 'easter', @@ -107,7 +107,7 @@ protected function easterSaturday( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): Holiday { $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Canada/Quebec.php b/src/Yasumi/Provider/Canada/Quebec.php index 82fa8ef52..76123c05e 100644 --- a/src/Yasumi/Provider/Canada/Quebec.php +++ b/src/Yasumi/Provider/Canada/Quebec.php @@ -79,7 +79,7 @@ protected function saintJeanBaptisteDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'saintJeanBaptisteDay', diff --git a/src/Yasumi/Provider/ChristianHolidays.php b/src/Yasumi/Provider/ChristianHolidays.php index bf982546c..a9ef033c3 100644 --- a/src/Yasumi/Provider/ChristianHolidays.php +++ b/src/Yasumi/Provider/ChristianHolidays.php @@ -50,7 +50,7 @@ protected function corpusChristi( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OTHER + string $type = Holiday::TYPE_OTHER, ): Holiday { return new Holiday( 'corpusChristi', @@ -85,7 +85,7 @@ protected function allSaintsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('allSaintsDay', [], new \DateTime("{$year}-11-1", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -113,7 +113,7 @@ protected function assumptionOfMary( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'assumptionOfMary', @@ -145,7 +145,7 @@ protected function goodFriday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { $holiday = 'goodFriday'; $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P2D')); @@ -182,7 +182,7 @@ protected function epiphany( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('epiphany', [], new \DateTime("{$year}-1-6", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -212,7 +212,7 @@ protected function stJosephsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('stJosephsDay', [], new \DateTime("{$year}-3-19", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -241,7 +241,7 @@ protected function stGeorgesDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('stGeorgesDay', [], new \DateTime("{$year}-4-23", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -301,7 +301,7 @@ protected function reformationDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'reformationDay', @@ -412,7 +412,7 @@ protected function easter( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('easter', [], $this->calculateEaster($year, $timezone), $locale, $type); } @@ -437,7 +437,7 @@ protected function pentecost( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'pentecost', @@ -471,7 +471,7 @@ protected function easterMonday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'easterMonday', @@ -505,7 +505,7 @@ protected function ascensionDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'ascensionDay', @@ -536,7 +536,7 @@ protected function pentecostMonday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'pentecostMonday', @@ -571,7 +571,7 @@ protected function christmasEve( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OBSERVANCE + string $type = Holiday::TYPE_OBSERVANCE, ): Holiday { return new Holiday( 'christmasEve', @@ -603,7 +603,7 @@ protected function christmasDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'christmasDay', @@ -635,7 +635,7 @@ protected function secondChristmasDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'secondChristmasDay', @@ -669,7 +669,7 @@ protected function ashWednesday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { $holiday = 'ashWednesday'; $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P46D')); @@ -705,7 +705,7 @@ protected function immaculateConception( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'immaculateConception', @@ -741,7 +741,7 @@ protected function stStephensDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'stStephensDay', @@ -776,7 +776,7 @@ protected function maundyThursday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { $holiday = 'maundyThursday'; $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P3D')); @@ -813,7 +813,7 @@ 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", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -843,7 +843,7 @@ protected function annunciation( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'annunciation', diff --git a/src/Yasumi/Provider/CommonHolidays.php b/src/Yasumi/Provider/CommonHolidays.php index 762e84897..1914c4a65 100644 --- a/src/Yasumi/Provider/CommonHolidays.php +++ b/src/Yasumi/Provider/CommonHolidays.php @@ -53,7 +53,7 @@ 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", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -83,7 +83,7 @@ protected function internationalWorkersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'internationalWorkersDay', @@ -119,7 +119,7 @@ protected function stMartinsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'stMartinsDay', @@ -151,7 +151,7 @@ protected function internationalWomensDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'internationalWomensDay', @@ -186,7 +186,7 @@ protected function newYearsEve( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday('newYearsEve', [], new \DateTime("{$year}-12-31", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type); } @@ -216,7 +216,7 @@ protected function valentinesDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'valentinesDay', @@ -250,7 +250,7 @@ protected function worldAnimalDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'worldAnimalDay', @@ -285,7 +285,7 @@ protected function fathersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'fathersDay', @@ -320,7 +320,7 @@ protected function mothersDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'mothersDay', @@ -355,7 +355,7 @@ protected function victoryInEuropeDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'victoryInEuropeDay', @@ -392,7 +392,7 @@ protected function armisticeDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'armisticeDay', @@ -420,7 +420,7 @@ protected function summerTime( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): ?Holiday { $date = $this->calculateSummerWinterTime($year, $timezone, true); @@ -454,7 +454,7 @@ protected function winterTime( int $year, string $timezone, string $locale, - ?string $type = null + ?string $type = null, ): ?Holiday { $date = $this->calculateSummerWinterTime($year, $timezone, false); @@ -496,7 +496,7 @@ protected function winterTime( private function calculateSummerWinterTime( int $year, string $timezone, - bool $summer + bool $summer, ): ?\DateTimeImmutable { $zone = DateTimeZoneFactory::getDateTimeZone($timezone); diff --git a/src/Yasumi/Provider/Germany.php b/src/Yasumi/Provider/Germany.php index a2b3a7aae..2fb294a58 100644 --- a/src/Yasumi/Provider/Germany.php +++ b/src/Yasumi/Provider/Germany.php @@ -55,7 +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)); + $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)); diff --git a/src/Yasumi/Provider/Germany/Bavaria.php b/src/Yasumi/Provider/Germany/Bavaria.php index 210ce52d1..aaea61e20 100644 --- a/src/Yasumi/Provider/Germany/Bavaria.php +++ b/src/Yasumi/Provider/Germany/Bavaria.php @@ -50,5 +50,6 @@ public function initialize(): void $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 index 033a7e001..04e85d1af 100644 --- a/src/Yasumi/Provider/Germany/Berlin.php +++ b/src/Yasumi/Provider/Germany/Berlin.php @@ -55,8 +55,8 @@ public function initialize(): void $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); } - if (2020 === $this->year) { - $this->addHoliday($this->dayOfLiberation($this->timezone, $this->locale)); + if (2020 === $this->year || 2025 === $this->year) { + $this->addHoliday($this->dayOfLiberation($this->year, $this->timezone, $this->locale)); } } @@ -68,6 +68,7 @@ public function initialize(): void * * @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, @@ -78,14 +79,15 @@ public function initialize(): void * @throws \Exception */ protected function dayOfLiberation( + int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'dayOfLiberation', [], - new \DateTime('2020-05-08', DateTimeZoneFactory::getDateTimeZone($timezone)), + new \DateTime("{$year}-05-08", DateTimeZoneFactory::getDateTimeZone($timezone)), $locale, $type ); diff --git a/src/Yasumi/Provider/Iran.php b/src/Yasumi/Provider/Iran.php new file mode 100644 index 000000000..8ead12ac2 --- /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/Slovakia.php b/src/Yasumi/Provider/Slovakia.php index 603d6eda1..f6b0474d0 100644 --- a/src/Yasumi/Provider/Slovakia.php +++ b/src/Yasumi/Provider/Slovakia.php @@ -86,10 +86,12 @@ public function initialize(): void $this->calculateSaintsCyrilAndMethodiusDay(); // 29.8. $this->calculateSlovakNationalUprisingDay(); - // 1.9. + // 1.9.(<2024) $this->calculateSlovakConstitutionDay(); // 15.9. $this->calculateOurLadyOfSorrowsDay(); + // 30.10.2018 + $this->calculateDeclarationOfTheSlovakNation(); // 1.11. $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_BANK)); // 17.11. @@ -114,6 +116,31 @@ public function getSources(): array ]; } + /** + * 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. * @@ -189,6 +216,8 @@ protected function calculateSlovakNationalUprisingDay(): void * 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 \InvalidArgumentException * @throws UnknownLocaleException @@ -196,16 +225,18 @@ protected function calculateSlovakNationalUprisingDay(): 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', DateTimeZoneFactory::getDateTimeZone($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 + )); + } } /** diff --git a/src/Yasumi/Provider/SouthKorea.php b/src/Yasumi/Provider/SouthKorea.php index c32ac9084..2947d5067 100644 --- a/src/Yasumi/Provider/SouthKorea.php +++ b/src/Yasumi/Provider/SouthKorea.php @@ -250,7 +250,7 @@ protected function dayAfterNewYearsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'dayAfterNewYearsDay', @@ -269,7 +269,7 @@ protected function twoDaysLaterNewYearsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'twoDaysLaterNewYearsDay', @@ -292,7 +292,7 @@ protected function seollal( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { return null; @@ -321,7 +321,7 @@ protected function dayBeforeSeollal( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { return null; @@ -350,7 +350,7 @@ protected function dayAfterSeollal( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['seollal'][$year])) { return null; @@ -377,7 +377,7 @@ protected function independenceMovementDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'independenceMovementDay', @@ -398,7 +398,7 @@ protected function arborDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { $datetime = 1960 === $year ? "{$year}-3-21" : "{$year}-4-5"; @@ -421,7 +421,7 @@ protected function buddhasBirthday( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['buddhasBirthday'][$year])) { return null; @@ -448,7 +448,7 @@ protected function childrensDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'childrensDay', @@ -469,7 +469,7 @@ protected function memorialDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'memorialDay', @@ -493,7 +493,7 @@ protected function constitutionDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'constitutionDay', @@ -514,7 +514,7 @@ protected function liberationDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'liberationDay', @@ -538,7 +538,7 @@ protected function chuseok( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { return null; @@ -568,7 +568,7 @@ protected function dayBeforeChuseok( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { return null; @@ -598,7 +598,7 @@ protected function dayAfterChuseok( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): ?Holiday { if (! isset(self::LUNAR_HOLIDAY['chuseok'][$year])) { return null; @@ -628,7 +628,7 @@ protected function armedForcesDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'armedForcesDay', @@ -649,7 +649,7 @@ protected function nationalFoundationDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'nationalFoundationDay', @@ -672,7 +672,7 @@ protected function hangulDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'hangulDay', @@ -695,7 +695,7 @@ protected function unitedNationsDay( int $year, string $timezone, string $locale, - string $type = Holiday::TYPE_OFFICIAL + string $type = Holiday::TYPE_OFFICIAL, ): Holiday { return new Holiday( 'unitedNationsDay', diff --git a/src/Yasumi/ProviderInterface.php b/src/Yasumi/ProviderInterface.php index 1e6278021..7e5121a47 100644 --- a/src/Yasumi/ProviderInterface.php +++ b/src/Yasumi/ProviderInterface.php @@ -209,7 +209,7 @@ public function previous(string $key): ?Holiday; public function between( \DateTimeInterface $startDate, \DateTimeInterface $endDate, - ?bool $equals = null + ?bool $equals = null, ): BetweenFilter; /** diff --git a/src/Yasumi/SubstituteHoliday.php b/src/Yasumi/SubstituteHoliday.php index eccec5939..97c755be7 100644 --- a/src/Yasumi/SubstituteHoliday.php +++ b/src/Yasumi/SubstituteHoliday.php @@ -66,7 +66,7 @@ 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; diff --git a/src/Yasumi/Yasumi.php b/src/Yasumi/Yasumi.php index e9238c973..870f99873 100644 --- a/src/Yasumi/Yasumi.php +++ b/src/Yasumi/Yasumi.php @@ -73,7 +73,7 @@ class Yasumi public static function nextWorkingDay( string $class, \DateTimeInterface $startDate, - int $workingDays = 1 + int $workingDays = 1, ): \DateTimeInterface { $date = $startDate instanceof \DateTime ? \DateTimeImmutable::createFromMutable($startDate) : $startDate; $provider = null; @@ -186,7 +186,7 @@ public static function getAvailableLocales(): array public static function createByISO3166_2( string $isoCode, int $year = self::YEAR_LOWER_BOUND, - string $locale = self::DEFAULT_LOCALE + string $locale = self::DEFAULT_LOCALE, ): ProviderInterface { $availableProviders = self::getProviders(); @@ -277,7 +277,7 @@ public static function getProviders(): array public static function prevWorkingDay( string $class, \DateTimeInterface $startDate, - int $workingDays = 1 + int $workingDays = 1, ): \DateTimeInterface { $date = $startDate instanceof \DateTime ? \DateTimeImmutable::createFromMutable($startDate) : $startDate; $provider = null; diff --git a/tests/Germany/Bavaria/AssumptionOfMaryTest.php b/tests/Germany/Bavaria/AssumptionOfMaryTest.php new file mode 100644 index 000000000..5bf174ccb --- /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. + * + * @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 + */ + 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 function HolidayDataProvider(): array + { + return $this->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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OTHER); + } +} diff --git a/tests/Germany/Berlin/DayOfLiberation2020Test.php b/tests/Germany/Berlin/DayOfLiberationTest.php similarity index 69% rename from tests/Germany/Berlin/DayOfLiberation2020Test.php rename to tests/Germany/Berlin/DayOfLiberationTest.php index 835beef9a..c1c94d377 100644 --- a/tests/Germany/Berlin/DayOfLiberation2020Test.php +++ b/tests/Germany/Berlin/DayOfLiberationTest.php @@ -21,9 +21,9 @@ use Yasumi\tests\HolidayTestCase; /** - * Class for testing Day of Liberation 2020 in Berlin (Germany). + * Class for testing Day of Liberation in Berlin (Germany). */ -class DayOfLiberation2020Test extends BerlinBaseTestCase implements HolidayTestCase +class DayOfLiberationTest extends BerlinBaseTestCase implements HolidayTestCase { /** * The name of the holiday to be tested. @@ -31,9 +31,9 @@ class DayOfLiberation2020Test extends BerlinBaseTestCase implements HolidayTestC public const HOLIDAY = 'dayOfLiberation'; /** - * The year in which the holiday takes place. + * The years in which the holiday takes place. */ - public const YEAR = 2020; + public static array $years = [2020, 2025]; /** * Test the holiday defined in this test. @@ -42,12 +42,14 @@ class DayOfLiberation2020Test extends BerlinBaseTestCase implements HolidayTestC */ public function testHolidayInYear(): void { - $this->assertHoliday( - self::REGION, - self::HOLIDAY, - self::YEAR, - new \DateTime(self::YEAR . '-05-08', new \DateTimeZone(self::TIMEZONE)) - ); + foreach (self::$years as $year) { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + $year, + new \DateTime($year . '-05-08', new \DateTimeZone(self::TIMEZONE)) + ); + } } /** @@ -57,10 +59,12 @@ public function testHolidayInYear(): void */ public function testHolidayBeforeYear(): void { + reset(self::$years); + $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(1000, self::YEAR - 1) + $this->generateRandomYear(1000, current(self::$years) - 1) ); } @@ -71,10 +75,12 @@ public function testHolidayBeforeYear(): void */ public function testHolidayAfterYear(): void { + end(self::$years); + $this->assertNotHoliday( self::REGION, self::HOLIDAY, - $this->generateRandomYear(self::YEAR + 1) + $this->generateRandomYear(current(self::$years) + 1) ); } @@ -83,10 +89,12 @@ public function testHolidayAfterYear(): void */ public function testTranslation(): void { + reset(self::$years); + $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - self::YEAR, + current(self::$years), [self::LOCALE => 'Tag der Befreiung'] ); } @@ -96,10 +104,12 @@ public function testTranslation(): void */ public function testHolidayType(): void { + reset(self::$years); + $this->assertHolidayType( self::REGION, self::HOLIDAY, - self::YEAR, + current(self::$years), Holiday::TYPE_OFFICIAL ); } diff --git a/tests/Germany/GermanyTest.php b/tests/Germany/GermanyTest.php index 2577a4780..fb9a939c8 100644 --- a/tests/Germany/GermanyTest.php +++ b/tests/Germany/GermanyTest.php @@ -87,7 +87,10 @@ public function testBankHolidays(): void */ public function testOtherHolidays(): void { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER); + $this->assertDefinedHolidays([ + 'newYearsEve', + 'pentecost', + ], self::REGION, $this->year, Holiday::TYPE_OTHER); } /** diff --git a/tests/Germany/PentecostTest.php b/tests/Germany/PentecostTest.php index 6b415e8c6..8277dd7b7 100644 --- a/tests/Germany/PentecostTest.php +++ b/tests/Germany/PentecostTest.php @@ -73,6 +73,6 @@ public function testTranslation(): void */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER); } } diff --git a/tests/Iran/AnniversaryOfIslamicRevolutionTest.php b/tests/Iran/AnniversaryOfIslamicRevolutionTest.php new file mode 100644 index 000000000..0734ff3ef --- /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, + $this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testAnniversaryOfIslamicRevolutionAfterEstablishment(): void + { + $year = $this->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, + $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'انقلاب اسلامی پنجاه و هفت', + 'en' => 'Enqelab e Eslami', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->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..9e5229172 --- /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, + $this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testDeathOfKhomeiniAfterEstablishment(): void + { + $year = $this->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, + $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'مرگ خمینی', + 'en' => 'Marg e Khomeini', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->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..b2afb67ba --- /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..6c6f0b8fe --- /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 = $this->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..1aee7ee8b --- /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, + $this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testIslamicRepublicDayBeforeEquinoxYear(): void + { + $year = $this->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 = $this->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 = $this->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, + $this->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, $this->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..94f34bb07 --- /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, + $this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testNationalizationOfTheIranianOilIndustryAfterEstablishment(): void + { + $year = $this->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, + $this->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, $this->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..31926b82e --- /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 = $this->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, + $this->generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz2Test.php b/tests/Iran/Nowruz2Test.php new file mode 100644 index 000000000..e1487c75f --- /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 = $this->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, + $this->generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz3Test.php b/tests/Iran/Nowruz3Test.php new file mode 100644 index 000000000..51df83842 --- /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 = $this->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, + $this->generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/Nowruz4Test.php b/tests/Iran/Nowruz4Test.php new file mode 100644 index 000000000..9b27e6741 --- /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 = $this->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, + $this->generateRandomYear(), + [ + self::LOCALE => 'نوروز', + 'en' => 'Nowruz', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Iran/RevoltOfKhordad15Test.php b/tests/Iran/RevoltOfKhordad15Test.php new file mode 100644 index 000000000..7d3b7b07f --- /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, + $this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * @throws \Exception + */ + public function testRevoltOfKhordad15AfterEstablishment(): void + { + $year = $this->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, + $this->generateRandomYear(self::ESTABLISHMENT_YEAR), + [ + self::LOCALE => 'قیام ۱۵ خرداد', + 'en' => 'Qiam e Panzdah e Khordad', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->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..84209f767 --- /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 = $this->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, + $this->generateRandomYear(), + [ + self::LOCALE => 'سیزده بدر', + 'en' => 'Sizdah be dar', + ] + ); + } + + /** + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Portugal/PortugueseRepublicDayTest.php b/tests/Portugal/PortugueseRepublicDayTest.php index c9088055c..ee52961a3 100644 --- a/tests/Portugal/PortugueseRepublicDayTest.php +++ b/tests/Portugal/PortugueseRepublicDayTest.php @@ -138,7 +138,7 @@ private function randomYearsBeforeEstablishment(): \Generator */ private function randomYearsOnAfterEstablishment(): \Generator { - yield $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + yield $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::HOLIDAY_YEAR_SUSPENDED - 1); yield self::ESTABLISHMENT_YEAR; } diff --git a/tests/Randomizer.php b/tests/Randomizer.php index d851fe42e..8bdfa5b7a 100644 --- a/tests/Randomizer.php +++ b/tests/Randomizer.php @@ -42,7 +42,7 @@ public function generateRandomDates( int $day, ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $data = []; $range ??= 1000; @@ -68,7 +68,7 @@ public function generateRandomDates( public function generateRandomEasterDates( ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $data = []; $range ??= 1000; @@ -97,7 +97,7 @@ public function generateRandomEasterDates( public function generateRandomEasterMondayDates( ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $range ??= 1000; @@ -122,7 +122,7 @@ public function generateRandomModifiedEasterDates( callable $cb, ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $data = []; $range ??= 1000; @@ -152,7 +152,7 @@ public function generateRandomModifiedEasterDates( public function generateRandomGoodFridayDates( ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $range ??= 1000; @@ -175,7 +175,7 @@ public function generateRandomGoodFridayDates( public function generateRandomPentecostDates( ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { $range ??= 1000; @@ -203,7 +203,7 @@ public function generateRandomDatesWithHolidayMovedToMonday( int $day, ?string $timezone = null, ?int $iterations = null, - ?int $range = null + ?int $range = null, ): array { return $this->generateRandomDatesWithModifier($month, $day, function ($range, \DateTime $date): void { if ($this->isWeekend($date)) { @@ -232,7 +232,7 @@ public function generateRandomDatesWithModifier( callable $callback, int $iterations, int $range, - ?string $timezone = null + ?string $timezone = null, ): array { $data = []; @@ -260,7 +260,7 @@ public function generateRandomDatesWithModifier( */ public function generateRandomYear( ?int $lowerLimit = null, - ?int $upperLimit = null + ?int $upperLimit = null, ): int { return self::numberBetween($lowerLimit ?? 1000, $upperLimit ?? 9999); } @@ -275,7 +275,7 @@ public function generateRandomYear( */ public function isWeekend( \DateTimeInterface $dateTime, - array $weekendDays = [0, 6] + array $weekendDays = [0, 6], ): bool { return \in_array((int) $dateTime->format('w'), $weekendDays, true); } diff --git a/tests/Slovakia/DeclarationOfTheSlovakNationTest.php b/tests/Slovakia/DeclarationOfTheSlovakNationTest.php new file mode 100644 index 000000000..bfb397fc1 --- /dev/null +++ b/tests/Slovakia/DeclarationOfTheSlovakNationTest.php @@ -0,0 +1,88 @@ + + */ + +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. + * + * @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 + */ + 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 function HolidayDataProvider(): array + { + return $this->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/SlovakConstitutionDayTest.php b/tests/Slovakia/SlovakConstitutionDayTest.php index 73a6749aa..5b0f68fa2 100644 --- a/tests/Slovakia/SlovakConstitutionDayTest.php +++ b/tests/Slovakia/SlovakConstitutionDayTest.php @@ -42,7 +42,11 @@ class SlovakConstitutionDayTest extends SlovakiaBaseTestCase implements HolidayT */ 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); + } } /** @@ -67,7 +71,7 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( self::REGION, self::HOLIDAY, - $this->generateRandomYear(), + $this->generateRandomYear(null, 2013), [self::LOCALE => 'Deň Ústavy Slovenskej republiky'] ); } @@ -79,6 +83,6 @@ public function testTranslation(): void */ public function testHolidayType(): void { - $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(null, 2013), Holiday::TYPE_OFFICIAL); } } diff --git a/tests/Slovakia/SlovakiaTest.php b/tests/Slovakia/SlovakiaTest.php index 26b4259eb..2638a42e4 100644 --- a/tests/Slovakia/SlovakiaTest.php +++ b/tests/Slovakia/SlovakiaTest.php @@ -50,11 +50,18 @@ public function testOfficialHolidays(): void { $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); } /** diff --git a/tests/Ukraine/SubstitutedHolidayTest.php b/tests/Ukraine/SubstitutedHolidayTest.php index 176fa7870..84573ce32 100644 --- a/tests/Ukraine/SubstitutedHolidayTest.php +++ b/tests/Ukraine/SubstitutedHolidayTest.php @@ -64,7 +64,7 @@ public function assertHolidayWithSubstitution( string $key, int $year, \DateTimeInterface $expectedOfficial, - ?\DateTimeInterface $expectedSubstitution = null + ?\DateTimeInterface $expectedSubstitution = null, ): void { $holidays = Yasumi::create($provider, $year); diff --git a/tests/YasumiBase.php b/tests/YasumiBase.php index 2f83f16b2..cfbe336bc 100644 --- a/tests/YasumiBase.php +++ b/tests/YasumiBase.php @@ -53,7 +53,7 @@ public function assertDefinedHolidays( array $expectedHolidays, string $provider, int $year, - string $type + string $type, ): void { $holidays = Yasumi::create($provider, $year); @@ -98,7 +98,7 @@ public function assertHoliday( string $provider, string $key, int $year, - \DateTimeInterface $expected + \DateTimeInterface $expected, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday($key); @@ -125,7 +125,7 @@ public function assertSubstituteHoliday( string $provider, string $key, int $year, - \DateTimeInterface $expected + \DateTimeInterface $expected, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday('substituteHoliday:' . $key); @@ -150,7 +150,7 @@ public function assertSubstituteHoliday( public function assertNotSubstituteHoliday( string $provider, string $key, - int $year + int $year, ): void { $this->assertNotHoliday( $provider, @@ -174,7 +174,7 @@ public function assertNotSubstituteHoliday( public function assertNotHoliday( string $provider, string $key, - int $year + int $year, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday($key); @@ -199,7 +199,7 @@ public function assertTranslatedHolidayName( string $provider, string $key, int $year, - array $translations + array $translations, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday($key); @@ -244,7 +244,7 @@ public function assertHolidayType( string $provider, string $key, int $year, - string $type + string $type, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday($key); @@ -270,7 +270,7 @@ public function assertDayOfWeek( string $provider, string $key, int $year, - string $expectedDayOfWeek + string $expectedDayOfWeek, ): void { $holidays = Yasumi::create($provider, $year); $holiday = $holidays->getHoliday($key);