File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -414,12 +414,13 @@ public function addConst($name, $value)
414414 */
415415 public function setProperties (array $ props )
416416 {
417+ $ this ->properties = array ();
417418 foreach ($ props as $ v ) {
418419 if (!$ v instanceof Property) {
419420 throw new Nette \InvalidArgumentException ('Argument must be Nette\PhpGenerator\Property[]. ' );
420421 }
422+ $ this ->properties [$ v ->getName ()] = $ v ;
421423 }
422- $ this ->properties = $ props ;
423424 return $ this ;
424425 }
425426
@@ -463,12 +464,13 @@ public function addProperty($name, $value = NULL)
463464 */
464465 public function setMethods (array $ methods )
465466 {
467+ $ this ->methods = array ();
466468 foreach ($ methods as $ v ) {
467469 if (!$ v instanceof Method) {
468470 throw new Nette \InvalidArgumentException ('Argument must be Nette\PhpGenerator\Method[]. ' );
469471 }
472+ $ this ->methods [$ v ->getName ()] = $ v ;
470473 }
471- $ this ->methods = $ methods ;
472474 return $ this ;
473475 }
474476
Original file line number Diff line number Diff line change @@ -156,12 +156,13 @@ public function getName()
156156 */
157157 public function setParameters (array $ val )
158158 {
159+ $ this ->parameters = array ();
159160 foreach ($ val as $ v ) {
160161 if (!$ v instanceof Parameter) {
161162 throw new Nette \InvalidArgumentException ('Argument must be Nette\PhpGenerator\Parameter[]. ' );
162163 }
164+ $ this ->parameters [$ v ->getName ()] = $ v ;
163165 }
164- $ this ->parameters = $ val ;
165166 return $ this ;
166167 }
167168
Original file line number Diff line number Diff line change @@ -65,3 +65,20 @@ $method->addParameter('res', NULL)
6565 ->setTypeHint ('array ' );
6666
6767Assert::matchFile (__DIR__ . '/ClassType.expect ' , (string ) $ class );
68+
69+
70+ // global setters & getters
71+ $ methods = $ class ->getMethods ();
72+ Assert::count (3 , $ methods );
73+ $ class ->setMethods (array_values ($ methods ));
74+ Assert::same ($ methods , $ class ->getMethods ());
75+
76+ $ properties = $ class ->getProperties ();
77+ Assert::count (3 , $ properties );
78+ $ class ->setProperties (array_values ($ properties ));
79+ Assert::same ($ properties , $ class ->getProperties ());
80+
81+ $ parameters = $ method ->getParameters ();
82+ Assert::count (2 , $ parameters );
83+ $ method ->setParameters (array_values ($ parameters ));
84+ Assert::same ($ parameters , $ method ->getParameters ());
You can’t perform that action at this time.
0 commit comments