IniFileLoaderTest.php 2.1 KB

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