Skip to content

Commit

Permalink
Add International Workers Day
Browse files Browse the repository at this point in the history
Removed holiday provider with the unit tests, replaced with just a
single random year test for the other holidays. Formatted unit test
method so that each parameters is on a separate line for readability.

Signed-off-by: Sacha Telgenhof <me@sachatelgenhof.com>
  • Loading branch information
stelgenhof committed Nov 2, 2024
1 parent 5e84d12 commit c0b7526
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/Yasumi/Provider/Bulgaria.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function initialize(): void

// // 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->internationalWorkersDay($this->year, $this->timezone, $this->locale));

//
// // Add Catholic holidays
// $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/internationalWorkersDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// Translations for International Workers' Day
return [
'bg' => 'Ден на труда и на международната работническа солидарност',
'bs_Latn' => 'Praznik rada',
'ca' => 'Dia del Treball',
'cs' => 'Svátek práce',
Expand Down
1 change: 1 addition & 0 deletions tests/Bulgaria/BulgariaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testOfficialHolidays(): void
{
$holidays = [
'newYearsDay',
'internationalWorkersDay',
];

if ($this->year >= 1990) {
Expand Down
57 changes: 57 additions & 0 deletions tests/Bulgaria/InternationalWorkersDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 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\Bulgaria;

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

class InternationalWorkersDayTest extends BulgariaBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'internationalWorkersDay';

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

public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Ден на труда и на международната работническа солидарност']
);
}

public function testHolidayType(): void
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
Holiday::TYPE_OFFICIAL
);
}
}
23 changes: 12 additions & 11 deletions tests/Bulgaria/LiberationDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LiberationDayTest extends BulgariaBaseTestCase implements HolidayTestCase

public function testHoliday(): void
{
$year = self::ESTABLISHMENT_YEAR;
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
Expand All @@ -39,15 +39,11 @@ public function testHoliday(): void

public function testNotHoliday(): void
{
$this->assertNotHoliday(self::REGION, self::HOLIDAY, self::ESTABLISHMENT_YEAR - 1);
}

/**
* @return array<array<int, \DateTime>>
*/
public function HolidayDataProvider(): array
{
return $this->generateRandomDates(3, 3, self::TIMEZONE, null, 2000);
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1)
);
}

public function testTranslation(): void
Expand All @@ -62,6 +58,11 @@ public function testTranslation(): void

public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL);
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
Holiday::TYPE_OFFICIAL
);
}
}
28 changes: 14 additions & 14 deletions tests/Bulgaria/NewYearsDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@ class NewYearsDayTest extends BulgariaBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'newYearsDay';

/**
* @dataProvider HolidayDataProvider
*/
public function testHoliday(int $year, \DateTime $expected): void
public function testHoliday(): void
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* @return array<array<int, \DateTime>>
*/
public function HolidayDataProvider(): array
{
return $this->generateRandomDates(1, 1, self::TIMEZONE);
$year = $this->generateRandomYear();
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new \DateTime("{$year}-01-01", new \DateTimeZone(self::TIMEZONE))
);
}

public function testTranslation(): void
Expand All @@ -52,6 +47,11 @@ 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_OFFICIAL
);
}
}

0 comments on commit c0b7526

Please sign in to comment.