TypedDefinitionEnsuringPluginDiscoveryDecoratorTest.php in Plugin 8.2
File
tests/src/Unit/PluginDiscovery/TypedDefinitionEnsuringPluginDiscoveryDecoratorTest.php
View source
<?php
namespace Drupal\Tests\plugin\Unit\PluginDiscovery;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\plugin\PluginDefinition\PluginDefinitionInterface;
use Drupal\plugin\PluginDiscovery\TypedDefinitionEnsuringPluginDiscoveryDecorator;
use Drupal\plugin\PluginType\PluginTypeInterface;
use Drupal\Tests\UnitTestCase;
class TypedDefinitionEnsuringPluginDiscoveryDecoratorTest extends UnitTestCase {
protected $pluginManager;
protected $pluginType;
protected $sut;
protected function setUp() : void {
$this->pluginManager = $this
->createMock(PluginManagerInterface::class);
$this->pluginType = $this
->createMock(PluginTypeInterface::class);
$this->sut = new TypedDefinitionEnsuringPluginDiscoveryDecorator($this->pluginType, $this->pluginManager);
}
public function testConstruct() {
$this->sut = new TypedDefinitionEnsuringPluginDiscoveryDecorator($this->pluginType, $this->pluginManager);
$this
->assertInstanceOf(TypedDefinitionEnsuringPluginDiscoveryDecorator::class, $this->sut);
}
public function testGetDefinitions() {
$decorated_plugin_id_a = $this
->randomMachineName();
$decorated_plugin_definition_a = [
'id' => $decorated_plugin_id_a,
];
$decorated_plugin_id_b = $this
->randomMachineName();
$decorated_plugin_definition_b = [
'id' => $decorated_plugin_id_b,
];
$decorated_plugin_definitions = [
$decorated_plugin_id_a => $decorated_plugin_definition_a,
$decorated_plugin_id_b => $decorated_plugin_definition_b,
];
$this->pluginManager
->expects($this
->once())
->method('getDefinitions')
->willReturn($decorated_plugin_definitions);
$typed_plugin_definition_a = $this
->createMock(PluginDefinitionInterface::class);
$typed_plugin_definition_b = $this
->createMock(PluginDefinitionInterface::class);
$map = [
[
$decorated_plugin_definition_a,
$typed_plugin_definition_a,
],
[
$decorated_plugin_definition_b,
$typed_plugin_definition_b,
],
];
$this->pluginType
->expects($this
->atLeastOnce())
->method('ensureTypedPluginDefinition')
->willReturnMap($map);
$expected_plugin_definitions = [
$decorated_plugin_id_a => $typed_plugin_definition_a,
$decorated_plugin_id_b => $typed_plugin_definition_b,
];
$this
->assertSame($expected_plugin_definitions, $this->sut
->getDefinitions());
}
}