class FiberPlaceholderTest

Same name in other branches
  1. 11.x core/modules/big_pipe/tests/src/Unit/Render/FiberPlaceholderTest.php \Drupal\Tests\big_pipe\Unit\Render\FiberPlaceholderTest

@coversDefaultClass \Drupal\big_pipe\Render\BigPipe @group big_pipe

Hierarchy

Expanded class hierarchy of FiberPlaceholderTest

File

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

Namespace

Drupal\Tests\big_pipe\Unit\Render
View source
class FiberPlaceholderTest extends UnitTestCase {
    
    /**
     * @covers \Drupal\big_pipe\Render\BigPipe::sendPlaceholders
     */
    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();
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
FiberPlaceholderTest::testLongPlaceholderFiberSuspendingLoop public function @covers \Drupal\big_pipe\Render\BigPipe::sendPlaceholders
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
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.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
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::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
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::setUp protected function 358
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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