Merge "Correctly format null error reporting level"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 2 Sep 2019 16:54:48 +0000 (16:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 2 Sep 2019 16:54:48 +0000 (16:54 +0000)
1  2 
tests/phpunit/MediaWikiIntegrationTestCase.php

@@@ -182,10 -182,8 +182,10 @@@ abstract class MediaWikiIntegrationTest
                global $IP;
                parent::setUpBeforeClass();
                if ( !file_exists( "$IP/LocalSettings.php" ) ) {
 -                      echo 'A working MediaWiki installation with a configured LocalSettings.php file is'
 -                      . ' required for tests that extend ' . self::class;
 +                              echo "File \"$IP/LocalSettings.php\" could not be found. "
 +                              . "Test case " . static::class . " extends " . self::class . " "
 +                              . "which requires a working MediaWiki installation.\n"
 +                              . ( new RuntimeException() )->getTraceAsString();
                        die();
                }
                self::initializeForStandardPhpunitEntrypointIfNeeded();
                $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;
  
                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 );
                }
                        $this->setService( 'ContentLanguage', $lang );
                        $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() );
                } else {
 -                      $this->setMwGlobals( 'wgLanguageCode', $lang );
 +                      $this->setMwGlobals( [
 +                              'wgLanguageCode' => $lang,
 +                              'wgContLang' => Language::factory( $lang ),
 +                      ] );
                }
        }