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();
36 public function testContainerWithoutLazyServices() {
37 $container = new ContainerBuilder();
38 $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer');
40 $this->proxyServicesPass->process($container);
42 $this->assertCount(1, $container->getDefinitions());
43 $this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
49 public function testContainerWithLazyServices() {
50 $container = new ContainerBuilder();
51 $container->register('plugin_cache_clearer', 'Drupal\Core\Plugin\CachedDiscoveryClearer')
54 $this->proxyServicesPass->process($container);
56 $this->assertCount(2, $container->getDefinitions());
58 $non_proxy_definition = $container->getDefinition('drupal.proxy_original_service.plugin_cache_clearer');
59 $this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $non_proxy_definition->getClass());
60 $this->assertFalse($non_proxy_definition->isLazy());
61 $this->assertTrue($non_proxy_definition->isPublic());
63 $this->assertEquals('Drupal\Core\ProxyClass\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
69 public function testContainerWithLazyServicesWithoutProxyClass() {
70 $container = new ContainerBuilder();
71 $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist')
74 $this->setExpectedException(InvalidArgumentException::class);
75 $this->proxyServicesPass->process($container);