Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
contactinquid committed Dec 1, 2023
1 parent dfd79c2 commit 466dbcb
Show file tree
Hide file tree
Showing 13 changed files with 901 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/Yasumi/Provider/Mexico.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ public function initialize(): void
$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));

// Add Christian holidays
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->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->goodFriday($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));
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));

// Mexican holidays
$this->calculateConstitutionDay();
$this->calculateBenitoJuarezBirthday();
$this->calculateRevolutionDay();
$this->calculateDiscoveryOfAmerica();
$this->addIndependenceDay();
$this->calculateDayOfTheDeaths();
$this->calculateChristmasEve();
$this->calculateNewYearsEve();
}
Expand Down Expand Up @@ -112,7 +118,7 @@ private function calculateConstitutionDay(): void
'en' => 'Constitution Day',
'es' => 'Día de la Constitución',
],
new \DateTime("first monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)
new \DateTime("first monday of february {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE)
);
}
}
Expand All @@ -124,14 +130,25 @@ private function calculateConstitutionDay(): void
*/
private function calculateBenitoJuarezBirthday(): void
{
if ($this->year >= 1806) {
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", new \DateTimeZone($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)
new \DateTime("third monday of march {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE)
);
}
}
Expand All @@ -150,7 +167,7 @@ private function calculateRevolutionDay(): void
'en' => 'Revolution Day',
'es' => 'Día de la Revolución',
],
new \DateTime("third monday of november {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)
new \DateTime("third monday of november {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE)
);
}
}
Expand All @@ -169,7 +186,7 @@ private function calculateDiscoveryOfAmerica(): void
'en' => 'Discovery of America',
'es' => 'Día de la Raza',
],
new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)
new \DateTime("second monday of october {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale, Holiday::TYPE_OBSERVANCE)
);
}
}
Expand Down Expand Up @@ -208,4 +225,22 @@ private function calculateNewYearsEve(): void
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 calculateDayOfTheDeaths(): void
{
$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)
);
}
}
79 changes: 79 additions & 0 deletions tests/Mexico/AllSaintsDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2023 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

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<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);
}
}
79 changes: 79 additions & 0 deletions tests/Mexico/AssumptionOfMaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2023 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

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<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);
}
}
59 changes: 59 additions & 0 deletions tests/Mexico/BenitoJuarezBirthdayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Yasumi\tests\Mexico;

use Yasumi\Holiday;
use Yasumi\tests\HolidayTestCase;

class BenitoJuarezBirthdayTest extends MexicoBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'benitoJuarezBirthday';

public const ESTABLISHMENT_YEAR = 1806;

public function testHoliday(): void
{
$year = self::ESTABLISHMENT_YEAR;
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new \DateTime("{$year}-03-21", new \DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests that holiday is not present before establishment year.
*/
public function testNotHoliday(): void
{
$this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1);
}

/**
* Tests translated name of the holiday.
*
* @throws \Exception
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$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);
}
}
Loading

0 comments on commit 466dbcb

Please sign in to comment.