value . ':' . $nonce->value->toString(); $cacheStore->expects('has') ->once() ->with($expectedKey) ->andReturn(false); $cacheStore->expects('set') ->once() ->with($expectedKey, 'used', 300) ->andReturn(true); // WHEN $isValid = $validator->validateAndConsume($nonce, $clientIdentifier); // THEN expect($isValid)->toBeTrue(); }); it('rejects an already consumed nonce', function (): void { // GIVEN $cacheStore = Mockery::mock(CacheInterface::class); $logger = new NullLogger(); $validator = new CachedNonceValidator($logger, $cacheStore); $clientIdentifier = new ClientIdentifier('arcadia_id_' . str_repeat('a', 32)); $nonce = new Nonce(Uuid::uuid7()); $expectedKey = 'nonce:' . $clientIdentifier->value . ':' . $nonce->value->toString(); $cacheStore->expects('has') ->once() ->with($expectedKey) ->andReturn(true); $cacheStore->shouldNotReceive('set'); // WHEN $isValid = $validator->validateAndConsume($nonce, $clientIdentifier); // THEN expect($isValid)->toBeFalse(); }); });