Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 2194d3e

Browse files
jhofmJens Schulze
authored andcommitted
feat(CustomObject): add CustomObjectByIdGetRequest
1 parent 7172e1c commit 2194d3e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @author @jenschude <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Request\CustomObjects;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Model\CustomObject\CustomObject;
10+
use Commercetools\Core\Request\AbstractByIdGetRequest;
11+
use Commercetools\Core\Response\ApiResponseInterface;
12+
use Commercetools\Core\Model\MapperInterface;
13+
14+
/**
15+
* @package Commercetools\Core\Request\CustomObjects
16+
* @method CustomObject mapResponse(ApiResponseInterface $response)
17+
* @method CustomObject mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
18+
*/
19+
class CustomObjectByIdGetRequest extends AbstractByIdGetRequest
20+
{
21+
protected $resultClass = CustomObject::class;
22+
23+
/**
24+
* @param string $id
25+
* @param Context $context
26+
*/
27+
public function __construct($id, Context $context = null)
28+
{
29+
parent::__construct(CustomObjectsEndpoint::endpoint(), $id, $context);
30+
}
31+
32+
/**
33+
* @param string $id
34+
* @param Context $context
35+
* @return static
36+
*/
37+
public static function ofId($id, Context $context = null)
38+
{
39+
return new static($id, $context);
40+
}
41+
}

tests/integration/CustomObject/CustomObjectQueryRequestTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Commercetools\Core\Error\ConcurrentModificationError;
1111
use Commercetools\Core\Model\CustomObject\CustomObject;
1212
use Commercetools\Core\Model\CustomObject\CustomObjectDraft;
13+
use Commercetools\Core\Request\CustomObjects\CustomObjectByIdGetRequest;
1314
use Commercetools\Core\Request\CustomObjects\CustomObjectByKeyGetRequest;
1415
use Commercetools\Core\Request\CustomObjects\CustomObjectCreateRequest;
1516
use Commercetools\Core\Request\CustomObjects\CustomObjectDeleteByKeyRequest;
@@ -140,7 +141,7 @@ public function testQuery()
140141
$this->assertSame($customObject->getId(), $result->getAt(0)->getId());
141142
}
142143

143-
public function testGetById()
144+
public function testGetByContainerAndKey()
144145
{
145146
$draft = $this->getDraft();
146147
$customObject = $this->createCustomObject($draft);
@@ -156,6 +157,21 @@ public function testGetById()
156157
$this->assertSame($customObject->getId(), $result->getId());
157158
}
158159

160+
public function testGetById()
161+
{
162+
$draft = $this->getDraft();
163+
$customObject = $this->createCustomObject($draft);
164+
165+
$request = CustomObjectByIdGetRequest::ofId(
166+
$customObject->getId()
167+
);
168+
$response = $request->executeWithClient($this->getClient());
169+
$result = $request->mapResponse($response);
170+
171+
$this->assertInstanceOf(CustomObject::class, $customObject);
172+
$this->assertSame($customObject->getId(), $result->getId());
173+
}
174+
159175
public function testDeleteByKey()
160176
{
161177
$draft = $this->getDraft();

tests/unit/Request/GenericByIdGetRequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Commercetools\Core\Model\Channel\Channel;
1212
use Commercetools\Core\Model\Customer\Customer;
1313
use Commercetools\Core\Model\CustomerGroup\CustomerGroup;
14+
use Commercetools\Core\Model\CustomObject\CustomObject;
1415
use Commercetools\Core\Model\DiscountCode\DiscountCode;
1516
use Commercetools\Core\Model\Inventory\InventoryEntry;
1617
use Commercetools\Core\Model\Message\Message;
@@ -31,6 +32,7 @@
3132
use Commercetools\Core\Request\Channels\ChannelByIdGetRequest;
3233
use Commercetools\Core\Request\CustomerGroups\CustomerGroupByIdGetRequest;
3334
use Commercetools\Core\Request\Customers\CustomerByIdGetRequest;
35+
use Commercetools\Core\Request\CustomObjects\CustomObjectByIdGetRequest;
3436
use Commercetools\Core\Request\DiscountCodes\DiscountCodeByIdGetRequest;
3537
use Commercetools\Core\Request\Inventory\InventoryByIdGetRequest;
3638
use Commercetools\Core\Request\Messages\MessageByIdGetRequest;
@@ -88,6 +90,10 @@ public function mapResultProvider()
8890
CustomerByIdGetRequest::class,
8991
Customer::class,
9092
],
93+
CustomObjectByIdGetRequest::class => [
94+
CustomObjectByIdGetRequest::class,
95+
CustomObject::class
96+
],
9197
DiscountCodeByIdGetRequest::class => [
9298
DiscountCodeByIdGetRequest::class,
9399
DiscountCode::class,

0 commit comments

Comments
 (0)