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 <noreply@anthropic.com>
This commit is contained in:
Frank
2026-08-22 17:18:36 +02:00
co-authored by Claude Sonnet 5
parent 6b1436dfe7
commit 779ddcbccb
2 changed files with 9 additions and 6 deletions
+7 -1
View File
@@ -207,6 +207,7 @@ class GameDashboardServiceTest extends TestCase
public function testToggleReady(): void public function testToggleReady(): void
{ {
$user = new User(); $user = new User();
$user->setIsVerified(true);
$game = new Game(); $game = new Game();
$game->setNumberOfPlayers(1); $game->setNumberOfPlayers(1);
$session = new Session(); $session = new Session();
@@ -254,8 +255,13 @@ class GameDashboardServiceTest extends TestCase
$session->addPlayer($player2); $session->addPlayer($player2);
$repo = $this->createMock(\App\Game\Repository\SessionSettingRepository::class); $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') $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 = new SessionSetting();
$setting1->setName(SessionSettingType::READY_AT_FOR_PLAYER1); $setting1->setName(SessionSettingType::READY_AT_FOR_PLAYER1);
@@ -91,10 +91,6 @@ class GameResponseServiceChatVerifyCodeTest extends TestCase
// Mock rights // Mock rights
$rightsSetting = new SessionSetting(); $rightsSetting = new SessionSetting();
$rightsSetting->setValue(json_encode(['chat'])); $rightsSetting->setValue(json_encode(['chat']));
$this->sessionSettingRepository->method('getSetting')
->willReturnMap([
[$session, SessionSettingType::RIGHTS_FOR_PLAYER1, $player, $rightsSetting],
]);
// Mock verify codes // Mock verify codes
$verifyCodesSetting = new SessionSetting(); $verifyCodesSetting = new SessionSetting();
@@ -115,7 +111,8 @@ class GameResponseServiceChatVerifyCodeTest extends TestCase
->method('dispatch') ->method('dispatch')
->willReturnArgument(0); ->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'); ->method('flush');
$raw = json_encode(['message' => '/chat Hello look at my code secret123', 'ts' => '123']); $raw = json_encode(['message' => '/chat Hello look at my code secret123', 'ts' => '123']);