diff --git a/src/Yasumi/Provider/Mexico.php b/src/Yasumi/Provider/Mexico.php new file mode 100644 index 000000000..c4f47a3cc --- /dev/null +++ b/src/Yasumi/Provider/Mexico.php @@ -0,0 +1,269 @@ + + */ + +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)); + $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $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)); + + // Mexican holidays + $this->calculateConstitutionDay(); + $this->calculateBenitoJuarezBirthday(); + $this->calculateRevolutionDay(); + $this->calculateDiscoveryOfAmerica(); + $this->addIndependenceDay(); + $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 + */ + private 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. + */ + private 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, Holiday::TYPE_OBSERVANCE) + ); + } + } + + /* + * Benito Juárez's birthday. + * + * Anniversary of the birth of Benito Juárez on March 21, 1806, observed on the third Monday of March. + */ + private 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, Holiday::TYPE_OBSERVANCE) + ); + } + + 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, Holiday::TYPE_OBSERVANCE) + ); + } + } + + /* + * Revolution Day. + * + * Anniversary of the start of the Mexican Revolution on November 20, 1910, observed on the third Monday of November. + */ + private 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, Holiday::TYPE_OBSERVANCE) + ); + } + } + + /* + * Discovery of America. + * + * Anniversary of the Discovery of America on October 12, 1492, observed on the second Monday of October. + */ + private 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. + */ + private 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) + ); + } + + /* + * New Year's Eve. + * + * New Year's Eve is the last day of the year, December 31, in the Gregorian calendar. + */ + private 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) + ); + } + + /** + * 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. + */ + private 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_OTHER) + ); + } + } + + /* + * 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. + */ + private 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 + )); + } + } +} diff --git a/tests/Mexico/AllSaintsDayTest.php b/tests/Mexico/AllSaintsDayTest.php new file mode 100644 index 000000000..d15d15f28 --- /dev/null +++ b/tests/Mexico/AllSaintsDayTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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(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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/AssumptionOfMaryTest.php b/tests/Mexico/AssumptionOfMaryTest.php new file mode 100644 index 000000000..5f6e190bd --- /dev/null +++ b/tests/Mexico/AssumptionOfMaryTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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 the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/BenitoJuarezBirthdayTest.php b/tests/Mexico/BenitoJuarezBirthdayTest.php new file mode 100644 index 000000000..a2558c9e6 --- /dev/null +++ b/tests/Mexico/BenitoJuarezBirthdayTest.php @@ -0,0 +1,59 @@ +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, + $this->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, $this->generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/ChristmasTest.php b/tests/Mexico/ChristmasTest.php new file mode 100644 index 000000000..21ddedae4 --- /dev/null +++ b/tests/Mexico/ChristmasTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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(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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/EasterMondayTest.php b/tests/Mexico/EasterMondayTest.php new file mode 100644 index 000000000..dd37cbb2b --- /dev/null +++ b/tests/Mexico/EasterMondayTest.php @@ -0,0 +1,70 @@ + + */ + +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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE); + } +} diff --git a/tests/Mexico/EpiphanyTest.php b/tests/Mexico/EpiphanyTest.php new file mode 100644 index 000000000..ca0915db9 --- /dev/null +++ b/tests/Mexico/EpiphanyTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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(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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/GoodFridayTest.php b/tests/Mexico/GoodFridayTest.php new file mode 100644 index 000000000..62ad7ef77 --- /dev/null +++ b/tests/Mexico/GoodFridayTest.php @@ -0,0 +1,70 @@ + + */ + +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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/ImmaculateConceptionTest.php b/tests/Mexico/ImmaculateConceptionTest.php new file mode 100644 index 000000000..71f2bae07 --- /dev/null +++ b/tests/Mexico/ImmaculateConceptionTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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(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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/IndependenceDayTest.php b/tests/Mexico/IndependenceDayTest.php new file mode 100644 index 000000000..763398759 --- /dev/null +++ b/tests/Mexico/IndependenceDayTest.php @@ -0,0 +1,83 @@ + + */ + +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, + $this->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, $this->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..b3f40141f --- /dev/null +++ b/tests/Mexico/InternationalWorkersDayTest.php @@ -0,0 +1,79 @@ + + */ + +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. + * + * @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(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, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/MexicoBaseTestCase.php b/tests/Mexico/MexicoBaseTestCase.php new file mode 100644 index 000000000..5875f5057 --- /dev/null +++ b/tests/Mexico/MexicoBaseTestCase.php @@ -0,0 +1,37 @@ + + */ + +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..402bd3dd5 --- /dev/null +++ b/tests/Mexico/NewYearsDayTest.php @@ -0,0 +1,66 @@ +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 function NewYearsDayDataProvider(): array + { + return $this->generateRandomDates(1, 1, self::TIMEZONE); + } + + /** + * Tests translated name of New Years Day. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + self::REGION, + self::HOLIDAY, + $this->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, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Mexico/VirginOfGuadalupeTest.php b/tests/Mexico/VirginOfGuadalupeTest.php new file mode 100644 index 000000000..c8aa40089 --- /dev/null +++ b/tests/Mexico/VirginOfGuadalupeTest.php @@ -0,0 +1,62 @@ +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 = $this->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 = $this->generateRandomYear(self::ESTABLISHMENT_YEAR); + $this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OFFICIAL); + } +}