File tree Expand file tree Collapse file tree 4 files changed +19
-16
lines changed
Expand file tree Collapse file tree 4 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 11.idea
22
33/vendor /
4+ /.phpunit.result.cache
Original file line number Diff line number Diff line change @@ -112,6 +112,19 @@ public function toArray(): array
112112 $ out = $ item ->toArray ();
113113 break ;
114114 }
115+ if ($ name == self ::ROOT && is_array ($ item )) {
116+ foreach ($ item as $ i ) {
117+ // array of ValueObjects
118+ if ($ i instanceof AbstractValueObject) {
119+ $ out [] = $ i ->toArray ();
120+ } // array of other types
121+ else {
122+ $ out [] = $ i ;
123+ }
124+ }
125+ break ;
126+ }
127+
115128 // ValueObject element
116129 if ($ item instanceof AbstractValueObject) {
117130 $ out [$ name ] = $ item ->toArray ();
Original file line number Diff line number Diff line change 66use OGSoft \ValueObjects \Exceptions \ValidatorException ;
77use PHPUnit \Framework \TestCase ;
88use Tests \ValueObjects \CarValueObject ;
9- use Tests \ValueObjects \RootValueObject ;
109
1110final class ValueObjectTest extends TestCase
1211{
@@ -63,16 +62,6 @@ public function testNull()
6362 $ car = new CarValueObject ();
6463 $ this ->expectException (ValidatorException::class);
6564 $ car ->init ($ data );
66- $ this ->assertTrue (true );
67- }
68-
69- public function testRoot ()
70- {
71- $ data = ["winter " => true ];
72-
73- $ tire = new RootValueObject ();
74- $ tire ->init (["root " => $ data ]);
75- $ this ->assertEquals ($ data , $ tire ->toArray ());
7665 }
7766}
7867
Original file line number Diff line number Diff line change 77class RootValueObject extends AbstractMyValueObject
88{
99 /**
10- * @var TireValueObject
10+ * @var CarValueObject
1111 */
1212 protected $ root ;
1313
1414 /**
15- * @return TireValueObject
15+ * @return CarValueObject
1616 */
17- public function getRoot (): TireValueObject
17+ public function getRoot (): CarValueObject
1818 {
1919 return $ this ->root ;
2020 }
2121
2222 /**
23- * @param TireValueObject $root
23+ * @param CarValueObject $root
2424 * @return RootValueObject
2525 */
26- public function setRoot (TireValueObject $ root ): RootValueObject
26+ public function setRoot (CarValueObject $ root ): RootValueObject
2727 {
2828 $ this ->root = $ root ;
2929 return $ this ;
You can’t perform that action at this time.
0 commit comments