[DependencyInjection] Add ParameterBag::remove

This commit is contained in:
Jordi Boggiano 2012-05-07 18:13:02 +02:00
parent f14961b747
commit 3d9990a0ec
2 changed files with 25 additions and 0 deletions

View File

@ -126,6 +126,18 @@ class ParameterBag implements ParameterBagInterface
return array_key_exists(strtolower($name), $this->parameters);
}
/**
* Removes a parameter.
*
* @param string $key The key
*
* @api
*/
public function remove($key)
{
unset($this->parameters[$key]);
}
/**
* Replaces parameter placeholders (%name%) by their values for all parameters.
*/

View File

@ -43,6 +43,19 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $bag->all(), '->clear() removes all parameters');
}
/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::remove
*/
public function testRemove()
{
$bag = new ParameterBag(array(
'foo' => 'foo',
'bar' => 'bar',
));
$bag->remove('foo');
$this->assertEquals(array('bar' => 'bar'), $bag->all(), '->remove() removes a parameter');
}
/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::get
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::set