You are here

protected function ConfigUpdateUnitTestBase::getEntityManagerMock in Configuration Update Manager 8

Creates a mock entity manager for the test.

See also

ConfigUpdateUnitTestBase::entityDefinitionInformation

1 call to ConfigUpdateUnitTestBase::getEntityManagerMock()
ConfigReverterTest::setUp in tests/src/Unit/ConfigReverterTest.php

File

tests/src/Unit/ConfigUpdateUnitTestBase.php, line 37

Class

ConfigUpdateUnitTestBase
Base class for unit testing in Config Update Manager.

Namespace

Drupal\Tests\config_update\Unit

Code

protected function getEntityManagerMock() {
  $definitions = [];
  $map = [];
  foreach ($this->entityDefinitionInformation as $info) {
    $def = $this
      ->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface')
      ->getMock();
    $def
      ->expects($this
      ->any())
      ->method('getConfigPrefix')
      ->willReturn($info['prefix']);
    $def
      ->expects($this
      ->any())
      ->method('entityClassImplements')
      ->willReturn(TRUE);
    $def
      ->method('getKey')
      ->willReturn('id');
    $def
      ->getConfigPrefix();
    $definitions[$info['type']] = $def;
    $map[] = [
      $info['type'],
      FALSE,
      $def,
    ];
    $map[] = [
      $info['type'],
      TRUE,
      $def,
    ];
  }

  // Add in a content entity definition, which shouldn't be recognized by the
  // config lister class.
  $def = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityTypeInterface')
    ->getMock();
  $def
    ->expects($this
    ->any())
    ->method('entityClassImplements')
    ->willReturn(FALSE);
  $definitions['content_entity'] = $def;
  $manager = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityTypeManagerInterface')
    ->getMock();
  $manager
    ->method('getDefinitions')
    ->willReturn($definitions);
  $manager
    ->method('getDefinition')
    ->will($this
    ->returnValueMap($map));
  $manager
    ->method('getStorage')
    ->will($this
    ->returnCallback([
    $this,
    'mockGetStorage',
  ]));
  return $manager;
}