Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5121859

Browse filesBrowse files
committed
add tests
1 parent 47e2363 commit 5121859
Copy full SHA for 5121859

File tree

1 file changed

+63
-0
lines changed
Filter options

1 file changed

+63
-0
lines changed

‎src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,53 @@ public function testInvokeEachLazyOptionOnlyOnce()
230230
$this->assertSame(2, $calls);
231231
}
232232

233+
////////////////////////////////////////////////////////////////////////////
234+
// setNested()/isNested()/getNestedOptions()
235+
////////////////////////////////////////////////////////////////////////////
236+
237+
public function testSetNestedReturnsNewResolver()
238+
{
239+
$this->assertNotSame($this->resolver, $this->resolver->setNested('foo'));
240+
$this->assertInstanceOf('Symfony\Component\OptionsResolver\OptionsResolver', $this->resolver->setNested('bar'));
241+
}
242+
243+
public function testSetNested()
244+
{
245+
$this->resolver->setNested('one', array('un' => '1'));
246+
$this->resolver->setNested('two', array('deux' => '2', 'vingt' => 20));
247+
248+
$this->assertEquals(array(
249+
'one' => array('un' => '1'),
250+
'two' => array('deux' => '2', 'vingt' => 20),
251+
), $this->resolver->resolve());
252+
}
253+
254+
/**
255+
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
256+
*/
257+
public function testFailIfSetNestedFromLazyOption()
258+
{
259+
$this->resolver->setDefault('lazy', function (Options $options) {
260+
$options->setNested('nested', array('number' => 42));
261+
});
262+
263+
$this->resolver->resolve();
264+
}
265+
266+
public function testIsNested()
267+
{
268+
$this->assertFalse($this->resolver->isNested('foo'));
269+
$this->resolver->setNested('foo', array('number' => 42));
270+
$this->assertTrue($this->resolver->isNested('foo'));
271+
}
272+
273+
public function testIsNestedWithNoValue()
274+
{
275+
$this->assertFalse($this->resolver->isNested('foo'));
276+
$this->resolver->setNested('foo');
277+
$this->assertTrue($this->resolver->isNested('foo'));
278+
}
279+
233280
////////////////////////////////////////////////////////////////////////////
234281
// setRequired()/isRequired()/getRequiredOptions()
235282
////////////////////////////////////////////////////////////////////////////
@@ -1547,4 +1594,20 @@ public function testCountFailsOutsideResolve()
15471594

15481595
count($this->resolver);
15491596
}
1597+
1598+
////////////////////////////////////////////////////////////////////////////
1599+
// Nested options
1600+
////////////////////////////////////////////////////////////////////////////
1601+
1602+
/**
1603+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
1604+
* @expectedExceptionMessage The nested options in the option "z" could not be resolved.
1605+
*/
1606+
public function testResolveFailsIfNonExistingNestedOption()
1607+
{
1608+
$this->resolver->setNested('z', array('one' => '1'));
1609+
$this->resolver->setNested('a', array('two' => '2'));
1610+
1611+
$this->resolver->resolve(array('z' => array('foo' => 'bar')));
1612+
}
15501613
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.