which we weren't treating right. * $limit in wfDebugBacktrace() is the number of returned frames, we thus need to take into account the wfDebugBacktrace() frame, which is sliced from debug_backtrace(). * wfGetCaller() needs to add a level for itself. * MWDebug::warning() was logging itself as the warning issuer, which is useless (the call a few lines before was right, though) MWDebugTest.php changed accordingly. * Removed double call to wfGetCaller( $callerOffset + 1 ) * Documented the meaning of wfGetCaller() parameter * Added unit test Change-Id: Ief50f4c810bad8b03bb2bf9dc6d945d9acb29851
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?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' => 'MWDebugTest::testAddWarning',
|
|
) ),
|
|
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"
|
|
);
|
|
}
|
|
}
|