31 lines
609 B
PHP
31 lines
609 B
PHP
<?php
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
use App\Auth\TokenGenerator;
|
|
use RuntimeException;
|
|
|
|
class FakeTokenGenerator implements TokenGenerator
|
|
{
|
|
private int $callCount = 0;
|
|
|
|
/**
|
|
* @param string[] $tokens
|
|
*/
|
|
public function __construct(private array $tokens)
|
|
{
|
|
}
|
|
|
|
public function generate(): string
|
|
{
|
|
if ($this->callCount >= count($this->tokens)) {
|
|
throw new RuntimeException(
|
|
'FakeTokenGenerator exhausted'
|
|
);
|
|
}
|
|
$token = $this->tokens[$this->callCount];
|
|
$this->callCount++;
|
|
|
|
return $token;
|
|
}
|
|
}
|