ES
apps/winzik / tests / Lyrics / FakeLyricsHttp.php · commit 6576d6f
<?phpnamespace Tests\Lyrics;use JumPHP\Async\Task;use JumPHP\Bridge\JsBridge;use JumPHP\Http\Http;use JumPHP\Http\HttpResponse;/** The Internet of the lyrics in memory: each request answered at once by $route (LRCLIB, MyMemory, the marketplace...). */final class FakeLyricsHttp extends Http{    /** @var list<array{method: string, url: string, headers: array<string, string>}> */    public array $requests = [];    /** @param \Closure(string, string, array<string, string>): HttpResponse $route */    public function __construct(JsBridge $bridge, private \Closure $route)    {        parent::__construct($bridge);    }    public function request(string $method, string $url, string|array|null $body = null, array $headers = [], ?float $timeout = null): Task    {        $this->requests[] = ['method' => $method, 'url' => $url, 'headers' => $headers];        $t = new Task();        $t->settle(($this->route)($method, $url, $headers));        return $t;    }    /** @return list<string> the addresses asked, in order */    public function urls(): array    {        return array_map(fn (array $r) => $r['url'], $this->requests);    }}