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\ContainerBuilder;
18 class CheckDefinitionValidityPassTest extends TestCase
21 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
23 public function testProcessDetectsSyntheticNonPublicDefinitions()
25 $container = new ContainerBuilder();
26 $container->register('a')->setSynthetic(true)->setPublic(false);
28 $this->process($container);
32 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
34 public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
36 $container = new ContainerBuilder();
37 $container->register('a')->setSynthetic(false)->setAbstract(false);
39 $this->process($container);
42 public function testProcess()
44 $container = new ContainerBuilder();
45 $container->register('a', 'class');
46 $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
47 $container->register('c', 'class')->setAbstract(true);
48 $container->register('d', 'class')->setSynthetic(true);
50 $this->process($container);
52 $this->addToAssertionCount(1);
55 public function testValidTags()
57 $container = new ContainerBuilder();
58 $container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
59 $container->register('b', 'class')->addTag('foo', array('bar' => null));
60 $container->register('c', 'class')->addTag('foo', array('bar' => 1));
61 $container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
63 $this->process($container);
65 $this->addToAssertionCount(1);
69 * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
71 public function testInvalidTags()
73 $container = new ContainerBuilder();
74 $container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
76 $this->process($container);
79 protected function process(ContainerBuilder $container)
81 $pass = new CheckDefinitionValidityPass();
82 $pass->process($container);