function DrupalKernelRequestStackTest::onRequest

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelRequestStackTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelRequestStackTest::onRequest()

Records the current request and master request for testing.

Parameters

\Symfony\Component\HttpKernel\Event\RequestEvent $event: The request event.

File

core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelRequestStackTest.php, line 163

Class

DrupalKernelRequestStackTest
Tests the usage of the request stack as part of request processing.

Namespace

Drupal\KernelTests\Core\DrupalKernel

Code

public function onRequest(RequestEvent $event) : void {
  $request_stack = $this->container
    ->get('request_stack');
  if ($request_stack->getCurrentRequest() !== $event->getRequest()) {
    throw new \Exception('Current request is not the same as the event request.');
  }
  $this->recordedRequests = [
    'main' => $request_stack->getMainRequest(),
    'parent' => $request_stack->getParentRequest(),
    'current' => $request_stack->getCurrentRequest(),
  ];
  $this->recordedRequestStackCount = $this->getRequestStackCount($request_stack);
}

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