class StackedHttpKernelTest
Tests Drupal\Core\StackMiddleware\StackedHttpKernel.
Attributes
#[CoversClass(StackedHttpKernel::class)]
#[Group('StackMiddleware')]
  Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase- class \Drupal\Tests\Core\StackMiddleware\StackedHttpKernelTest extends \Drupal\Tests\UnitTestCase
 
Expanded class hierarchy of StackedHttpKernelTest
File
- 
              core/tests/ Drupal/ Tests/ Core/ StackMiddleware/ StackedHttpKernelTest.php, line 20 
Namespace
Drupal\Tests\Core\StackMiddlewareView source
class StackedHttpKernelTest extends UnitTestCase {
  
  /**
   * Tests that stacked kernel is constructed with a list of middlewares.
   */
  public function testDeprecatedMiddlewaresArgument() : void {
    $request = new Request();
    $expected = new Response();
    $basicKernel = $this->createMock(HttpKernelInterface::class);
    $basicKernel->expects($this->once())
      ->method('handle')
      ->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE)
      ->willReturn($expected);
    $this->expectDeprecation('Calling Drupal\\Core\\StackMiddleware\\StackedHttpKernel::__construct() with an array of $middlewares is deprecated in drupal:11.3.0 and it will throw an error in drupal:12.0.0. Pass in a lazy iterator instead. See https://www.drupal.org/node/3538740');
    $stack = new StackedHttpKernel($basicKernel, [
      $basicKernel,
    ]);
    $actual = $stack->handle($request);
    $this->assertSame($expected, $actual);
  }
  
  /**
   * Tests that stacked kernel is constructed with a list of closures.
   */
  public function testClosureMiddlewareArgument() : void {
    $request = new Request();
    $expected = new Response();
    $basicKernel = $this->createMock(HttpKernelInterface::class);
    $basicKernel->expects($this->once())
      ->method('handle')
      ->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE)
      ->willReturn($expected);
    $stack = new StackedHttpKernel($basicKernel, new \ArrayIterator([
      $basicKernel,
    ]));
    $actual = $stack->handle($request);
    $this->assertSame($expected, $actual);
  }
  
  /**
   * Tests that stacked kernel invokes the terminate call in all middlewares.
   */
  public function testTerminate() : void {
    $request = new Request();
    $response = new Response();
    $basicKernel = $this->createMockForIntersectionOfInterfaces([
      HttpKernelInterface::class,
      TerminableInterface::class,
    ]);
    $basicKernel->expects($this->once())
      ->method('terminate')
      ->with($request, $response);
    $outer = $this->createMock(HttpKernelInterface::class);
    $middle = $this->createMockForIntersectionOfInterfaces([
      HttpKernelInterface::class,
      TerminableInterface::class,
    ]);
    $middle->expects($this->once())
      ->method('terminate')
      ->with($request, $response);
    $inner = $this->createMock(HttpKernelInterface::class);
    $middlewares = new \ArrayIterator([
      $outer,
      $middle,
      $inner,
      $basicKernel,
    ]);
    $stack = new StackedHttpKernel($outer, $middlewares);
    $stack->terminate($request, $response);
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides | 
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| StackedHttpKernelTest::testClosureMiddlewareArgument | public | function | Tests that stacked kernel is constructed with a list of closures. | |
| StackedHttpKernelTest::testDeprecatedMiddlewaresArgument | public | function | Tests that stacked kernel is constructed with a list of middlewares. | |
| StackedHttpKernelTest::testTerminate | public | function | Tests that stacked kernel invokes the terminate call in all middlewares. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | 366 | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
