[OptionsResolver] Fixed Options::replace() method

This commit is contained in:
Bernhard Schussek 2012-05-11 15:53:40 +02:00
parent 16f7d20dff
commit 2b46975e32
2 changed files with 19 additions and 1 deletions

View File

@ -111,8 +111,9 @@ class Options implements ArrayAccess, Iterator, Countable
}
$this->options = array();
foreach ($options as $option => $value) {
$this->options[$option] = $value;
$this->set($option, $value);
}
}

View File

@ -198,4 +198,21 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
$this->options->get('foo');
}
public function testReplaceClearsAndSets()
{
$this->options->set('one', '1');
$this->options->replace(array(
'two' => '2',
'three' => function (Options $options) {
return '2' === $options['two'] ? '3' : 'foo';
}
));
$this->assertEquals(array(
'two' => '2',
'three' => '3',
), $this->options->all());
}
}