function StackedKernelPassTest::testProcessWithStackedKernel
Tests process with stacked kernel.
@legacy-covers ::process
File
-
core/
tests/ Drupal/ Tests/ Core/ DependencyInjection/ Compiler/ StackedKernelPassTest.php, line 57
Class
Namespace
Drupal\Tests\Core\DependencyInjection\CompilerCode
public function testProcessWithStackedKernel() : void {
$stacked_kernel = new Definition(StackedHttpKernel::class);
$stacked_kernel->setPublic(TRUE);
$this->containerBuilder
->setDefinition('http_kernel', $stacked_kernel);
$this->containerBuilder
->setDefinition('http_kernel.basic', $this->createMiddlewareServiceDefinition(FALSE, 0));
$this->containerBuilder
->setDefinition('http_kernel.three', $this->createMiddlewareServiceDefinition());
$this->containerBuilder
->setDefinition('http_kernel.one', $this->createMiddlewareServiceDefinition(TRUE, 10));
$this->containerBuilder
->setDefinition('http_kernel.two', $this->createMiddlewareServiceDefinition(TRUE, 5));
$this->stackedKernelPass
->process($this->containerBuilder);
$stacked_kernel_args = $this->containerBuilder
->getDefinition('http_kernel')
->getArguments();
// Check the stacked kernel args.
$this->assertSame('http_kernel.one', (string) $stacked_kernel_args[0]);
$this->assertInstanceOf(IteratorArgument::class, $stacked_kernel_args[1]);
$middlewares = $stacked_kernel_args[1]->getValues();
$this->assertCount(4, $middlewares);
$this->assertSame('http_kernel.one', (string) $middlewares[0]);
$this->assertSame('http_kernel.two', (string) $middlewares[1]);
$this->assertSame('http_kernel.three', (string) $middlewares[2]);
$this->assertSame('http_kernel.basic', (string) $middlewares[3]);
// Check the modified definitions.
$definition = $this->containerBuilder
->getDefinition('http_kernel.one');
$args = $definition->getArguments();
$this->assertSame('http_kernel.one.http_middleware_inner', (string) $args[0]);
$this->assertSame('test', $args[1]);
$alias = $this->containerBuilder
->getAlias('http_kernel.one.http_middleware_inner');
$this->assertSame('http_kernel.two', (string) $alias);
$definition = $this->containerBuilder
->getDefinition('http_kernel.two');
$args = $definition->getArguments();
$this->assertSame('http_kernel.two.http_middleware_inner', (string) $args[0]);
$this->assertSame('test', $args[1]);
$alias = $this->containerBuilder
->getAlias('http_kernel.two.http_middleware_inner');
$this->assertSame('http_kernel.three', (string) $alias);
$definition = $this->containerBuilder
->getDefinition('http_kernel.three');
$args = $definition->getArguments();
$this->assertSame('http_kernel.three.http_middleware_inner', (string) $args[0]);
$this->assertSame('test', $args[1]);
$alias = $this->containerBuilder
->getAlias('http_kernel.three.http_middleware_inner');
$this->assertSame('http_kernel.basic', (string) $alias);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.