@@ 566-651 (lines=86) @@ | ||
563 | $this->assertSame($expectedJson, $scope->toJson()); |
|
564 | } |
|
565 | ||
566 | public function testSerializingCollectionResourceWithHasOneInclude() : void |
|
567 | { |
|
568 | $this->manager->parseIncludes('author'); |
|
569 | ||
570 | $booksData = [ |
|
571 | [ |
|
572 | 'id' => 1, |
|
573 | 'title' => 'Foo', |
|
574 | 'year' => '1991', |
|
575 | '_author' => [ |
|
576 | 'id' => 1, |
|
577 | 'name' => 'Dave', |
|
578 | ], |
|
579 | ], |
|
580 | [ |
|
581 | 'id' => 2, |
|
582 | 'title' => 'Bar', |
|
583 | 'year' => '1997', |
|
584 | '_author' => [ |
|
585 | 'id' => 2, |
|
586 | 'name' => 'Bob', |
|
587 | ], |
|
588 | ], |
|
589 | ]; |
|
590 | ||
591 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
592 | $scope = new Scope($this->manager, $resource); |
|
593 | ||
594 | $expected = [ |
|
595 | 'data' => [ |
|
596 | [ |
|
597 | 'type' => 'books', |
|
598 | 'id' => '1', |
|
599 | 'attributes' => [ |
|
600 | 'title' => 'Foo', |
|
601 | 'year' => 1991, |
|
602 | ], |
|
603 | 'relationships' => [ |
|
604 | 'author' => [ |
|
605 | 'data' => [ |
|
606 | 'type' => 'people', |
|
607 | 'id' => '1', |
|
608 | ], |
|
609 | ], |
|
610 | ], |
|
611 | ], |
|
612 | [ |
|
613 | 'type' => 'books', |
|
614 | 'id' => '2', |
|
615 | 'attributes' => [ |
|
616 | 'title' => 'Bar', |
|
617 | 'year' => 1997, |
|
618 | ], |
|
619 | 'relationships' => [ |
|
620 | 'author' => [ |
|
621 | 'data' => [ |
|
622 | 'type' => 'people', |
|
623 | 'id' => '2', |
|
624 | ], |
|
625 | ], |
|
626 | ], |
|
627 | ], |
|
628 | ], |
|
629 | 'included' => [ |
|
630 | [ |
|
631 | 'type' => 'people', |
|
632 | 'id' => '1', |
|
633 | 'attributes' => [ |
|
634 | 'name' => 'Dave', |
|
635 | ], |
|
636 | ], |
|
637 | [ |
|
638 | 'type' => 'people', |
|
639 | 'id' => '2', |
|
640 | 'attributes' => [ |
|
641 | 'name' => 'Bob', |
|
642 | ], |
|
643 | ], |
|
644 | ], |
|
645 | ]; |
|
646 | ||
647 | $this->assertSame($expected, $scope->toArray()); |
|
648 | ||
649 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"relationships":{"author":{"data":{"type":"people","id":"2"}}}}],"included":[{"type":"people","id":"1","attributes":{"name":"Dave"}},{"type":"people","id":"2","attributes":{"name":"Bob"}}]}'; |
|
650 | $this->assertSame($expectedJson, $scope->toJson()); |
|
651 | } |
|
652 | ||
653 | public function testSerializingCollectionResourceWithEmptyHasOneInclude() : void |
|
654 | { |
|
@@ 1068-1152 (lines=85) @@ | ||
1065 | $this->assertSame($expectedJson, $scope->toJson()); |
|
1066 | } |
|
1067 | ||
1068 | public function testSerializingItemResourceWithNestedIncludes() : void |
|
1069 | { |
|
1070 | $this->manager->parseIncludes(['author', 'author.published']); |
|
1071 | ||
1072 | $bookData = [ |
|
1073 | 'id' => 1, |
|
1074 | 'title' => 'Foo', |
|
1075 | 'year' => '1991', |
|
1076 | '_author' => [ |
|
1077 | 'id' => 1, |
|
1078 | 'name' => 'Dave', |
|
1079 | '_published' => [ |
|
1080 | [ |
|
1081 | 'id' => 1, |
|
1082 | 'title' => 'Foo', |
|
1083 | 'year' => '1991', |
|
1084 | ], |
|
1085 | [ |
|
1086 | 'id' => 2, |
|
1087 | 'title' => 'Bar', |
|
1088 | 'year' => '2015', |
|
1089 | ], |
|
1090 | ], |
|
1091 | ], |
|
1092 | ]; |
|
1093 | ||
1094 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
1095 | ||
1096 | $scope = new Scope($this->manager, $resource); |
|
1097 | ||
1098 | $expected = [ |
|
1099 | 'data' => [ |
|
1100 | 'type' => 'books', |
|
1101 | 'id' => '1', |
|
1102 | 'attributes' => [ |
|
1103 | 'title' => 'Foo', |
|
1104 | 'year' => 1991, |
|
1105 | ], |
|
1106 | 'relationships' => [ |
|
1107 | 'author' => [ |
|
1108 | 'data' => [ |
|
1109 | 'type' => 'people', |
|
1110 | 'id' => '1', |
|
1111 | ], |
|
1112 | ], |
|
1113 | ], |
|
1114 | ], |
|
1115 | 'included' => [ |
|
1116 | [ |
|
1117 | 'type' => 'books', |
|
1118 | 'id' => '2', |
|
1119 | 'attributes' => [ |
|
1120 | 'title' => 'Bar', |
|
1121 | 'year' => 2015, |
|
1122 | ], |
|
1123 | ], |
|
1124 | [ |
|
1125 | 'type' => 'people', |
|
1126 | 'id' => '1', |
|
1127 | 'attributes' => [ |
|
1128 | 'name' => 'Dave', |
|
1129 | ], |
|
1130 | 'relationships' => [ |
|
1131 | 'published' => [ |
|
1132 | 'data' => [ |
|
1133 | [ |
|
1134 | 'type' => 'books', |
|
1135 | 'id' => '1', |
|
1136 | ], |
|
1137 | [ |
|
1138 | 'type' => 'books', |
|
1139 | 'id' => '2', |
|
1140 | ], |
|
1141 | ], |
|
1142 | ], |
|
1143 | ], |
|
1144 | ], |
|
1145 | ], |
|
1146 | ]; |
|
1147 | ||
1148 | $this->assertSame($expected, $scope->toArray()); |
|
1149 | ||
1150 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},"included":[{"type":"books","id":"2","attributes":{"title":"Bar","year":2015}},{"type":"people","id":"1","attributes":{"name":"Dave"},"relationships":{"published":{"data":[{"type":"books","id":"1"},{"type":"books","id":"2"}]}}}]}'; |
|
1151 | $this->assertSame($expectedJson, $scope->toJson()); |
|
1152 | } |
|
1153 | ||
1154 | public function testSerializingItemResourceWithSelfLink() : void |
|
1155 | { |