You are here

protected function KeyTestBase::setUp in Key 8

Overrides UnitTestCase::setUp

1 call to KeyTestBase::setUp()
KeyEntityTest::setUp in tests/src/Unit/Entity/KeyEntityTest.php
1 method overrides KeyTestBase::setUp()
KeyEntityTest::setUp in tests/src/Unit/Entity/KeyEntityTest.php

File

tests/src/Unit/KeyTestBase.php, line 48

Class

KeyTestBase
Provides a base class for key tests.

Namespace

Drupal\Tests\key\Unit

Code

protected function setUp() {
  parent::setUp();

  // Mock the Config object, but methods will be mocked in the test class.
  $this->config = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();

  // Mock ConfigEntityStorage object, but methods will be mocked in the test
  // class.
  $this->configStorage = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')
    ->disableOriginalConstructor()
    ->getMock();

  // Mock EntityTypeManager service.
  $this->entityTypeManager = $this
    ->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')
    ->disableOriginalConstructor()
    ->getMock();
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('key')
    ->willReturn($this->configStorage);

  // Create a dummy container.
  $this->container = new ContainerBuilder();
  $this->container
    ->set('entity_type.manager', $this->entityTypeManager);

  // Each test class should call \Drupal::setContainer() in its own setUp
  // method so that test classes can add mocked services to the container
  // without affecting other test classes.
}