8c84dc7e8041cbca2607c235c3ba63bd988a754d
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Loader / PhpFileLoaderTest.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\Loader;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
17 use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
18 use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
19 use Symfony\Component\Config\FileLocator;
20
21 class PhpFileLoaderTest extends TestCase
22 {
23     public function testSupports()
24     {
25         $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator());
26
27         $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
28         $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
29         $this->assertTrue($loader->supports('with_wrong_ext.yml', 'php'), '->supports() returns true if the resource with forced type is loadable');
30     }
31
32     public function testLoad()
33     {
34         $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());
35
36         $loader->load(__DIR__.'/../Fixtures/php/simple.php');
37
38         $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');
39     }
40
41     public function testConfigServices()
42     {
43         $fixtures = realpath(__DIR__.'/../Fixtures');
44         $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());
45         $loader->load($fixtures.'/config/services9.php');
46
47         $container->compile();
48         $dumper = new PhpDumper($container);
49         $this->assertStringEqualsFile($fixtures.'/php/services9_compiled.php', str_replace(str_replace('\\', '\\\\', $fixtures.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), '%path%', $dumper->dump()));
50     }
51
52     /**
53      * @dataProvider provideConfig
54      */
55     public function testConfig($file)
56     {
57         $fixtures = realpath(__DIR__.'/../Fixtures');
58         $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());
59         $loader->load($fixtures.'/config/'.$file.'.php');
60
61         $container->compile();
62
63         $dumper = new YamlDumper($container);
64         $this->assertStringEqualsFile($fixtures.'/config/'.$file.'.expected.yml', $dumper->dump());
65     }
66
67     public function provideConfig()
68     {
69         yield array('basic');
70         yield array('defaults');
71         yield array('instanceof');
72         yield array('prototype');
73         yield array('child');
74
75         if (\PHP_VERSION_ID >= 70000) {
76             yield array('php7');
77         }
78     }
79
80     /**
81      * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
82      * @expectedExceptionMessage The service "child_service" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.
83      */
84     public function testAutoConfigureAndChildDefinitionNotAllowed()
85     {
86         $fixtures = realpath(__DIR__.'/../Fixtures');
87         $container = new ContainerBuilder();
88         $loader = new PhpFileLoader($container, new FileLocator());
89         $loader->load($fixtures.'/config/services_autoconfigure_with_parent.php');
90         $container->compile();
91     }
92
93     /**
94      * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
95      * @expectedExceptionMessage Invalid factory "factory:method": the `service:method` notation is not available when using PHP-based DI configuration. Use "[ref('factory'), 'method']" instead.
96      */
97     public function testFactoryShortNotationNotAllowed()
98     {
99         $fixtures = realpath(__DIR__.'/../Fixtures');
100         $container = new ContainerBuilder();
101         $loader = new PhpFileLoader($container, new FileLocator());
102         $loader->load($fixtures.'/config/factory_short_notation.php');
103         $container->compile();
104     }
105 }