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.

Event Timeline

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.

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 subscribed.

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

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