r108873 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108872‎ | r108873 | r108874 >
Date:23:07, 13 January 2012
Author:hashar
Status:ok (Comments)
Tags:
Comment:
some tests for MWDebug

Really incomplete. We need better testing.

Added two new public methods so we can get or clear the internal logs.
Modified paths:
  • /trunk/phase3/includes/debug/Debug.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/debug (added) (history)
  • /trunk/phase3/tests/phpunit/includes/debug/MWDebugTest.php (added) (history)

Diff [purge]

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
156 + native
Index: trunk/phase3/includes/debug/Debug.php
@@ -85,6 +85,21 @@
8686 }
8787
8888 /**
 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+ /**
89104 * Adds a warning entry to the log
90105 *
91106 * @param $msg
@@ -274,4 +289,4 @@
275290
276291 return $html;
277292 }
278 -}
\ No newline at end of file
 293+}

Comments

#Comment by Krinkle (talk | contribs)   23:39, 13 January 2012
+	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()
+		);
+	}
+

So log() takes stacktrace(-1) as caller, but warning() doesn't ?

#Comment by Hashar (talk | contribs)   23:41, 13 January 2012

That is the code I was investigating in includes/debug/Debug.php

Note that all tests works for me :-)

#Comment by Krinkle (talk | contribs)   23:44, 13 January 2012

Well, if a test is assuming "wrong" output and MWDebug does that, the test comes out at successful :D

Status & tagging log