From b988c3c9caf22d4f883952fc4a6bff9a2fee91c3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Tue, 1 Oct 2024 09:55:24 +0200 Subject: [PATCH] fix ISO code for Denmark --- phpstan-baseline.neon | 30 ++++++++++++ src/Countries/Country.php | 4 ++ src/Countries/Denmark.php | 2 +- ...nish_holidays_with_the_wrong_ISO_code.snap | 46 +++++++++++++++++++ tests/Countries/DenmarkTest.php | 12 +++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays_with_the_wrong_ISO_code.snap diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bf7869c43..376e27bdf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -40,6 +40,36 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:arafat\\.$#" + count: 1 + path: src/Countries/Malaysia.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:ashura\\.$#" + count: 1 + path: src/Countries/Malaysia.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:eidAlAdha\\.$#" + count: 1 + path: src/Countries/Malaysia.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:eidAlFitr\\.$#" + count: 1 + path: src/Countries/Malaysia.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:islamicNewYear\\.$#" + count: 1 + path: src/Countries/Malaysia.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:prophetMuhammadBirthday\\.$#" + count: 1 + path: src/Countries/Malaysia.php + - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Morocco\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" count: 1 diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 6d531e697..009fab835 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -115,6 +115,10 @@ public static function find(string $countryCode): ?Country { $countryCode = strtolower($countryCode); + if ($countryCode === 'da') { + $countryCode = 'dk'; // @todo remove with new major and change the ISO code for Denmark + } + foreach (glob(__DIR__.'/../Countries/*.php') as $filename) { if (basename($filename) === 'Country.php') { continue; diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 3d4e091eb..df689e0a6 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -8,7 +8,7 @@ class Denmark extends Country { public function countryCode(): string { - return 'da'; + return 'dk'; } protected function allHolidays(int $year): array diff --git a/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays_with_the_wrong_ISO_code.snap b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays_with_the_wrong_ISO_code.snap new file mode 100644 index 000000000..705cd12ee --- /dev/null +++ b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays_with_the_wrong_ISO_code.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Nyt\u00e5r", + "date": "2024-01-01" + }, + { + "name": "Sk\u00e6rtorsdag", + "date": "2024-03-28" + }, + { + "name": "Langfredag", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skedag", + "date": "2024-03-31" + }, + { + "name": "Anden P\u00e5skedag", + "date": "2024-04-01" + }, + { + "name": "Kristi Himmelfartsdag", + "date": "2024-05-09" + }, + { + "name": "Pinse", + "date": "2024-05-19" + }, + { + "name": "Anden Pinsedag", + "date": "2024-05-20" + }, + { + "name": "Juleaften", + "date": "2024-12-24" + }, + { + "name": "Juledag", + "date": "2024-12-25" + }, + { + "name": "Anden Juledag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/DenmarkTest.php b/tests/Countries/DenmarkTest.php index 64034ba09..caa885efc 100644 --- a/tests/Countries/DenmarkTest.php +++ b/tests/Countries/DenmarkTest.php @@ -8,6 +8,18 @@ it('can calculate danish holidays', function () { CarbonImmutable::setTestNow('2024-01-01'); + $holidays = Holidays::for(country: 'dk')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate danish holidays with the wrong ISO code', function () { + CarbonImmutable::setTestNow('2024-01-01'); + $holidays = Holidays::for(country: 'da')->get(); expect($holidays)