File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,43 @@ public function testEncodeObjectWithAttributesOnlyInArray()
158158 $ this ->assertEquals ($ expected , $ actual );
159159 }
160160
161+ /**
162+ * Test encode simple object with attributes only associative array.
163+ */
164+ public function testEncodeObjectWithAttributesOnlyInAssocArray ()
165+ {
166+ $ author = Author::instance (9 , 'Dan ' , 'Gebhardt ' );
167+ $ endcoder = Encoder::instance ([
168+ Author::class => function ($ factory , $ container ) {
169+ $ schema = new AuthorSchema ($ factory , $ container );
170+ $ schema ->linkRemove (Author::LINK_COMMENTS );
171+ return $ schema ;
172+ }
173+ ], $ this ->encoderOptions );
174+
175+ $ actual = $ endcoder ->encode (['key_doesnt_matter ' => $ author ]);
176+
177+ $ expected = <<<EOL
178+ {
179+ "data" : [{
180+ "type" : "people",
181+ "id" : "9",
182+ "attributes" : {
183+ "first_name" : "Dan",
184+ "last_name" : "Gebhardt"
185+ },
186+ "links" : {
187+ "self" : "http://example.com/people/9"
188+ }
189+ }]
190+ }
191+ EOL ;
192+ // remove formatting from 'expected'
193+ $ expected = json_encode (json_decode ($ expected ));
194+
195+ $ this ->assertEquals ($ expected , $ actual );
196+ }
197+
161198 /**
162199 * Test encode simple object in pretty format.
163200 */
You can’t perform that action at this time.
0 commit comments