QA: use the most specific PHPUnit assertion possible #414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a long established best practice.
PHPUnit contains a variety of assertions and the ones available has been extended hugely over the years.
To have the most reliable tests, the most specific assertion should be used.
Refs:
Most notably, this changes nearly all calls to
assertEquals()
toassertSame()
, whereassertEquals()
does a loose type comparison andassertSame()
does a strict type comparison.Refs:
Note: this change now causes two tests to fail on PHP 5.4-5.6 and three tests to fail on PHP 5.2-5.3.
Based on these test results, the methods under test are not PHP cross-version compatible as they return different results depending on the PHP version.
We'll need to decide what the desired behaviour should be and will need to adjust the code base to fix this. Input for this very welcome.
Test failure details
The first two fail on all PHP 5.x builds. The third only on PHP 5.2 and 5.3.