4 * @covers MediaWikiTestCase
5 * @author Adam Shorland
7 class MediaWikiTestCaseTest
extends MediaWikiTestCase
{
9 const GLOBAL_KEY_NONEXISTING
= 'MediaWikiTestCaseTestGLOBAL-NONExisting';
11 private static $startGlobals = array(
12 'MediaWikiTestCaseTestGLOBAL-ExistingString' => 'foo',
13 'MediaWikiTestCaseTestGLOBAL-ExistingStringEmpty' => '',
14 'MediaWikiTestCaseTestGLOBAL-ExistingArray' => array( 1, 'foo' => 'bar' ),
15 'MediaWikiTestCaseTestGLOBAL-ExistingArrayEmpty' => array(),
18 public static function setUpBeforeClass() {
19 parent
::setUpBeforeClass();
20 foreach ( self
::$startGlobals as $key => $value ) {
21 $GLOBALS[$key] = $value;
25 public static function tearDownAfterClass() {
26 parent
::tearDownAfterClass();
27 foreach ( self
::$startGlobals as $key => $value ) {
28 unset( $GLOBALS[$key] );
32 public function provideExistingKeysAndNewValues() {
33 $providedArray = array();
34 foreach ( array_keys( self
::$startGlobals ) as $key ) {
35 $providedArray[] = array( $key, 'newValue' );
36 $providedArray[] = array( $key, array( 'newValue' ) );
38 return $providedArray;
42 * @dataProvider provideExistingKeysAndNewValues
44 * @covers MediaWikiTestCase::setMwGlobals
45 * @covers MediaWikiTestCase::tearDown
47 public function testSetGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
48 $this->setMwGlobals( $globalKey, $newValue );
52 'Global failed to correctly set'
58 self
::$startGlobals[$globalKey],
60 'Global failed to be restored on tearDown'
65 * @dataProvider provideExistingKeysAndNewValues
67 * @covers MediaWikiTestCase::stashMwGlobals
68 * @covers MediaWikiTestCase::tearDown
70 public function testStashedGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
71 $this->stashMwGlobals( $globalKey );
72 $GLOBALS[$globalKey] = $newValue;
76 'Global failed to correctly set'
82 self
::$startGlobals[$globalKey],
84 'Global failed to be restored on tearDown'
89 * @covers MediaWikiTestCase::stashMwGlobals
91 public function testExceptionThrownWhenStashingNonExistentGlobals() {
92 $this->setExpectedException(
94 'Global with key ' . self
::GLOBAL_KEY_NONEXISTING
. ' doesn\'t exist and cant be stashed'
97 $this->stashMwGlobals( self
::GLOBAL_KEY_NONEXISTING
);