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:
@@ -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);
|
||||
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user