79 lines
2.9 KiB
PHP
79 lines
2.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Tests\Components\DependencyInjection\ParameterBag;
|
|
|
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
|
|
|
class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\ParameterBag\ParameterBag::__construct
|
|
*/
|
|
public function testConstructor()
|
|
{
|
|
$bag = new ParameterBag($parameters = array(
|
|
'foo' => 'foo',
|
|
'bar' => 'bar',
|
|
));
|
|
$this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\ParameterBag\ParameterBag::clear
|
|
*/
|
|
public function testClear()
|
|
{
|
|
$bag = new ParameterBag($parameters = array(
|
|
'foo' => 'foo',
|
|
'bar' => 'bar',
|
|
));
|
|
$bag->clear();
|
|
$this->assertEquals(array(), $bag->all(), '->clear() removes all parameters');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\ParameterBag\ParameterBag::get
|
|
* @covers Symfony\Components\DependencyInjection\ParameterBag\ParameterBag::set
|
|
*/
|
|
public function testGetSet()
|
|
{
|
|
$bag = new ParameterBag(array('foo' => 'bar'));
|
|
$bag->set('bar', 'foo');
|
|
$this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter');
|
|
|
|
$bag->set('foo', 'baz');
|
|
$this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter');
|
|
|
|
$bag->set('Foo', 'baz1');
|
|
$this->assertEquals('baz1', $bag->get('foo'), '->set() converts the key to lowercase');
|
|
$this->assertEquals('baz1', $bag->get('FOO'), '->get() converts the key to lowercase');
|
|
|
|
try {
|
|
$bag->get('baba');
|
|
$this->fail('->get() throws an \InvalidArgumentException if the key does not exist');
|
|
} catch (\Exception $e) {
|
|
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an \InvalidArgumentException if the key does not exist');
|
|
$this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->get() throws an \InvalidArgumentException if the key does not exist');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\ParameterBag\ParameterBag::has
|
|
*/
|
|
public function testHas()
|
|
{
|
|
$bag = new ParameterBag(array('foo' => 'bar'));
|
|
$this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined');
|
|
$this->assertTrue($bag->has('Foo'), '->has() converts the key to lowercase');
|
|
$this->assertFalse($bag->has('bar'), '->has() returns false if a parameter is not defined');
|
|
}
|
|
}
|