You are here

protected function PluginTypeManagerTest::setUp in Plugin 8.2

Same name in this branch
  1. 8.2 tests/src/Unit/PluginType/PluginTypeManagerTest.php \Drupal\Tests\plugin\Unit\PluginType\PluginTypeManagerTest::setUp()
  2. 8.2 tests/src/Kernel/PluginType/PluginTypeManagerTest.php \Drupal\Tests\plugin\Kernel\PluginType\PluginTypeManagerTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/PluginType/PluginTypeManagerTest.php, line 88

Class

PluginTypeManagerTest
@coversDefaultClass \Drupal\plugin\PluginType\PluginTypeManager

Namespace

Drupal\Tests\plugin\Unit\PluginType

Code

protected function setUp() : void {
  FileCacheFactory::setPrefix($this
    ->randomMachineName());
  $plugin_type_id_a = 'foo';
  $this->pluginTypeDefinitions[$plugin_type_id_a] = [
    'label' => 'Foo',
    'description' => 'This is Foo.',
    'provider' => 'foo',
    'plugin_manager_service_id' => 'plugin.manager.foo',
  ];
  $plugin_type_id_b = 'bar';
  $this->pluginTypeDefinitions[$plugin_type_id_b] = [
    'label' => 'Bar',
    'description' => 'I am Bar(t).',
    'provider' => 'bar',
    'plugin_manager_service_id' => 'plugin.manager.bar',
  ];
  $this->pluginManagers = [
    $plugin_type_id_a => $this
      ->createMock(PluginManagerInterface::class),
    $plugin_type_id_b => $this
      ->createMock(PluginManagerInterface::class),
  ];
  vfsStreamWrapper::register();
  $root = new vfsStreamDirectory('modules');
  vfsStreamWrapper::setRoot($root);
  $this->moduleHandler = $this
    ->createMock(ModuleHandlerInterface::class);
  $this->moduleHandler
    ->expects($this
    ->any())
    ->method('getModuleDirectories')
    ->willReturn(array(
    'module_a' => vfsStream::url('modules/module_a'),
    'module_b' => vfsStream::url('modules/module_b'),
  ));
  $class_resolver = $this
    ->createMock(ClassResolverInterface::class);
  $this->typedConfigurationManager = $this
    ->createMock(TypedConfigManagerInterface::class);
  $this->container = $this
    ->createMock(ContainerInterface::class);
  $map = [
    [
      'class_resolver',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $class_resolver,
    ],
    [
      'config.typed',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this->typedConfigurationManager,
    ],
    [
      'string_translation',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this
        ->getStringTranslationStub(),
    ],
    [
      $this->pluginTypeDefinitions[$plugin_type_id_a]['plugin_manager_service_id'],
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this->pluginManagers[$plugin_type_id_a],
    ],
    [
      $this->pluginTypeDefinitions[$plugin_type_id_b]['plugin_manager_service_id'],
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this->pluginManagers[$plugin_type_id_b],
    ],
  ];
  $this->container
    ->expects($this
    ->any())
    ->method('get')
    ->willReturnMap($map);
  $url = vfsStream::url('modules');
  mkdir($url . '/module_a');
  file_put_contents($url . '/module_a/module_a.plugin_type.yml', $this
    ->buildPluginDefinitionYaml($plugin_type_id_a, $this->pluginTypeDefinitions[$plugin_type_id_a]['label'], $this->pluginTypeDefinitions[$plugin_type_id_a]['description'], $this->pluginTypeDefinitions[$plugin_type_id_a]['provider'], $this->pluginTypeDefinitions[$plugin_type_id_a]['plugin_manager_service_id']));
  mkdir($url . '/module_b');
  file_put_contents($url . '/module_b/module_b.plugin_type.yml', $this
    ->buildPluginDefinitionYaml($plugin_type_id_b, $this->pluginTypeDefinitions[$plugin_type_id_b]['label'], $this->pluginTypeDefinitions[$plugin_type_id_b]['description'], $this->pluginTypeDefinitions[$plugin_type_id_b]['provider'], $this->pluginTypeDefinitions[$plugin_type_id_b]['plugin_manager_service_id']));
  $this->sut = new PluginTypeManager($this->container, $this->moduleHandler);
}