Skip to content

Commit

Permalink
[OptionsResolver] Added options resolver tests to improve coverage
Browse files Browse the repository at this point in the history
[OptionsResolver] Fixed test names and iterator test
  • Loading branch information
l3l0 committed Jun 10, 2012
1 parent 6266b72 commit 83ff200
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/Symfony/Component/OptionsResolver/Tests/OptionsTest.php
Expand Up @@ -215,4 +215,86 @@ public function testReplaceClearsAndSets()
'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));
}
}

0 comments on commit 83ff200

Please sign in to comment.