update fake token generator to take a preset number of tokens
This commit is contained in:
parent
414679f15b
commit
56b528999e
2 changed files with 18 additions and 2 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue