2010-03-18 07:48:03 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2010-03-18 07:48:03 +00:00
* ( c ) Fabien Potencier < fabien . potencier @ symfony - project . com >
2010-04-07 02:07:59 +01:00
*
2010-03-18 07:48:03 +00:00
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Symfony\Tests\Components\DependencyInjection\Loader ;
use Symfony\Components\DependencyInjection\Builder ;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader ;
class IniLoaderTest extends \PHPUnit_Framework_TestCase
{
2010-05-06 12:25:53 +01:00
static protected $fixturesPath ;
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
static public function setUpBeforeClass ()
2010-03-18 07:48:03 +00:00
{
2010-05-06 12:25:53 +01:00
self :: $fixturesPath = realpath ( __DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/' );
2010-03-18 07:48:03 +00:00
}
2010-05-06 12:25:53 +01:00
public function testLoader ()
2010-03-18 07:48:03 +00:00
{
2010-05-06 12:25:53 +01:00
$loader = new IniFileLoader ( self :: $fixturesPath . '/ini' );
$config = $loader -> load ( 'parameters.ini' );
$this -> assertEquals ( array ( 'foo' => 'bar' , 'bar' => '%foo%' ), $config -> getParameters (), '->load() takes a single file name as its first argument' );
2010-05-07 15:09:11 +01:00
try {
2010-05-06 12:25:53 +01:00
$loader -> load ( 'foo.ini' );
$this -> fail ( '->load() throws an InvalidArgumentException if the loaded file does not exist' );
2010-05-07 15:09:11 +01:00
} catch ( \Exception $e ) {
2010-05-06 12:25:53 +01:00
$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' );
}
2010-05-07 15:09:11 +01:00
try {
2010-05-06 12:25:53 +01:00
@ $loader -> load ( 'nonvalid.ini' );
$this -> fail ( '->load() throws an InvalidArgumentException if the loaded file is not parseable' );
2010-05-07 15:09:11 +01:00
} catch ( \Exception $e ) {
2010-05-06 12:25:53 +01:00
$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' );
}
2010-03-18 07:48:03 +00:00
}
}