From 0f02086990341197085808a385e1fea6ef339f37 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 13 Jan 2012 23:07:52 +0000 Subject: [PATCH] some tests for MWDebug Really incomplete. We need better testing. Added two new public methods so we can get or clear the internal logs. --- includes/debug/Debug.php | 17 +++++- tests/phpunit/includes/debug/MWDebugTest.php | 54 ++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/includes/debug/MWDebugTest.php diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php index 010745963d..d56b65bc23 100644 --- a/includes/debug/Debug.php +++ b/includes/debug/Debug.php @@ -84,6 +84,21 @@ class MWDebug { ); } + /** + * Returns internal log array + */ + public static function getLog() { + return self::$log; + } + + /** + * Clears internal log array and deprecation tracking + */ + public static function clearLog() { + self::$log = array(); + self::$deprecationWarnings = array(); + } + /** * Adds a warning entry to the log * @@ -274,4 +289,4 @@ class MWDebug { return $html; } -} \ No newline at end of file +} diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php new file mode 100644 index 0000000000..e36e42fbfa --- /dev/null +++ b/tests/phpunit/includes/debug/MWDebugTest.php @@ -0,0 +1,54 @@ +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' ); + + $this->assertCount( 1, + 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' ); + + $this->assertCount( 3, + MWDebug::getLog(), + "Only one deprecated warning per function should be kept" + ); + } +} -- 2.20.1