[go: up one dir, main page]

Page MenuHomePhabricator

vendor/bin/phpunit fails with MobileFrontend integration tests
Closed, ResolvedPublic

Description

vendor/bin/phpunit extensions/MobileFrontend/tests/phpunit/integration/ results in

Error: Call to a member function getIP() on null in /Users/kharlan/src/mediawiki/includes/user/User.php on line 2260

Call Stack:
    0.0146     395680   1. {main}() /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/phpunit:0
    0.0923    2472248   2. PHPUnit\TextUI\Command::main(???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/phpunit:53
    0.0923    2472360   3. PHPUnit\TextUI\Command->run(???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.2045    5212448   4. PHPUnit\TextUI\TestRunner->getTest(???, ???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/TextUI/Command.php:169
    0.2197    5432688   5. PHPUnit\Framework\TestSuite->addTestFiles(???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:65
    0.2940    7734552   6. PHPUnit\Framework\TestSuite->addTestFile(???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:403
    0.2959    7860032   7. PHPUnit\Framework\TestSuite->addTestSuite(???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:377
    0.2959    7860288   8. PHPUnit\Framework\TestSuite->__construct(???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:290
    0.2962    7942568   9. PHPUnit\Framework\TestSuite->addTestMethod(???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:187
    0.2962    7942992  10. PHPUnit\Framework\TestSuite::createTest(???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:882
    0.2965    7947312  11. PHPUnit\Util\Test::getProvidedData(???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Framework/TestSuite.php:482
    0.2966    7947440  12. PHPUnit\Util\Test::getDataFromDataProviderAnnotation(???, ???, ???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Util/Test.php:449
    0.2966    7950392  13. ReflectionMethod->invoke(???) /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Util/Test.php:521
    0.2966    7950392  14. MobileFormatterTest->provideHtmlTransform() /Users/kharlan/src/mediawiki/vendor/phpunit/phpunit/src/Util/Test.php:521
    0.5278   16096424  15. MediaWiki\Session\SessionManager->shutdown() /Users/kharlan/src/mediawiki/includes/session/SessionManager.php:0
    0.5279   16096424  16. MediaWiki\Session\SessionBackend->shutdown() /Users/kharlan/src/mediawiki/includes/session/SessionManager.php:449
    0.5279   16096424  17. MediaWiki\Session\SessionBackend->save(???) /Users/kharlan/src/mediawiki/includes/session/SessionBackend.php:217
    0.5281   16097120  18. User->getName() /Users/kharlan/src/mediawiki/includes/session/SessionBackend.php:734

while php tests/phpunit/phpunit.php extensions/MobileFrontend/tests/phpunit/integration/ works fine.

The line that triggers the problem is in extensions/MobileFrontend/tests/phpunit/integration/MobileFormatterTest.php, line 230, where we have wfMessage( 'mobile-frontend-missing-image' ) . ']</span>',. wfMessage() ends up getting to User.php:2260 where $this->getRequest() returns null.

Event Timeline

This happens because wfMessage() is called in the context of a data provider, so the initializeForStandardPhpunitEntrypointIfNeeded() code in MediaWikiIntegrationTestCase is not called, and it's that code which loads Setup.php and sets the request object.

I'm getting this error now even with a clean install with no extensions installed, and just the Vector skin.

Change 623324 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/extensions/MobileFrontend@master] PHPUnit: Set up classes in data provider

https://gerrit.wikimedia.org/r/623324

Looking at topics like this, it seems like in your data provider you'll need to do something like call MediaWikiIntegrationTestCase::setUpBeforeClass() to ensure the relevant MediaWiki classes are available. The patch I've pushed does that, although there's still an issue with LiquidThreads:

Warning: Use of undefined constant NS_LQT_THREAD - assumed 'NS_LQT_THREAD' (this will throw an Error in a future version of PHP) in /var/www/html/extensions/LiquidThreads/classes/Dispatch.php on line 122

And we should probably have a method that is not called MediaWikiIntegrationTestCase::setUpBeforeClass() for dataProvider methods to call.

Change 623324 abandoned by Kosta Harlan:
[mediawiki/extensions/MobileFrontend@master] PHPUnit: Set up classes in data provider

Reason:

https://gerrit.wikimedia.org/r/623324

Daimona subscribed.

The test cases using wfMessage have been removed in r626593, and integration tests are now passing with the standard entry point:

$ vendor/bin/phpunit extensions/MobileFrontend/tests/phpunit/integration/
Using PHP 8.1.20
PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

...............................................................  63 / 236 ( 26%)
............................................................... 126 / 236 ( 53%)
............................................................... 189 / 236 ( 80%)
...............................................                 236 / 236 (100%)

Time: 00:01.101, Memory: 74.50 MB

OK (236 tests, 432 assertions)

Hence resolving this.

I'm sure there are lots of ways to (re)introduce similar issues, but hopefully it should be much harder to do so once T227900 and T332865 are done.