Clean up transactions after test.
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 27 Aug 2012 12:38:25 +0000 (14:38 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 27 Aug 2012 12:38:25 +0000 (14:38 +0200)
MediaWikiTestCase::teardown() will now rollback any transactions
left open by a test case. This is intended to make sure tests do
not provide "interesting" results casued by transaction state
leaking from other tests.

Change-Id: Ia225251efd5aafbaa6674e2732ab1ba7761bfadc

tests/phpunit/MediaWikiTestCase.php

index c873c51..49c2a70 100644 (file)
@@ -115,7 +115,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        }
 
        protected function tearDown() {
-               // Cleaning up temoporary files
+               // Cleaning up temporary files
                foreach ( $this->tmpfiles as $fname ) {
                        if ( is_file( $fname ) || ( is_link( $fname ) ) ) {
                                unlink( $fname );
@@ -124,6 +124,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        }
                }
 
+               // clean up open transactions
+               if( $this->needsDB() && $this->db ) {
+                       while( $this->db->trxLevel() > 0 ) {
+                               $this->db->rollback();
+                       }
+               }
+
                parent::tearDown();
        }