From c74e36e0f51c52f679ef7792074381373df9805c Mon Sep 17 00:00:00 2001 From: AJ <60591772+devajmeireles@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:53:50 -0300 Subject: [PATCH 1/2] code --- src/Countries/Brazil.php | 41 +++++++++++++++ .../it_can_calculate_brazil_holidays.snap | 50 +++++++++++++++++++ tests/Countries/BrazilTest.php | 18 +++++++ 3 files changed, 109 insertions(+) create mode 100644 src/Countries/Brazil.php create mode 100644 tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap create mode 100644 tests/Countries/BrazilTest.php diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php new file mode 100644 index 00000000..7da5cc21 --- /dev/null +++ b/src/Countries/Brazil.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Dia de Ano Novo' => '01-01', + 'Dia de Tiradentes' => '04-21', + 'Dia do Trabalhador' => '05-01', + 'Independência do Brasil' => '09-07', + 'Nossa Senhora Aparecida' => '10-12', + 'Finados' => '11-02', + 'Proclamação da República' => '11-15', + 'Natal' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); + + return [ + 'Páscoa' => $easter, + 'Carnaval' => $easter->subDays(47), + 'Sexta-feira Santa' => $easter->subDays(2), + 'Corpus Christi' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap new file mode 100644 index 00000000..6e767523 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Dia de Ano Novo", + "date": "2024-01-01" + }, + { + "name": "Carnaval", + "date": "2024-02-13" + }, + { + "name": "Sexta-feira Santa", + "date": "2024-03-29" + }, + { + "name": "P\u00e1scoa", + "date": "2024-03-31" + }, + { + "name": "Dia de Tiradentes", + "date": "2024-04-21" + }, + { + "name": "Dia do Trabalhador", + "date": "2024-05-01" + }, + { + "name": "Corpus Christi", + "date": "2024-05-30" + }, + { + "name": "Independ\u00eancia do Brasil", + "date": "2024-09-07" + }, + { + "name": "Nossa Senhora Aparecida", + "date": "2024-10-12" + }, + { + "name": "Finados", + "date": "2024-11-02" + }, + { + "name": "Proclama\u00e7\u00e3o da Rep\u00fablica", + "date": "2024-11-15" + }, + { + "name": "Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php new file mode 100644 index 00000000..91be74d4 --- /dev/null +++ b/tests/Countries/BrazilTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 093578e7c07514a6256837ab50723bb5a40dd785 Mon Sep 17 00:00:00 2001 From: AJ <60591772+devajmeireles@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:09:06 -0300 Subject: [PATCH 2/2] removing one --- src/Countries/Brazil.php | 1 - .../BrazilTest/it_can_calculate_brazil_holidays.snap | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 7da5cc21..4c93f100 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -32,7 +32,6 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); return [ - 'Páscoa' => $easter, 'Carnaval' => $easter->subDays(47), 'Sexta-feira Santa' => $easter->subDays(2), 'Corpus Christi' => $easter->addDays(60), diff --git a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap index 6e767523..5be3e640 100644 --- a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap +++ b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap @@ -11,10 +11,6 @@ "name": "Sexta-feira Santa", "date": "2024-03-29" }, - { - "name": "P\u00e1scoa", - "date": "2024-03-31" - }, { "name": "Dia de Tiradentes", "date": "2024-04-21"