Throw exception from Maintenance::fatalError when in PHPUnit tests
Why:
- The Maintenance::fatalError method calls the exit method, which when called causes the PHPUnit test suites to exit early.
- This means that code that calls ::fatalError cannot be tested unless the method is mocked for each test.
- To avoid this problem the ::fatalError method should not call exit() when running PHPUnit tests, as described in T272241. Instead, it should throw an exception which can be caught when the call is expected.
What:
- Create MaintenanceFatalError which extends Exception, which is thrown by Maintenance::fatalError instead of calling exit() if the 'MW_PHPUNIT_TEST' constant is defined.
- This new exception takes the error code passed to the ::fatalError method and uses it as the exception error code.
- Create MaintenanceBaseTestCase::expectCallToFatalError which makes it easier for tests to assert that a call to Maintenance::fatalError occurs. This can optionally assert that the $code passed is as expected.
- Code which wishes to assert against the provided $msg can use ::expectOutputString or ::expectOutputRegex.
Bug: T272241
Change-Id: I554a963c63eb4f22ebb3273053a7b83a33dcb4d1