From f344eb536cb9bc3da84d8c19be68492303f21726 Mon Sep 17 00:00:00 2001 From: tristan Date: Tue, 9 Jun 2026 10:05:26 +0200 Subject: [PATCH] test(rtt) : custom deficit week reduces closing balance --- .../Rtt/RttClosingBalanceServiceTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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);