Page MenuHomePhabricator

Clarify confusing error "ConfigException: GlobalVarConfig::get: undefined option: ServiceWiringFiles" when using Title etc. in a unit test
Closed, ResolvedPublic

Description

E.g. https://gerrit.wikimedia.org/r/c/mediawiki/core/+/532558 fails with:

12:24:00 1) ParserFactoryTest::testAllArgumentsWerePassed
12:24:00 ConfigException: GlobalVarConfig::get: undefined option: 'ServiceWiringFiles'

The error is super unhelpful, as none of it is connected to the failing test in any obvious way.

Details

Related Gerrit Patches:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 27 2019, 10:00 AM
Tgr added a subscriber: Tgr.Aug 28 2019, 9:45 PM

You can't use Title in unit tests. It loads a bunch of services just to parse the page name, and services are not set up for unit tests.

Tgr renamed this task from ParserFactoryTest::testAllArgumentsWerePassed: ConfigException: GlobalVarConfig::get: undefined option: 'ServiceWiringFiles' to Clarify confusing error "ConfigException: GlobalVarConfig::get: undefined option: ServiceWiringFiles" when using Title etc. in a unit test.Aug 28 2019, 9:46 PM
Tgr updated the task description. (Show Details)

Repurposing the task to make this error message less terrible.

Hmm I see, so we have some tests that will use the title from parser if it gives one.

Tgr added a comment.Aug 29 2019, 11:05 PM

Or more likely just fetch it. The error is usually triggered by Title::newFromText. You can probably avoid it by using a Title construction method that does not involve namespace parsing.

Krinkle moved this task from Inbox to PHPUnit on the MediaWiki-Core-Testing board.Sep 4 2019, 5:46 PM
Krinkle added a subscriber: Krinkle.

Was there a stack trace? If it contains UnitTestCase, it means no unmocked globals are allowed. Is this ticket resolved?

Was there a stack trace? If it contains UnitTestCase, it means no unmocked globals are allowed. Is this ticket resolved?

The ticket was repurposed to explicitly and clearly warn that using un-mocked globals is not allowed in unit tests, rather than the current error test.

I suppose UnitTestCase could override run() and catch ConfigException and then re-throw with an additional message to specify that not only is a global config var undefined - that config vars in general are disabled in a UnitTestCase.

Change 534575 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/core@master] Tests: Provide clearer error when config is accessed via unit test

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

kostajh claimed this task.Sep 5 2019, 7:15 AM
Krinkle closed this task as Resolved.Sep 5 2019, 6:50 PM

Change 534575 merged by jenkins-bot:
[mediawiki/core@master] Tests: Provide clearer error when config is accessed via unit test

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