You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When assertEqualsCanonicalizing() is utilized the assertion result display will crash when one of the array elements, which is presented in the diff, is not castable to string.
Current behavior
When test is run the testing framework crashes with, at-first confusing, error message:
1) FooTest::testFoo
Object of class stdClass could not be converted to int
It seems to happen when an array contains both objects and scalar values, which would be a common case for serialized objects.
This is a problem in cases where you want to compare a list of objects, but the order doesn't matter.
A potential solution could be to use usort() with a custom sorting function that handles cases like this. I would assume that if it handled objects compared to scalar values with simply saying that a scalar value is lower than an object and then compared other cases as per usual, then the problem would be solved.
A temporary fix in the case I've encountered is to "pre-serialize" the objects in the list before asserting.
Summary
When
assertEqualsCanonicalizing()
is utilized the assertion result display will crash when one of the array elements, which is presented in the diff, is not castable to string.Current behavior
When test is run the testing framework crashes with, at-first confusing, error message:
How to reproduce
Expected behavior
The diff should handle such cases properly and display e.g. object ID, similarly to how e.g.
assertSame()
does it:The text was updated successfully, but these errors were encountered: