/** * Get export document action (day definite) * * @Method ("GET") * @Route ( * "/dd/export/{id}.{_format}", * name="wk_dhl_api_b2b_get_export_dd", * requirements={ * "id"="^\d{12}$", * "_format"="(xml|json|pdf)" * }, * defaults={ * "_format"="json" * } * ) * * @param Request $request * @return Response */ public function getExportDocDDAction(Request $request) { try { $shipmentNumber = new ShipmentNumberType($request->query->get('id')); $result = $this->connection->getExportDocDD($shipmentNumber); if ($request->query->get('_format') == 'pdf') { return new Response(base64_decode($result->ExportDocData->ExportDocPDFData), Response::HTTP_OK, array('content-type' => 'application/pdf')); } 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 getting an export document (DD) * * @param ShipmentNumberType $shipmentNumber * @param GetExportDocResponse $expectedResponse * @param Exception $expectedException * * @dataProvider provideGetExportDocData */ public function testGetExportDocDD(ShipmentNumberType $shipmentNumber, GetExportDocResponse $expectedResponse = null, Exception $expectedException = null) { if ($expectedException) { $this->clientWillThrowException($expectedException); // Fire the function which is to be tested $this->connection->getExportDocDD($shipmentNumber); } elseif ($expectedResponse) { // Stubbing $this->client->expects($this->any())->method('__soapCall')->willReturn($expectedResponse); // Fire the function which is to be tested $response = $this->connection->getExportDocDD($shipmentNumber); // 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); } }