|
41 | 41 | use Firstred\PostNL\Entity\Response\GetLocationsInAreaResponse; |
42 | 42 | use Firstred\PostNL\Entity\Response\GetNearestLocationsResponse; |
43 | 43 | use Firstred\PostNL\Entity\Response\ResponseLocation; |
| 44 | +use Firstred\PostNL\Exception\CifException; |
44 | 45 | use Firstred\PostNL\HttpClient\MockHttpClient; |
45 | 46 | use Firstred\PostNL\PostNL; |
46 | 47 | use Firstred\PostNL\Service\LocationServiceInterface; |
|
56 | 57 | use Psr\Http\Message\RequestInterface; |
57 | 58 | use Psr\Http\Message\ResponseInterface; |
58 | 59 | use ReflectionObject; |
| 60 | + |
59 | 61 | use function file_get_contents; |
| 62 | + |
60 | 63 | use const _RESPONSES_DIR_; |
61 | 64 |
|
62 | 65 | /** |
@@ -320,6 +323,37 @@ public function testGetLocationRest($response) |
320 | 323 | $this->assertEquals(expected: '161503', actual: $result->getLocationCode()); |
321 | 324 | } |
322 | 325 |
|
| 326 | + /** @throws */ |
| 327 | + #[TestDox(text: 'can handle HTTP 400 error response correctly')] |
| 328 | + public function testHttp400Error(): void |
| 329 | + { |
| 330 | + $response = PsrMessage::parseResponse(message: file_get_contents(filename: _RESPONSES_DIR_.'/rest/location/nearestlocationsbypostcode-error400.http')); |
| 331 | + |
| 332 | + $mock = new MockHandler(queue: [$response]); |
| 333 | + $handler = HandlerStack::create(handler: $mock); |
| 334 | + $mockClient = new MockHttpClient(); |
| 335 | + $mockClient->setHandler(handler: $handler); |
| 336 | + $this->postnl->setHttpClient(httpClient: $mockClient); |
| 337 | + |
| 338 | + $this->expectException(exception: CifException::class); |
| 339 | + $this->expectExceptionMessage(message: 'Request format is invalid'); |
| 340 | + |
| 341 | + $this->postnl->getNearestLocations(getNearestLocations: (new GetNearestLocations()) |
| 342 | + ->setCountrycode(Countrycode: 'NL') |
| 343 | + ->setLocation(Location: new Location( |
| 344 | + Postalcode: '0000AB', |
| 345 | + AllowSundaySorting: true, |
| 346 | + DeliveryDate: '29-06-2016', |
| 347 | + DeliveryOptions: ['PG', 'PGE'], |
| 348 | + OpeningTime: '09:00:00', |
| 349 | + Options: ['Daytime'], |
| 350 | + City: 'Hoofddorp', |
| 351 | + Street: 'Siriusdreef', |
| 352 | + HouseNr: '42', |
| 353 | + HouseNrExt: 'A', |
| 354 | + ))); |
| 355 | + } |
| 356 | + |
323 | 357 | /** |
324 | 358 | * @return array[] |
325 | 359 | */ |
|
0 commit comments