Skip to content

Commit da2df88

Browse files
committed
Merge branch '0.x' into 47-throw-exception-if-type-or-id-is-not-string
2 parents 2e4148f + 95c6160 commit da2df88

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6161
- **BREAKING**: `Art4\JsonApiClient\Utils\Manager` removed, use `Art4\JsonApiClient\Manager\ErrorAbortManager` instead
6262
- **BREAKING**: `Art4\JsonApiClient\Utils\ManagerInterface` removed, use `Art4\JsonApiClient\Manager` instead
6363

64+
## [0.10.1] - 2019-09-23
65+
66+
### Deprecated
67+
68+
- Providing the fields `type` or `id` in a resource not as a string will be throw a ValidationException in v1.0, provide them always as strings instead.
69+
6470
## [0.10] - 2018-11-07
6571

6672
### Added
@@ -304,7 +310,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
304310
- Validator fits nearly 100% specification
305311
- Full test coverage
306312

307-
[Unreleased]: https://github.com/Art4/json-api-client/compare/0.10...HEAD
313+
[Unreleased]: https://github.com/Art4/json-api-client/compare/0.10.1...HEAD
314+
[0.10.1]: https://github.com/Art4/json-api-client/compare/0.10...0.10.1
308315
[0.10]: https://github.com/Art4/json-api-client/compare/0.9.1...0.10
309316
[0.9.1]: https://github.com/Art4/json-api-client/compare/0.9...0.9.1
310317
[0.9]: https://github.com/Art4/json-api-client/compare/0.8.1...0.9

src/V1/ResourceIdentifier.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ protected function parse($object)
5151
throw new ValidationException('A resource object MUST contain an id');
5252
}
5353

54-
if (is_object($object->type) or is_array($object->type)) {
55-
throw new ValidationException('Resource type cannot be an array or object');
54+
if (! is_string($object->type)) {
55+
if (is_object($object->type) or is_array($object->type)) {
56+
throw new ValidationException('Resource type cannot be an array or object');
57+
}
58+
59+
@trigger_error('Parsing `type` not as string is deprecated since version 0.10.1 and will be throw an Exception in 1.0. Provide `type` always as string instead', E_USER_DEPRECATED);
5660
}
5761

58-
if (is_object($object->id) or is_array($object->id)) {
59-
throw new ValidationException('Resource Id cannot be an array or object');
62+
if (! is_string($object->id)) {
63+
if (is_object($object->id) or is_array($object->id)) {
64+
throw new ValidationException('Resource Id cannot be an array or object');
65+
}
66+
67+
@trigger_error('Parsing `id` not as string is deprecated since version 0.10.1 and will be throw an Exception in 1.0. Provide `id` always as string instead', E_USER_DEPRECATED);
6068
}
6169

6270
$this->set('type', strval($object->type));

src/V1/ResourceItem.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ protected function parse($object)
4848
throw new ValidationException('A resource object MUST contain a type');
4949
}
5050

51-
if (is_object($object->type) or is_array($object->type)) {
52-
throw new ValidationException('Resource type cannot be an array or object');
51+
if (! is_string($object->type)) {
52+
if (is_object($object->type) or is_array($object->type)) {
53+
throw new ValidationException('Resource type cannot be an array or object');
54+
}
55+
56+
@trigger_error('Parsing `type` not as string is deprecated since version 0.10.1 and will be throw an Exception in 1.0. Provide `type` always as string instead', E_USER_DEPRECATED);
5357
}
5458

5559
$this->set('type', strval($object->type));
@@ -62,8 +66,12 @@ protected function parse($object)
6266
throw new ValidationException('A resource object MUST contain an id');
6367
}
6468

65-
if (is_object($object->id) or is_array($object->id)) {
66-
throw new ValidationException('Resource id cannot be an array or object');
69+
if (! is_string($object->id)) {
70+
if (is_object($object->id) or is_array($object->id)) {
71+
throw new ValidationException('Resource id cannot be an array or object');
72+
}
73+
74+
@trigger_error('Parsing `id` not as string is deprecated since version 0.10.1 and will be throw an Exception in 1.0. Provide `id` always as string instead', E_USER_DEPRECATED);
6775
}
6876

6977
$this->set('id', strval($object->id));

tests/Fixtures/Factory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function make($name, array $args = [])
3737
{
3838
return $this->testcase
3939
->getMockBuilder('Art4\JsonApiClient\\' . $name . 'Interface') // Mock only the interfaces
40+
->disableOriginalConstructor()
41+
->disableOriginalClone()
42+
->disableArgumentCloning()
43+
->disallowMockingUnknownTypes()
4044
->getMock();
4145
}
4246
}

tests/Fixtures/V1Factory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function __construct($testcase)
4949
*/
5050
public function make($name, array $args = [])
5151
{
52-
return $this->testcase->getMockBuilder(AccessableElement::class)->getMock();
52+
return $this->testcase->getMockBuilder(AccessableElement::class)
53+
->disableOriginalConstructor()
54+
->disableOriginalClone()
55+
->disableArgumentCloning()
56+
->disallowMockingUnknownTypes()
57+
->getMock();
5358
}
5459
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"data": {
3+
"type": "posts",
4+
"id": 1,
5+
"attributes": {
6+
"title": "Post 1 title",
7+
"content": "Post 1 content"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)