Page MenuHomePhabricator

PHPUnit integration tests fail with "No such service: HookContainer"
Closed, ResolvedPublicBUG REPORT

Description

When I try to run many PHPUnit integration tests, I get a whole bunch of errors like this:

$ php8.0 vendor/bin/phpunit tests/phpunit/includes/TitleTest.php
PHP Deprecated:  Premature access to service container [Called from Message::inContentLanguage in /var/www/html/w/includes/language/Message.php at line 868] in /var/www/html/w/includes/debug/MWDebug.php on line 380
...
PHPUnit 8.5.26 #StandWithUkraine

ESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  63 / 628 ( 10%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Time: 788 ms, Memory: 28.00 MB

There was 1 error:

1) TitleTest::testInNamespace
Wikimedia\Services\NoSuchServiceException: No such service: HookContainer in /var/www/html/w/vendor/wikimedia/services/src/ServiceContainer.php:468
Stack trace:
#0 /var/www/html/w/vendor/wikimedia/services/src/ServiceContainer.php(416): Wikimedia\Services\ServiceContainer->createService()
#1 /var/www/html/w/includes/MediaWikiServices.php(299): Wikimedia\Services\ServiceContainer->getService()
#2 /var/www/html/w/includes/MediaWikiServices.php(1029): MediaWiki\MediaWikiServices->getService()
#3 /var/www/html/w/includes/MediaWikiServices.php(382): MediaWiki\MediaWikiServices->getHookContainer()
#4 /var/www/html/w/includes/MediaWikiServices.php(241): MediaWiki\MediaWikiServices::resetGlobalInstance()
#5 /var/www/html/w/includes/Setup.php(274): MediaWiki\MediaWikiServices::allowGlobalInstance()
#6 /var/www/html/w/tests/phpunit/bootstrap.php(42): require_once('...')
#7 /var/www/html/w/tests/phpunit/MediaWikiIntegrationTestCase.php(178): wfRequireOnceInGlobalScope()
#8 /var/www/html/w/tests/phpunit/MediaWikiIntegrationTestCase.php(198): MediaWikiIntegrationTestCase::initializeForStandardPhpunitEntrypointIfNeeded()
#9 /var/www/html/w/vendor/phpunit/phpunit/src/Framework/TestSuite.php(571): MediaWikiIntegrationTestCase::mediaWikiSetUpBeforeClass()
#10 /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(659): PHPUnit\Framework\TestSuite->run()
#11 /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php(235): PHPUnit\TextUI\TestRunner->doRun()
#12 /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php(194): PHPUnit\TextUI\Command->run()
#13 /var/www/html/w/vendor/phpunit/phpunit/phpunit(98): PHPUnit\TextUI\Command::main()
#14 /var/www/html/w/vendor/bin/phpunit(120): include('...')
#15 {main}
ERRORS!
Tests: 629, Assertions: 0, Errors: 1, Skipped: 100.

I'm running a fresh, clean install on an up-to-date master, and just ran composer update and php maintenance/update.php. Some tests that exhibit the problem: includes/TitleTest.php, includes/preferences/DefaultPreferencesFactoryTest.php, includes/Permissions/PermissionManagerTest.php. I don't know what the best strategy is to debug.

Event Timeline

In case it's relevant, I get a whole list of those "premature access to service container" warnings also, with no extensions installed. The only change I made to the LocalSettings.php generated by the installer is loading the Vector skin.

In case it's relevant, I get a whole list of those "premature access to service container" warnings also, with no extensions installed. The only change I made to the LocalSettings.php generated by the installer is loading the Vector skin.

For the "premature access to service container", see T297292: Fix "Deprecated: Premature access to service" from data providers when using vendor/bin/phpunit; IIRC that happens when code in a data provider accesses MediaWiki services.

In case it's relevant, I get a whole list of those "premature access to service container" warnings also, with no extensions installed. The only change I made to the LocalSettings.php generated by the installer is loading the Vector skin.

For the "premature access to service container", see T297292: Fix "Deprecated: Premature access to service" from data providers when using vendor/bin/phpunit; IIRC that happens when code in a data provider accesses MediaWiki services.

Right, looking at the debugger, that seems to be what is going on in multiple data providers in that class:

image.png (1×1 px, 460 KB)

Krinkle assigned this task to kostajh.