Merge "While testing, turn off DataBase::ignoreErrors."
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 908c076..cbf9a8e 100644 (file)
@@ -5,6 +5,20 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        public $regex = '';
        public $runDisabled = false;
 
+       /**
+        * $called tracks whether the setUp and tearDown method has been called.
+        * class extending MediaWikiTestCase usually override setUp and tearDown
+        * but forget to call the parent.
+        *
+        * The array format takes a method name as key and anything as a value.
+        * By asserting the key exist, we know the child class has called the
+        * parent.
+        *
+        * This property must be private, we do not want child to override it,
+        * they should call the appropriate parent method instead.
+        */
+       private $called = array();
+
        /**
         * @var Array of TestUser
         */
@@ -150,6 +164,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected function setUp() {
                wfProfileIn( __METHOD__ );
                parent::setUp();
+               $this->called['setUp'] = 1;
 
                /*
                //@todo: global variables to restore for *every* test
@@ -216,6 +231,16 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * Make sure MediaWikiTestCase extending classes have called their
+        * parent setUp method
+        */
+       final public function testMediaWikiTestCaseParentSetupCalled() {
+               $this->assertArrayHasKey( 'setUp', $this->called,
+                       get_called_class() . "::setUp() must call parent::setUp()"
+               );
+       }
+
        /**
         * Individual test functions may override globals (either directly or through this
         * setMwGlobals() function), however one must call this method at least once for