Problem/Motivation
Discovered when starting to get PHPStan running against Drupal core in #3178534: Start running PHPStan on Drupal core (level 0), several errors were reported where the void return value of PHPUnit assertions were returned. These are bugs where the documentation says the method returns TRUE in the case of success, in fact this is not the case and the method returns NULL (and an exception is thrown if the assertion fails, so FALSE is never returned either).
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3204764-2.patch | 26.83 KB | longwave |
Comments
Comment #2
longwaveThere is an argument that each of these methods should always return TRUE as per the docs, but as they currently return NULL I think we should follow PHPUnit convention and also return NULL from our custom assertion helpers.
Comment #4
mondrakeSould be good to add a
voidtypehint to the assertions then; it would be good to do here so the changes are enforced. Otherwise, #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods is already a follow-up.Comment #5
mondrakeIs #3131900: Refactor assertions that assign return values to variables now a duplicate/obsolete then?
Comment #6
longwaveThat is related but I don't think it's an exact duplicate? This one is hopefully more straightforward because the current docs are just wrong for each of these methods, so to me this is just a straight cleanup.
Comment #7
mondrake#6 agree
Comment #9
catchMakes sense to fix the documentation here then do actual refactoring in the other issue.
Committed 7e1043e and pushed to 9.2.x. Thanks!
Comment #11
mondrakeStrange that this is not failing... now this is asserting both emptiness and non emptiness in case $count is true, one of the two should fail.
Comment #12
longwaveOh yes, well spotted. The issue is this is only ever called once, the TRUE path is never exercised: