use MediaWiki\Logger\MonologSpi;
use MediaWiki\MediaWikiServices;
use Psr\Log\LoggerInterface;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+use Wikimedia\Rdbms\Database;
use Wikimedia\TestingAccessWrapper;
/**
protected static function resetGlobalServices( Config $bootstrapConfig = null ) {
$oldServices = MediaWikiServices::getInstance();
$oldConfigFactory = $oldServices->getConfigFactory();
+ $oldLoadBalancerFactory = $oldServices->getDBLoadBalancerFactory();
$testConfig = self::makeTestConfig( $bootstrapConfig );
$serviceLocator = MediaWikiServices::getInstance();
self::installTestServices(
$oldConfigFactory,
+ $oldLoadBalancerFactory,
$serviceLocator
);
return $serviceLocator;
/**
* @param ConfigFactory $oldConfigFactory
+ * @param LBFactory $oldLoadBalancerFactory
* @param MediaWikiServices $newServices
*
* @throws MWException
*/
private static function installTestServices(
ConfigFactory $oldConfigFactory,
+ LBFactory $oldLoadBalancerFactory,
MediaWikiServices $newServices
) {
// Use bootstrap config for all configuration.
[ 'main' => $bootstrapConfig ]
)
);
+ $newServices->resetServiceForTesting( 'DBLoadBalancerFactory' );
+ $newServices->redefineService(
+ 'DBLoadBalancerFactory',
+ function ( MediaWikiServices $services ) use ( $oldLoadBalancerFactory ) {
+ return $oldLoadBalancerFactory;
+ }
+ );
}
/**
* The key is added to the array of globals that will be reset afterwards
* in the tearDown().
*
- * @example
- * <code>
+ * @par Example
+ * @code
* protected function setUp() {
* $this->setMwGlobals( 'wgRestrictStuff', true );
* }
* }
*
* function testQuux() {}
- * </code>
+ * @endcode
*
* @param array|string $pairs Key to the global variable, or an array
* of key/value pairs.
$oldInstance = MediaWikiServices::getInstance();
$oldConfigFactory = $oldInstance->getConfigFactory();
+ $oldLoadBalancerFactory = $oldInstance->getDBLoadBalancerFactory();
$testConfig = self::makeTestConfig( null, $configOverrides );
$newInstance = new MediaWikiServices( $testConfig );
self::installTestServices(
$oldConfigFactory,
+ $oldLoadBalancerFactory,
$newInstance
);
MediaWikiServices::forceGlobalInstance( $newInstance );
private function addCoreDBData() {
if ( $this->db->getType() == 'oracle' ) {
-
# Insert 0 user to prevent FK violations
# Anonymous user
if ( !$this->db->selectField( 'user', '1', [ 'user_id' => 0 ] ) ) {
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();
if ( $db->getType() == 'oracle' ) {
$db->query( 'BEGIN FILL_WIKI_INFO; END;' );
}
+
+ Hooks::run( 'UnitTestsAfterDatabaseSetup', [ $db, $prefix ] );
}
/**
if ( !isset( $wgNamespaceContentModels[$ns] ) ||
$wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT
) {
-
$wikitextNS = $ns;
return $wikitextNS;