Page MenuHomePhabricator

Maintenance::fatalError cannot be covered in tests
Closed, ResolvedPublic

Description

Tests for maintenance scripts might want to cover some situations that cause the script to fatal. Currently, this isn't possible because Maintenance::fatalError calls exit() and brings the suite down. I think a quick and effective solution might be to create a new error type, MaintenanceFatalError extends \Error. Then the exit() can be replaced with throwing this error, either always (but need to ensure this won't break anything), or only if MW_PHPUNIT_TEST is defined.

Event Timeline

See also T99268: RfC: Create a proper command-line runner for MediaWiki maintenance tasks (currently, there are quite a few things making maintenance scripts hard to test).

Change #1059475 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@master] Throw exception from Maintenance::fatalError when in PHPUnit tests

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

Change #1059475 merged by jenkins-bot:

[mediawiki/core@master] Throw exception from Maintenance::fatalError when in PHPUnit tests

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