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 .
2011-01-15 13:29:43 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . 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 .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Tests\Component\DependencyInjection\Loader ;
2010-03-18 07:48:03 +00:00
2010-08-20 22:09:55 +01:00
use Symfony\Component\DependencyInjection\ContainerBuilder ;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader ;
2011-02-10 15:15:51 +00:00
use Symfony\Component\Config\FileLocator ;
2010-03-18 07:48:03 +00:00
2010-06-27 17:28:29 +01:00
class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
2010-03-18 07:48:03 +00:00
{
2012-07-09 13:38:28 +01:00
protected static $fixturesPath ;
2010-03-18 07:48:03 +00:00
2012-07-09 13:38:28 +01:00
public static function setUpBeforeClass ()
2010-03-18 07:48:03 +00:00
{
2010-06-28 08:31:54 +01:00
self :: $fixturesPath = realpath ( __DIR__ . '/../Fixtures/' );
2010-03-18 07:48:03 +00:00
}
2010-06-27 17:28:29 +01:00
/**
2010-08-20 22:09:55 +01:00
* @ covers Symfony\Component\DependencyInjection\Loader\IniFileLoader :: __construct
* @ covers Symfony\Component\DependencyInjection\Loader\IniFileLoader :: load
2010-06-27 17:28:29 +01:00
*/
2010-05-06 12:25:53 +01:00
public function testLoader ()
2010-03-18 07:48:03 +00:00
{
2010-07-16 08:12:58 +01:00
$container = new ContainerBuilder ();
2011-02-09 23:44:02 +00:00
$loader = new IniFileLoader ( $container , new FileLocator ( self :: $fixturesPath . '/ini' ));
2010-07-16 08:12:58 +01:00
$loader -> load ( 'parameters.ini' );
2011-09-25 10:33:07 +01:00
$this -> assertEquals ( array ( 'foo' => 'bar' , 'bar' => '%foo%' ), $container -> getParameterBag () -> all (), '->load() takes a single file name as its first argument' );
2010-05-06 12:25:53 +01:00
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' );
2011-06-24 15:28:15 +01:00
$this -> assertEquals ( 'The "nonvalid.ini" file is not valid.' , $e -> getMessage (), '->load() throws an InvalidArgumentException if the loaded file is not parseable' );
2010-05-06 12:25:53 +01:00
}
2010-03-18 07:48:03 +00:00
}
2010-07-18 10:26:47 +01:00
/**
2010-08-20 22:09:55 +01:00
* @ covers Symfony\Component\DependencyInjection\Loader\IniFileLoader :: supports
2010-07-18 10:26:47 +01:00
*/
public function testSupports ()
{
2011-02-09 23:44:02 +00:00
$loader = new IniFileLoader ( new ContainerBuilder (), new FileLocator ());
2010-07-18 10:26:47 +01:00
$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' );
}
2010-03-18 07:48:03 +00:00
}