HomePhorge

Throw exception from Maintenance::fatalError when in PHPUnit tests

This commit no longer exists in the repository. It may have been part of a branch which was deleted.

Description

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

Details

Provenance
Dreamy JazzAuthored on Aug 3 2024, 9:00 PM

Event Timeline

Dreamy Jazz <dreamyjazzwikipedia@gmail.com> committed rMW65d62ae39ea1: Throw exception from Maintenance::fatalError when in PHPUnit tests (authored by Dreamy Jazz <dreamyjazzwikipedia@gmail.com>).Aug 3 2024, 10:54 PM

Commit No Longer Exists

This commit no longer exists in the repository.