summaryrefslogtreecommitdiff
path: root/tests/phpunit/tests/MediaWikiTestCaseTest.php
blob: 2846fde000e6bb294370d85d9800401ab2cb1540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

/**
 * @covers MediaWikiTestCase
 * @author Adam Shorland
 */
class MediaWikiTestCaseTest extends MediaWikiTestCase {

	const GLOBAL_KEY_EXISTING = 'MediaWikiTestCaseTestGLOBAL-Existing';
	const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting';

	public static function setUpBeforeClass() {
		parent::setUpBeforeClass();
		$GLOBALS[self::GLOBAL_KEY_EXISTING] = 'foo';
	}

	public static function tearDownAfterClass() {
		parent::tearDownAfterClass();
		unset( $GLOBALS[self::GLOBAL_KEY_EXISTING] );
	}

	/**
	 * @covers MediaWikiTestCase::setMwGlobals
	 * @covers MediaWikiTestCase::tearDown
	 */
	public function testSetGlobalsAreRestoredOnTearDown() {
		$this->setMwGlobals( self::GLOBAL_KEY_EXISTING, 'bar' );
		$this->assertEquals(
			'bar',
			$GLOBALS[self::GLOBAL_KEY_EXISTING],
			'Global failed to correctly set'
		);

		$this->tearDown();

		$this->assertEquals(
			'foo',
			$GLOBALS[self::GLOBAL_KEY_EXISTING],
			'Global failed to be restored on tearDown'
		);
	}

	/**
	 * @covers MediaWikiTestCase::stashMwGlobals
	 * @covers MediaWikiTestCase::tearDown
	 */
	public function testStashedGlobalsAreRestoredOnTearDown() {
		$this->stashMwGlobals( self::GLOBAL_KEY_EXISTING );
		$GLOBALS[self::GLOBAL_KEY_EXISTING] = 'bar';
		$this->assertEquals(
			'bar',
			$GLOBALS[self::GLOBAL_KEY_EXISTING],
			'Global failed to correctly set'
		);

		$this->tearDown();

		$this->assertEquals(
			'foo',
			$GLOBALS[self::GLOBAL_KEY_EXISTING],
			'Global failed to be restored on tearDown'
		);
	}

	/**
	 * @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 );
	}

}