-
Notifications
You must be signed in to change notification settings - Fork 95
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
PhpUnit always returns true when comparing Ds\Map #122
Comments
This btw is my hacky fix; add a custom comparator which compares the json versions of the two maps. https://gist.github.com/robincafolla/739e3253a7c9f4b4363d4d1aa39e2af5 But it won't work if you're using objects as keys. |
This is the bug right here. |
I think this is also a poor choice to convert objects to arrays for comparison. Any object that overrides comparison (ie. |
I agree. I was originally going to open the issue on PHPUnit, but I didn't have a suggestion for them on how to improve it. I'll open an issue later for them to add support for |
@robincafolla it's simple, they should use |
I'm going to open an issue on the comparator repo. |
This issue happens for every Ds\Collection, not only Ds\Map. Since issue on the comparator repo was closed and I needed something better than the fix posted here, I created the following comparator: @robincafolla 's comparator result (for a empty Vector vs Vector with two empty objects):
My comparator result:
Hopefully someone will find that useful. |
@jacek-foremski I think you should also check that both arguments are an instance of the same class. |
@rtheunissen This is done in the parent class (SebastianBergmann\Comparator\ObjectComparator) |
php -v: PHP 7.2.9-1+ubuntu16.04.1+deb.sury.org+1
When
PHPUnit\Framework\TestCase::assertEquals
is used to compare two Maps it always returns true, regardless of contents.Example:
Explanation:
This seems to happen because
SebastianBergmann\Exporter::toArray
uses(array)
to cast objects for comparison. Since whenever you cast aDs\Map
to an array it becomes an empty array this means thatassertEquals
always returns true.You might argue that this is a bug in PhpUnit, but I felt I should open it here first to see how you think a comparison should be done on Maps.
The text was updated successfully, but these errors were encountered: