Files
MeshVault/tests/Unit/Console/FakeConsoleServices.php
T

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace MeshVault\Tests\Unit\Console;
use MeshVault\Console\ConsoleServices;
use Throwable;
final class FakeConsoleServices implements ConsoleServices
{
/** @var list<array{0: string, 1: list<string>}> */
public array $imports = [];
public int $runs = 0;
/** @param list<int|null> $jobs */
public function __construct(
private readonly int $importResult = 1,
private readonly ?Throwable $importError = null,
private array $jobs = [],
private readonly ?Throwable $workerError = null,
) {
}
public function import(string $sourcePath, array $extensions): int
{
$this->imports[] = [$sourcePath, $extensions];
if ($this->importError !== null) {
throw $this->importError;
}
return $this->importResult;
}
public function runWorkerOnce(callable $shouldStop): ?int
{
$this->runs++;
if ($this->workerError !== null) {
throw $this->workerError;
}
// The real worker consults the callback between items; mirror that contract.
$shouldStop();
return array_shift($this->jobs);
}
}