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
PHPUnit 11.4.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.9
Configuration: /var/www/app/phpunit.xml
F 1 / 1 (100%)
Time: 00:00.005, Memory: 8.00 MB
There was 1 failure:
1) DumbTest::testMisleadingDiffOutput
Failed asserting that two arrays are equal.
--- Expected+++ Actual@@ @@
Array (
0 => Array (
0 => stdClass Object (
- 'foobar' => 'A'+ 'foobar' => 'B'
)
- 1 => 2024-10-17T00:00:00.000000+0000+ 1 => 2024-10-16T00:00:00.000000+0000
)
1 => Array (
0 => stdClass Object (...)
- 1 => 2024-10-16T00:00:00.000000+0000+ 1 => 2024-10-17T00:00:00.000000+0000
)
)
It's confusing because as diff is given for \DateTime objects, it may suggest that stdClass instances in second element of actual and expected array are equals.
Expected behavior
After some investigation, I saw that ObjectComparator keeps track of processed pair of expected and actual values to avoid redundant comparison: that's why diff on stdClass is not displayed on second elements. DateTimeComparator, even though it extends ObjectComparator does not have the same behavior on keeping track of processed comparisons. I think it should.
As a result, the testing output could be
PHPUnit 11.4.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.9
Configuration: /var/www/app/phpunit.xml
F 1 / 1 (100%)
Time: 00:00.005, Memory: 8.00 MB
There was 1 failure:
1) DumbTest::testMisleadingDiffOutput
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
0 => Array (
0 => stdClass Object (
- 'foobar' => 'A'
+ 'foobar' => 'B'
)
- 1 => 2024-10-17T00:00:00.000000+0000
+ 1 => 2024-10-16T00:00:00.000000+0000
)
1 => [...]
)
myclabs/deep-copy 1.12.0 Create deep copies (clones) of yo...
nikic/php-parser v5.3.1 A PHP parser written in PHP
phar-io/manifest 2.0.4 Component for reading phar.io man...
phar-io/version 3.2.1 Library for handling version info...
sebastian/cli-parser 3.0.2 Library for parsing CLI options
sebastian/code-unit-reverse-lookup 4.0.1 Looks up which function or method...
sebastian/code-unit 3.0.1 Collection of value objects that ...
sebastian/comparator 6.1.0 Provides the functionality to com...
sebastian/complexity 4.0.1 Library for calculating the compl...
sebastian/diff 6.0.2 Diff implementation
sebastian/environment 7.2.0 Provides functionality to handle ...
sebastian/exporter 6.1.3 Provides the functionality to exp...
sebastian/global-state 7.0.2 Snapshotting of global state
sebastian/lines-of-code 3.0.1 Library for counting the lines of...
sebastian/object-enumerator 6.0.1 Traverses array structures and ob...
sebastian/object-reflector 4.0.1 Allows reflection of object attri...
phpunit/php-code-coverage 11.0.7 Library that provides collection,...
phpunit/php-file-iterator 5.1.0 FilterIterator implementation tha...
phpunit/php-invoker 5.0.1 Invoke callables with a timeout
phpunit/php-text-template 4.0.1 Simple template engine.
phpunit/php-timer 7.0.1 Utility class for timing
phpunit/phpunit 11.4.1 The PHP Unit Testing framework.
sebastian/recursion-context 6.0.2 Provides functionality to recursi...
sebastian/type 5.1.0 Collection of value objects that ...
sebastian/version 5.0.2 Library that helps with managing ...
theseer/tokenizer 1.2.3 A small library for converting to...
The text was updated successfully, but these errors were encountered:
Summary
In some cases, the diff ouptut can be confusing when assertEquals fails on comparing objects or arrays containing \DateTime.
Current behavior
Given this test
Testing output below is generated
It's confusing because as diff is given for
\DateTime
objects, it may suggest thatstdClass
instances in second element ofactual
andexpected
array are equals.Expected behavior
After some investigation, I saw that
ObjectComparator
keeps track of processed pair ofexpected
andactual
values to avoid redundant comparison: that's why diff onstdClass
is not displayed on second elements.DateTimeComparator
, even though it extendsObjectComparator
does not have the same behavior on keeping track of processed comparisons. I think it should.As a result, the testing output could be
Additional information
phpunit.xml
composer.json
composer info | sort
The text was updated successfully, but these errors were encountered: