ad698d2bff48328105ef004c4eccfe9d717ec6fa
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / ResolveInvalidReferencesPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerInterface;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20 class ResolveInvalidReferencesPassTest extends TestCase
21 {
22     public function testProcess()
23     {
24         $container = new ContainerBuilder();
25         $def = $container
26             ->register('foo')
27             ->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
28             ->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
29         ;
30
31         $this->process($container);
32
33         $arguments = $def->getArguments();
34         $this->assertNull($arguments[0]);
35         $this->assertCount(0, $def->getMethodCalls());
36     }
37
38     public function testProcessIgnoreNonExistentServices()
39     {
40         $container = new ContainerBuilder();
41         $def = $container
42             ->register('foo')
43             ->setArguments(array(new Reference('bar')))
44         ;
45
46         $this->process($container);
47
48         $arguments = $def->getArguments();
49         $this->assertEquals('bar', (string) $arguments[0]);
50     }
51
52     public function testProcessRemovesPropertiesOnInvalid()
53     {
54         $container = new ContainerBuilder();
55         $def = $container
56             ->register('foo')
57             ->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
58         ;
59
60         $this->process($container);
61
62         $this->assertEquals(array(), $def->getProperties());
63     }
64
65     /**
66      * @group legacy
67      */
68     public function testStrictFlagIsPreserved()
69     {
70         $container = new ContainerBuilder();
71         $container->register('bar');
72         $def = $container
73             ->register('foo')
74             ->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
75         ;
76
77         $this->process($container);
78
79         $this->assertFalse($def->getArgument(0)->isStrict());
80     }
81
82     protected function process(ContainerBuilder $container)
83     {
84         $pass = new ResolveInvalidReferencesPass();
85         $pass->process($container);
86     }
87 }