You are here

public function DerivativeDiscoveryDecoratorTest::testGetDeriverClassWithClassedDefinitions in Drupal 8

Tests getDeriverClass with classed objects instead of arrays.

@covers ::getDeriverClass

File

core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php, line 94

Class

DerivativeDiscoveryDecoratorTest
Unit tests for the derivative discovery decorator.

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDeriverClassWithClassedDefinitions() {
  $definitions = [];
  $definition = $this
    ->prophesize(DerivablePluginDefinitionInterface::class);
  $definition
    ->id()
    ->willReturn('non_container_aware_discovery');
  $definition
    ->getDeriver()
    ->willReturn(TestDerivativeDiscoveryWithObject::class);
  $definitions['non_container_aware_discovery'] = $definition
    ->reveal();
  $this->discoveryMain
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue($definitions));
  $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
  $definitions = $discovery
    ->getDefinitions();

  // Ensure that both test derivatives got added.
  $this
    ->assertContainsOnlyInstancesOf(DerivablePluginDefinitionInterface::class, $definitions);
  $this
    ->assertEquals([
    'non_container_aware_discovery:test_discovery_0',
    'non_container_aware_discovery:test_discovery_1',
  ], array_keys($definitions));
}