3 namespace Drupal\Tests\Core\DependencyInjection\Compiler;
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;
11 * @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass
12 * @group DependencyInjection
14 class ProxyServicesPassTest extends UnitTestCase {
17 * The tested proxy services pass.
19 * @var \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass
21 protected $proxyServicesPass;
26 protected function setUp() {
29 $this->proxyServicesPass = new ProxyServicesPass();
35 public function testContainerWithoutLazyServices() {
36 $container = new ContainerBuilder();
37 $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer');
39 $this->proxyServicesPass->process($container);
41 $this->assertCount(2, $container->getDefinitions());
42 $this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
48 public function testContainerWithLazyServices() {
49 $container = new ContainerBuilder();
50 $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer')
53 $this->proxyServicesPass->process($container);
55 $this->assertCount(3, $container->getDefinitions());
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());
62 $this->assertEquals('Drupal\Core\ProxyClass\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
68 public function testContainerWithLazyServicesWithoutProxyClass() {
69 $container = new ContainerBuilder();
70 $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist')
73 $this->setExpectedException(InvalidArgumentException::class);
74 $this->proxyServicesPass->process($container);