['status' => 201, 'body' => 'готово']]); try { $response = (new HttpClient())->post('https://api.example.com/orders', '{"id":1}', ['X-Test: да']); assertSame(201, $response['status']); assertSame('готово', $response['body']); $recorded = HttpClient::recorded(); assertCount(1, $recorded); assertSame('POST', $recorded[0]['method']); assertSame('https://api.example.com/orders', $recorded[0]['url']); assertSame('{"id":1}', $recorded[0]['body']); } finally { HttpClient::reset(); } }); test('HttpClient: адрес без своей маски отвечает пустым 200, а не падением', function (): void { HttpClient::fake(['https://known.example.com/*' => ['status' => 500]]); try { $response = (new HttpClient())->get('https://unknown.example.com/'); assertSame(200, $response['status']); assertSame('', $response['body']); } finally { HttpClient::reset(); } }); test('HttpClient: reset() выключает подмену и чистит журнал', function (): void { HttpClient::fake(); (new HttpClient())->get('https://example.com'); assertCount(1, HttpClient::recorded()); HttpClient::reset(); assertSame([], HttpClient::recorded()); }); test('HttpClient: ходит только по http и https', function (): void { // Даже под подменой: запрет не должен зависеть от того, тест это или бой HttpClient::fake(['*' => ['status' => 200, 'body' => 'не должно дойти']]); try { foreach (['file://localhost/etc/passwd', 'gopher://127.0.0.1:6379/_x', 'ftp://example.com/a'] as $url) { assertThrows(static fn () => (new HttpClient())->get($url), 'схема не должна пройти: ' . $url); } assertCount(0, HttpClient::recorded(), 'до сети ничего не ушло'); assertTrue(HttpClient::allowedScheme('https://example.com/hook')); assertTrue(HttpClient::allowedScheme('http://10.0.0.5:8080/hook'), 'внутренние адреса по http разрешены'); } finally { HttpClient::reset(); } });