function BlockComponentRenderArrayTest::testOnBuildRenderNullBuild

@covers ::onBuildRender

File

core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php, line 505

Class

BlockComponentRenderArrayTest
@coversDefaultClass \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray[[api-linebreak]] @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testOnBuildRenderNullBuild() : void {
  $block = $this->prophesize(BlockPluginInterface::class);
  $access_result = AccessResult::allowed();
  $block->access($this->account
    ->reveal(), TRUE)
    ->willReturn($access_result)
    ->shouldBeCalled();
  $block->getCacheContexts()
    ->willReturn([]);
  $block->getCacheTags()
    ->willReturn([
    'test',
  ]);
  $block->getCacheMaxAge()
    ->willReturn(Cache::PERMANENT);
  $block->build()
    ->willReturn(NULL);
  $this->expectException(\UnexpectedValueException::class);
  $this->expectExceptionMessage(sprintf('The block "%s" did not return an array', get_class($block->reveal())));
  $this->blockManager
    ->createInstance('some_block_id', [
    'id' => 'some_block_id',
  ])
    ->willReturn($block->reveal());
  $component = new SectionComponent('some-uuid', 'some-region', [
    'id' => 'some_block_id',
  ]);
  $event = new SectionComponentBuildRenderArrayEvent($component, [], FALSE);
  $subscriber = new BlockComponentRenderArray($this->account
    ->reveal());
  $subscriber->onBuildRender($event);
}

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