3 namespace Drupal\Tests\Core\Plugin\Discovery;
5 use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator
12 class ContainerDerivativeDiscoveryDecoratorTest extends UnitTestCase {
15 * @covers ::getDefinitions
17 public function testGetDefinitions() {
18 $example_service = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
19 $example_container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
22 $example_container->expects($this->once())
24 ->with($this->equalTo('example_service'))
25 ->will($this->returnValue($example_service));
27 \Drupal::setContainer($example_container);
30 $definitions['container_aware_discovery'] = [
31 'id' => 'container_aware_discovery',
32 'deriver' => '\Drupal\Tests\Core\Plugin\Discovery\TestContainerDerivativeDiscovery',
34 $definitions['non_container_aware_discovery'] = [
35 'id' => 'non_container_aware_discovery',
36 'deriver' => '\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery',
39 $discovery_main = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface');
40 $discovery_main->expects($this->any())
41 ->method('getDefinitions')
42 ->will($this->returnValue($definitions));
44 $discovery = new ContainerDerivativeDiscoveryDecorator($discovery_main);
45 $definitions = $discovery->getDefinitions();
47 // Ensure that both the instances from container and non-container test derivatives got added.
48 $this->assertEquals(4, count($definitions));