function PsrResponseSubscriberTest::testConvertsSeekableBodyWithoutStreaming

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/EventSubscriber/PsrResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\PsrResponseSubscriberTest::testConvertsSeekableBodyWithoutStreaming()

Tests that a seekable body results in a non-streamed response.

@legacy-covers ::onKernelView

File

core/tests/Drupal/Tests/Core/EventSubscriber/PsrResponseSubscriberTest.php, line 77

Class

PsrResponseSubscriberTest
Tests Drupal\Core\EventSubscriber\PsrResponseSubscriber.

Namespace

Drupal\Tests\Core\EventSubscriber

Code

public function testConvertsSeekableBodyWithoutStreaming() : void {
  $body = $this->createStub(StreamInterface::class);
  $body->method('isSeekable')
    ->willReturn(TRUE);
  $psr_response = $this->createStub(ResponseInterface::class);
  $psr_response->method('getBody')
    ->willReturn($body);
  $factory = $this->createMock(HttpFoundationFactoryInterface::class);
  $factory->expects($this->once())
    ->method('createResponse')
    ->with($psr_response, FALSE)
    ->willReturn($this->createStub(Response::class));
  $subscriber = new PsrResponseSubscriber($factory);
  $event = $this->createEvent($psr_response);
  $subscriber->onKernelView($event);
  $this->assertInstanceOf(Response::class, $event->getResponse());
}

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