Problem/Motivation
This is a child issue of #2949363: Impossible to make trigger_error in some files without test fails
In that issue we discovered that we can't perform test discovery on files which @trigger_error() for deprecation without causing false-fail test runs.
These include abstract classes, such as base classes, traits, and interfaces.
The problem: TestDiscovery uses reflection, which loads the file, which triggers the deprecation error whether the class is used or not in any test.
In #2296635: Evaluate performance impact of limiting test discovery to *Test.php filename suffix we considered excluding all files from scan except for *test.php files. This presents BC problems because it could lead to false positives for the unaware.
Proposed resolution
Modify TestDiscovery to exclude reflection on files which end in TestBase.php, Trait.php and Iterface.php.
This mitigates the problem of triggering E_USER_DEPRECATED in the various abstract test types, while also allowing greater BC than simply ignoring all files that don't end in *Test.php.
Map:
- #8: version with exclude TestBase.php, Trait.php and Interface.php
- #14: version with exclude TestBase.php and Trait.php
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2973127-18.patch | 3.47 KB | Anonymous (not verified) |
| #16 | 2973127-8.patch | 3.41 KB | Anonymous (not verified) |
| #14 | 2973127-14.patch | 3.16 KB | Anonymous (not verified) |
Comments
Comment #2
mile23This is because the test suite classes call
PHPUnit\Framework\TestSuite::addTestFile()at some point, which performs reflection. We can't really change that.This means we have to change
TestDiscovery::scanDirectory()to exclude*TestBase.php, since the test suite classes usescanDirectory().Comment #3
mile23Modified
scanDirectory()and added a test.Comment #4
mile23Boo. Perform
strtolower()once.Comment #5
Anonymous (not verified) commentedWhy we need strolower at all?) We expect to here some naming patterns, let's compare them more strictly. This will also help prevent accidental coincidences like
TestBasE.php= Bas (bioaktive substanz) + E (vitamin) 🙃Maybe also include interface.php? Something like:
Edit:
Comment #6
Anonymous (not verified) commentedComment #8
Anonymous (not verified) commentedOkay, let's remove extra
KernelExampleTraITcheck, but save 'KernelExampleTest3' to ensure, that we check correct keys.Comment #9
mile23I limited to *TestBase.php and *Trait.php because that's what @alexpott had mentioned in #28 and #29 in #2949363: Impossible to make trigger_error in some files without test fails
I'm not even sure we have any test interfaces to exclude... Does contrib?
Comment #10
alexpottI think we can now skip this issue a move on doing #2296635: Evaluate performance impact of limiting test discovery to *Test.php filename suffix in a planned fashion since the bug of triggering deprecation messages when scanning all the tests is now fixed.
Comment #11
mile23#2949363: Impossible to make trigger_error in some files without test fails only fixes it for run-tests.sh. This bug still exists for the test suite classes. See #2.
Comment #12
Anonymous (not verified) commentedSo this check is based only on the fact that technically the syntax allows you to do this case. Although we have not real cases :) I agree to remove, for the sake of performance.
interfaces in tests folder
Interfaces with trigger:
Comment #13
alexpottI think it is fine to exclude interfaces now - eventually once we fully implement #2296635: Evaluate performance impact of limiting test discovery to *Test.php filename suffix we'll not need this but this is a good halfway step.
Comment #14
Anonymous (not verified) commented#13: Done.
Comment #15
alexpott/me should have been clearer... by
I meant that excluding interfaces as done in #8 seems fine. Sorry.
Comment #16
Anonymous (not verified) commentedHah, np) Reupload #8 + updated the scope in Title/IS.
Comment #18
Anonymous (not verified) commentedOpps, reroll.
Comment #19
mile23Added a CR: https://www.drupal.org/node/2974044
Updated IS for clarity.
I can't RTBC or I would. :-)
Comment #20
Anonymous (not verified) commentedRTBC++
Comment #21
borisson_RTBC based on #19 and #20 and the fact that there is sufficient test-coverage.
Comment #23
alexpottUsing run-tests.sh --list command to test this will a few popular contrib modules lying around. Good news is that core is unaffected. Interestingly the following differences are found:
So this looks great. These are abstract classes that shouldn't be listed and as a result of this change won't be. Nice one.
Comment #25
mile23@mixologic put out the fire, so we can go back to RTBC.
Comment #27
Anonymous (not verified) commentedComment #28
alexpottCommitted 8f92d9a and pushed to 8.6.x. Thanks!
Only committed to 8.6.x because we shouldn't add new deprecations to 8.5.x so this is really more of a task. Also I'm not sure how long this code will actually hang about about if we do #2296635: Evaluate performance impact of limiting test discovery to *Test.php filename suffix during 8.x - I think we could deprecate support for non *Test.php classes in 8.6.x and remove support in 8.7.x - so this code might only last to 8.7.x - still it is better to have it than not.
Comment #30
mile23Published CR.