You are here

class ExceptionTestSiteSubscriber in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php \Drupal\Core\EventSubscriber\ExceptionTestSiteSubscriber

Custom handling of errors when in a system-under-test.

Hierarchy

Expanded class hierarchy of ExceptionTestSiteSubscriber

1 string reference to 'ExceptionTestSiteSubscriber'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ExceptionTestSiteSubscriber
exception.test_site in core/core.services.yml
Drupal\Core\EventSubscriber\ExceptionTestSiteSubscriber

File

core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php, line 11

Namespace

Drupal\Core\EventSubscriber
View source
class ExceptionTestSiteSubscriber extends HttpExceptionSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected static function getPriority() {
    return 3;
  }

  /**
   * {@inheritdoc}
   */
  protected function getHandledFormats() {
    return [
      'html',
    ];
  }

  /**
   * Checks for special handling of errors inside Simpletest.
   *
   * @todo The $headers array appears to not actually get used at all in the
   *   original code. It's quite possible that this entire method is now
   *   vestigial and can be removed.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
   */
  public function on500(GetResponseForExceptionEvent $event) {
    $exception = $event
      ->getException();
    $error = Error::decodeException($exception);
    $headers = [];

    // When running inside the testing framework, we relay the errors
    // to the tested site by the way of HTTP headers.
    if (DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {

      // $number does not use drupal_static as it should not be reset
      // as it uniquely identifies each PHP error.
      static $number = 0;
      $assertion = [
        $error['@message'],
        $error['%type'],
        [
          'function' => $error['%function'],
          'file' => $error['%file'],
          'line' => $error['%line'],
        ],
      ];
      $headers['X-Drupal-Assertion-' . $number] = rawurlencode(serialize($assertion));
      $number++;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExceptionTestSiteSubscriber::getHandledFormats protected function Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase::getHandledFormats
ExceptionTestSiteSubscriber::getPriority protected static function Specifies the priority of all listeners in this class. Overrides HttpExceptionSubscriberBase::getPriority
ExceptionTestSiteSubscriber::on500 public function Checks for special handling of errors inside Simpletest.
HttpExceptionSubscriberBase::getSubscribedEvents public static function Registers the methods in this class that should be listeners.
HttpExceptionSubscriberBase::onException public function Handles errors for this subscriber.