Skip to content

Protect removing from FrozenParameterBag #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ParameterBag/FrozenParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public function __construct(array $parameters = array())

/**
* {@inheritdoc}
*
* @api
*/
public function clear()
{
Expand All @@ -52,8 +50,6 @@ public function clear()

/**
* {@inheritdoc}
*
* @api
*/
public function add(array $parameters)
{
Expand All @@ -62,11 +58,17 @@ public function add(array $parameters)

/**
* {@inheritdoc}
*
* @api
*/
public function set($name, $value)
{
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.');
}
}
17 changes: 11 additions & 6 deletions Tests/ParameterBag/FrozenParameterBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

class FrozenParameterBagTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag::__construct
*/
public function testConstructor()
{
$parameters = array(
Expand All @@ -29,7 +26,6 @@ public function testConstructor()
}

/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag::clear
* @expectedException \LogicException
*/
public function testClear()
Expand All @@ -39,7 +35,6 @@ public function testClear()
}

/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag::set
* @expectedException \LogicException
*/
public function testSet()
Expand All @@ -49,12 +44,22 @@ public function testSet()
}

/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag::add
* @expectedException \LogicException
*/
public function testAdd()
{
$bag = new FrozenParameterBag(array());
$bag->add(array());
}

/**
* @expectedException \LogicException
*/
public function testRemove()
{
$bag = new FrozenParameterBag(array(
'foo' => 'bar'
));
$bag->remove('foo');
}
}