Page MenuHomePhabricator

MediaWikiServicesTest::testDefaultServiceInstantiation fails when run on its own
Closed, ResolvedPublic

Description

It's possible this is something with my local setup (but I see the same behavior in an experimental patch on CI so I suspect not), but when I run php tests/phpunit/phpunit.php tests/phpunit/includes/MediaWikiServicesTest.php, this class fails on testDefaultServiceInstantiation.

That test is pretty straightforward:

public function testDefaultServiceInstantiation() {
    // Check all services in the default instance, not a dummy instance!
    // Note that we instantiate all services here, including any that
    // were registered by extensions.
    $services = MediaWikiServices::getInstance();
    $names = $services->getServiceNames();

    foreach ( $names as $name ) {
        $this->assertTrue( $services->hasService( $name ) );
        $service = $services->getService( $name );
        $this->assertIsObject( $service );
    }
}

The failure I get:

php tests/phpunit/phpunit.php tests/phpunit/includes/MediaWikiServicesTest.php --filter "testDefaultServiceInstantiation"

PHPUnit 8.5.21 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 1.63 seconds, Memory: 50.50 MB

There was 1 error:

1) MediaWikiServicesTest::testDefaultServiceInstantiation
Error: Call to a member function inNamespace() on null

/Users/kostajh/src/mediawiki/w/skins/MinervaNeue/includes/ServiceWiring.php:93
/Users/kostajh/src/mediawiki/w/vendor/wikimedia/services/src/ServiceContainer.php:447
/Users/kostajh/src/mediawiki/w/vendor/wikimedia/services/src/ServiceContainer.php:416
/Users/kostajh/src/mediawiki/w/includes/MediaWikiServices.php:291
/Users/kostajh/src/mediawiki/w/tests/phpunit/includes/MediaWikiServicesTest.php:386
/Users/kostajh/src/mediawiki/w/tests/phpunit/MediaWikiIntegrationTestCase.php:456

ERRORS!
Tests: 1, Assertions: 9, Errors: 1.

Following the stack trace, it looks like there is no $wgTitle associated with the RequestContext::getMain() call. I suppose that when php tests/phpunit/phpunit.php is run with all test suites, there is some test that accidentally populates $wgTitle? Not sure.

I can fix the error by setting $wgTitle in the run() method in MediaWikiIntegrationTestCase, but maybe there's some other solution I am missing.

I also wonder how many other tests fail when run on their own but that's a task for another day.

Event Timeline

Change 743692 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/core@master] phpunit: Set $wgTitle for MediaWikiIntegrationTestCase

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

IContextSource::getTitle is documented to return null, Minerva has to check RequestContext::hasTitle before use it. This can also happen for maintenance script. In my opinion setting deprecated $wgTitle is not what should be done.

IContextSource::getTitle is documented to return null, Minerva has to check RequestContext::hasTitle before use it. This can also happen for maintenance script. In my opinion setting deprecated $wgTitle is not what should be done.

Yeah, I agree, that would be going a step backwards.

Change 743692 abandoned by Kosta Harlan:

[mediawiki/core@master] phpunit: Set $wgTitle for MediaWikiIntegrationTestCase

Reason:

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

Change 743906 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/skins/MinervaNeue@master] ServiceWiring: Add fallback for when title is null

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

Change 744074 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/skins/MinervaNeue@master] ServiceWiring: Allow for Title to be null

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

Change 743906 merged by jenkins-bot:

[mediawiki/skins/MinervaNeue@master] ServiceWiring: Add fallback for when title is null

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

Krinkle assigned this task to kostajh.
Krinkle triaged this task as Medium priority.

Change 744074 abandoned by Kosta Harlan:

[mediawiki/skins/MinervaNeue@master] ServiceWiring: Allow for Title to be null

Reason:

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