update fake token generator to take a preset number of tokens

This commit is contained in:
Yisroel Baum 2026-05-20 10:22:10 +03:00
parent 414679f15b
commit 56b528999e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 18 additions and 2 deletions

View file

@ -3,11 +3,27 @@
namespace Tests\Fakes; namespace Tests\Fakes;
use App\Auth\TokenGenerator; use App\Auth\TokenGenerator;
use RuntimeException;
class FakeTokenGenerator implements TokenGenerator class FakeTokenGenerator implements TokenGenerator
{ {
private int $callCount = 0;
/**
* @param string[] $tokens
*/
public function __construct(private array $tokens) {}
public function generate(): string public function generate(): string
{ {
return 'fake-token-123'; if ($this->callCount >= count($this->tokens)) {
throw new RuntimeException(
'FakeTokenGenerator exhausted'
);
}
$token = $this->tokens[$this->callCount];
$this->callCount++;
return $token;
} }
} }

View file

@ -22,7 +22,7 @@ class CreateSessionTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->sessionRepo = new FakeSessionRepository(); $this->sessionRepo = new FakeSessionRepository();
$this->tokenGenerator = new FakeTokenGenerator(); $this->tokenGenerator = new FakeTokenGenerator(['fake-token-123']);
$this->clock = new FakeClock( $this->clock = new FakeClock(
new DateTimeImmutable('2026-05-18 12:00:00') new DateTimeImmutable('2026-05-18 12:00:00')
); );