function StackedKernelPassTest::testProcessWithStackedKernelAndFinalHttpMiddleware

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/StackedKernelPassTest.php \Drupal\Tests\Core\DependencyInjection\Compiler\StackedKernelPassTest::testProcessWithStackedKernelAndFinalHttpMiddleware()
  2. 10 core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/StackedKernelPassTest.php \Drupal\Tests\Core\DependencyInjection\Compiler\StackedKernelPassTest::testProcessWithStackedKernelAndFinalHttpMiddleware()

Tests that class declared 'final' can be added as http_middleware.

File

core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/StackedKernelPassTest.php, line 123

Class

StackedKernelPassTest
Tests Drupal\Core\DependencyInjection\Compiler\StackedKernelPass.

Namespace

Drupal\Tests\Core\DependencyInjection\Compiler

Code

public function testProcessWithStackedKernelAndFinalHttpMiddleware() : void {
  $stacked_kernel = new Definition(StackedHttpKernel::class);
  $stacked_kernel->setPublic(TRUE);
  $this->containerBuilder
    ->setDefinition('http_kernel', $stacked_kernel);
  $basic_kernel = $this->createMock(HttpKernelInterface::class);
  $basic_definition = (new Definition($basic_kernel::class))->setPublic(TRUE);
  $this->containerBuilder
    ->setDefinition('http_kernel.basic', $basic_definition);
  $this->containerBuilder
    ->setDefinition('http_kernel.one', (new Definition(TestHttpMiddlewareClass::class))->setPublic(TRUE)
    ->addTag('http_middleware', [
    'priority' => 200,
    'responder' => TRUE,
  ]));
  // First middleware class declared final.
  $this->containerBuilder
    ->setDefinition('http_kernel.two', (new Definition(FinalTestHttpMiddlewareClass::class))->setPublic(TRUE)
    ->addTag('http_middleware', [
    'priority' => 100,
    'responder' => TRUE,
  ]));
  // Second middleware class declared final, this time without implementing
  // TerminableInterface.
  $this->containerBuilder
    ->setDefinition('http_kernel.three', (new Definition(FinalTestNonTerminableHttpMiddlewareClass::class))->setPublic(TRUE)
    ->addTag('http_middleware', [
    'priority' => 50,
    'responder' => TRUE,
  ]));
  $this->stackedKernelPass
    ->process($this->containerBuilder);
  $this->assertIsObject($this->containerBuilder
    ->get('http_kernel'));
}

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