Skip to content

Commit d1fd306

Browse files
committed
Relationships Links can be an object with href link
refs #57
1 parent d059897 commit d1fd306

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/V1/RelationshipLink.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ protected function parse($object)
6060
$links = get_object_vars($object);
6161

6262
if (array_key_exists('self', $links)) {
63-
if (! is_string($links['self'])) {
64-
throw new ValidationException('property "self" has to be a string, "' . gettype($links['self']) . '" given.');
63+
if (! is_string($links['self']) and ! is_object($links['self'])) {
64+
throw new ValidationException('property "self" has to be a string or object, "' . gettype($links['self']) . '" given.');
6565
}
6666

67-
$this->set('self', strval($links['self']));
67+
$this->setLink('self', $links['self']);
6868

6969
unset($links['self']);
7070
}

tests/Unit/RelationshipLinkTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ public function testCreateWithoutSelfAndRelatedPropertiesThrowsException()
311311
*
312312
* @param mixed $input
313313
*/
314-
public function testSelfMustBeAString($input)
314+
public function testSelfMustBeAStringOrObject($input)
315315
{
316316
$link = new RelationshipLink($this->manager, $this->relationship);
317317

318318
// Input must be a string
319-
if (gettype($input) === 'string') {
319+
if (gettype($input) === 'string' or gettype($input) === 'object') {
320320
$this->assertInstanceOf('Art4\JsonApiClient\RelationshipLink', $link);
321321

322322
return;
@@ -327,7 +327,7 @@ public function testSelfMustBeAString($input)
327327

328328
$this->setExpectedException(
329329
'Art4\JsonApiClient\Exception\ValidationException',
330-
'property "self" has to be a string, "' . gettype($input) . '" given.'
330+
'property "self" has to be a string or object, "' . gettype($input) . '" given.'
331331
);
332332

333333
$link->parse($object);

tests/Unit/V1/RelationshipLinkTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,20 @@ public function testCreateWithoutSelfAndRelatedPropertiesThrowsException()
264264
}
265265

266266
/**
267-
* @dataProvider jsonValuesProviderWithoutString
267+
* @dataProvider jsonValuesProviderWithoutObjectAndString
268268
*
269269
* self: a link for the relationship itself (a "relationship link").
270270
*
271271
* @param mixed $input
272272
*/
273-
public function testSelfMustBeAString($input)
273+
public function testSelfMustBeAStringOrObject($input)
274274
{
275275
$object = new \stdClass();
276276
$object->self = $input;
277277

278278
$this->expectException(ValidationException::class);
279279
$this->expectExceptionMessage(
280-
'property "self" has to be a string, "' . gettype($input) . '" given.'
280+
'property "self" has to be a string or object, "' . gettype($input) . '" given.'
281281
);
282282

283283
$link = new RelationshipLink($object, $this->manager, $this->relationship);

0 commit comments

Comments
 (0)