63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service\Notification;
|
|
|
|
use App\Service\Notification\WorkingDayCalculator;
|
|
use App\Service\PublicHolidayServiceInterface;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class WorkingDayCalculatorTest extends TestCase
|
|
{
|
|
public function testWeekdayIsWorkingDay(): void
|
|
{
|
|
// Mardi 08/07/2025
|
|
self::assertTrue($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-08')));
|
|
}
|
|
|
|
public function testSaturdayAndSundayAreNotWorkingDays(): void
|
|
{
|
|
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-12'))); // samedi
|
|
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-13'))); // dimanche
|
|
}
|
|
|
|
public function testPublicHolidayIsNotWorkingDay(): void
|
|
{
|
|
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-14'))); // lundi férié
|
|
}
|
|
|
|
public function testNextWorkingDayFromWeekdayIsTomorrow(): void
|
|
{
|
|
// Mardi 08/07 -> Mercredi 09/07
|
|
self::assertSame(
|
|
'2025-07-09',
|
|
$this->calculator()->nextWorkingDay(new DateTimeImmutable('2025-07-08'))->format('Y-m-d')
|
|
);
|
|
}
|
|
|
|
public function testNextWorkingDayFromFridaySkipsWeekend(): void
|
|
{
|
|
// Vendredi 11/07 -> lundi 14/07 est férié -> mardi 15/07
|
|
self::assertSame(
|
|
'2025-07-15',
|
|
$this->calculator()->nextWorkingDay(new DateTimeImmutable('2025-07-11'))->format('Y-m-d')
|
|
);
|
|
}
|
|
|
|
private function calculator(): WorkingDayCalculator
|
|
{
|
|
$holidays = $this->createStub(PublicHolidayServiceInterface::class);
|
|
$holidays->method('getHolidaysDayByYears')->willReturn([
|
|
// Lundi 14/07/2025 férié
|
|
'2025-07-14' => 'Fête nationale',
|
|
]);
|
|
|
|
return new WorkingDayCalculator($holidays);
|
|
}
|
|
}
|