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

class MWDebugTest extends MediaWikiTestCase {


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

	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' => 'MWDebug::warning',
			) ),
			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"
		);
	}
}