jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/333590 )

Change subject: TitleBlacklistTest singleton can now be destroyed
......................................................................


TitleBlacklistTest singleton can now be destroyed

The test suite set $wgTitleBlacklistSources with a fixture source of
directories.  Unfortunately when running tests from MediaWiki core the
TitleBlacklist has already been set with empty value and thus setting
the global is a noop.

That later causes a test to fail because the blacklist is emtpy.

Add TitleBlacklistTest::destroySingleton() so a test can reset the
singleton when changing $wgTitleBlacklistSources.

Since that is solely for testing, throw an exception unless we had
MW_PHPUNIT_TEST defined.

Bug: T155980
Change-Id: I99c3185811ed7b2225953fa6960096985e97c4d2
---
M TitleBlacklist.list.php
M tests/phpunit/ApiQueryTitleBlacklistTest.php
2 files changed, 31 insertions(+), 5 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/TitleBlacklist.list.php b/TitleBlacklist.list.php
index efa41e3..55f3add 100644
--- a/TitleBlacklist.list.php
+++ b/TitleBlacklist.list.php
@@ -17,6 +17,10 @@
  */
 class TitleBlacklist {
        private $mBlacklist = null, $mWhitelist = null;
+
+       /** @var TitleBlacklist */
+       protected static $instance = null;
+
        const VERSION = 3;      // Blacklist format
 
        /**
@@ -25,12 +29,28 @@
         * @return TitleBlacklist
         */
        public static function singleton() {
-               static $instance = null;
-
-               if ( $instance === null ) {
-                       $instance = new self;
+               if ( self::$instance === null ) {
+                       self::$instance = new self;
                }
-               return $instance;
+               return self::$instance;
+       }
+
+       /**
+        * Destroy/reset the current singleton instance.
+        *
+        * This is solely for testing and will fail unless MW_PHPUNIT_TEST is
+        * defined.
+        */
+       public static function destroySingleton() {
+
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+                       throw new MWException(
+                               'Can not invoke ' . __METHOD__ . '() ' .
+                               'out of tests (MW_PHPUNIT_TEST not set).'
+                       );
+               }
+
+               self::$instance = null;
        }
 
        /**
diff --git a/tests/phpunit/ApiQueryTitleBlacklistTest.php 
b/tests/phpunit/ApiQueryTitleBlacklistTest.php
index ab3a83a..d0036dd 100644
--- a/tests/phpunit/ApiQueryTitleBlacklistTest.php
+++ b/tests/phpunit/ApiQueryTitleBlacklistTest.php
@@ -22,6 +22,7 @@
                parent::setUp();
                $this->doLogin();
 
+               TitleBlacklist::destroySingleton();
                $this->setMwGlobals( 'wgTitleBlacklistSources', array(
                        array(
                                'type' => 'file',
@@ -30,6 +31,11 @@
                ) );
        }
 
+       function tearDown() {
+               TitleBlacklist::destroySingleton();
+               parent::tearDown();
+       }
+
        /**
         * Verify we allow a title which is not blacklisted
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/333590
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I99c3185811ed7b2225953fa6960096985e97c4d2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to