Make sure MaintenanceFixup's shutdown is simulated
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 7 Dec 2012 16:08:15 +0000 (11:08 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 7 Dec 2012 16:08:15 +0000 (11:08 -0500)
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

tests/phpunit/maintenance/MaintenanceTest.php

index 4a6f08f..a0ed745 100644 (file)
@@ -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
+}