Version 1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Loader / DirectoryLoaderTest.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\Loader\PhpFileLoader;
17 use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
18 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19 use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
20 use Symfony\Component\Config\Loader\LoaderResolver;
21 use Symfony\Component\Config\FileLocator;
22
23 class DirectoryLoaderTest extends TestCase
24 {
25     private static $fixturesPath;
26
27     private $container;
28     private $loader;
29
30     public static function setUpBeforeClass()
31     {
32         self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
33     }
34
35     protected function setUp()
36     {
37         $locator = new FileLocator(self::$fixturesPath);
38         $this->container = new ContainerBuilder();
39         $this->loader = new DirectoryLoader($this->container, $locator);
40         $resolver = new LoaderResolver(array(
41             new PhpFileLoader($this->container, $locator),
42             new IniFileLoader($this->container, $locator),
43             new YamlFileLoader($this->container, $locator),
44             $this->loader,
45         ));
46         $this->loader->setResolver($resolver);
47     }
48
49     public function testDirectoryCanBeLoadedRecursively()
50     {
51         $this->loader->load('directory/');
52         $this->assertEquals(array('ini' => 'ini', 'yaml' => 'yaml', 'php' => 'php'), $this->container->getParameterBag()->all(), '->load() takes a single directory');
53     }
54
55     public function testImports()
56     {
57         $this->loader->resolve('directory/import/import.yml')->load('directory/import/import.yml');
58         $this->assertEquals(array('ini' => 'ini', 'yaml' => 'yaml'), $this->container->getParameterBag()->all(), '->load() takes a single file that imports a directory');
59     }
60
61     /**
62      * @expectedException        \InvalidArgumentException
63      * @expectedExceptionMessage The file "foo" does not exist (in:
64      */
65     public function testExceptionIsRaisedWhenDirectoryDoesNotExist()
66     {
67         $this->loader->load('foo/');
68     }
69
70     public function testSupports()
71     {
72         $loader = new DirectoryLoader(new ContainerBuilder(), new FileLocator());
73
74         $this->assertTrue($loader->supports('directory/'), '->supports("directory/") returns true');
75         $this->assertTrue($loader->supports('directory/', 'directory'), '->supports("directory/", "directory") returns true');
76         $this->assertFalse($loader->supports('directory'), '->supports("directory") returns false');
77         $this->assertTrue($loader->supports('directory', 'directory'), '->supports("directory", "directory") returns true');
78         $this->assertFalse($loader->supports('directory', 'foo'), '->supports("directory", "foo") returns false');
79     }
80 }