You are here

protected function PluginTypeTest::setUp in Plugin 8.2

Overrides UnitTestCase::setUp

File

tests/src/Unit/PluginType/PluginTypeTest.php, line 50

Class

PluginTypeTest
@coversDefaultClass \Drupal\plugin\PluginType\PluginType

Namespace

Drupal\Tests\plugin\Unit\PluginType

Code

protected function setUp() : void {
  $this->pluginTypeDefinition = [
    'id' => $this
      ->randomMachineName(),
    'label' => $this
      ->getRandomGenerator()
      ->string(),
    'description' => $this
      ->getRandomGenerator()
      ->string(),
    'provider' => $this
      ->randomMachineName(),
    'plugin_manager_service_id' => $this
      ->randomMachineName(),
    'field_type' => (bool) mt_rand(0, 1),
  ];
  $class_resolver = $this
    ->createMock(ClassResolverInterface::class);
  $typed_config_manager = $this
    ->createMock(TypedConfigManagerInterface::class);
  $typed_config_manager
    ->expects($this
    ->atLeastOnce())
    ->method('hasConfigSchema')
    ->willReturn(TRUE);
  $this->pluginManager = $this
    ->createMock(PluginManagerInterface::class);
  $this->container = $this
    ->createMock(ContainerInterface::class);
  $map = [
    [
      'class_resolver',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $class_resolver,
    ],
    [
      'config.typed',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $typed_config_manager,
    ],
    [
      'string_translation',
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this
        ->getStringTranslationStub(),
    ],
    [
      $this->pluginTypeDefinition['plugin_manager_service_id'],
      ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
      $this->pluginManager,
    ],
  ];
  $this->container
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->willReturnMap($map);
  $this->sut = PluginType::createFromDefinition($this->container, $this->pluginTypeDefinition);
}