File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -454,8 +454,11 @@ public function getResourceName()
454454
455455 /**
456456 * Convert the object into something JSON serializable.
457+ *
458+ * @return array
457459 */
458- public function jsonSerialize (): mixed
460+ #[\ReturnTypeWillChange]
461+ public function jsonSerialize (): array
459462 {
460463 return $ this ->toArray ();
461464 }
Original file line number Diff line number Diff line change @@ -250,4 +250,19 @@ public function it_can_define_primitive_after_resource_name()
250250
251251 $ this ->assertEquals ('tests ' , $ resource ->getResource ()->getResourceKey ());
252252 }
253+
254+ /** @test */
255+ public function it_can_convert_into_something_that_is_json_serializable ()
256+ {
257+ $ jsonSerialized = $ this ->fractal
258+ ->collection ($ this ->testBooks , new TestTransformer ())
259+ ->jsonSerialize ();
260+
261+ $ expectedArray = ['data ' => [
262+ ['id ' => 1 , 'author ' => 'Philip K Dick ' ],
263+ ['id ' => 2 , 'author ' => 'George R. R. Satan ' ],
264+ ]];
265+
266+ $ this ->assertEquals ($ expectedArray , $ jsonSerialized );
267+ }
253268}
You can’t perform that action at this time.
0 commit comments