Introduce stashMwGlobals method to MediaWikiTestCase
[lhc/web/wiklou.git] / tests / phpunit / tests / MediaWikiTestCaseTest.php
1 <?php
2
3 /**
4 * @covers MediaWikiTestCase
5 * @author Adam Shorland
6 */
7 class MediaWikiTestCaseTest extends MediaWikiTestCase {
8
9 const GLOBAL_KEY_EXISTING = 'MediaWikiTestCaseTestGLOBAL-Existing';
10
11 public static function setUpBeforeClass() {
12 parent::setUpBeforeClass();
13 $GLOBALS[self::GLOBAL_KEY_EXISTING] = 'foo';
14 }
15
16 public static function tearDownAfterClass() {
17 parent::tearDownAfterClass();
18 unset( $GLOBALS[self::GLOBAL_KEY_EXISTING] );
19 }
20
21 /**
22 * @covers MediaWikiTestCase::setMwGlobals
23 * @covers MediaWikiTestCase::tearDown
24 */
25 public function testSetGlobalsAreRestoredOnTearDown() {
26 $this->setMwGlobals( self::GLOBAL_KEY_EXISTING, 'bar' );
27 $this->assertEquals(
28 'bar',
29 $GLOBALS[self::GLOBAL_KEY_EXISTING],
30 'Global failed to correctly set'
31 );
32
33 $this->tearDown();
34
35 $this->assertEquals(
36 'foo',
37 $GLOBALS[self::GLOBAL_KEY_EXISTING],
38 'Global failed to be restored on tearDown'
39 );
40 }
41
42 /**
43 * @covers MediaWikiTestCase::stashMwGlobals
44 * @covers MediaWikiTestCase::tearDown
45 */
46 public function testStashedGlobalsAreRestoredOnTearDown() {
47 $this->stashMwGlobals( self::GLOBAL_KEY_EXISTING );
48 $GLOBALS[self::GLOBAL_KEY_EXISTING] = 'bar';
49 $this->assertEquals(
50 'bar',
51 $GLOBALS[self::GLOBAL_KEY_EXISTING],
52 'Global failed to correctly set'
53 );
54
55 $this->tearDown();
56
57 $this->assertEquals(
58 'foo',
59 $GLOBALS[self::GLOBAL_KEY_EXISTING],
60 'Global failed to be restored on tearDown'
61 );
62 }
63
64 }