*
* @param array|string $globalKeys Key to the global variable, or an array of keys.
*
+ * @throws Exception when trying to stash an unset global
* @since 1.23
*/
protected function stashMwGlobals( $globalKeys ) {
// setMwGlobals() on the same global would override the original
// value.
if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
+ if ( !array_key_exists( $globalKey, $GLOBALS ) ) {
+ throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
+ }
// 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
// and if is_object but this does account for objects within objects!
class MediaWikiTestCaseTest extends MediaWikiTestCase {
const GLOBAL_KEY_EXISTING = 'MediaWikiTestCaseTestGLOBAL-Existing';
+ const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting';
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
);
}
+ /**
+ * @covers MediaWikiTestCase::stashMwGlobals
+ */
+ public function testExceptionThrownWhenStashingNonExistentGlobals() {
+ $this->setExpectedException(
+ 'Exception',
+ 'Global with key ' . self::GLOBAL_KEY_NONEXISTING . ' doesn\'t exist and cant be stashed'
+ );
+
+ $this->stashMwGlobals( self::GLOBAL_KEY_NONEXISTING );
+ }
+
}