diff --git a/tests/Service/Rtt/RttClosingBalanceServiceTest.php b/tests/Service/Rtt/RttClosingBalanceServiceTest.php index 173f904..6e0837e 100644 --- a/tests/Service/Rtt/RttClosingBalanceServiceTest.php +++ b/tests/Service/Rtt/RttClosingBalanceServiceTest.php @@ -80,6 +80,23 @@ final class RttClosingBalanceServiceTest extends TestCase ); } + public function testCustomDeficitWeekReducesClosingBalance(): void + { + // CUSTOM (4h) : une semaine de récup +3h puis une semaine déficitaire -1h + // (toutes deux sans tranches 25/50). Le déficit doit réduire la clôture. + $recovery = new WeekRecoveryDetail(totalMinutes: 180, isFlatRecovery: true); // +3h + $deficit = new WeekRecoveryDetail(totalMinutes: -60, isFlatRecovery: true); // -1h + + $closing = $this->service()->fold(new WeekRecoveryDetail(), [$recovery, $deficit], $this->payments()); + + // 3h - 1h = 2h reportées, et la somme des buckets égale toujours le total. + self::assertSame(120, $closing->totalMinutes); + self::assertSame( + 120, + $closing->base25Minutes + $closing->bonus25Minutes + $closing->base50Minutes + $closing->bonus50Minutes, + ); + } + public function testBucketSumAlwaysEqualsTotalInvariant(): void { $opening = new WeekRecoveryDetail(base25Minutes: 200, bonus25Minutes: 50, base50Minutes: 100, bonus50Minutes: 50, totalMinutes: 400);