LoaderResolverTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Tests\Loader;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\Config\Loader\LoaderResolver;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  16. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  17. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  18. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  19. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  20. class LoaderResolverTest extends TestCase
  21. {
  22. private static $fixturesPath;
  23. /** @var LoaderResolver */
  24. private $resolver;
  25. protected function setUp()
  26. {
  27. self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
  28. $container = new ContainerBuilder();
  29. $this->resolver = new LoaderResolver(array(
  30. new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')),
  31. new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')),
  32. new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')),
  33. new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')),
  34. new ClosureLoader($container),
  35. ));
  36. }
  37. public function provideResourcesToLoad()
  38. {
  39. return array(
  40. array('ini_with_wrong_ext.xml', 'ini', IniFileLoader::class),
  41. array('xml_with_wrong_ext.php', 'xml', XmlFileLoader::class),
  42. array('php_with_wrong_ext.yml', 'php', PhpFileLoader::class),
  43. array('yaml_with_wrong_ext.ini', 'yaml', YamlFileLoader::class),
  44. );
  45. }
  46. /**
  47. * @dataProvider provideResourcesToLoad
  48. */
  49. public function testResolvesForcedType($resource, $type, $expectedClass)
  50. {
  51. $this->assertInstanceOf($expectedClass, $this->resolver->resolve($resource, $type));
  52. }
  53. }