Add two new hooks to fix broken CentralAuth unit tests
authorMax Semenik <maxsem.wiki@gmail.com>
Thu, 29 Jun 2017 00:14:18 +0000 (17:14 -0700)
committerKaldari <rkaldari@wikimedia.org>
Wed, 5 Jul 2017 17:18:27 +0000 (10:18 -0700)
* UnitTestsAfterDatabaseSetup
* UnitTestsBeforeDatabaseTeardown
Bug T168802 necessitates that CentralAuth creates its tables
before any user tests are run, due to its extensive hooking
into everything. This change adds two hooks for that, called
after DB initialization is done and before teardown begins. The
corresponding CentralAuth change is
at I618840fafd22d9b6471eb470ef0414e354aa17f5

Bug: T168802
Change-Id: If7050513719833d4167a24283885d7c10a25856b

docs/hooks.txt
tests/phpunit/MediaWikiTestCase.php

index 62e5bdb..8825151 100644 (file)
@@ -3452,6 +3452,14 @@ $title: Title object of the page that we're about to undelete
 $title: title object related to the revision
 $rev: revision (object) that will be viewed
 
+'UnitTestsAfterDatabaseSetup': Called right after MediaWiki's test infrastructure
+has finished creating/duplicating core tables for unit tests.
+$database: Database in question
+$prefix: Table prefix to be used in unit tests
+
+'UnitTestsBeforeDatabaseTeardown': Called right before MediaWiki tears down its
+database infrastructure used for unit tests.
+
 'UnitTestsList': Called when building a list of paths containing PHPUnit tests.
 Since 1.24: Paths pointing to a directory will be recursively scanned for
 test case files matching the suffix "Test.php".
index 26ee420..15833dc 100644 (file)
@@ -5,6 +5,8 @@ use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\Logger\MonologSpi;
 use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerInterface;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+use Wikimedia\Rdbms\Database;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -1113,6 +1115,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        return;
                }
 
+               Hooks::run( 'UnitTestsBeforeDatabaseTeardown' );
+
                foreach ( $wgJobClasses as $type => $class ) {
                        // Delete any jobs under the clone DB (or old prefix in other stores)
                        JobQueueGroup::singleton()->get( $type )->delete();
@@ -1215,6 +1219,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                if ( $db->getType() == 'oracle' ) {
                        $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
                }
+
+               Hooks::run( 'UnitTestsAfterDatabaseSetup', [ $db, $prefix ] );
        }
 
        /**