Problem/Motivation
PHPUnit8 introduced several warnings about things that are going away in PHPUnit 9. At the moment DrupalCI ignores these warnings and the tests pass. However if you run tests locally you see the warnings and think you test has failed.
For example running ./vendor/bin/phpunit -v -c ./core core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php you'll see:
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.13
Configuration: /Users/alex/dev/sites/drupal8alt.dev/core/phpunit.xml
Testing Drupal\Tests\Core\Extension\ExtensionSerializationTest
W. 2 / 2 (100%)
Time: 245 ms, Memory: 6.00 MB
There was 1 warning:
1) Drupal\Tests\Core\Extension\ExtensionSerializationTest::testServiceAppRouteUsage
readAttribute() is deprecated and will be removed in PHPUnit 9.
getObjectAttribute() is deprecated and will be removed in PHPUnit 9.
/Users/alex/dev/sites/drupal8alt.dev/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
/Users/alex/dev/sites/drupal8alt.dev/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
/Users/alex/dev/sites/drupal8alt.dev/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:621
/Users/alex/dev/sites/drupal8alt.dev/vendor/phpunit/phpunit/src/TextUI/Command.php:200
/Users/alex/dev/sites/drupal8alt.dev/vendor/phpunit/phpunit/src/TextUI/Command.php:159
WARNINGS!
Tests: 2, Assertions: 3, Warnings: 1.
This is critical because local testing and DrupalCI testing do not match.
Proposed resolution
Remaining tasks
User interface changes
None
API changes
New test trait that our test base classes use to ignore warnings.
Data model changes
None
Release notes snippet
None
Comments
Comment #2
alexpottComment #3
alexpottHere's the patch from #3110543-33: [meta] Support PHPUnit 9 in Drupal 9.
Comment #4
alexpottComment #5
alexpottComment #6
mile23Speaking of which, see: #2905007: Allow run-tests.sh to report skipped/incomplete PHPUnit tests
Depreception!
I really wish we could turn this off easily so we can see the tech debt without having to find the deprecation trait to alter it. Does convertWarningsToExceptions or similar let us do this?
Comment #7
alexpott@Mile23 I envisage that we're going to clear out this warnings very quickly. So we can support PHPUnit 9 so I don't like contrib or custom will have to wait long. So I'm not sure that turning it off is that worthwhile.
convertWarningsToExceptionsdoesn't work.Comment #8
mile23Patch applies and works locally for me, tests are green...
Give this annotation a neighbor that's a @todo pointing to #3110543: [meta] Support PHPUnit 9 in Drupal 9 and it's RTBC afaic.
Comment #9
alexpott@Mile23 good idea.
Comment #10
mile23LGTM.
Comment #11
alexpottI resolved the conflict in core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
Comment #12
alexpottRerolled again.
Comment #14
catchCommitted 00d95c7 and pushed to 9.0.x. Thanks!