You are here

class TypedDefinitionEnsuringPluginDiscoveryDecoratorTest in Plugin 8.2

@coversDefaultClass \Drupal\plugin\PluginDiscovery\TypedDefinitionEnsuringPluginDiscoveryDecorator

@group Plugin

Hierarchy

Expanded class hierarchy of TypedDefinitionEnsuringPluginDiscoveryDecoratorTest

File

tests/src/Unit/PluginDiscovery/TypedDefinitionEnsuringPluginDiscoveryDecoratorTest.php, line 16

Namespace

Drupal\Tests\plugin\Unit\PluginDiscovery
View source
class TypedDefinitionEnsuringPluginDiscoveryDecoratorTest extends UnitTestCase {

  /**
   * The original plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $pluginManager;

  /**
   * The type of the plugin definitions to decorate.
   *
   * @var \Drupal\plugin\PluginType\PluginTypeInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $pluginType;

  /**
   * The class under test.
   *
   * @var \Drupal\plugin\PluginDiscovery\TypedDefinitionEnsuringPluginDiscoveryDecorator
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    $this->pluginManager = $this
      ->createMock(PluginManagerInterface::class);
    $this->pluginType = $this
      ->createMock(PluginTypeInterface::class);
    $this->sut = new TypedDefinitionEnsuringPluginDiscoveryDecorator($this->pluginType, $this->pluginManager);
  }

  /**
   * @covers ::__construct
   */
  public function testConstruct() {
    $this->sut = new TypedDefinitionEnsuringPluginDiscoveryDecorator($this->pluginType, $this->pluginManager);
    $this
      ->assertInstanceOf(TypedDefinitionEnsuringPluginDiscoveryDecorator::class, $this->sut);
  }

  /**
   * @covers ::getDefinitions
   * @covers ::processDecoratedDefinitions
   */
  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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::$pluginManager protected property The original plugin manager.
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::$pluginType protected property The type of the plugin definitions to decorate.
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::$sut protected property The class under test.
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::setUp protected function Overrides UnitTestCase::setUp
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::testConstruct public function @covers ::__construct
TypedDefinitionEnsuringPluginDiscoveryDecoratorTest::testGetDefinitions public function @covers ::getDefinitions @covers ::processDecoratedDefinitions
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.