/** * Cancel pickup action * * @Method ("DELETE") * @Route ( * "/pickup/{id}.{_format}", * name="wk_dhl_api_b2b_cancel_pickup", * requirements={ * "id"="\d+", * "_format"="(xml|json)" * }, * defaults={ * "_format"="json" * } * ) * * @param Request $request * @return Response */ public function cancelPickupAction(Request $request) { try { $result = $this->connection->cancelPickup($request->query->get('id')); return $this->generateResponse($result); } catch (BadRequestHttpException $exception) { return $this->generateError($exception->getMessage(), $exception->getCode(), 400); } catch (\InvalidArgumentException $exception) { return $this->generateError($exception->getMessage(), 1001, 400); } catch (\Exception $exception) { return $this->generateError($exception->getMessage(), 1000); } }
/** * Tests canceling a pickup * * @param string $confirmationNumber * @param CancelPickupResponse $expectedResponse * @param Exception $expectedException * * @dataProvider provideCancelPickupData */ public function testCancelPickup($confirmationNumber, CancelPickupResponse $expectedResponse = null, Exception $expectedException = null) { if ($expectedException) { $this->clientWillThrowException($expectedException); // Fire the function which is to be tested $this->connection->cancelPickup($confirmationNumber); } elseif ($expectedResponse) { // Stubbing $this->client->expects($this->any())->method('__soapCall')->willReturn($expectedResponse); // Fire the function which is to be tested $response = $this->connection->cancelPickup($confirmationNumber); // check if the response has a status information with the expected status code $this->assertArrayHasKey('Status', $response); $this->assertArrayHasKey('StatusCode', $response['Status']); $this->assertSame($expectedResponse->toArray(), $response); } }