4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
19 class CheckDefinitionValidityPassTest extends TestCase
22 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
24 public function testProcessDetectsSyntheticNonPublicDefinitions()
26 $container = new ContainerBuilder();
27 $container->register('a')->setSynthetic(true)->setPublic(false);
29 $this->process($container);
33 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
36 public function testProcessDetectsSyntheticPrototypeDefinitions()
38 $container = new ContainerBuilder();
39 $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
41 $this->process($container);
45 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
48 public function testProcessDetectsSharedPrototypeDefinitions()
50 $container = new ContainerBuilder();
51 $container->register('a')->setShared(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
53 $this->process($container);
57 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
59 public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
61 $container = new ContainerBuilder();
62 $container->register('a')->setSynthetic(false)->setAbstract(false);
64 $this->process($container);
68 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
71 public function testLegacyProcessDetectsBothFactorySyntaxesUsed()
73 $container = new ContainerBuilder();
74 $container->register('a')->setFactory(array('a', 'b'))->setFactoryClass('a');
76 $this->process($container);
79 public function testProcess()
81 $container = new ContainerBuilder();
82 $container->register('a', 'class');
83 $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
84 $container->register('c', 'class')->setAbstract(true);
85 $container->register('d', 'class')->setSynthetic(true);
87 $this->process($container);
89 $this->addToAssertionCount(1);
92 public function testValidTags()
94 $container = new ContainerBuilder();
95 $container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
96 $container->register('b', 'class')->addTag('foo', array('bar' => null));
97 $container->register('c', 'class')->addTag('foo', array('bar' => 1));
98 $container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
100 $this->process($container);
102 $this->addToAssertionCount(1);
106 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
108 public function testInvalidTags()
110 $container = new ContainerBuilder();
111 $container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
113 $this->process($container);
116 protected function process(ContainerBuilder $container)
118 $pass = new CheckDefinitionValidityPass();
119 $pass->process($container);