From 3cbaac08cd978fa324d719139ed306880f49304c Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Sun, 14 Sep 2014 21:07:14 +0200 Subject: [PATCH] MediaWikiTestCase: Enforce children call parent::tearDown Can't be implemented as a test case because that's not being run before MediaWikiTestCase::tearDown. Also there's no parent destructor, so no need to call one. Also fixed BagOStuffTest. Change-Id: Ifd8659b6c8a748c6716099f8822e2c50ab51bda7 --- tests/phpunit/MediaWikiTestCase.php | 11 ++++++++++- tests/phpunit/includes/objectcache/BagOStuffTest.php | 3 --- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 1166817506..995853ea79 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -88,6 +88,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->backupStaticAttributes = false; } + public function __destruct() { + // Complain if self::setUp() was called, but not self::tearDown() + // $this->called['setUp'] will be checked by self::testMediaWikiTestCaseParentSetupCalled() + if ( isset( $this->called['setUp'] ) && !isset( $this->called['tearDown'] ) ) { + throw new MWException( get_called_class() . "::tearDown() must call parent::tearDown()" ); + } + } + public function run( PHPUnit_Framework_TestResult $result = null ) { /* Some functions require some kind of caching, and will end up using the db, * which we can't allow, as that would open a new connection for mysql. @@ -192,7 +200,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function setUp() { wfProfileIn( __METHOD__ ); parent::setUp(); - $this->called['setUp'] = 1; + $this->called['setUp'] = true; $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) ); @@ -221,6 +229,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function tearDown() { wfProfileIn( __METHOD__ ); + $this->called['tearDown'] = true; // Cleaning up temporary files foreach ( $this->tmpFiles as $fileName ) { if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) { diff --git a/tests/phpunit/includes/objectcache/BagOStuffTest.php b/tests/phpunit/includes/objectcache/BagOStuffTest.php index 160ddad020..987b6e6467 100644 --- a/tests/phpunit/includes/objectcache/BagOStuffTest.php +++ b/tests/phpunit/includes/objectcache/BagOStuffTest.php @@ -23,9 +23,6 @@ class BagOStuffTest extends MediaWikiTestCase { $this->cache->delete( wfMemcKey( 'test' ) ); } - protected function tearDown() { - } - public function testMerge() { $key = wfMemcKey( 'test' ); -- 2.20.1