You are here

public function StackedKernelPassTest::testProcessWithStackedKernel in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/StackedKernelPassTest.php \Drupal\Tests\Core\DependencyInjection\Compiler\StackedKernelPassTest::testProcessWithStackedKernel()

@covers ::process

File

core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/StackedKernelPassTest.php, line 44
Contains \Drupal\Tests\Core\DependencyInjection\Compiler\StackedKernelPassTest.

Class

StackedKernelPassTest
@coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass @group DependencyInjection

Namespace

Drupal\Tests\Core\DependencyInjection\Compiler

Code

public function testProcessWithStackedKernel() {
  $stacked_kernel = new Definition('Stack\\StackedHttpKernel');
  $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((string) $stacked_kernel_args[0], 'http_kernel.one');
  $this
    ->assertCount(4, $stacked_kernel_args[1]);
  $this
    ->assertSame((string) $stacked_kernel_args[1][0], 'http_kernel.one');
  $this
    ->assertSame((string) $stacked_kernel_args[1][1], 'http_kernel.two');
  $this
    ->assertSame((string) $stacked_kernel_args[1][2], 'http_kernel.three');
  $this
    ->assertSame((string) $stacked_kernel_args[1][3], 'http_kernel.basic');

  // Check the modified definitions.
  $definition = $this->containerBuilder
    ->getDefinition('http_kernel.one');
  $args = $definition
    ->getArguments();
  $this
    ->assertSame('http_kernel.two', (string) $args[0]);
  $this
    ->assertSame('test', $args[1]);
  $definition = $this->containerBuilder
    ->getDefinition('http_kernel.two');
  $args = $definition
    ->getArguments();
  $this
    ->assertSame('http_kernel.three', (string) $args[0]);
  $this
    ->assertSame('test', $args[1]);
  $definition = $this->containerBuilder
    ->getDefinition('http_kernel.three');
  $args = $definition
    ->getArguments();
  $this
    ->assertSame('http_kernel.basic', (string) $args[0]);
  $this
    ->assertSame('test', $args[1]);
}