summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/debug/MWDebugTest.php
blob: 9026cb90d646c4d512b2537a5cb0267824d406f7 (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
<?php

class MWDebugTest extends MediaWikiTestCase {


	protected function setUp() {
		parent::setUp();
		// Make sure MWDebug class is enabled
		static $MWDebugEnabled = false;
		if ( !$MWDebugEnabled ) {
			MWDebug::init();
			$MWDebugEnabled = true;
		}
		/** Clear log before each test */
		MWDebug::clearLog();
		wfSuppressWarnings();
	}

	protected function tearDown() {
		wfRestoreWarnings();
		parent::tearDown();
	}

	function testAddLog() {
		MWDebug::log( 'logging a string' );
		$this->assertEquals(
			array( array(
				'msg' => 'logging a string',
				'type' => 'log',
				'caller' => __METHOD__,
			) ),
			MWDebug::getLog()
		);
	}

	function testAddWarning() {
		MWDebug::warning( 'Warning message' );
		$this->assertEquals(
			array( array(
				'msg' => 'Warning message',
				'type' => 'warn',
				'caller' => 'MWDebugTest::testAddWarning',
			) ),
			MWDebug::getLog()
		);
	}

	function testAvoidDuplicateDeprecations() {
		MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
		MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );

		// assertCount() not available on WMF integration server
		$this->assertEquals( 1,
			count( MWDebug::getLog() ),
			"Only one deprecated warning per function should be kept"
		);
	}

	function testAvoidNonConsecutivesDuplicateDeprecations() {
		MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
		MWDebug::warning( 'some warning' );
		MWDebug::log( 'we could have logged something too' );
		// Another deprecation
		MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );

		// assertCount() not available on WMF integration server
		$this->assertEquals( 3,
			count( MWDebug::getLog() ),
			"Only one deprecated warning per function should be kept"
		);
	}
}