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

Assert expected data types in tests #9268

Merged
merged 4 commits into from
Dec 17, 2023

Conversation

mvorisek
Copy link
Contributor

Use TestCase::assertSame() instead of TestCase::assertEquals() which does not assert expected data type.

Fix php_unit_strict rule.

@mvorisek mvorisek changed the title Assert specific types in tests Assert expected data types in tests Dec 17, 2023
@@ -56,7 +56,7 @@ function test_parse_bytes()

foreach ($data as $value => $expected) {
$result = parse_bytes($value);
$this->assertEquals($expected, $result, "Invalid parse_bytes() result for $value");
$this->{'assertEquals'}($expected, $result, "Invalid parse_bytes() result for $value");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???? here and in some other places.

Copy link
Contributor Author

@mvorisek mvorisek Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{'assertEquals'} is a hack for PHP CS Fixer to still allow TestCase::assertEquals() to be used.

The (fixed) php_unit_strict rule is risky, so I reviewed them manually to prevent bad changed. Here, I would expect bytes to be parsed to integer, so I kept original assertEquals, so with a fix in future, the test will still pass. The fix/improvement is here: #9268. In that PR, the test is hardened to assertSame.

@alecpl alecpl merged commit 8c82b29 into roundcube:master Dec 17, 2023
15 checks passed
@mvorisek mvorisek deleted the phpunit_strict_cmp branch December 17, 2023 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants