8000 [OptionsResolver] Added options resolver tests to improve coverage · symfony/symfony@83ff200 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83ff200

Browse files
committed
[OptionsResolver] Added options resolver tests to improve coverage
[OptionsResolver] Fixed test names and iterator test
1 parent 6266b72 commit 83ff200

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/Symfony/Component/OptionsResolver/Tests/OptionsTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,86 @@ public function testReplaceClearsAndSets()
215215
'three' => '3',
216216
), $this->options->all());
217217
}
218+
219+
public function testClearRemovesAllOptions()
220+
{
221+
$this->options->set('one', 1);
222+
$this->options->set('two', 2);
223+
224+
$this->options->clear();
225+
226+
$this->assertEmpty($this->options->all());
227+
228+
}
229+
230+
/**
231+
* @covers Symfony\Component\OptionsResolver\Options::replace
232+
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
233+
*/
234+
public function testCannotReplaceAfterOptionWasRead()
235+
{
236+
$this->options->set('one', 1);
237+
$this->options->all();
238+
239+
$this->options->replace(array(
240+
'two' => '2',
241+
));
242+
}
243+
244+
/**
245+
* @covers Symfony\Component\OptionsResolver\Options::overload
246+
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
247+
*/
248+
public function testCannotOverloadAfterOptionWasRead()
249+
{
250+
$this->options->set('one', 1);
251+
$this->options->all();
252+
253+
$this->options->overload('one', 2);
254+
}
255+
256+
/**
257+
* @covers Symfony\Component\OptionsResolver\Options::clear
258+
* @expectedException Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
259+
*/
260+
public function testCannotClearAfterOptionWasRead()
261+
{
262+
$this->options->set('one', 1);
263+
$this->options->all();
264+
265+
$this->options->clear();
266+
}
267+
268+
public function testOverloadCannotBeEvaluatedLazilyWithoutExpectedClousureParams()
269+
{
270+
$this->options->set('foo', 'bar');
271+
272+
$this->options->overload('foo', function () {
273+
return 'test';
274+
});
275+
276+
$this->assertNotEquals('test', $this->options->get('foo'));
277+
$this->assertTrue(is_callable($this->options->get('foo')));
278+
}
279+
280+
public function testOverloadCannotBeEvaluatedLazilyWithoutFirstParamTypeHint()
281+
{
282+
$this->options->set('foo', 'bar');
283+
284+
$this->options->overload('foo', function ($object) {
285+
return 'test';
286+
});
287+
288+
$this->assertNotEquals('test', $this->options->get('foo'));
289+
$this->assertTrue(is_callable($this->options->get('foo')));
290+
}
291+
292+
public function testOptionsIteration()
293+
{
294+
$this->options->set('foo', 'bar');
295+
$this->options->set('foo1', 'bar1');
296+
$expectedResult = array('foo' => 'bar', 'foo1' => 'bar1');
297+
298+
$this->assertEquals($expectedResult, iterator_to_array($this->options, true));
299+
}
218300
}

0 commit comments

Comments
 (0)
0