You are here

protected function StorageFactoryTest::setUp in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/StorageFactoryTest.php \Drupal\Tests\radioactivity\Unit\StorageFactoryTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/StorageFactoryTest.php, line 43

Class

StorageFactoryTest
@coversDefaultClass \Drupal\radioactivity\StorageFactory @group radioactivity

Namespace

Drupal\Tests\radioactivity\Unit

Code

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

  // Mock the radioactivity.storage configuration.
  $this->config = $this
    ->getMockBuilder(ImmutableConfig::class)
    ->disableOriginalConstructor()
    ->setMethods([
    'get',
  ])
    ->getMock();
  $this->configFactory = $this
    ->getMockBuilder(ConfigFactory::class)
    ->disableOriginalConstructor()
    ->setMethods([
    'get',
  ])
    ->getMock();
  $this->configFactory
    ->expects($this
    ->any())
    ->method('get')
    ->will($this
    ->returnValue($this->config));

  // Mock the class resolver and the classes it provides.
  $mockRestStorage = $this
    ->getMockBuilder(RestIncidentStorage::class)
    ->getMock();
  $mockDefaultStorage = $this
    ->getMockBuilder(DefaultIncidentStorage::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->classResolver = $this
    ->getMockBuilder(ClassResolverInterface::class)
    ->setMethods([
    'getInstanceFromDefinition',
  ])
    ->getMock();
  $this->classResolver
    ->expects($this
    ->any())
    ->method('getInstanceFromDefinition')
    ->will($this
    ->returnValueMap([
    [
      'radioactivity.rest_incident_storage',
      $mockRestStorage,
    ],
    [
      'radioactivity.default_incident_storage',
      $mockDefaultStorage,
    ],
  ]));
}