IniLoaderTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. require_once __DIR__.'/../../../../bootstrap.php';
  10. use Symfony\Components\DependencyInjection\Builder;
  11. use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
  12. $t = new LimeTest(5);
  13. $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
  14. $loader = new IniFileLoader($fixturesPath.'/ini');
  15. $config = $loader->load(array('parameters.ini'));
  16. $t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes an array of file names as its first argument');
  17. $loader = new IniFileLoader($fixturesPath.'/ini');
  18. $config = $loader->load('parameters.ini');
  19. $t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');
  20. $loader = new IniFileLoader($fixturesPath.'/ini');
  21. $config = $loader->load(array('parameters.ini', 'parameters1.ini'));
  22. $t->is($config->getParameters(), array('foo' => 'foo', 'bar' => '%foo%', 'baz' => 'baz'), '->load() merges parameters from all given files');
  23. try
  24. {
  25. $loader->load('foo.ini');
  26. $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
  27. }
  28. catch (InvalidArgumentException $e)
  29. {
  30. $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
  31. }
  32. try
  33. {
  34. @$loader->load('nonvalid.ini');
  35. $t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
  36. }
  37. catch (InvalidArgumentException $e)
  38. {
  39. $t->pass('->load() throws an InvalidArgumentException if the loaded file is not parseable');
  40. }