Commit 03d37513 authored by catch's avatar catch
Browse files

Issue #3355675 by effulgentsia, longwave: Drupal 9 uses PHP syntax that's...

Issue #3355675 by effulgentsia, longwave: Drupal 9 uses PHP syntax that's deprecated in PHP 8.2, so exclude that from error_reporting() and DeprecationListenerTrait
parent 24f669fe
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1035,7 +1035,14 @@ public static function bootEnvironment($app_root = NULL) {
    }

    // Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
    error_reporting(E_STRICT | E_ALL);
    $error_reporting = E_STRICT | E_ALL;

    // Drupal 9 uses PHP syntax that's deprecated in PHP 8.2.
    if (PHP_VERSION_ID >= 80200) {
      $error_reporting &= ~E_DEPRECATED;
    }

    error_reporting($error_reporting);

    // Override PHP settings required for Drupal to work properly.
    // sites/default/default.settings.php contains more runtime settings.
+3 −2
Original line number Diff line number Diff line
@@ -162,8 +162,9 @@ public function providerTestExport() {
        new \stdClass(),
      ],
      [
        // A not-stdClass object.
        "Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))",
        // A not-stdClass object. Since PHP 8.2 exported namespace is prefixed,
        // see https://github.com/php/php-src/pull/8233 for reasons.
        (PHP_VERSION_ID >= 80200 ? '\\' : '') . "Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))",
        new StubVariableTestClass(),
      ],
    ];
+4 −0
Original line number Diff line number Diff line
@@ -164,6 +164,10 @@ protected function registerErrorHandler() {
      if (($type === E_USER_DEPRECATED || $type === E_DEPRECATED) && static::isDeprecationSkipped($msg)) {
        return;
      }
      // Drupal 9 uses PHP syntax that's deprecated in PHP 8.2.
      if (PHP_VERSION_ID >= 80200 && $type === E_DEPRECATED) {
        return;
      }
      return call_user_func($this->previousHandler, $type, $msg, $file, $line, $context);
    };

+39 −0
Original line number Diff line number Diff line
@@ -179,3 +179,42 @@ class_alias('\Drupal\Tests\DocumentElement', '\Behat\Mink\Element\DocumentElemen
// thrown if an assert fails, but this call does not turn runtime assertions on
// if they weren't on already.
Handle::register();

// Drupal 9 uses PHP syntax that's deprecated in PHP 8.2. Therefore, for
// PHP 8.2, the error handler registered in
// \Drupal\Tests\Listeners\DeprecationListenerTrait::registerErrorHandler()
// ignores E_DEPRECATED errors. However, that error handler is not used
// during:
// - The execution of data providers.
// - The child process of tests that are executed in a separate (isolated)
//   process, such as kernel tests.
//
// To silence E_DEPRECATED errors during the above, re-register the error
// handler that has already been set by symfony/phpunit-bridge/bootstrap.php,
// but constrain it to not get called for E_DEPRECATED errors. It is still
// useful for E_USER_DEPRECATED and other error types.
if (PHP_VERSION_ID >= 80200) {
  // Get the current error handler without changing it.
  $error_handler = set_error_handler(NULL);
  restore_error_handler();

  if ($error_handler) {
    // Replace the current error handler with the same one, but filter out
    // E_DEPRECATED errors.
    restore_error_handler();
    set_error_handler($error_handler, E_ALL & ~E_DEPRECATED);

    // The above results in PHP's built-in error handler getting called for
    // E_DEPRECATED errors. Silence those errors too. Note that
    // \PHPUnit\TextUI\TestRunner::handleConfiguration() can get called twice
    // (once before running data providers, then again before running tests),
    // whereas tests/bootstrap.php is included via include_once(), so the 2nd
    // handleConfiguration() call can reset error_reporting to the value in
    // phpunit.xml. However, that's okay, because for those cases, the error
    // handler registered in
    // \Drupal\Tests\Listeners\DeprecationListenerTrait::registerErrorHandler()
    // is in use, and it ignores E_DEPRECATED errors for PHP 8.2 regardless of
    // the error_reporting value.
    error_reporting(error_reporting() & ~E_DEPRECATED);
  }
}