72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\State;
|
|
|
|
use App\State\EmployeeLeaveSummaryProvider;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class EmployeeLeaveSummaryProviderTest extends TestCase
|
|
{
|
|
public function testComputeAccruedDaysFromStartProratesPartialFirstMonth(): void
|
|
{
|
|
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
|
|
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
|
|
|
|
$result = $method->invoke(
|
|
$provider,
|
|
25.0,
|
|
25.0 / 12.0,
|
|
new DateTimeImmutable('2025-06-10'),
|
|
new DateTimeImmutable('2026-02-28')
|
|
);
|
|
|
|
self::assertEqualsWithDelta(18.125, $result, 0.0001);
|
|
}
|
|
|
|
public function testComputeAccruingDaysTotalMatchesAlainCase(): void
|
|
{
|
|
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
|
|
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
|
|
|
|
$days = $method->invoke(
|
|
$provider,
|
|
25.0,
|
|
25.0 / 12.0,
|
|
new DateTimeImmutable('2025-06-10'),
|
|
new DateTimeImmutable('2026-02-28')
|
|
);
|
|
$saturdays = $method->invoke(
|
|
$provider,
|
|
5.0,
|
|
5.0 / 12.0,
|
|
new DateTimeImmutable('2025-06-10'),
|
|
new DateTimeImmutable('2026-02-28')
|
|
);
|
|
|
|
self::assertEqualsWithDelta(21.75, $days + $saturdays, 0.0001);
|
|
}
|
|
|
|
public function testComputeAccruedDaysFromStartIncludesLastDayOfMonth(): void
|
|
{
|
|
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
|
|
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
|
|
|
|
$result = $method->invoke(
|
|
$provider,
|
|
25.0,
|
|
25.0 / 12.0,
|
|
new DateTimeImmutable('2026-02-01 12:50:18'),
|
|
new DateTimeImmutable('2026-02-28 00:00:00')
|
|
);
|
|
|
|
self::assertEqualsWithDelta(25.0 / 12.0, $result, 0.0001);
|
|
}
|
|
}
|