|
22 | 22 |
|
23 | 23 | class MockHttpClientTest extends HttpClientTestCase
|
24 | 24 | {
|
| 25 | + /** |
| 26 | + * @dataProvider validResponseFactoryProvider |
| 27 | + */ |
| 28 | + public function testValidResponseFactory($responseFactory) |
| 29 | + { |
| 30 | + (new MockHttpClient($responseFactory))->request('GET', 'https://foo.bar'); |
| 31 | + |
| 32 | + $this->addToAssertionCount(1); |
| 33 | + } |
| 34 | + |
| 35 | + public function validResponseFactoryProvider() |
| 36 | + { |
| 37 | + return [ |
| 38 | + [static function (): MockResponse { return new MockResponse(); }], |
| 39 | + [new MockResponse()], |
| 40 | + [[new MockResponse()]], |
| 41 | + [new \ArrayIterator([new MockResponse()])], |
| 42 | + [null], |
| 43 | + [(static function (): \Generator { yield new MockResponse(); })()], |
| 44 | + ]; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @dataProvider invalidResponseFactoryProvider |
| 49 | + */ |
| 50 | + public function testInvalidResponseFactory($responseFactory, string $expectedExceptionMessage) |
| 51 | + { |
| 52 | + $this->expectException(TransportException::class); |
| 53 | + $this->expectExceptionMessage($expectedExceptionMessage); |
| 54 | + |
| 55 | + (new MockHttpClient($responseFactory))->request('GET', 'https://foo.bar'); |
| 56 | + } |
| 57 | + |
| 58 | + public function invalidResponseFactoryProvider() |
| 59 | + { |
| 60 | + return [ |
| 61 | + [static function (): \Generator { yield new MockResponse(); }, 'The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "Generator" given.'], |
| 62 | + [static function (): array { return [new MockResponse()]; }, 'The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "array" given.'], |
| 63 | + [(static function (): \Generator { yield 'ccc'; })(), 'The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "string" given.'], |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
25 | 67 | protected function getHttpClient(string $testCase): HttpClientInterface
|
26 | 68 | {
|
27 | 69 | $responses = [];
|
|
0 commit comments