function ContentLengthTest::testHandle

Same name in this branch
  1. 11.x core/modules/big_pipe/tests/src/Unit/StackMiddleware/ContentLengthTest.php \Drupal\Tests\big_pipe\Unit\StackMiddleware\ContentLengthTest::testHandle()
Same name in other branches
  1. 10 core/modules/big_pipe/tests/src/Unit/StackMiddleware/ContentLengthTest.php \Drupal\Tests\big_pipe\Unit\StackMiddleware\ContentLengthTest::testHandle()
  2. 10 core/tests/Drupal/Tests/Core/StackMiddleware/ContentLengthTest.php \Drupal\Tests\Core\StackMiddleware\ContentLengthTest::testHandle()

@covers ::handle @dataProvider providerTestSetContentLengthHeader

File

core/tests/Drupal/Tests/Core/StackMiddleware/ContentLengthTest.php, line 24

Class

ContentLengthTest
@coversDefaultClass \Drupal\Core\StackMiddleware\ContentLength @group Middleware

Namespace

Drupal\Tests\Core\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.