44d45fba915c4752b758d3cf4528ff9800000273
[yaffs-website] / web / core / tests / Drupal / Tests / Core / DependencyInjection / Compiler / ProxyServicesPassTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\DependencyInjection\Compiler;
4
5 use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
6 use Drupal\Core\DependencyInjection\ContainerBuilder;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass
12  * @group DependencyInjection
13  */
14 class ProxyServicesPassTest extends UnitTestCase {
15
16   /**
17    * The tested proxy services pass.
18    *
19    * @var \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass
20    */
21   protected $proxyServicesPass;
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     $this->proxyServicesPass = new ProxyServicesPass();
30   }
31
32   /**
33    * @covers ::process
34    */
35   public function testContainerWithoutLazyServices() {
36     $container = new ContainerBuilder();
37     $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer');
38
39     $this->proxyServicesPass->process($container);
40
41     $this->assertCount(2, $container->getDefinitions());
42     $this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
43   }
44
45   /**
46    * @covers ::process
47    */
48   public function testContainerWithLazyServices() {
49     $container = new ContainerBuilder();
50     $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer')
51       ->setLazy(TRUE);
52
53     $this->proxyServicesPass->process($container);
54
55     $this->assertCount(3, $container->getDefinitions());
56
57     $non_proxy_definition = $container->getDefinition('drupal.proxy_original_service.plugin_cache_clearer');
58     $this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $non_proxy_definition->getClass());
59     $this->assertFalse($non_proxy_definition->isLazy());
60     $this->assertTrue($non_proxy_definition->isPublic());
61
62     $this->assertEquals('Drupal\Core\ProxyClass\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
63   }
64
65   /**
66    * @covers ::process
67    */
68   public function testContainerWithLazyServicesWithoutProxyClass() {
69     $container = new ContainerBuilder();
70     $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist')
71       ->setLazy(TRUE);
72
73     $this->setExpectedException(InvalidArgumentException::class);
74     $this->proxyServicesPass->process($container);
75   }
76
77 }