File tree 5 files changed +51
-9
lines changed
5 files changed +51
-9
lines changed Original file line number Diff line number Diff line change @@ -60,11 +60,11 @@ protected function parse($object)
60
60
$ links = get_object_vars ($ object );
61
61
62
62
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. ' );
65
65
}
66
66
67
- $ this ->set ('self ' , strval ( $ links ['self ' ]) );
67
+ $ this ->setLink ('self ' , $ links ['self ' ]);
68
68
69
69
unset($ links ['self ' ]);
70
70
}
Original file line number Diff line number Diff line change @@ -665,4 +665,19 @@ public function testParseIdAsInteger()
665
665
// Test full array
666
666
$ this ->assertEquals (json_decode ($ string , true ), $ document ->asArray (true ));
667
667
}
668
+
669
+ /**
670
+ * @test
671
+ */
672
+ public function testParseLinksInRelationshipsCorrectly ()
673
+ {
674
+ $ string = $ this ->getJsonString ('17_relationship_links.json ' );
675
+ $ document = Helper::parseResponseBody ($ string );
676
+
677
+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Document ' , $ document );
678
+ $ this ->assertSame (['data ' ], $ document ->getKeys ());
679
+
680
+ // Test full array
681
+ $ this ->assertEquals (json_decode ($ string , true ), $ document ->asArray (true ));
682
+ }
668
683
}
Original file line number Diff line number Diff line change @@ -311,12 +311,12 @@ public function testCreateWithoutSelfAndRelatedPropertiesThrowsException()
311
311
*
312
312
* @param mixed $input
313
313
*/
314
- public function testSelfMustBeAString ($ input )
314
+ public function testSelfMustBeAStringOrObject ($ input )
315
315
{
316
316
$ link = new RelationshipLink ($ this ->manager , $ this ->relationship );
317
317
318
318
// Input must be a string
319
- if (gettype ($ input ) === 'string ' ) {
319
+ if (gettype ($ input ) === 'string ' or gettype ( $ input ) === ' object ' ) {
320
320
$ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipLink ' , $ link );
321
321
322
322
return ;
@@ -327,7 +327,7 @@ public function testSelfMustBeAString($input)
327
327
328
328
$ this ->setExpectedException (
329
329
'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. '
331
331
);
332
332
333
333
$ link ->parse ($ object );
Original file line number Diff line number Diff line change @@ -264,20 +264,20 @@ public function testCreateWithoutSelfAndRelatedPropertiesThrowsException()
264
264
}
265
265
266
266
/**
267
- * @dataProvider jsonValuesProviderWithoutString
267
+ * @dataProvider jsonValuesProviderWithoutObjectAndString
268
268
*
269
269
* self: a link for the relationship itself (a "relationship link").
270
270
*
271
271
* @param mixed $input
272
272
*/
273
- public function testSelfMustBeAString ($ input )
273
+ public function testSelfMustBeAStringOrObject ($ input )
274
274
{
275
275
$ object = new \stdClass ();
276
276
$ object ->self = $ input ;
277
277
278
278
$ this ->expectException (ValidationException::class);
279
279
$ 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. '
281
281
);
282
282
283
283
$ link = new RelationshipLink ($ object , $ this ->manager , $ this ->relationship );
Original file line number Diff line number Diff line change
1
+ {
2
+ "data" : [
3
+ {
4
+ "type" : " articles" ,
5
+ "id" : " 1" ,
6
+ "attributes" : {
7
+ "title" : " JSON API paints my bikeshed!"
8
+ },
9
+ "relationships" : {
10
+ "vid" : {
11
+ "data" : {
12
+ "type" : " taxonomy_vocabulary--taxonomy_vocabulary" ,
13
+ "id" : " e0b18172-b9fa-4a2f-88c0-ed19dca65a1b"
14
+ },
15
+ "links" : {
16
+ "self" : {
17
+ "href" : " */jsonapi/taxonomy_term/district/3fa7e3cd-ce96-4be7-abac-7203bf8a9f4f/relationships/vid"
18
+ },
19
+ "related" : {
20
+ "href" : " */jsonapi/taxonomy_term/district/3fa7e3cd-ce96-4be7-abac-7203bf8a9f4f/vid"
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ ]
27
+ }
You can’t perform that action at this time.
0 commit comments