phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

`TestCase::assertEquals(false, '0')` is failing

Open mvorisek opened this issue 3 years ago • 1 comments

Q A
PHPUnit version 9.5.10
PHP version 7.4
Installation Method Composer

Summary

TestCase::assertEquals(false, '0')

currently produces:

Failed asserting that '0' matches expected false.

and does NOT match the php weak comparison: https://3v4l.org/qQkXC

also $this->assertEquals(false, 0) passes, so TestCase::assertEquals(false, '0') should pass too and be consistent

mvorisek avatar May 07 '22 16:05 mvorisek

changing https://github.com/sebastianbergmann/comparator/blob/main/src/ScalarComparator.php#L61 to

-        if (is_string($expected) || is_string($actual)) {
+        if ((is_string($expected) && !is_bool($actual)) || (is_string($actual) && !is_bool($expected))) {

fixes the issue for me

mvorisek avatar May 07 '22 16:05 mvorisek