Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Iterable Data #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Aweptimum
Copy link

@Aweptimum Aweptimum commented Oct 27, 2023

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

Added a test class, Vector, implementing \Iterator and a corresponding test case in the SerializerTest that demonstrates iterable data doesn't play nice with the serializer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant