@@ -154,6 +154,9 @@ public function verifyDoesNotMarkVerifiedWhenValidationFails(): void
154154 #[Test]
155155 public function triggerChallengeGeneratesCodeCreatesStateAndNotifies (): void
156156 {
157+ $ sendPolicyStub = $ this ->createStub (OtpSendPolicyServiceInterface::class);
158+ $ sendPolicyStub ->method ('canSend ' )->willReturn (true );
159+
157160 $ codeGeneratorStub = $ this ->createStub (OtpCodeGeneratorServiceInterface::class);
158161 $ codeGeneratorStub ->method ('generateCode ' )->willReturn ($ code = uniqid ());
159162
@@ -174,11 +177,33 @@ public function triggerChallengeGeneratesCodeCreatesStateAndNotifies(): void
174177 stateService: $ stateServiceSpy ,
175178 codeGenerator: $ codeGeneratorStub ,
176179 notifierFactory: $ notifierFactoryStub ,
180+ sendPolicy: $ sendPolicyStub ,
177181 );
178182
179183 $ sut ->triggerChallenge (userId: $ userId );
180184 }
181185
186+ #[Test]
187+ public function triggerChallengeDoesNothingWhenCooldownActive (): void
188+ {
189+ $ sendPolicyStub = $ this ->createStub (OtpSendPolicyServiceInterface::class);
190+ $ sendPolicyStub ->method ('canSend ' )->willReturn (false );
191+
192+ $ stateServiceSpy = $ this ->createMock (OtpChallengeStateServiceInterface::class);
193+ $ stateServiceSpy ->expects ($ this ->never ())->method ('createChallengeState ' );
194+
195+ $ notifierFactorySpy = $ this ->createMock (OtpNotifierFactoryInterface::class);
196+ $ notifierFactorySpy ->expects ($ this ->never ())->method ('create ' );
197+
198+ $ sut = $ this ->getSut (
199+ stateService: $ stateServiceSpy ,
200+ notifierFactory: $ notifierFactorySpy ,
201+ sendPolicy: $ sendPolicyStub ,
202+ );
203+
204+ $ sut ->triggerChallenge (userId: uniqid ());
205+ }
206+
182207 #[Test]
183208 public function resendThrowsCooldownExceptionWhenSendNotAllowed (): void
184209 {
0 commit comments