feat(rtt) : skip 25/50 deficit cascade for flat (custom) recovery weeks

This commit is contained in:
2026-06-09 10:07:55 +02:00
parent fa3861b122
commit 8a0eb40616
2 changed files with 121 additions and 41 deletions
+64 -11
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Tests\State;
use App\Dto\Contracts\ContractPhase;
use App\Dto\Rtt\EmployeeRttWeekSummary;
use App\Entity\Contract;
use App\Entity\Employee;
use App\Entity\EmployeeContractPeriod;
@@ -201,6 +202,54 @@ final class EmployeeRttSummaryProviderTest extends TestCase
self::assertSame(2030, $year);
}
/**
* Build an uninitialized provider with a RequestStack pre-loaded with the given query.
*
* The provider's repository/service dependencies are typed against final classes
* (EmployeeRepository, RttRecoveryComputationService, etc.) which PHPUnit cannot
* double. We bypass full instantiation by using newInstanceWithoutConstructor and
* only setting the properties that the tested private methods actually read:
* `requestStack` and `phaseResolver`.
*/
public function testFlatDeficitWeekIsNotDrainedFromTiers(): void
{
$provider = $this->buildProvider([]);
// Semaine CUSTOM déficitaire (-120), aucune tranche accumulée.
$weeks = [$this->weekSummary(-120, true)];
$result = $this->invokePrivate($provider, 'applyDeficitCascade', $weeks, 0, 0);
// Buckets restent à 0 ; le total négatif est conservé (le cumul est calculé ailleurs).
self::assertSame(0, $result[0]->base25Minutes);
self::assertSame(0, $result[0]->base50Minutes);
self::assertSame(-120, $result[0]->totalMinutes);
self::assertTrue($result[0]->isFlatRecovery);
}
public function testStandardDeficitWeekDrainsFiftyThenTwentyFive(): void
{
$provider = $this->buildProvider([]);
// Semaine 35h/39h déficitaire (-100), avec 60 en 50% et 120 en 25% accumulés.
$weeks = [$this->weekSummary(-100, false)];
$result = $this->invokePrivate($provider, 'applyDeficitCascade', $weeks, 120, 60);
self::assertSame(-60, $result[0]->base50Minutes); // 60 drainés du 50%
self::assertSame(-40, $result[0]->base25Minutes); // 40 restants drainés du 25%
self::assertSame(-100, $result[0]->totalMinutes);
}
public function testFlatPositiveWeekIsUntouched(): void
{
$provider = $this->buildProvider([]);
$weeks = [$this->weekSummary(180, true)];
$result = $this->invokePrivate($provider, 'applyDeficitCascade', $weeks, 0, 0);
self::assertSame(180, $result[0]->totalMinutes);
self::assertSame(0, $result[0]->base25Minutes);
}
// -----------------------------------------------------------------------
// Test harness helpers.
// -----------------------------------------------------------------------
@@ -247,17 +296,21 @@ final class EmployeeRttSummaryProviderTest extends TestCase
return $employee;
}
/**
* Build an uninitialized provider with a RequestStack pre-loaded with the given query.
*
* The provider's repository/service dependencies are typed against final classes
* (EmployeeRepository, RttRecoveryComputationService, etc.) which PHPUnit cannot
* double. We bypass full instantiation by using newInstanceWithoutConstructor and
* only setting the properties that the tested private methods actually read:
* `requestStack` and `phaseResolver`.
*
* @param array<string, string> $request query parameters (year, phaseId, ...)
*/
private function weekSummary(int $totalMinutes, bool $isFlat, int $base25 = 0, int $base50 = 0): EmployeeRttWeekSummary
{
return new EmployeeRttWeekSummary(
month: 6,
weekNumber: 1,
weekStart: '2026-06-01',
weekEnd: '2026-06-07',
overtimeMinutes: $totalMinutes,
base25Minutes: $base25,
base50Minutes: $base50,
totalMinutes: $totalMinutes,
isFlatRecovery: $isFlat,
);
}
private function buildProvider(array $request = []): EmployeeRttSummaryProvider
{
$requestStack = new RequestStack();