| 11 | use PHPUnit\Framework\TestCase; |
| 12 | |
| 13 | class ExternalHttpClientTest extends TestCase { |
| 14 | public function testRequestUsesSecurityOptionsAndReturnsBody(): void { |
| 15 | $captured = []; |
| 16 | $response = new class() { |
| 17 | public function getStatusCode(): int { |
| 18 | return 200; |
| 19 | } |
| 20 | |
| 21 | public function getBody(): string { |
| 22 | return '{"ok":true}'; |
| 23 | } |
| 24 | }; |
| 25 | $client = new class($response, $captured) { |
| 26 | public array $captured; |
| 27 | private object $response; |
| 28 | |
| 29 | public function __construct(object $response, array &$captured) { |
| 30 | $this->response = $response; |
| 31 | $this->captured =& $captured; |
| 32 | } |
| 33 | |
| 34 | public function request(string $method, string $url, array $options): object { |
| 35 | $this->captured = compact('method', 'url', 'options'); |
| 36 | return $this->response; |
| 37 | } |
| 38 | }; |
| 39 | $service = new class($client) implements IClientService { |
| 40 | public function __construct(private object $client) { |
| 41 | } |
| 42 | |
| 43 | public function newClient(): object { |
| 44 | return $this->client; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | $result = (new ExternalHttpClient($service))->request('https://93.184.216.34/data'); |
| 49 | |
| 50 | $this->assertSame(200, $result['status']); |
| 51 | $this->assertSame('{"ok":true}', $result['body']); |
| 52 | $this->assertNull($result['error']); |
| 53 | $this->assertFalse($captured['options']['allow_redirects']); |
| 54 | $this->assertTrue($captured['options']['verify']); |
| 55 | $this->assertSame(10, $captured['options']['connect_timeout']); |
| 56 | $this->assertSame(60, $captured['options']['timeout']); |
| 57 | $this->assertArrayNotHasKey('stream', $captured['options']); |
| 58 | } |
| 59 | } |
nothing calls this directly
no outgoing calls
no test coverage detected