Skip to content

Tests: use strict assertions#692

Merged
mblaney merged 2 commits intosimplepie:masterfrom
jrfnl:feature/tests-use-strict-assertions
Aug 21, 2021
Merged

Tests: use strict assertions#692
mblaney merged 2 commits intosimplepie:masterfrom
jrfnl:feature/tests-use-strict-assertions

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.

jrfnl added 2 commits August 15, 2021 12:27
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.

2 participants