From: Brad Jorsch Date: Fri, 7 Dec 2012 16:08:15 +0000 (-0500) Subject: Make sure MaintenanceFixup's shutdown is simulated X-Git-Tag: 1.31.0-rc.0~21396^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=a2093fecb3e59d959cd50238ec4d7ec1fdce5a2f;p=lhc%2Fweb%2Fwiklou.git Make sure MaintenanceFixup's shutdown is simulated Previously, MaintenanceTest created a MaintenanceFixup in setUp and relied on each test to call MaintenanceFixup's simulateShutdown instead of making sure this was called in tearDown. Change Iee1261e7 broke this by introducing a meta-test in a parent class. Fixing that also allows us to not have to special-case failed tests. Change-Id: I67c8615dd94734bb55ca48aac0c66298accbe0b4 --- diff --git a/tests/phpunit/maintenance/MaintenanceTest.php b/tests/phpunit/maintenance/MaintenanceTest.php index 4a6f08fa4f..a0ed745c12 100644 --- a/tests/phpunit/maintenance/MaintenanceTest.php +++ b/tests/phpunit/maintenance/MaintenanceTest.php @@ -88,15 +88,16 @@ class MaintenanceFixup extends Maintenance { * Safety net around register_shutdown_function of Maintenance.php */ public function __destruct() { - if ( ( ! $this->shutdownSimulated ) && ( ! $this->testCase->hasFailed() ) ) { + if ( ! $this->shutdownSimulated ) { // Someone generated a MaintenanceFixup instance without calling // simulateShutdown. We'd have to raise a PHPUnit exception to correctly // flag this illegal usage. However, we are already in a destruktor, which // would trigger undefined behaviour. Hence, we can only report to the // error output :( Hopefully people read the PHPUnit output. - fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " destructed without " - . "calling simulateShutdown method. Call simulateShutdown on the " - . "instance before it gets destructed." ); + $name = $this->testCase->getName(); + fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " for test $name " + . "destructed without calling simulateShutdown method. Call " + . "simulateShutdown on the instance before it gets destructed." ); } // The following guard is required, as PHP does not offer default destructors :( @@ -148,6 +149,14 @@ class MaintenanceTest extends MediaWikiTestCase { $this->m = new MaintenanceFixup( $this ); } + protected function tearDown() { + if ( $this->m ) { + $this->m->simulateShutdown(); + $this->m = null; + } + parent::tearDown(); + } + /** * asserts the output before and after simulating shutdown @@ -167,6 +176,7 @@ class MaintenanceTest extends MediaWikiTestCase { "Output before shutdown simulation" ); $this->m->simulateShutdown(); + $this->m = null; $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" ); $this->expectOutputString( $postShutdownOutput ); @@ -809,4 +819,4 @@ class MaintenanceTest extends MediaWikiTestCase { } -} \ No newline at end of file +}