From 779ddcbccbe9be7be973993f45ab6a885312f70e Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 22 Aug 2026 17:18:36 +0200 Subject: [PATCH] Fix 3 pre-existing failing tests - testToggleReady: user was never marked verified, so toggleReady() returned false before doing anything (an isVerified() gate was added to the service after this test was written). - testCheckAllPlayersReadyTransitionsStatus: entityManager mock returned the same SessionSettingRepository for every getRepository() call, but the service now also fetches a GameSettingRepository for the session's total-time setting, causing a TypeError. Route the mock by requested class instead. - testChatRegeneratesVerifyCodesIfShared: two competing method('getSetting') stubs were registered without with() constraints; PHPUnit keeps the first one it sees active for every call, so the (correct, more complete) willReturnCallback stub was silently dead code and the regeneration path never actually ran. Dropped the redundant first stub, and updated the flush() count now that the real flow (chat tracking + code regeneration) executes. Co-Authored-By: Claude Sonnet 5 --- tests/Game/GameDashboardServiceTest.php | 8 +++++++- tests/Game/GameResponseServiceChatVerifyCodeTest.php | 7 ++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Game/GameDashboardServiceTest.php b/tests/Game/GameDashboardServiceTest.php index 47b6c02..6daf74f 100644 --- a/tests/Game/GameDashboardServiceTest.php +++ b/tests/Game/GameDashboardServiceTest.php @@ -207,6 +207,7 @@ class GameDashboardServiceTest extends TestCase public function testToggleReady(): void { $user = new User(); + $user->setIsVerified(true); $game = new Game(); $game->setNumberOfPlayers(1); $session = new Session(); @@ -254,8 +255,13 @@ class GameDashboardServiceTest extends TestCase $session->addPlayer($player2); $repo = $this->createMock(\App\Game\Repository\SessionSettingRepository::class); + $gameSettingRepo = $this->createMock(\App\Game\Repository\GameSettingRepository::class); + $gameSettingRepo->method('getSetting')->willReturn(null); // Falls back to the default total time + $this->entityManager->method('getRepository') - ->willReturn($repo); + ->willReturnCallback(function ($class) use ($repo, $gameSettingRepo) { + return $class === \App\Game\Entity\GameSetting::class ? $gameSettingRepo : $repo; + }); $setting1 = new SessionSetting(); $setting1->setName(SessionSettingType::READY_AT_FOR_PLAYER1); diff --git a/tests/Game/GameResponseServiceChatVerifyCodeTest.php b/tests/Game/GameResponseServiceChatVerifyCodeTest.php index 38f558f..c18b2a4 100644 --- a/tests/Game/GameResponseServiceChatVerifyCodeTest.php +++ b/tests/Game/GameResponseServiceChatVerifyCodeTest.php @@ -91,10 +91,6 @@ class GameResponseServiceChatVerifyCodeTest extends TestCase // Mock rights $rightsSetting = new SessionSetting(); $rightsSetting->setValue(json_encode(['chat'])); - $this->sessionSettingRepository->method('getSetting') - ->willReturnMap([ - [$session, SessionSettingType::RIGHTS_FOR_PLAYER1, $player, $rightsSetting], - ]); // Mock verify codes $verifyCodesSetting = new SessionSetting(); @@ -115,7 +111,8 @@ class GameResponseServiceChatVerifyCodeTest extends TestCase ->method('dispatch') ->willReturnArgument(0); - $this->entityManager->expects($this->once()) + // Flushed twice: once for the chat-tracking update, once for the code regeneration + $this->entityManager->expects($this->exactly(2)) ->method('flush'); $raw = json_encode(['message' => '/chat Hello look at my code secret123', 'ts' => '123']);