Skip to content

Commit

Permalink
[OptionsResolver] Made the OptionsResolver clonable
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Jul 12, 2012
1 parent 70307e5 commit a924dab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Symfony/Component/OptionsResolver/OptionsResolver.php
Expand Up @@ -67,6 +67,14 @@ public function __construct()
$this->defaultOptions = new Options();
}

/**
* Clones the resolver.
*/
public function __clone()
{
$this->defaultOptions = clone $this->defaultOptions;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -210,7 +218,7 @@ public function isRequired($option)
/**
* {@inheritdoc}
*/
public function resolve(array $options)
public function resolve(array $options = array())
{
$this->validateOptionsExistence($options);
$this->validateOptionsCompleteness($options);
Expand Down
Expand Up @@ -206,5 +206,5 @@ public function isRequired($option);
* @throws Exception\OptionDefinitionException If a cyclic dependency is detected
* between two lazy options.
*/
public function resolve(array $options);
public function resolve(array $options = array());
}
Expand Up @@ -612,4 +612,25 @@ public function testResolveSucceedsIfOptionRequiredAndValueAllowed()

$this->assertEquals($options, $this->resolver->resolve($options));
}

public function testClone()
{
$this->resolver->setDefaults(array('one' => '1'));

$clone = clone $this->resolver;

// Changes after cloning don't affect each other
$this->resolver->setDefaults(array('two' => '2'));
$clone->setDefaults(array('three' => '3'));

$this->assertEquals(array(
'one' => '1',
'two' => '2',
), $this->resolver->resolve());

$this->assertEquals(array(
'one' => '1',
'three' => '3',
), $clone->resolve());
}
}

0 comments on commit a924dab

Please sign in to comment.