Esempio n. 1
0
 /**
  * Update shipment action (day definite)
  *
  * @Method ("PUT")
  * @Route (
  *      "/dd/shipment/{id}.{_format}",
  *      name="wk_dhl_api_b2b_update_shipment_dd",
  *      requirements={
  *          "id"="^\d{12}$",
  *          "_format"="(xml|json)"
  *      },
  *      defaults={
  *          "_format"="json"
  *      }
  * )
  *
  * @param Request $request
  * @return Response
  */
 public function updateShipmentDDAction(Request $request)
 {
     try {
         $shipmentNumber = new ShipmentNumberType($request->query->get('id'));
         $shipmentOrder = $this->serializer->deserialize($request->getContent(), 'Wk\\DhlApiBundle\\Model\\B2b\\ShipmentOrderDDType', 'json');
         $result = $this->connection->updateShipmentDD($shipmentNumber, $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);
     }
 }
Esempio n. 2
0
 /**
  * Tests updating a shipment (DD)
  *
  * @param ShipmentNumberType     $shipmentNumber
  * @param ShipmentOrderDDType    $shipmentOrder
  * @param UpdateShipmentResponse $expectedResponse
  * @param Exception              $expectedException
  *
  * @dataProvider provideUpdateShipmentDDData
  */
 public function testUpdateShipmentDD(ShipmentNumberType $shipmentNumber, ShipmentOrderDDType $shipmentOrder, UpdateShipmentResponse $expectedResponse = null, Exception $expectedException = null)
 {
     if ($expectedException) {
         $this->clientWillThrowException($expectedException);
         // Fire the function which is to be tested
         $this->connection->updateShipmentDD($shipmentNumber, $shipmentOrder);
     } elseif ($expectedResponse) {
         // Stubbing
         $this->client->expects($this->any())->method('__soapCall')->willReturn($expectedResponse);
         // Fire the function which is to be tested
         $response = $this->connection->updateShipmentDD($shipmentNumber, $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);
     }
 }