/** * Create shipment action (day definite) * * @Method ("POST") * @Route ( * "/dd/shipment.{_format}", * name="wk_dhl_api_b2b_create_shipment_dd", * requirements={ * "_format"="(xml|json)" * }, * defaults={ * "_format"="json" * } * ) * * @param Request $request * @return Response */ public function createShipmentDDAction(Request $request) { try { $shipmentOrder = $this->serializer->deserialize($request->getContent(), 'Wk\\DhlApiBundle\\Model\\B2b\\ShipmentOrderDDType', 'json'); $result = $this->connection->createShipmentDD($shipmentOrder); 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 creating a shipment (DD) * * @param ShipmentOrderDDType $shipmentOrder * @param CreateShipmentResponse $expectedResponse * @param Exception $expectedException * * @dataProvider provideCreateShipmentDDData */ public function testCreateShipmentDD(ShipmentOrderDDType $shipmentOrder, CreateShipmentResponse $expectedResponse = null, Exception $expectedException = null) { if ($expectedException) { $this->clientWillThrowException($expectedException); // Fire the function which is to be tested $this->connection->createShipmentDD($shipmentOrder); } elseif ($expectedResponse) { // Stubbing $this->client->expects($this->any())->method('__soapCall')->willReturn($expectedResponse->toStdClass()); // Fire the function which is to be tested $response = $this->connection->createShipmentDD($shipmentOrder); // 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); } }