@@ -230,6 +230,53 @@ public function testInvokeEachLazyOptionOnlyOnce()
230
230
$ this ->assertSame (2 , $ calls );
231
231
}
232
232
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
+
233
280
////////////////////////////////////////////////////////////////////////////
234
281
// setRequired()/isRequired()/getRequiredOptions()
235
282
////////////////////////////////////////////////////////////////////////////
@@ -1547,4 +1594,20 @@ public function testCountFailsOutsideResolve()
1547
1594
1548
1595
count ($ this ->resolver );
1549
1596
}
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
+ }
1550
1613
}
0 commit comments