function BlockRepositoryTest::setUp

Same name in other branches
  1. 9 core/modules/block/tests/src/Unit/BlockRepositoryTest.php \Drupal\Tests\block\Unit\BlockRepositoryTest::setUp()
  2. 8.9.x core/modules/block/tests/src/Unit/BlockRepositoryTest.php \Drupal\Tests\block\Unit\BlockRepositoryTest::setUp()
  3. 11.x core/modules/block/tests/src/Unit/BlockRepositoryTest.php \Drupal\Tests\block\Unit\BlockRepositoryTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/block/tests/src/Unit/BlockRepositoryTest.php, line 41

Class

BlockRepositoryTest
@coversDefaultClass \Drupal\block\BlockRepository @group block

Namespace

Drupal\Tests\block\Unit

Code

protected function setUp() : void {
    parent::setUp();
    $active_theme = $this->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')
        ->disableOriginalConstructor()
        ->getMock();
    $this->theme = $this->randomMachineName();
    $active_theme->expects($this->atLeastOnce())
        ->method('getName')
        ->willReturn($this->theme);
    $active_theme->expects($this->atLeastOnce())
        ->method('getRegions')
        ->willReturn([
        'top',
        'center',
        'bottom',
    ]);
    $theme_manager = $this->createMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
    $theme_manager->expects($this->atLeastOnce())
        ->method('getActiveTheme')
        ->willReturn($active_theme);
    $this->contextHandler = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextHandlerInterface');
    $this->blockStorage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
    
    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject $entity_type_manager */
    $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $entity_type_manager->expects($this->any())
        ->method('getStorage')
        ->willReturn($this->blockStorage);
    $this->blockRepository = new BlockRepository($entity_type_manager, $theme_manager, $this->contextHandler);
}

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