function DeprecationHandler::preBootstrap

Load configuration and setup.

This needs to execute before PHPUnit's extension bootstrap phase, since there is the need to set early both the error handler and the debug class loader. This static method is called by the bootstrap.php code, that is executed first before the extensions bootstrap.

Parameters

\PHPUnit\TextUI\Configuration\Configuration $configuration: The PHPUnit configuration.

1 call to DeprecationHandler::preBootstrap()
bootstrap.php in core/tests/bootstrap.php

File

core/tests/Drupal/TestTools/Extension/DeprecationBridge/DeprecationHandler.php, line 38

Class

DeprecationHandler
Drupal's PHPUnit extension to manage code deprecation.

Namespace

Drupal\TestTools\Extension\DeprecationBridge

Code

public static function preBootstrap(PhpUnitConfiguration $configuration) : void {
  $config = Configuration::instance();
  // Find the extension parameters from current PHPUnit configuration.
  $extensionBootstrappers = $configuration->extensionBootstrappers();
  $parameters = [];
  foreach ($extensionBootstrappers as $bootstrapper) {
    if ($bootstrapper['className'] === self::class) {
      $parameters = $bootstrapper['parameters'];
      break;

    }
  }
  $config->load($parameters);
  // Get the overridden configuration provided via env variable.
  $environmentVariable = getenv('DRUPAL_DEPRECATION_FILTER_CONFIG');
  if ($environmentVariable !== FALSE) {
    $overrideConfig = (array) json_decode($environmentVariable);
    $config->load($overrideConfig);
  }
  // Get the legacy configuration provided via Symfony env variable.
  $config->load(self::legacySymfonyConfiguration());
  // Determine if project ignores are enabled. If so, loads the deprecation
  // patterns to be ignored from the ignore file and sets the error handler
  // to Drupal\TestTools\ErrorHandler\BootstrapErrorHandler. This allows to
  // capture deprecations triggered by PHP or by the DebugClassLoader, that
  // can occur before tests' ::setUp() methods are called.
  if ($config->projectIgnoresEnabled) {
    $config->loadDeprecationIgnorePatterns();
    // We pass an instance of the PHPUnit error handler to redirect any error
    // not managed by our layer back to PHPUnit.
    set_error_handler(new BootstrapErrorHandler(PhpUnitErrorHandler::instance()));
  }
  // Enable the DebugClassLoader to get deprecations for methods' signature
  // changes.
  if ($config->debugClassLoaderEnabled) {
    DebugClassLoader::enable();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.