[DependencyInjection] fixed FrozenParameterBag and improved Parameter…

This commit is contained in:
Tomaz Ahlin 2015-07-02 10:07:17 +02:00 committed by Fabien Potencier
parent 7c36f0b9a0
commit 3ad0794aa1
3 changed files with 24 additions and 0 deletions

View File

@ -69,4 +69,12 @@ class FrozenParameterBag extends ParameterBag
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritdoc}
*/
public function remove($name)
{
throw new LogicException('Impossible to call remove() on a frozen ParameterBag.');
}
}

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\DependencyInjection\ParameterBag;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
/**
@ -25,6 +26,8 @@ interface ParameterBagInterface
/**
* Clears all parameters.
*
* @throws LogicException if the ParameterBagInterface can not be cleared
*
* @api
*/
public function clear();
@ -34,6 +37,8 @@ interface ParameterBagInterface
*
* @param array $parameters An array of parameters
*
* @throws LogicException if the parameter can not be added
*
* @api
*/
public function add(array $parameters);
@ -66,6 +71,8 @@ interface ParameterBagInterface
* @param string $name The parameter name
* @param mixed $value The parameter value
*
* @throws LogicException if the parameter can not be set
*
* @api
*/
public function set($name, $value);

View File

@ -57,4 +57,13 @@ class FrozenParameterBagTest extends \PHPUnit_Framework_TestCase
$bag = new FrozenParameterBag(array());
$bag->add(array());
}
/**
* @expectedException \LogicException
*/
public function testRemove()
{
$bag = new FrozenParameterBag(array('foo' => 'bar'));
$bag->remove('foo');
}
}