Skip to content

Commit b25a327

Browse files
committed
Update attribute representation to latest spec
1 parent 8b9e2f4 commit b25a327

File tree

7 files changed

+248
-144
lines changed

7 files changed

+248
-144
lines changed

src/Document/Document.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,33 @@
2929
class Document implements DocumentInterface
3030
{
3131
/** Reserved keyword */
32-
const KEYWORD_LINKS = 'links';
32+
const KEYWORD_LINKS = 'links';
3333
/** Reserved keyword */
34-
const KEYWORD_SELF = 'self';
34+
const KEYWORD_SELF = 'self';
3535
/** Reserved keyword */
36-
const KEYWORD_FIRST = 'first';
36+
const KEYWORD_FIRST = 'first';
3737
/** Reserved keyword */
38-
const KEYWORD_LAST = 'last';
38+
const KEYWORD_LAST = 'last';
3939
/** Reserved keyword */
40-
const KEYWORD_NEXT = 'next';
40+
const KEYWORD_NEXT = 'next';
4141
/** Reserved keyword */
42-
const KEYWORD_PREV = 'prev';
42+
const KEYWORD_PREV = 'prev';
4343
/** Reserved keyword */
44-
const KEYWORD_RELATED = 'related';
44+
const KEYWORD_RELATED = 'related';
4545
/** Reserved keyword */
46-
const KEYWORD_LINKAGE = 'linkage';
46+
const KEYWORD_LINKAGE = 'linkage';
4747
/** Reserved keyword */
48-
const KEYWORD_TYPE = 'type';
48+
const KEYWORD_TYPE = 'type';
4949
/** Reserved keyword */
50-
const KEYWORD_ID = 'id';
50+
const KEYWORD_ID = 'id';
5151
/** Reserved keyword */
52-
const KEYWORD_META = 'meta';
52+
const KEYWORD_ATTRIBUTES = 'attributes';
5353
/** Reserved keyword */
54-
const KEYWORD_DATA = 'data';
54+
const KEYWORD_META = 'meta';
5555
/** Reserved keyword */
56-
const KEYWORD_INCLUDED = 'included';
56+
const KEYWORD_DATA = 'data';
57+
/** Reserved keyword */
58+
const KEYWORD_INCLUDED = 'included';
5759

5860
/** Reserved keyword */
5961
const KEYWORD_ERRORS = 'errors';

src/Document/Presenters/ElementPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private function convertResourceToArray(ResourceObjectInterface $resource, $isSh
279279
'"type" and "id" are reserved keywords and cannot be used as resource object attributes'
280280
);
281281
if (empty($attributes) === false) {
282-
$representation += $attributes;
282+
$representation[Document::KEYWORD_ATTRIBUTES] = $attributes;
283283
}
284284

285285
if ($isShowSelf === true) {

tests/Document/DocumentTest.php

Lines changed: 92 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ public function testAddToDataArrayedShowMembers()
139139
{
140140
"data" : [
141141
{
142-
"type" : "people",
143-
"id" : "123",
144-
"firstName" : "John",
145-
"lastName" : "Dow",
142+
"type" : "people",
143+
"id" : "123",
144+
"attributes" : {
145+
"firstName" : "John",
146+
"lastName" : "Dow"
147+
},
146148
"links" : {
147149
"self" : "selfUrl"
148150
},
@@ -180,10 +182,12 @@ public function testAddToDataNotArrayedHiddenMembers()
180182
$expected = <<<EOL
181183
{
182184
"data" : {
183-
"type" : "people",
184-
"id" : "123",
185-
"firstName" : "John",
186-
"lastName" : "Dow"
185+
"type" : "people",
186+
"id" : "123",
187+
"attributes" : {
188+
"firstName" : "John",
189+
"lastName" : "Dow"
190+
}
187191
}
188192
}
189193
EOL;
@@ -277,8 +281,10 @@ public function testAddLinkToDataShowLinkMembers()
277281
"data" : {
278282
"type" : "people",
279283
"id" : "123",
280-
"firstName" : "John",
281-
"lastName" : "Dow",
284+
"attributes" : {
285+
"firstName" : "John",
286+
"lastName" : "Dow"
287+
},
282288
"links" : {
283289
"link-name" : {
284290
"self" : "peopleSelfUrl/selfSubUrl",
@@ -351,8 +357,10 @@ public function testAddLinkToDataHideLinkMembersExceptLinkage()
351357
"data" : {
352358
"type" : "people",
353359
"id" : "123",
354-
"firstName" : "John",
355-
"lastName" : "Dow",
360+
"attributes" : {
361+
"firstName" : "John",
362+
"lastName" : "Dow"
363+
},
356364
"links" : {
357365
"link-name" : {
358366
"linkage" : { "type" : "comments", "id" : "321" }
@@ -420,10 +428,12 @@ public function testAddMultipleLinksToData()
420428
$expected = <<<EOL
421429
{
422430
"data" : {
423-
"type" : "people",
424-
"id" : "123",
425-
"firstName" : "John",
426-
"lastName" : "Dow",
431+
"type" : "people",
432+
"id" : "123",
433+
"attributes" : {
434+
"firstName" : "John",
435+
"lastName" : "Dow"
436+
},
427437
"links" : {
428438
"link-name" : {
429439
"linkage" : [
@@ -493,10 +503,12 @@ public function testAddLinkToDataHideLinkMembersExceptMeta()
493503
$expected = <<<EOL
494504
{
495505
"data" : {
496-
"type" : "people",
497-
"id" : "123",
498-
"firstName" : "John",
499-
"lastName" : "Dow",
506+
"type" : "people",
507+
"id" : "123",
508+
"attributes" : {
509+
"firstName" : "John",
510+
"lastName" : "Dow"
511+
},
500512
"links" : {
501513
"link-name" : {
502514
"meta" : { "some" : "comment meta" }
@@ -563,10 +575,12 @@ public function testAddReferenceToData()
563575
$expected = <<<EOL
564576
{
565577
"data" : {
566-
"type" : "people",
567-
"id" : "123",
568-
"firstName" : "John",
569-
"lastName" : "Dow",
578+
"type" : "people",
579+
"id" : "123",
580+
"attributes" : {
581+
"firstName" : "John",
582+
"lastName" : "Dow"
583+
},
570584
"links" : {
571585
"link-name" : "peopleSelfUrl/relatedSubUrl"
572586
}
@@ -617,10 +631,12 @@ public function testAddEmptyLinkToData()
617631
$expected = <<<EOL
618632
{
619633
"data" : {
620-
"type" : "people",
621-
"id" : "123",
622-
"firstName" : "John",
623-
"lastName" : "Dow",
634+
"type" : "people",
635+
"id" : "123",
636+
"attributes" : {
637+
"firstName" : "John",
638+
"lastName" : "Dow"
639+
},
624640
"links" : {
625641
"link-name" : []
626642
}
@@ -671,10 +687,12 @@ public function testAddNullLinkToData()
671687
$expected = <<<EOL
672688
{
673689
"data" : {
674-
"type" : "people",
675-
"id" : "123",
676-
"firstName" : "John",
677-
"lastName" : "Dow",
690+
"type" : "people",
691+
"id" : "123",
692+
"attributes" : {
693+
"firstName" : "John",
694+
"lastName" : "Dow"
695+
},
678696
"links" : {
679697
"link-name" : null
680698
}
@@ -710,10 +728,12 @@ public function testAddToIncludedShowMembers()
710728
"data" : null,
711729
"included" : [
712730
{
713-
"type" : "people",
714-
"id" : "123",
715-
"firstName" : "John",
716-
"lastName" : "Dow",
731+
"type" : "people",
732+
"id" : "123",
733+
"attributes" : {
734+
"firstName" : "John",
735+
"lastName" : "Dow"
736+
},
717737
"links" : {
718738
"self" : "selfUrl"
719739
},
@@ -753,10 +773,12 @@ public function testAddToIncludedHideMembers()
753773
"data" : null,
754774
"included" : [
755775
{
756-
"type" : "people",
757-
"id" : "123",
758-
"firstName" : "John",
759-
"lastName" : "Dow"
776+
"type" : "people",
777+
"id" : "123",
778+
"attributes" : {
779+
"firstName" : "John",
780+
"lastName" : "Dow"
781+
}
760782
}
761783
]
762784
}
@@ -820,10 +842,12 @@ public function testAddLinkToIncludedShowLinkMembers()
820842
{
821843
"data" : null,
822844
"included" : [{
823-
"type" : "people",
824-
"id" : "123",
825-
"firstName" : "John",
826-
"lastName" : "Dow",
845+
"type" : "people",
846+
"id" : "123",
847+
"attributes" : {
848+
"firstName" : "John",
849+
"lastName" : "Dow"
850+
},
827851
"links" : {
828852
"self" : "peopleSelfUrl/",
829853
"link-name" : {
@@ -898,10 +922,12 @@ public function testAddLinkToIncludedHideMembersForLinkedResource()
898922
{
899923
"data" : null,
900924
"included" : [{
901-
"type" : "people",
902-
"id" : "123",
903-
"firstName" : "John",
904-
"lastName" : "Dow",
925+
"type" : "people",
926+
"id" : "123",
927+
"attributes" : {
928+
"firstName" : "John",
929+
"lastName" : "Dow"
930+
},
905931
"links" : {
906932
"self" : "peopleSelfUrl/",
907933
"link-name" : {
@@ -959,10 +985,12 @@ public function testAddEmptyLinkToIncluded()
959985
{
960986
"data" : null,
961987
"included" : [{
962-
"type" : "people",
963-
"id" : "123",
964-
"firstName" : "John",
965-
"lastName" : "Dow",
988+
"type" : "people",
989+
"id" : "123",
990+
"attributes" : {
991+
"firstName" : "John",
992+
"lastName" : "Dow"
993+
},
966994
"links" : {
967995
"self" : "peopleSelfUrl/",
968996
"link-name" : []
@@ -1018,10 +1046,12 @@ public function testAddNullLinkToIncluded()
10181046
{
10191047
"data" : null,
10201048
"included" : [{
1021-
"type" : "people",
1022-
"id" : "123",
1023-
"firstName" : "John",
1024-
"lastName" : "Dow",
1049+
"type" : "people",
1050+
"id" : "123",
1051+
"attributes" : {
1052+
"firstName" : "John",
1053+
"lastName" : "Dow"
1054+
},
10251055
"links" : {
10261056
"self" : "peopleSelfUrl/",
10271057
"link-name" : null
@@ -1077,10 +1107,12 @@ public function testAddReferenceLinkToIncluded()
10771107
{
10781108
"data" : null,
10791109
"included" : [{
1080-
"type" : "people",
1081-
"id" : "123",
1082-
"firstName" : "John",
1083-
"lastName" : "Dow",
1110+
"type" : "people",
1111+
"id" : "123",
1112+
"attributes" : {
1113+
"firstName" : "John",
1114+
"lastName" : "Dow"
1115+
},
10841116
"links" : {
10851117
"self" : "peopleSelfUrl/",
10861118
"link-name" : "peopleSelfUrl/relatedSubUrl"

0 commit comments

Comments
 (0)