From 66afa6ecd0d9cd4711bdf7a87152fc1ed03edf90 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sat, 14 May 2016 22:09:13 -0700 Subject: [PATCH] MWDebugTest: disable MWDebug on test teardown MWDebug::init() is currently irreversible -- once MWDebug is enabled, it cannot be disabled in that execution context. This means that the MWDebug test suite (which enables MWDebug) has a nasty side-effect -- all the tests that run after it run with MWDebug enabled. So add an MWDebug::deinit(), and call it on test teardown. Ostensibly this is a great use-case for services and dependency injection. The reason I am not going that route is that it's not entirely clear to me what the MWDebug class is supposed to represent. If I were going to spend any substantial amount of time on this, I would be trying to move it out of core and into an extension, not converting it into a service. Change-Id: I52c511be049bc276d203d07283e3aa0944f22d34 --- includes/debug/MWDebug.php | 9 +++++++++ tests/phpunit/includes/debug/MWDebugTest.php | 14 ++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/includes/debug/MWDebug.php b/includes/debug/MWDebug.php index 13d25a86b4..d90ef8a7d1 100644 --- a/includes/debug/MWDebug.php +++ b/includes/debug/MWDebug.php @@ -75,6 +75,15 @@ class MWDebug { self::$enabled = true; } + /** + * Disable the debugger. + * + * @since 1.28 + */ + public static function deinit() { + self::$enabled = false; + } + /** * Add ResourceLoader modules to the OutputPage object if debugging is * enabled. diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php index 9c2bc750d4..c1449ea0a4 100644 --- a/tests/phpunit/includes/debug/MWDebugTest.php +++ b/tests/phpunit/includes/debug/MWDebugTest.php @@ -4,20 +4,18 @@ class MWDebugTest extends MediaWikiTestCase { protected function setUp() { parent::setUp(); - // Make sure MWDebug class is enabled - static $MWDebugEnabled = false; - if ( !$MWDebugEnabled ) { - MWDebug::init(); - $MWDebugEnabled = true; - } /** Clear log before each test */ MWDebug::clearLog(); + } + + public static function setUpBeforeClass() { + MWDebug::init(); MediaWiki\suppressWarnings(); } - protected function tearDown() { + public static function tearDownAfterClass() { + MWDebug::deinit(); MediaWiki\restoreWarnings(); - parent::tearDown(); } /** -- 2.20.1