Index: trunk/phase3/tests/phpunit/includes/debug/MWDebugTest.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class MWDebugTest extends MediaWikiTestCase { |
| 5 | + |
| 6 | + function tearDown() { |
| 7 | + /** Clear log before each test */ |
| 8 | + MWDebug::clearLog(); |
| 9 | + } |
| 10 | + |
| 11 | + function testAddLog() { |
| 12 | + MWDebug::log( 'logging a string' ); |
| 13 | + $this->assertEquals( array( array( |
| 14 | + 'msg' => 'logging a string', |
| 15 | + 'type' => 'log', |
| 16 | + 'caller' => __METHOD__ , |
| 17 | + ) ), |
| 18 | + MWDebug::getLog() |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + function testAddWarning() { |
| 23 | + MWDebug::warning( 'Warning message' ); |
| 24 | + $this->assertEquals( array( array( |
| 25 | + 'msg' => 'Warning message', |
| 26 | + 'type' => 'warn', |
| 27 | + 'caller' => 'MWDebug::warning', |
| 28 | + ) ), |
| 29 | + MWDebug::getLog() |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + function testAvoidDuplicateDeprecations() { |
| 34 | + MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); |
| 35 | + MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); |
| 36 | + |
| 37 | + $this->assertCount( 1, |
| 38 | + MWDebug::getLog(), |
| 39 | + "Only one deprecated warning per function should be kept" |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + function testAvoidNonConsecutivesDuplicateDeprecations() { |
| 44 | + MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); |
| 45 | + MWDebug::warning( 'some warning' ); |
| 46 | + MWDebug::log( 'we could have logged something too' ); |
| 47 | + // Another deprecation |
| 48 | + MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); |
| 49 | + |
| 50 | + $this->assertCount( 3, |
| 51 | + MWDebug::getLog(), |
| 52 | + "Only one deprecated warning per function should be kept" |
| 53 | + ); |
| 54 | + } |
| 55 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/debug/MWDebugTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 56 | + native |
Index: trunk/phase3/includes/debug/Debug.php |
— | — | @@ -85,6 +85,21 @@ |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
| 89 | + * Returns internal log array |
| 90 | + */ |
| 91 | + public static function getLog() { |
| 92 | + return self::$log; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Clears internal log array and deprecation tracking |
| 97 | + */ |
| 98 | + public static function clearLog() { |
| 99 | + self::$log = array(); |
| 100 | + self::$deprecationWarnings = array(); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
89 | 104 | * Adds a warning entry to the log |
90 | 105 | * |
91 | 106 | * @param $msg |
— | — | @@ -274,4 +289,4 @@ |
275 | 290 | |
276 | 291 | return $html; |
277 | 292 | } |
278 | | -} |
\ No newline at end of file |
| 293 | +} |