wiki.techinc.nl/tests/phpunit/includes/debug/MWDebugTest.php
Alexandre Emsenhuber 5af2159512 Moved warning stuff into MWDebug class.
- Group common code in one instead of doing checks one
  time in GlobalFunctions.php and another time in Debug.php
- Remove the code catching the fact that a warning is due
  to a deprecation warning, no longer needed
- Pass the caller offset from wfDeprecated() to
  MWDebug::deprecated(); this was breaking deprecation
  notices for global objects.
- Changed PHP error level for deprecation notices (when
  $wgDevelopmentWarnings is set to true) from E_USER_NOTICE
  to E_USER_DEPRECATED since we now require PHP 5.3+
- Added E_USER_DEPRECATED to wfSuppressWarnings() and
  removed the check for the E_DEPRECATED constant being set
  now that we require PHP 5.3+
- Fixed MWDebugTest by calling wfSuppressWarnings() and
  wfRestoreWarnings() in setUp() and tearDown()

Change-Id: I6810b57c90d384de55a2cf177047767cdb734f79
2012-08-28 15:33:44 +02:00

68 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();
wfSuppressWarnings();
}
function tearDown() {
wfRestoreWarnings();
}
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"
);
}
}