File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
src/Symfony/Component/OptionsResolver Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ public function __construct()
67
67
$ this ->defaultOptions = new Options ();
68
68
}
69
69
70
+ /**
71
+ * Clones the resolver.
72
+ */
73
+ public function __clone ()
74
+ {
75
+ $ this ->defaultOptions = clone $ this ->defaultOptions ;
76
+ }
77
+
70
78
/**
71
79
* {@inheritdoc}
72
80
*/
@@ -210,7 +218,7 @@ public function isRequired($option)
210
218
/**
211
219
* {@inheritdoc}
212
220
*/
213
- public function resolve (array $ options )
221
+ public function resolve (array $ options = array () )
214
222
{
215
223
$ this ->validateOptionsExistence ($ options );
216
224
$ this ->validateOptionsCompleteness ($ options );
Original file line number Diff line number Diff line change @@ -206,5 +206,5 @@ public function isRequired($option);
206
206
* @throws Exception\OptionDefinitionException If a cyclic dependency is detected
207
207
* between two lazy options.
208
208
*/
209
- public function resolve (array $ options );
209
+ public function resolve (array $ options = array () );
210
210
}
Original file line number Diff line number Diff line change @@ -612,4 +612,25 @@ public function testResolveSucceedsIfOptionRequiredAndValueAllowed()
612
612
613
613
$ this ->assertEquals ($ options , $ this ->resolver ->resolve ($ options ));
614
614
}
615
+
616
+ public function testClone ()
617
+ {
618
+ $ this ->resolver ->setDefaults (array ('one ' => '1 ' ));
619
+
620
+ $ clone = clone $ this ->resolver ;
621
+
622
+ // Changes after cloning don't affect each other
623
+ $ this ->resolver ->setDefaults (array ('two ' => '2 ' ));
624
+ $ clone ->setDefaults (array ('three ' => '3 ' ));
625
+
626
+ $ this ->assertEquals (array (
627
+ 'one ' => '1 ' ,
628
+ 'two ' => '2 ' ,
629
+ ), $ this ->resolver ->resolve ());
630
+
631
+ $ this ->assertEquals (array (
632
+ 'one ' => '1 ' ,
633
+ 'three ' => '3 ' ,
634
+ ), $ clone ->resolve ());
635
+ }
615
636
}
You can’t perform that action at this time.
0 commit comments