dunglas / doctrine-json-odm

An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
https://dunglas.fr
MIT License
586 stars 66 forks source link

Test Iterable Data #128

Open Aweptimum opened 1 year ago

Aweptimum commented 1 year ago

This isn't meant to be merged, it's just a test case illustrating that the serializer doesn't play nice with classes implementing \Iterator as pointed out in #127

If you clone this branch, run the tests, and put a breakpoint before the assert in testIterable, you'll see the serialized output of the Vector class in $data is:

{"#type":"Dunglas\\DoctrineJsonOdm\\Tests\\Fixtures\\TestBundle\\Document\\Vector","0":1,"1":2,"2":3,"3":4,"4":5}

Which cannot be deserialized and the test fails

If you remove the \Iterator interface from the Vector class and re-run the tests, this is the serialized output in $data:

{"#type":"Dunglas\\DoctrineJsonOdm\\Tests\\Fixtures\\TestBundle\\Document\\Vector","array":[1,2,3,4,5]}

Which can be deserialized and the test passes