diff --git a/src/modules/mo/mo_dhl/Configurator.php b/src/modules/mo/mo_dhl/Configurator.php index 7eabf125..5b3ecca4 100644 --- a/src/modules/mo/mo_dhl/Configurator.php +++ b/src/modules/mo/mo_dhl/Configurator.php @@ -359,7 +359,7 @@ public function buildGKV(LoggerInterface $logger = null) * @param LoggerInterface $logger * @return Api\ParcelShipping\Client */ - public function buildParcelShipping(LoggerInterface $logger): \Mediaopt\DHL\Api\ParcelShipping\Client + public function buildParcelShipping(LoggerInterface $logger = null): \Mediaopt\DHL\Api\ParcelShipping\Client { $credentials = $this->buildParcelShippingCredentials(); @@ -368,7 +368,7 @@ public function buildParcelShipping(LoggerInterface $logger): \Mediaopt\DHL\Api\ $apiKeyAuthentication = new ApiKeyAuthentication($credentials->getAdditionalFields()['api-key']); $basicAuthentication = new BasicAuthAuthentication($credentials->getUsername(), $credentials->getPassword()); - $loggingPlugin = new class($logger) implements Plugin { + $loggingPlugin = new class($logger ?: $this->buildLogger()) implements Plugin { private $logger; public function __construct(LoggerInterface $logger) diff --git a/tests/Api/GKV/BaseGKVTest.php b/tests/Api/GKV/BaseGKVTest.php index 57912d73..d7d08550 100644 --- a/tests/Api/GKV/BaseGKVTest.php +++ b/tests/Api/GKV/BaseGKVTest.php @@ -7,6 +7,7 @@ namespace sdk\GKV; +use Mediaopt\DHL\Api\GKV\CommunicationType; use Mediaopt\DHL\Api\GKV\CountryType; use Mediaopt\DHL\Api\GKV\NameType; use Mediaopt\DHL\Api\GKV\NativeAddressTypeNew; @@ -30,11 +31,11 @@ class BaseGKVTest extends TestCase { /** - * @return \Mediaopt\DHL\Api\GKV + * @return \Mediaopt\DHL\Api\ParcelShipping\Client */ - protected function buildGKV() + protected function buildParcelShipping() { - return (new \TestConfigurator())->buildGKV(); + return (new \TestConfigurator())->buildParcelShipping(); } /** @@ -51,9 +52,10 @@ protected function getUniqueShipmentId() */ protected function createShipmentToGermany($product = 'V01PAK'): Shipment { - $gkv = $this->buildGKV(); - $ShipmentDetails = new ShipmentDetailsTypeType($product, new BillingNumber(Ekp::build($gkv->getSoapCredentials()->getEkp()), Process::build(Process::PAKET), Participation::build('01')), (new \DateTime())->format('Y-m-d'), new ShipmentItemType(12)); - $Receiver = (new ReceiverType('a b'))->setAddress(new ReceiverNativeAddressType(null, null, 'Elbestr.', '28/29', '12045', 'Berlin', null, new CountryType('DE'))); + $ShipmentDetails = new ShipmentDetailsTypeType($product, new BillingNumber(Ekp::build('3333333333'), Process::build(Process::PAKET), Participation::build('01')), (new \DateTime())->format('Y-m-d'), new ShipmentItemType(12)); + $Receiver = (new ReceiverType('a b')) + ->setAddress(new ReceiverNativeAddressType(null, null, 'Elbestr.', '28/29', '12045', 'Berlin', null, new CountryType('DE'))) + ->setCommunication((new CommunicationType())->setContactPerson('a b')->setEmail('a@b.de')->setPhone('030123')); $Shipper = (new ShipperType(new NameType('a b', null, null), new NativeAddressTypeNew('Elbestr.', '28', '12045', 'Berlin', new CountryType('DE')))); $shipment = new Shipment($ShipmentDetails, $Shipper, $Receiver); return $shipment; diff --git a/tests/Api/GKV/CreateShipmentOrderTest.php b/tests/Api/GKV/CreateShipmentOrderTest.php index 58a60981..3d8cec67 100644 --- a/tests/Api/GKV/CreateShipmentOrderTest.php +++ b/tests/Api/GKV/CreateShipmentOrderTest.php @@ -9,10 +9,12 @@ require_once 'BaseGKVTest.php'; +use Mediaopt\DHL\Adapter\ParcelShippingConverter; use Mediaopt\DHL\Api\GKV\CreateShipmentOrderRequest; -use Mediaopt\DHL\Api\GKV\CreateShipmentOrderResponse; use Mediaopt\DHL\Api\GKV\ShipmentOrderType; use Mediaopt\DHL\Api\GKV\Version; +use Mediaopt\DHL\Api\MyAccount\Runtime\Client\Client; +use Psr\Http\Message\ResponseInterface; /** * @author Mediaopt GmbH @@ -25,9 +27,12 @@ public function testCreateShipment() $shipment = $this->createShipmentToGermany(); $shipmentOrder = new ShipmentOrderType('123', $shipment); $request = new CreateShipmentOrderRequest(new Version(3, 4, 0), $shipmentOrder); - $response = $this->buildGKV()->createShipmentOrder($request); - $this->assertInstanceOf(CreateShipmentOrderResponse::class, $response); - $this->assertEquals(0, $response->getStatus()->getStatusCode(), implode(', ', $response->getCreationState()[0]->getLabelData()->getStatus()->getStatusMessage())); + $converter = new ParcelShippingConverter(); + [$query, $request] = $converter->convertCreateShipmentOrderRequest($request); + $response = $this->buildParcelShipping()->createOrders($request, $query, [], Client::FETCH_RESPONSE); + $this->assertInstanceOf(ResponseInterface::class, $response); + $payload = \json_decode($response->getBody(), true); + $this->assertEquals(200, $response->getStatusCode(), $payload['status']['detail']); } public function testCreateShipmentOutsideGermany() @@ -35,10 +40,14 @@ public function testCreateShipmentOutsideGermany() $shipment = $this->createShipmentToAustria(); $shipmentOrder = new ShipmentOrderType('123', $shipment); $request = new CreateShipmentOrderRequest(new Version(3, 4, 0), $shipmentOrder); - $response = $this->buildGKV()->createShipmentOrder($request); - $this->assertInstanceOf(CreateShipmentOrderResponse::class, $response); - $this->assertEquals(1101, $response->getStatus()->getStatusCode(), $response->getStatus()->getStatusText()); - $this->assertContains('Das angegebene Produkt ist für das Land nicht verfügbar.', $response->getCreationState()[0]->getLabelData()->getStatus()->getStatusMessage()); + $converter = new ParcelShippingConverter(); + [$query, $request] = $converter->convertCreateShipmentOrderRequest($request); + $response = $this->buildParcelShipping()->createOrders($request, $query, [], Client::FETCH_RESPONSE); + $this->assertInstanceOf(ResponseInterface::class, $response); + $body = $response->getBody()->getContents(); + $payload = \json_decode($body, true); + $this->assertEquals(400, $response->getStatusCode(), $payload['status']['detail']); + $this->assertContains('The product entered is not available for this country.', $body); } } diff --git a/tests/Api/GKV/GetLabelTest.php b/tests/Api/GKV/GetLabelTest.php index c3c2fc11..3a428921 100644 --- a/tests/Api/GKV/GetLabelTest.php +++ b/tests/Api/GKV/GetLabelTest.php @@ -9,9 +9,6 @@ require_once 'BaseGKVTest.php'; -use Mediaopt\DHL\Api\GKV\GetLabelRequest; -use Mediaopt\DHL\Api\GKV\GetLabelResponse; - /** * @author Mediaopt GmbH */ @@ -20,12 +17,10 @@ class GetLabelTest extends BaseGKVTest public function testGetLabelForIncorrectShipment() { - $gkv = $this->buildGKV(); - $request = new GetLabelRequest($this->createVersion(), $this->getUniqueShipmentId(), null, null, null, null, null); - $response = $gkv->getLabel($request); - $this->assertInstanceOf(GetLabelResponse::class, $response); - $this->assertEquals(2000, $response->getStatus()->getStatusCode()); - $this->assertEquals(2000, $response->getLabelData()[0]->getStatus()->getStatusCode()); - $this->assertNull($response->getLabelData()[0]->getLabelUrl()); + $gkv = $this->buildParcelShipping(); + $response = $gkv->getLabel([ + 'token' => $this->getUniqueShipmentId(), + ]); + $this->assertNull($response); } } diff --git a/tests/Api/GKV/GetManifestTest.php b/tests/Api/GKV/GetManifestTest.php deleted file mode 100644 index 451613e9..00000000 --- a/tests/Api/GKV/GetManifestTest.php +++ /dev/null @@ -1,48 +0,0 @@ -createVersion(), (new \DateTime())->format('Y-m-d')); - $response = $this->buildGKV()->getManifest($request); - $this->assertInstanceOf(GetManifestResponse::class, $response); - $this->assertNotFalse(base64_decode($response->getManifestData())); - $this->assertEquals(0, $response->getStatus()->getStatusCode()); - } - - public function testGetManifestForLastWeek() - { - $manifestDate = (new \DateTime('-7 days'))->format('Y-m-d'); - $request = new GetManifestRequest($this->createVersion(), $manifestDate); - $response = $this->buildGKV()->getManifest($request); - $this->assertInstanceOf(GetManifestResponse::class, $response); - $this->assertNotFalse(base64_decode($response->getManifestData())); - $this->assertEquals(0, $response->getStatus()->getStatusCode()); - } - - public function testGetManifestForNextWeek() - { - $manifestDate = (new \DateTime('+7 days'))->format('Y-m-d'); - $request = new GetManifestRequest($this->createVersion(), $manifestDate); - $response = $this->buildGKV()->getManifest($request); - $this->assertInstanceOf(GetManifestResponse::class, $response); - $this->assertGreaterThan(0, $response->getStatus()->getStatusCode()); - } -} diff --git a/tests/Api/GKV/GetVersionTest.php b/tests/Api/GKV/GetVersionTest.php deleted file mode 100644 index df05439a..00000000 --- a/tests/Api/GKV/GetVersionTest.php +++ /dev/null @@ -1,30 +0,0 @@ -buildGKV(); - $response = $gkv->getVersion($this->createVersion()); - $this->assertInstanceOf(GetVersionResponse::class, $response); - $this->assertInstanceOf(Version::class, $response->getVersion()); - $this->assertEquals(3, $response->getVersion()->getMajorRelease()); - $this->assertEquals(0, $response->getVersion()->getMinorRelease()); - } -} diff --git a/tests/Api/GKV/ValidateShipmentTest.php b/tests/Api/GKV/ValidateShipmentTest.php index 4d77dc33..109bc130 100644 --- a/tests/Api/GKV/ValidateShipmentTest.php +++ b/tests/Api/GKV/ValidateShipmentTest.php @@ -9,10 +9,11 @@ require_once 'BaseGKVTest.php'; +use Mediaopt\DHL\Adapter\ParcelShippingConverter; use Mediaopt\DHL\Api\GKV\CountryType; use Mediaopt\DHL\Api\GKV\ValidateShipmentOrderRequest; use Mediaopt\DHL\Api\GKV\ValidateShipmentOrderType; -use Mediaopt\DHL\Api\GKV\ValidateShipmentResponse; +use Psr\Http\Message\ResponseInterface; /** * @author Mediaopt GmbH @@ -25,9 +26,12 @@ public function testValidateShipment() $shipment = $this->createShipmentToGermany(); $shipmentOrder = new ValidateShipmentOrderType('123', $shipment); $request = new ValidateShipmentOrderRequest($this->createVersion(), $shipmentOrder); - $response = $this->buildGKV()->validateShipment($request); - $this->assertInstanceOf(ValidateShipmentResponse::class, $response); - $this->assertEquals(0, $response->getStatus()->getStatusCode(), $response->getStatus()->getStatusText()); + $converter = new ParcelShippingConverter(); + [$query, $request] = $converter->convertValidateShipmentOrderRequest($request); + $response = $this->buildParcelShipping()->createOrders($request, $query, [], \Mediaopt\DHL\Api\MyAccount\Runtime\Client\Client::FETCH_RESPONSE); + $this->assertInstanceOf(ResponseInterface::class, $response); + $payload = \json_decode($response->getBody(), true); + $this->assertEquals(200, $response->getStatusCode(), $payload['status']['detail']); } public function testValidateShipmentOutsideGermany() @@ -36,10 +40,14 @@ public function testValidateShipmentOutsideGermany() $shipment->getReceiver()->getAddress()->setOrigin(new CountryType('AT')); $shipmentOrder = new ValidateShipmentOrderType('123', $shipment); $request = new ValidateShipmentOrderRequest($this->createVersion(), $shipmentOrder); - $response = $this->buildGKV()->validateShipment($request); - $this->assertInstanceOf(ValidateShipmentResponse::class, $response); - $this->assertEquals(1101, $response->getStatus()->getStatusCode(), $response->getStatus()->getStatusText()); - $this->assertContains('Das angegebene Produkt ist für das Land nicht verfügbar.', $response->getValidationState()[0]->getStatus()->getStatusMessage(), implode(', ', $response->getValidationState()[0]->getStatus()->getStatusMessage())); + $converter = new ParcelShippingConverter(); + [$query, $request] = $converter->convertValidateShipmentOrderRequest($request); + $response = $this->buildParcelShipping()->createOrders($request, $query, [], \Mediaopt\DHL\Api\MyAccount\Runtime\Client\Client::FETCH_RESPONSE); + $this->assertInstanceOf(ResponseInterface::class, $response); + $body = $response->getBody()->getContents(); + $payload = \json_decode($body, true); + $this->assertEquals(400, $response->getStatusCode(), $payload['status']['detail']); + $this->assertContains('The product entered is not available for this country.', $body); } public function testValidateShipmentForYesterday() @@ -48,9 +56,13 @@ public function testValidateShipmentForYesterday() $shipment->getShipmentDetails()->setShipmentDate((new \DateTime('-1 day'))->format('Y-m-d')); $shipmentOrder = new ValidateShipmentOrderType('123', $shipment); $request = new ValidateShipmentOrderRequest($this->createVersion(), $shipmentOrder); - $response = $this->buildGKV()->validateShipment($request); - $this->assertInstanceOf(ValidateShipmentResponse::class, $response); - $this->assertEquals(1101, $response->getStatus()->getStatusCode(), $response->getStatus()->getStatusText()); - $this->assertContains('Bitte geben Sie ein gültiges Sendungsdatum an.', $response->getValidationState()[0]->getStatus()->getStatusMessage(), implode(', ', $response->getValidationState()[0]->getStatus()->getStatusMessage())); + $converter = new ParcelShippingConverter(); + [$query, $request] = $converter->convertValidateShipmentOrderRequest($request); + $response = $this->buildParcelShipping()->createOrders($request, $query, [], \Mediaopt\DHL\Api\MyAccount\Runtime\Client\Client::FETCH_RESPONSE); + $this->assertInstanceOf(ResponseInterface::class, $response); + $body = $response->getBody()->getContents(); + $payload = \json_decode($body, true); + $this->assertEquals(400, $response->getStatusCode(), $payload['status']['detail']); + $this->assertContains('Please enter a valid shipping date.', $body); } } diff --git a/tests/TestConfigurator.php b/tests/TestConfigurator.php index e4d34598..4826f139 100644 --- a/tests/TestConfigurator.php +++ b/tests/TestConfigurator.php @@ -117,7 +117,7 @@ protected function getStandortsuchePassword() */ protected function getEkp() { - return '2222222222'; + return '3333333333'; } /**