Problem/Motivation
Drupal core deprecation standards say we should:
a) @trigger_error()
for classes and files on file load, right after the namespace declaration.
b) Produce a test which proves that @trigger_error()
will be caught by the phpunit-bridge
See https://www.drupal.org/core/deprecation in the 'How We Deprecate' section.
Just one snag: We also have a test listener which enforces the validity of @covers
and @coversDefaultClasses
annotations. This is the DrupalStandardsListener
.
DrupalStandardsListener
calls class_exists()
on annotated classes, which can cause the file to be loaded by the class loader.
This means that outside of the context of the test itself, we can @trigger_error()
for deprecation. Needless to say, symfony/phpunit-bridge does not account for our use-case.
This leads to deprecation errors for tests of deprecated classes which are also annotated as @covers
.
Proposed resolution
Current hacky solution: Add @group legacy
to DrupalStandardsListener::endTest()
annotation.
Add your better idea here.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#23 | interdiff.txt | 1.12 KB | Mile23 |
#23 | 2878248_23.patch | 4.15 KB | Mile23 |
#20 | interdiff.txt | 1.9 KB | Mile23 |
#20 | 2878248_20.patch | 4.13 KB | Mile23 |
#20 | 2878248_20_test_only.patch | 3.12 KB | Mile23 |
Comments
Comment #2
Mile23Changing to 8.4.x because phpunit-bridge is only in 8.4.x. Ewps.
Here are two patches, test only and test passing.
The location of the fixture class is just the first one I thought of for PoC, since it's likely that a module's class file would need to be loaded by the classloader during a unit test.
And here's the kind of error I see without the fix:
Note that this error is being triggered within
DrupalStandardsListener::endTest()
.Comment #3
Mile23Comment #6
Mile23Forgot @group annotation.
Interdiff is for the full patch, but applies either way.
Comment #7
Mile23The patches in #2 and #6 add a test called
Drupal\Tests\Listeners\DrupalStandardsListenerDeprecationTest
.So here's a question: Why is
phpunit --testsuite unit
able to run it, but run-tests.sh is not? Look in the console log, it's not there: https://dispatcher.drupalci.org/job/drupal_patches/15702/consoleFullComment #8
Mile23And here's the answer: #2878269: Modify TestDiscovery so the testbot runs all the tests
Comment #9
Mile23Moved the test to \Drupal\Tests\Core\Listeners\ as a workaround for #2878269: Modify TestDiscovery so the testbot runs all the tests
Comment #11
dawehnerIt would be nice to explain in a common why this is needed.
Comment #12
Mile23Good idea.
Comment #13
dawehnerThank you @Mile23!
Comment #14
catchSorry coding standards checks don't like the empty documentation:
'This docblock has been intentionally left blank"?
edit: or whatever the coding standard skip annotation is for that file?
Comment #15
Mile23I got sidetracked with that phpunit problem and never got back to documentation...
Added and expanded docblock comments, since this is a complex test case.
Note that the test added here reveals a similar problems during code coverage report generation, where the tests pass but the coverage process also ends up throwing the error. Whether this matters or not is outside the scope of this issue, I think. We might need to re-think the placement of the
@trigger_error()
, unless we don't. :-)Comment #16
Mile23Re-running test.
Comment #17
dawehnerIs there a reason this cannot be placed inside the tests somehow? It feels weird to have that in system module.
Comment #18
Mile23If you can think of a better place, please suggest. :-)
It has to be autoloadable but not loaded at that point in testing.
Comment #19
dawehnerSo a hidden test module in core/modules would not work?
Comment #20
Mile23Moved to
core/modules/system/tests/modules/deprecation_test/
.Comment #21
dawehnerThank you @mile23, this is much better
Comment #23
Mile23Missed a doc reference to the class we just moved...
Comment #24
Mile23Moving back to RTBC because it's only a doc change, and the tests will likely run before a maintainer ends up here.
Comment #25
alexpottCommitted 1160fbb and pushed to 8.4.x. Thanks!