|
| 1 | +<?php |
| 2 | +declare (strict_types = 1); |
| 3 | +namespace ModusCreate\Test\Integration; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use GuzzleHttp\Client; |
| 7 | +use GuzzleHttp\Psr7\Request; |
| 8 | + |
| 9 | +class HTTPRequestTest extends TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var Client |
| 13 | + */ |
| 14 | + private $client; |
| 15 | + |
| 16 | + public function setUp() |
| 17 | + { |
| 18 | + $this->client = new Client; |
| 19 | + parent::setUp(); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @dataProvider requestProvider |
| 24 | + * |
| 25 | + * @param Request $request |
| 26 | + * @param string $expected |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function testEndpointSucceeds(Request $request, string $expected) |
| 30 | + { |
| 31 | + $actual = $this->client->send($request); |
| 32 | + $this->assertEquals($expected, (string)$actual->getBody()); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @return void |
| 37 | + */ |
| 38 | + public function requestProvider() : array |
| 39 | + { |
| 40 | + $notFoundResponse = file_get_contents(__DIR__ . '/../fixtures/notFound.json'); |
| 41 | + |
| 42 | + return [ |
| 43 | + [ |
| 44 | + new Request('GET', 'http://app:8000/vehicles/2015/Audi/A3'), |
| 45 | + file_get_contents(__DIR__ . '/../fixtures/2015AudiA3.json') |
| 46 | + ], |
| 47 | + [ |
| 48 | + new Request('GET', 'http://app:8000/vehicles/2015/Toyota/Yaris'), |
| 49 | + file_get_contents(__DIR__ . '/../fixtures/2015ToyotaYaris.json') |
| 50 | + ], |
| 51 | + [ |
| 52 | + new Request('GET', 'http://app:8000/vehicles/2015/Ford/Crown%20Victoria'), |
| 53 | + $notFoundResponse |
| 54 | + ], |
| 55 | + [ |
| 56 | + new Request('GET', 'http://app:8000/vehicles/undefined/Ford/Fusion'), |
| 57 | + $notFoundResponse |
| 58 | + ] |
| 59 | + ]; |
| 60 | + } |
| 61 | +} |
0 commit comments