Merge "Added DatabaseBase::startAtomic and endAtomic"
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / MWDebugTest.php
1 <?php
2
3 class MWDebugTest extends MediaWikiTestCase {
4
5
6 protected function setUp() {
7 parent::setUp();
8 // Make sure MWDebug class is enabled
9 static $MWDebugEnabled = false;
10 if ( !$MWDebugEnabled ) {
11 MWDebug::init();
12 $MWDebugEnabled = true;
13 }
14 /** Clear log before each test */
15 MWDebug::clearLog();
16 wfSuppressWarnings();
17 }
18
19 protected function tearDown() {
20 wfRestoreWarnings();
21 parent::tearDown();
22 }
23
24 /**
25 * @covers MWDebug::log
26 */
27 public function testAddLog() {
28 MWDebug::log( 'logging a string' );
29 $this->assertEquals(
30 array( array(
31 'msg' => 'logging a string',
32 'type' => 'log',
33 'caller' => __METHOD__,
34 ) ),
35 MWDebug::getLog()
36 );
37 }
38
39 /**
40 * @covers MWDebug::warning
41 */
42 public function testAddWarning() {
43 MWDebug::warning( 'Warning message' );
44 $this->assertEquals(
45 array( array(
46 'msg' => 'Warning message',
47 'type' => 'warn',
48 'caller' => 'MWDebugTest::testAddWarning',
49 ) ),
50 MWDebug::getLog()
51 );
52 }
53
54 /**
55 * @covers MWDebug::deprecated
56 */
57 public function testAvoidDuplicateDeprecations() {
58 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
59 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
60
61 // assertCount() not available on WMF integration server
62 $this->assertEquals( 1,
63 count( MWDebug::getLog() ),
64 "Only one deprecated warning per function should be kept"
65 );
66 }
67
68 /**
69 * @covers MWDebug::deprecated
70 */
71 public function testAvoidNonConsecutivesDuplicateDeprecations() {
72 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
73 MWDebug::warning( 'some warning' );
74 MWDebug::log( 'we could have logged something too' );
75 // Another deprecation
76 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
77
78 // assertCount() not available on WMF integration server
79 $this->assertEquals( 3,
80 count( MWDebug::getLog() ),
81 "Only one deprecated warning per function should be kept"
82 );
83 }
84 }