Skip to content

Commit 5970171

Browse files
committed
fix: mock EmailOTPMFAChallengeStrategy's new getCreatedAt() call in unit tests
CI broke on push: issueChallenge()/resendChallenge() gained a call to $otp->getCreatedAt() in an earlier commit this session (0330c3b, seeding the MFA countdown with the OTP's actual issuance time), but the strict Mockery mocks in EmailOTPMFAChallengeStrategyTest never declared that expectation - BadMethodCallException on every call, in both testIssueChallenge_storesPendingStateAndReturnsOtpInfo and testResendChallenge_delegatesToIssueChallenge. Only ran tests/TwoFactorLoginFlowTest.php locally in that earlier commit (the file the plan named), not the full suite - this unit test file was never exercised until CI's own full run caught it. Mock getCreatedAt() with a fixed DateTime and extend both tests' assertSame() to include the new otp_issued_at key in the expected result array, matching the real return shape. Verified in isolation: 5 tests, 8 assertions, green.
1 parent 2bcadb3 commit 5970171

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

tests/Unit/MFA/EmailOTPMFAChallengeStrategyTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ public function testIssueChallenge_storesPendingStateAndReturnsOtpInfo(): void
5050
{
5151
$user = $this->buildUser(42, 'user@example.com');
5252

53+
$issuedAt = new \DateTime('2026-01-01 00:00:00', new \DateTimeZone('UTC'));
54+
5355
$otp = \Mockery::mock(OAuth2OTP::class);
5456
$otp->shouldReceive('getLength')->andReturn(6);
5557
$otp->shouldReceive('getLifetime')->andReturn(120);
58+
$otp->shouldReceive('getCreatedAt')->andReturn($issuedAt);
5659

5760
$this->tokenService
5861
->shouldReceive('createOTPFromPayload')
@@ -67,7 +70,10 @@ public function testIssueChallenge_storesPendingStateAndReturnsOtpInfo(): void
6770

6871
$result = $this->strategy->issueChallenge($user, null, true);
6972

70-
$this->assertSame(['otp_length' => 6, 'otp_lifetime' => 120], $result);
73+
$this->assertSame(
74+
['otp_length' => 6, 'otp_lifetime' => 120, 'otp_issued_at' => $issuedAt->getTimestamp()],
75+
$result
76+
);
7177
$this->assertSame(42, Session::get('2fa_pending_user_id'));
7278
$this->assertTrue(Session::get('2fa_remember'));
7379
}
@@ -78,9 +84,12 @@ public function testResendChallenge_delegatesToIssueChallenge(): void
7884
{
7985
$user = $this->buildUser(7, 'resend@example.com');
8086

87+
$issuedAt = new \DateTime('2026-01-01 00:00:00', new \DateTimeZone('UTC'));
88+
8189
$otp = \Mockery::mock(OAuth2OTP::class);
8290
$otp->shouldReceive('getLength')->andReturn(6);
8391
$otp->shouldReceive('getLifetime')->andReturn(120);
92+
$otp->shouldReceive('getCreatedAt')->andReturn($issuedAt);
8493

8594
$this->tokenService
8695
->shouldReceive('createOTPFromPayload')
@@ -89,7 +98,10 @@ public function testResendChallenge_delegatesToIssueChallenge(): void
8998

9099
$result = $this->strategy->resendChallenge($user, null, false);
91100

92-
$this->assertSame(['otp_length' => 6, 'otp_lifetime' => 120], $result);
101+
$this->assertSame(
102+
['otp_length' => 6, 'otp_lifetime' => 120, 'otp_issued_at' => $issuedAt->getTimestamp()],
103+
$result
104+
);
93105
$this->assertSame(7, Session::get('2fa_pending_user_id'));
94106
}
95107

0 commit comments

Comments
 (0)