function ContentLengthTest::testHandle

@covers ::handle
@dataProvider providerTestSetContentLengthHeader

File

core/modules/big_pipe/tests/src/Unit/StackMiddleware/ContentLengthTest.php, line 27

Class

ContentLengthTest
Defines a test for ContentLength middleware.

Namespace

Drupal\Tests\big_pipe\Unit\StackMiddleware

Code

public function testHandle(false|int $expected_header, Response $response) : void {
  $kernel = $this->prophesize(HttpKernelInterface::class);
  $request = Request::create('/');
  $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, TRUE)
    ->willReturn($response);
  $middleware = new ContentLength($kernel->reveal());
  $response = $middleware->handle($request);
  if ($expected_header === FALSE) {
    $this->assertFalse($response->headers
      ->has('Content-Length'));
    return;
  }
  $this->assertSame((string) $expected_header, $response->headers
    ->get('Content-Length'));
}

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