From 76b18bc8b742b10ad3d83d49a0058702555c43e4 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 26 Oct 2016 11:39:31 +0200 Subject: [PATCH] fix(ShippingMethod): fix response object class of shipping method request by cart or location --- .../ShippingMethodByCartIdGetRequest.php | 3 ++- .../ShippingMethodByLocationGetRequest.php | 3 ++- .../ShippingMethodQueryRequestTest.php | 13 +++++++++++++ .../ShippingMethodByCartIdGetRequestTest.php | 2 +- .../ShippingMethodByLocationGetRequestTest.php | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Request/ShippingMethods/ShippingMethodByCartIdGetRequest.php b/src/Request/ShippingMethods/ShippingMethodByCartIdGetRequest.php index 9d94e36314..c34e43a059 100644 --- a/src/Request/ShippingMethods/ShippingMethodByCartIdGetRequest.php +++ b/src/Request/ShippingMethods/ShippingMethodByCartIdGetRequest.php @@ -5,6 +5,7 @@ namespace Commercetools\Core\Request\ShippingMethods; +use Commercetools\Core\Response\ResourceResponse; use Psr\Http\Message\ResponseInterface; use Commercetools\Core\Client\HttpMethod; use Commercetools\Core\Client\HttpRequest; @@ -74,6 +75,6 @@ public function httpRequest() */ public function buildResponse(ResponseInterface $response) { - return new PagedQueryResponse($response, $this, $this->getContext()); + return new ResourceResponse($response, $this, $this->getContext()); } } diff --git a/src/Request/ShippingMethods/ShippingMethodByLocationGetRequest.php b/src/Request/ShippingMethods/ShippingMethodByLocationGetRequest.php index fc33ec0a2e..de94559f8a 100644 --- a/src/Request/ShippingMethods/ShippingMethodByLocationGetRequest.php +++ b/src/Request/ShippingMethods/ShippingMethodByLocationGetRequest.php @@ -5,6 +5,7 @@ namespace Commercetools\Core\Request\ShippingMethods; +use Commercetools\Core\Response\ResourceResponse; use Psr\Http\Message\ResponseInterface; use Commercetools\Core\Client\HttpMethod; use Commercetools\Core\Client\HttpRequest; @@ -102,6 +103,6 @@ public function httpRequest() */ public function buildResponse(ResponseInterface $response) { - return new PagedQueryResponse($response, $this, $this->getContext()); + return new ResourceResponse($response, $this, $this->getContext()); } } diff --git a/tests/integration/ShippingMethod/ShippingMethodQueryRequestTest.php b/tests/integration/ShippingMethod/ShippingMethodQueryRequestTest.php index 500c08d78d..f5082d71f5 100644 --- a/tests/integration/ShippingMethod/ShippingMethodQueryRequestTest.php +++ b/tests/integration/ShippingMethod/ShippingMethodQueryRequestTest.php @@ -14,6 +14,7 @@ use Commercetools\Core\Model\ShippingMethod\ZoneRate; use Commercetools\Core\Model\ShippingMethod\ZoneRateCollection; use Commercetools\Core\Request\ShippingMethods\ShippingMethodByIdGetRequest; +use Commercetools\Core\Request\ShippingMethods\ShippingMethodByLocationGetRequest; use Commercetools\Core\Request\ShippingMethods\ShippingMethodCreateRequest; use Commercetools\Core\Request\ShippingMethods\ShippingMethodDeleteRequest; use Commercetools\Core\Request\ShippingMethods\ShippingMethodQueryRequest; @@ -81,6 +82,18 @@ public function testGetById() $this->assertInstanceOf('\Commercetools\Core\Model\ShippingMethod\ShippingMethod', $shippingMethod); $this->assertSame($shippingMethod->getId(), $result->getId()); + } + + public function testByLocation() + { + $draft = $this->getDraft(); + $shippingMethod = $this->createShippingMethod($draft); + + $request = ShippingMethodByLocationGetRequest::ofCountry('DE')->withState($this->getRegion()); + $response = $request->executeWithClient($this->getClient()); + $result = $request->mapResponse($response); + $this->assertInstanceOf('\Commercetools\Core\Model\ShippingMethod\ShippingMethodCollection', $result); + $this->assertSame($shippingMethod->getId(), $result->current()->getId()); } } diff --git a/tests/unit/Request/ShippingMethods/ShippingMethodByCartIdGetRequestTest.php b/tests/unit/Request/ShippingMethods/ShippingMethodByCartIdGetRequestTest.php index 77799b6fa2..105216d091 100644 --- a/tests/unit/Request/ShippingMethods/ShippingMethodByCartIdGetRequestTest.php +++ b/tests/unit/Request/ShippingMethods/ShippingMethodByCartIdGetRequestTest.php @@ -58,6 +58,6 @@ public function testBuildResponse() $request = ShippingMethodByCartIdGetRequest::ofCartId('id'); $response = $request->buildResponse($guzzleResponse); - $this->assertInstanceOf('\Commercetools\Core\Response\PagedQueryResponse', $response); + $this->assertInstanceOf('\Commercetools\Core\Response\ResourceResponse', $response); } } diff --git a/tests/unit/Request/ShippingMethods/ShippingMethodByLocationGetRequestTest.php b/tests/unit/Request/ShippingMethods/ShippingMethodByLocationGetRequestTest.php index ad826b1c44..1c545a8a4a 100644 --- a/tests/unit/Request/ShippingMethods/ShippingMethodByLocationGetRequestTest.php +++ b/tests/unit/Request/ShippingMethods/ShippingMethodByLocationGetRequestTest.php @@ -82,6 +82,6 @@ public function testBuildResponse() $request = ShippingMethodByLocationGetRequest::ofCountry('DE'); $response = $request->buildResponse($guzzleResponse); - $this->assertInstanceOf('\Commercetools\Core\Response\PagedQueryResponse', $response); + $this->assertInstanceOf('\Commercetools\Core\Response\ResourceResponse', $response); } }