From 4802a26be16296b9bde81161664fe176f65dbc06 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 8 Oct 2018 15:26:24 +0300 Subject: [PATCH] Correctly format null error reporting level Previously you could sometimes get the mysterious error "PHP error_reporting setting was left dirty: was 0x0 before test, 0x0 after test!" Change-Id: I425a694f9c2c71d917012ab9fb1780b5c2133ff4 --- tests/phpunit/MediaWikiIntegrationTestCase.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index 83f27e847d..f5e09e9378 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -584,6 +584,17 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->tmpFiles = array_merge( $this->tmpFiles, (array)$files ); } + private static function formatErrorLevel( $errorLevel ) { + switch ( gettype( $errorLevel ) ) { + case 'integer': + return '0x' . strtoupper( dechex( $errorLevel ) ); + case 'NULL': + return 'null'; + default: + throw new MWException( 'Unexpected error level type ' . gettype( $errorLevel ) ); + } + } + protected function tearDown() { global $wgRequest, $wgSQLMode; @@ -649,10 +660,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { if ( $phpErrorLevel !== $this->phpErrorLevel ) { ini_set( 'error_reporting', $this->phpErrorLevel ); - $oldHex = strtoupper( dechex( $this->phpErrorLevel ) ); - $newHex = strtoupper( dechex( $phpErrorLevel ) ); + $oldVal = self::formatErrorLevel( $this->phpErrorLevel ); + $newVal = self::formatErrorLevel( $phpErrorLevel ); $message = "PHP error_reporting setting was left dirty: " - . "was 0x$oldHex before test, 0x$newHex after test!"; + . "was $oldVal before test, $newVal after test!"; $this->fail( $message ); } -- 2.20.1