function FiberPlaceholderTest::testLongPlaceholderFiberSuspendingLoop

Same name and namespace in other branches
  1. 11.x core/modules/big_pipe/tests/src/Unit/Render/FiberPlaceholderTest.php \Drupal\Tests\big_pipe\Unit\Render\FiberPlaceholderTest::testLongPlaceholderFiberSuspendingLoop()

@covers \Drupal\big_pipe\Render\BigPipe::sendPlaceholders

File

core/modules/big_pipe/tests/src/Unit/Render/FiberPlaceholderTest.php, line 36

Class

FiberPlaceholderTest
@coversDefaultClass \Drupal\big_pipe\Render\BigPipe[[api-linebreak]] @group big_pipe

Namespace

Drupal\Tests\big_pipe\Unit\Render

Code

public function testLongPlaceholderFiberSuspendingLoop() : void {
  $request_stack = $this->prophesize(RequestStack::class);
  $request_stack->getMainRequest()
    ->willReturn(new Request());
  $request_stack->getCurrentRequest()
    ->willReturn(new Request());
  $callableResolver = $this->prophesize(CallableResolver::class);
  $callableResolver->getCallableFromDefinition(Argument::any())
    ->willReturn([
    TurtleLazyBuilder::class,
    'turtle',
  ]);
  $renderer = new Renderer($callableResolver->reveal(), $this->prophesize(ThemeManagerInterface::class)
    ->reveal(), $this->prophesize(ElementInfoManagerInterface::class)
    ->reveal(), $this->prophesize(PlaceholderGeneratorInterface::class)
    ->reveal(), $this->prophesize(RenderCacheInterface::class)
    ->reveal(), $request_stack->reveal(), [
    'required_cache_contexts' => [
      'languages:language_interface',
      'theme',
    ],
  ]);
  $session = $this->prophesize(SessionInterface::class);
  $session->start()
    ->willReturn(TRUE);
  $bigpipe = new BigPipe($renderer, $session->reveal(), $request_stack->reveal(), $this->prophesize(HttpKernelInterface::class)
    ->reveal(), $this->createMock(EventDispatcherInterface::class), $this->prophesize(ConfigFactoryInterface::class)
    ->reveal(), $this->prophesize(MessengerInterface::class)
    ->reveal());
  $response = new BigPipeResponse(new HtmlResponse());
  $attachments = [
    'library' => [],
    'drupalSettings' => [
      'ajaxPageState' => [],
    ],
    'big_pipe_placeholders' => [
      // cspell:disable-next-line
'callback=%5CDrupal%5CTests%5Cbig_pipe%5CUnit%5CRender%5CTurtleLazyBuilder%3A%3Aturtle&&token=uhKFNfT4eF449_W-kDQX8E5z4yHyt0-nSHUlwaGAQeU' => [
        '#lazy_builder' => [
          '\\Drupal\\Tests\\big_pipe\\Unit\\Render\\TurtleLazyBuilder::turtle',
          [],
        ],
      ],
    ],
  ];
  $response->setAttachments($attachments);
  // Construct minimal HTML response.
  // cspell:disable-next-line
  $content = '<html><body><span data-big-pipe-placeholder-id="callback=%5CDrupal%5CTests%5Cbig_pipe%5CUnit%5CRender%5CTurtleLazyBuilder%3A%3Aturtle&amp;&amp;token=uhKFNfT4eF449_W-kDQX8E5z4yHyt0-nSHUlwaGAQeU"></body></html>';
  $response->setContent($content);
  // Capture the result to avoid PHPUnit complaining.
  ob_start();
  $fiber = new \Fiber(function () use ($bigpipe, $response) {
    $bigpipe->sendContent($response);
  });
  $fiber->start();
  $this->assertFalse($fiber->isTerminated(), 'Placeholder fibers with long execution time supposed to return control before terminating');
  ob_get_clean();
}

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