*/
private $mwGlobals = [];
+ /**
+ * Holds list of MediaWiki configuration settings to be unset in tearDown().
+ * See also setMwGlobals().
+ * @var array
+ */
+ private $mwGlobalsToUnset = [];
+
/**
* Holds original loggers which have been replaced by setLogger()
* @var LoggerInterface[]
* which we can't allow, as that would open a new connection for mysql.
* Replace with a HashBag. They would not be going to persist anyway.
*/
- $hashCache = [ 'class' => 'HashBagOStuff' ];
+ $hashCache = [ 'class' => 'HashBagOStuff', 'reportDupes' => false ];
$objectCaches = [
CACHE_DB => $hashCache,
CACHE_ACCEL => $hashCache,
foreach ( $this->mwGlobals as $key => $value ) {
$GLOBALS[$key] = $value;
}
+ foreach ( $this->mwGlobalsToUnset as $value ) {
+ unset( $GLOBALS[$value] );
+ }
$this->mwGlobals = [];
+ $this->mwGlobalsToUnset = [];
$this->restoreLoggers();
if ( self::$serviceLocator && MediaWikiServices::getInstance() !== self::$serviceLocator ) {
*
* @param array|string $globalKeys Key to the global variable, or an array of keys.
*
- * @throws Exception When trying to stash an unset global
- *
* @note To allow changes to global variables to take effect on global service instances,
* call overrideMwServices().
*
// NOTE: make sure we only save the global once or a second call to
// setMwGlobals() on the same global would override the original
// value.
- if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
+ if (
+ !array_key_exists( $globalKey, $this->mwGlobals ) &&
+ !array_key_exists( $globalKey, $this->mwGlobalsToUnset )
+ ) {
if ( !array_key_exists( $globalKey, $GLOBALS ) ) {
- throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
+ $this->mwGlobalsToUnset[$globalKey] = $globalKey;
+ continue;
}
// NOTE: we serialize then unserialize the value in case it is an object
// this stops any objects being passed by reference. We could use clone
/** @var ExternalStoreDB $externalStoreDB */
$externalStoreDB = ExternalStore::getStoreObject( 'DB' );
- $defaultArray = (array) $wgDefaultExternalStore;
+ $defaultArray = (array)$wgDefaultExternalStore;
$dbws = [];
foreach ( $defaultArray as $url ) {
if ( strpos( $url, 'DB://' ) === 0 ) {
return false;
}
- $defaultArray = (array) $wgDefaultExternalStore;
+ $defaultArray = (array)$wgDefaultExternalStore;
foreach ( $defaultArray as $url ) {
if ( strpos( $url, 'DB://' ) === 0 ) {
return true;