Skip to content

Commit 8e23219

Browse files
committed
Add test for input data as assoc array
1 parent ced79f9 commit 8e23219

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/Encoder/EncodeSimpleObjectsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

0 commit comments

Comments
 (0)