IniFileLoaderTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Builder;
  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. $loader = new IniFileLoader(self::$fixturesPath.'/ini');
  26. $config = $loader->load('parameters.ini');
  27. $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $config->getParameterBag()->all(), '->load() takes a single file name as its first argument');
  28. try {
  29. $loader->load('foo.ini');
  30. $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
  31. } catch (\Exception $e) {
  32. $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
  33. $this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
  34. }
  35. try {
  36. @$loader->load('nonvalid.ini');
  37. $this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
  38. } catch (\Exception $e) {
  39. $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
  40. $this->assertEquals('The nonvalid.ini file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
  41. }
  42. }
  43. }