public function testLoader()
 {
     $loader = new IniFileLoader(self::$fixturesPath . '/ini');
     $config = $loader->load('parameters.ini');
     $this->assertEquals($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');
     try {
         $loader->load('foo.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
     } catch (\InvalidArgumentException $e) {
     }
     try {
         @$loader->load('nonvalid.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
     } catch (\InvalidArgumentException $e) {
     }
 }
Example #2
0
 /**
  * @covers Symfony\Components\DependencyInjection\Loader\IniFileLoader::__construct
  * @covers Symfony\Components\DependencyInjection\Loader\IniFileLoader::load
  */
 public function testLoader()
 {
     $loader = new IniFileLoader(self::$fixturesPath . '/ini');
     $config = $loader->load('parameters.ini');
     $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $config->getParameterBag()->all(), '->load() takes a single file name as its first argument');
     try {
         $loader->load('foo.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
         $this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
     }
     try {
         @$loader->load('nonvalid.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
         $this->assertEquals('The nonvalid.ini file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
     }
 }
Example #3
0
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once __DIR__.'/../../../../bootstrap.php';

use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader;

$t = new LimeTest(3);

$fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');

$loader = new IniFileLoader($fixturesPath.'/ini');
$config = $loader->load('parameters.ini');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');

try
{
  $loader->load('foo.ini');
  $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
catch (InvalidArgumentException $e)
{
  $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}

try
{
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
$t = new LimeTest(5);
$fixturesPath = realpath(__DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/');
$loader = new IniFileLoader($fixturesPath . '/ini');
$config = $loader->load(array('parameters.ini'));
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes an array of file names as its first argument');
$loader = new IniFileLoader($fixturesPath . '/ini');
$config = $loader->load('parameters.ini');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');
$loader = new IniFileLoader($fixturesPath . '/ini');
$config = $loader->load(array('parameters.ini', 'parameters1.ini'));
$t->is($config->getParameters(), array('foo' => 'foo', 'bar' => '%foo%', 'baz' => 'baz'), '->load() merges parameters from all given files');
try {
    $loader->load('foo.ini');
    $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try {
    @$loader->load('nonvalid.ini');
    $t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
Example #5
0
 /**
  * @covers Symfony\Components\DependencyInjection\Loader\IniFileLoader::supports
  */
 public function testSupports()
 {
     $loader = new IniFileLoader(new ContainerBuilder());
     $this->assertTrue($loader->supports('foo.ini'), '->supports() returns true if the resource is loadable');
     $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
 }