@@ -215,4 +215,86 @@ public function testReplaceClearsAndSets()
215
215
'three ' => '3 ' ,
216
216
), $ this ->options ->all ());
217
217
}
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
+ }
218
300
}
0 commit comments