IniFileLoaderTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  13. use Symfony\Component\Config\FileLocator;
  14. class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected static $fixturesPath;
  17. protected $container;
  18. protected $loader;
  19. public static function setUpBeforeClass()
  20. {
  21. self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
  22. }
  23. protected function setUp()
  24. {
  25. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  26. $this->markTestSkipped('The "Config" component is not available');
  27. }
  28. $this->container = new ContainerBuilder();
  29. $this->loader = new IniFileLoader($this->container, new FileLocator(self::$fixturesPath.'/ini'));
  30. }
  31. /**
  32. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
  33. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
  34. */
  35. public function testIniFileCanBeLoaded()
  36. {
  37. $this->loader->load('parameters.ini');
  38. $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $this->container->getParameterBag()->all(), '->load() takes a single file name as its first argument');
  39. }
  40. /**
  41. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
  42. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
  43. *
  44. * @expectedException \InvalidArgumentException
  45. * @expectedExceptionMessage The file "foo.ini" does not exist (in:
  46. */
  47. public function testExceptionIsRaisedWhenIniFileDoesNotExist()
  48. {
  49. $this->loader->load('foo.ini');
  50. }
  51. /**
  52. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
  53. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
  54. *
  55. * @expectedException \InvalidArgumentException
  56. * @expectedExceptionMessage The "nonvalid.ini" file is not valid.
  57. */
  58. public function testExceptionIsRaisedWhenIniFileCannotBeParsed()
  59. {
  60. @$this->loader->load('nonvalid.ini');
  61. }
  62. /**
  63. * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::supports
  64. */
  65. public function testSupports()
  66. {
  67. $loader = new IniFileLoader(new ContainerBuilder(), new FileLocator());
  68. $this->assertTrue($loader->supports('foo.ini'), '->supports() returns true if the resource is loadable');
  69. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  70. }
  71. }