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

Commit 3f2d2ed

Browse files
author
Jens Schulze
committed
Merge branch 'hotfix/v1.3.1'
2 parents 4f8f850 + 522127d commit 3f2d2ed

File tree

6 files changed

+104
-9
lines changed

6 files changed

+104
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="1.3.1"></a>
2+
## [1.3.1](https://github.com/sphereio/commercetools-php-sdk/compare/v1.3.0...v1.3.1) (2016-08-30)
3+
4+
5+
### Bug Fixes
6+
7+
* **CustomObject:** add version to custom object draft ([4963073](https://github.com/sphereio/commercetools-php-sdk/commit/4963073)), closes [#249](https://github.com/sphereio/commercetools-php-sdk/issues/249)
8+
9+
10+
111
<a name="1.3.0"></a>
212
# [1.3.0](https://github.com/sphereio/commercetools-php-sdk/compare/v1.2.3...v1.3.0) (2016-08-10)
313

src/AbstractHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
abstract class AbstractHttpClient
1616
{
17-
const VERSION = '1.3.0';
17+
const VERSION = '1.3.1';
1818

1919
/**
2020
* @var AdapterInterface

src/Model/CustomObject/CustomObjectDraft.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
use Commercetools\Core\Model\Common\Context;
99
use Commercetools\Core\Model\Common\JsonObject;
10-
use Commercetools\Core\Model\Common\Resource;
11-
use Commercetools\Core\Model\Common\DateTimeDecorator;
1210

1311
/**
1412
* @package Commercetools\Core\Model\CustomObject
@@ -19,12 +17,15 @@
1917
* @method CustomObjectDraft setKey(string $key = null)
2018
* @method mixed getValue()
2119
* @method CustomObjectDraft setValue($value = null)
20+
* @method int getVersion()
21+
* @method CustomObjectDraft setVersion(int $version = null)
2222
*/
2323
class CustomObjectDraft extends JsonObject
2424
{
2525
public function fieldDefinitions()
2626
{
2727
return [
28+
'version' => [static::TYPE => 'int'],
2829
'container' => [static::TYPE => 'string'],
2930
'key' => [static::TYPE => 'string'],
3031
'value' => [],

src/Request/CustomObjects/CustomObjectCreateRequest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace Commercetools\Core\Request\CustomObjects;
77

8+
use Commercetools\Core\Error\InvalidArgumentException;
89
use Commercetools\Core\Model\Common\Context;
910
use Commercetools\Core\Model\CustomObject\CustomObject;
1011
use Commercetools\Core\Model\CustomObject\CustomObjectDraft;
@@ -21,20 +22,23 @@ class CustomObjectCreateRequest extends AbstractCreateRequest
2122
protected $resultClass = '\Commercetools\Core\Model\CustomObject\CustomObject';
2223

2324
/**
24-
* @param CustomObjectDraft $customObject
25+
* @param CustomObjectDraft|CustomObject $customObject
2526
* @param Context $context
2627
*/
27-
public function __construct(CustomObjectDraft $customObject, Context $context = null)
28+
public function __construct($customObject, Context $context = null)
2829
{
30+
if (!($customObject instanceof CustomObject || $customObject instanceof CustomObjectDraft)) {
31+
throw new InvalidArgumentException();
32+
}
2933
parent::__construct(CustomObjectsEndpoint::endpoint(), $customObject, $context);
3034
}
3135

3236
/**
33-
* @param CustomObjectDraft $customObject
37+
* @param CustomObjectDraft|CustomObject $customObject
3438
* @param Context $context
3539
* @return static
3640
*/
37-
public static function ofObject(CustomObjectDraft $customObject, Context $context = null)
41+
public static function ofObject($customObject, Context $context = null)
3842
{
3943
return new static($customObject, $context);
4044
}

tests/integration/CustomObject/CustomObjectQueryRequestTest.php

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Commercetools\Core\CustomObject;
88

99
use Commercetools\Core\ApiTestCase;
10+
use Commercetools\Core\Error\ConcurrentModificationError;
11+
use Commercetools\Core\Model\CustomObject\CustomObject;
1012
use Commercetools\Core\Model\CustomObject\CustomObjectDraft;
1113
use Commercetools\Core\Request\CustomObjects\CustomObjectByKeyGetRequest;
1214
use Commercetools\Core\Request\CustomObjects\CustomObjectCreateRequest;
@@ -36,14 +38,92 @@ protected function createCustomObject(CustomObjectDraft $draft)
3638
$response = $request->executeWithClient($this->getClient());
3739
$customObject = $request->mapResponse($response);
3840

39-
$this->cleanupRequests[] = CustomObjectDeleteRequest::ofIdAndVersion(
41+
$this->cleanupRequests[] = $this->deleteRequest = CustomObjectDeleteRequest::ofIdAndVersion(
4042
$customObject->getId(),
4143
$customObject->getVersion()
4244
);
4345

4446
return $customObject;
4547
}
4648

49+
public function testCustomObjectWithVersion()
50+
{
51+
$draft = $this->getDraft();
52+
$customObject = $this->createCustomObject($draft);
53+
54+
$request = CustomObjectCreateRequest::ofObject($customObject);
55+
$response = $request->executeWithClient($this->getClient());
56+
$result = $request->mapResponse($response);
57+
$this->deleteRequest->setVersion($result->getVersion());
58+
59+
$this->assertNotSame($customObject->getVersion(), $result->getVersion());
60+
}
61+
62+
public function testCustomObjectWithVersionConflict()
63+
{
64+
$draft = $this->getDraft();
65+
$customObject = $this->createCustomObject($draft);
66+
67+
$request = CustomObjectCreateRequest::ofObject($customObject);
68+
$response = $request->executeWithClient($this->getClient());
69+
$result = $request->mapResponse($response);
70+
$this->deleteRequest->setVersion($result->getVersion());
71+
72+
$this->assertNotSame($customObject->getVersion(), $result->getVersion());
73+
74+
$request = CustomObjectCreateRequest::ofObject($customObject);
75+
$response = $request->executeWithClient($this->getClient());
76+
77+
$this->assertTrue($response->isError());
78+
$this->assertInstanceOf(
79+
'\Commercetools\Core\Error\ConcurrentModificationError',
80+
$response->getErrors()->getByCode(ConcurrentModificationError::CODE)
81+
);
82+
}
83+
84+
public function testCustomObjectDraftWithVersionConflict()
85+
{
86+
$draft = $this->getDraft();
87+
$customObject = $this->createCustomObject($draft);
88+
89+
$request = CustomObjectCreateRequest::ofObject($draft);
90+
$response = $request->executeWithClient($this->getClient());
91+
$result = $request->mapResponse($response);
92+
$this->deleteRequest->setVersion($result->getVersion());
93+
94+
$this->assertNotSame($customObject->getVersion(), $result->getVersion());
95+
96+
$draft->setVersion($customObject->getVersion());
97+
$request = CustomObjectCreateRequest::ofObject($draft);
98+
$response = $request->executeWithClient($this->getClient());
99+
100+
$this->assertTrue($response->isError());
101+
$this->assertInstanceOf(
102+
'\Commercetools\Core\Error\ConcurrentModificationError',
103+
$response->getErrors()->getByCode(ConcurrentModificationError::CODE)
104+
);
105+
}
106+
107+
public function testValidTypes()
108+
{
109+
$this->assertInstanceOf(
110+
'\Commercetools\Core\Request\CustomObjects\CustomObjectCreateRequest',
111+
CustomObjectCreateRequest::ofObject(CustomObject::of())
112+
);
113+
$this->assertInstanceOf(
114+
'\Commercetools\Core\Request\CustomObjects\CustomObjectCreateRequest',
115+
CustomObjectCreateRequest::ofObject(CustomObjectDraft::of())
116+
);
117+
}
118+
119+
/**
120+
* @expectedException \InvalidArgumentException
121+
*/
122+
public function testInvalidType()
123+
{
124+
CustomObjectCreateRequest::ofObject(new \stdClass());
125+
}
126+
47127
public function testQuery()
48128
{
49129
$draft = $this->getDraft();

tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commercetools-php-sdk-changelog",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "commercetools PHP SDK changelog generator package description",
55
"homepage": "https://github.com/sphereio/commercetools-php-sdk",
66
"bugs": "https://github.com/sphereio/commercetools-php-sdk/issues",

0 commit comments

Comments
 (0)