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