Problem/Motivation
This issue is a stop-gap for some of the problems brought forward in #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
symfony/phpunit-bridge adds a test listener to all phpunit tests. In the startTest()
event, this listener makes a list of @expectedDeprecation
annotations on the test method. During the test, it then uses an error handler to account for E_USER_DEPRECATED
errors triggered during the test. In the endTest()
event, it accounts for the list of errors and the list of expected errors and fails the test as needed.
If the test is marked as @runTestInSeparateProcess
, or otherwise signals that it should be isolated in a process, the start and end events happen, but no errors are ever handled. That's because they all happened in the context of a separate process, with no way to send the errors back to the listener.
This leads to the problem of @expectedDeprecation
s never having associated errors, leading to test fails based on these expectations.
This means that only non-isolated unit tests can legitimately set @expectedDeprecation
. Since our deprecation policy includes writing a test to prove that the deprecation error is triggered, this could lead to some large degree of code contortion to prove the error was triggered. https://www.drupal.org/core/deprecation
Proposed resolution
Add a wrapper test listener which determines whether the test was run in isolation, and if it was, and there were expected deprecations, mark the test as risky.
This is a half-way solution which should prevent false fails, while also letting the user know that their test might not be entirely useful.
Remaining tasks
There is an upstream issue to attempt to fix this: https://github.com/symfony/symfony/issues/23003
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#2 | 2884530_2.patch | 9.4 KB | Mile23 |
Comments
Comment #2
Mile23Patch which re-uses tests from #2870194-31: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
Adds
Drupal\Tests\Listeners\DrupalPhpUnitBridgeListener
which subclassesSymfonyTestsListener
.The best way to see the effects of this patch is to use the phpunit tool:
This will produce results as follows:
Comment #4
xjmPromoting to match the parent issue. I'm not totally sure about the interim solution here and wondering if we should wait for upstream, but at least I can set the issue priority. :P
I don't think skipped tests are surfaced on CI and I've never seen "risky" actually used before; do we have anything else that does so?
Comment #5
Mile23'Risky' generally means there's no assertion in the test. We got rid of all those for core, before 8.0 I think. https://phpunit.de/manual/4.8/en/risky-tests.html
The reason we'd do this is because process-isolated tests with @expectedDeprecation actually are risky. :-) They'll be seen as pass even if they fail, even if you use the phpunit runner. After the change here, we'd see R instead of . in a phpunit test run, and that's really the only change.
The only upstream interest is me, and I'm confused by symfony's testing system. Plus we're stuck at an old version of symfony, so we'd probably have to convince someone to OK a backport. https://github.com/symfony/symfony/issues/23003
I'm increasingly convinced the way to solve this is to make our own implementation, so we can include Simpletests.
Comment #6
Mile23symfony/phpunit-bridge can now deal with process-isolated deprecation errors, so this issue is outdated. #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code