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

Tests: use strict assertions #692

Merged
merged 2 commits into from
Aug 21, 2021

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 15, 2021

Tests: use strict assertions

PHPUnit contains a variety of assertions and the ones available have been extended hugely over the years.
To have the most reliable tests, the most specific assertion should be used.

Most notably, this changes calls to assertEquals() to assertSame(), where assertEquals() does a loose type comparison == and assertSame() does a strict type === comparison.

The only real exception to this is when comparing two objects, as in that case, the objectID will not be the same, so those should still use assertEquals() - or the PHPUnit 9.4.0 assertObjectEquals() method for comparing value objects using a callback method in the ValueObject class.

Tests: use strict assertions in custom assertion

The custom assertEqualsBin2Hex() assertion was using assertEquals() as well.
When changing this to assertSame(), it makes sense to also change the custom assertion method name to assertSameBin2Hex() and adjust all calls to the method.

PHPUnit contains a variety of assertions and the ones available have been extended hugely over the years.
To have the most reliable tests, the most specific assertion should be used.

Most notably, this changes calls to `assertEquals()` to `assertSame()`, where `assertEquals()` does a loose type comparison `==` and `assertSame()` does a strict type `===` comparison.

The only real exception to this is when comparing two objects, as in that case, the objectID will not be the same, so those should still use `assertEquals()` - or the PHPUnit 9.4.0 `assertObjectEquals()` method for comparing value objects using a callback method in the ValueObject class.
The custom `assertEqualsBin2Hex()` assertion was using `assertEquals()` as well.
When changing this to `assertSame()`, it makes sense to also change the custom assertion method name to `assertSameBin2Hex()` and adjust all calls to the method.
@mblaney mblaney merged commit e2d11a0 into simplepie:master Aug 21, 2021
@jrfnl jrfnl deleted the feature/tests-use-strict-assertions branch August 21, 2021 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants