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\Loader;
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;
23 class DirectoryLoaderTest extends TestCase
25 private static $fixturesPath;
30 public static function setUpBeforeClass()
32 self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
35 protected function setUp()
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),
46 $this->loader->setResolver($resolver);
49 public function testDirectoryCanBeLoadedRecursively()
51 $this->loader->load('directory/');
52 $this->assertEquals(array('ini' => 'ini', 'yaml' => 'yaml', 'php' => 'php'), $this->container->getParameterBag()->all(), '->load() takes a single directory');
55 public function testImports()
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');
62 * @expectedException \InvalidArgumentException
63 * @expectedExceptionMessage The file "foo" does not exist (in:
65 public function testExceptionIsRaisedWhenDirectoryDoesNotExist()
67 $this->loader->load('foo/');
70 public function testSupports()
72 $loader = new DirectoryLoader(new ContainerBuilder(), new FileLocator());
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');