IniFileLoaderTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Components\DependencyInjection\Loader;
  10. use Symfony\Components\DependencyInjection\ContainerBuilder;
  11. use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
  12. class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. static protected $fixturesPath;
  15. static public function setUpBeforeClass()
  16. {
  17. self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
  18. }
  19. /**
  20. * @covers Symfony\Components\DependencyInjection\Loader\IniFileLoader::__construct
  21. * @covers Symfony\Components\DependencyInjection\Loader\IniFileLoader::load
  22. */
  23. public function testLoader()
  24. {
  25. $container = new ContainerBuilder();
  26. $loader = new IniFileLoader($container, self::$fixturesPath.'/ini');
  27. $loader->load('parameters.ini');
  28. $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $container->getParameterBag()->all(), '->load() takes a single file name as its first argument');
  29. try {
  30. $loader->load('foo.ini');
  31. $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
  32. } catch (\Exception $e) {
  33. $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
  34. $this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
  35. }
  36. try {
  37. @$loader->load('nonvalid.ini');
  38. $this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
  39. } catch (\Exception $e) {
  40. $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
  41. $this->assertEquals('The nonvalid.ini file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
  42. }
  43. }
  44. }