merged branch l3l0/add-options-resolver-test (PR #4545)
Commits -------83ff200
[OptionsResolver] Added options resolver tests to improve coverage Discussion ---------- [OptionsResolver] Added options resolver tests Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes [![Build Status](https://secure.travis-ci.org/l3l0/symfony.png?branch=add-options-resolver-test)](http://travis-ci.org/l3l0/symfony) License of the code: MIT --------------------------------------------------------------------------- by travisbot at 2012-06-10T09:14:34Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1581756) (merged 320617b6 into6266b72d
). --------------------------------------------------------------------------- by l3l0 at 2012-06-10T11:41:15Z Fixed test names and replaced loop with iterator_to_array --------------------------------------------------------------------------- by travisbot at 2012-06-10T11:44:49Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1582569) (merged 68588202 into6266b72d
). --------------------------------------------------------------------------- by bschussek at 2012-06-10T12:38:47Z Could you please also squash the commits into one and prefix the commit message with "[OptionsResolver]"? --------------------------------------------------------------------------- by l3l0 at 2012-06-10T12:56:20Z Commits squashed --------------------------------------------------------------------------- by travisbot at 2012-06-10T13:01:35Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1583038) (merged83ff200e
into6266b72d
). --------------------------------------------------------------------------- by bschussek at 2012-06-10T14:52:16Z Thanks! @fabpot 👍
This commit is contained in:
commit
9a5b275514
@ -215,4 +215,86 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
'three' => '3',
|
||||
), $this->options->all());
|
||||
}
|
||||
|
||||
public function testClearRemovesAllOptions()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->set('two', 2);
|
||||
|
||||
$this->options->clear();
|
||||
|
||||
$this->assertEmpty($this->options->all());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::replace
|
||||
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotReplaceAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->replace(array(
|
||||
'two' => '2',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::overload
|
||||
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotOverloadAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->overload('one', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::clear
|
||||
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotClearAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->clear();
|
||||
}
|
||||
|
||||
public function testOverloadCannotBeEvaluatedLazilyWithoutExpectedClousureParams()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->overload('foo', function () {
|
||||
return 'test';
|
||||
});
|
||||
|
||||
$this->assertNotEquals('test', $this->options->get('foo'));
|
||||
$this->assertTrue(is_callable($this->options->get('foo')));
|
||||
}
|
||||
|
||||
public function testOverloadCannotBeEvaluatedLazilyWithoutFirstParamTypeHint()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->overload('foo', function ($object) {
|
||||
return 'test';
|
||||
});
|
||||
|
||||
$this->assertNotEquals('test', $this->options->get('foo'));
|
||||
$this->assertTrue(is_callable($this->options->get('foo')));
|
||||
}
|
||||
|
||||
public function testOptionsIteration()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('foo1', 'bar1');
|
||||
$expectedResult = array('foo' => 'bar', 'foo1' => 'bar1');
|
||||
|
||||
$this->assertEquals($expectedResult, iterator_to_array($this->options, true));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user