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

TestCase::assertEquals(false, '0') is failing #4967

Closed
mvorisek opened this issue May 7, 2022 · 1 comment
Closed

TestCase::assertEquals(false, '0') is failing #4967

mvorisek opened this issue May 7, 2022 · 1 comment
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken

Comments

@mvorisek
Copy link
Contributor

mvorisek commented May 7, 2022

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 mvorisek added the type/bug Something is broken label May 7, 2022
@mvorisek
Copy link
Contributor Author

mvorisek commented May 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants