function StackedKernelPassTest::testProcessWithStackedKernelAndFinalHttpMiddleware
Same name in other branches
- 11.x 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 105
Class
- StackedKernelPassTest
- @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass @group DependencyInjection
Namespace
Drupal\Tests\Core\DependencyInjection\CompilerCode
public function testProcessWithStackedKernelAndFinalHttpMiddleware() : void {
$stacked_kernel = new Definition(StackedHttpKernel::class);
$stacked_kernel->setPublic(TRUE);
$this->containerBuilder
->setDefinition('http_kernel', $stacked_kernel);
$basic_kernel = $this->getMockBuilder(HttpKernel::class)
->disableOriginalConstructor()
->onlyMethods([
'handle',
'terminate',
])
->getMock();
$basic_definition = (new Definition($basic_kernel::class))->setPublic(TRUE);
$this->containerBuilder
->setDefinition('http_kernel.basic', $basic_definition);
// Services tagged 'http_middleware', other than the highest priority
// middleware that is a responder, is also set as lazy by
// StackedKernelPass::process(). Add middleware classes declared final and
// confirm they are interface proxied correctly.
// @see https://symfony.com/doc/current/service_container/lazy_services.html#interface-proxifying
$first_responder = $this->getMockBuilder(HttpKernelInterface::class)
->getMock();
$this->containerBuilder
->setDefinition('http_kernel.one', (new Definition($first_responder::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.