File tree Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -121,13 +121,23 @@ public function addEntityField(ClassProperty $mapping): void
121
121
122
122
$ defaultValue = null ;
123
123
$ commentLines = [];
124
- if ('array ' === $ typeHint && !$ nullable ) {
125
- $ defaultValue = new Node \Expr \Array_ ([], ['kind ' => Node \Expr \Array_::KIND_SHORT ]);
126
- if (null !== $ mapping ->enumType ) {
124
+
125
+ if (null !== $ mapping ->enumType ) {
126
+ if ('array ' === $ typeHint ) {
127
+ // still need to add the use statement
128
+ $ this ->addUseStatementIfNecessary ($ mapping ->enumType );
129
+
127
130
$ commentLines = [\sprintf ('@return %s[] ' , Str::getShortClassName ($ mapping ->enumType ))];
131
+ if ($ nullable ) {
132
+ $ commentLines [0 ] .= '|null ' ;
133
+ } else {
134
+ $ defaultValue = new Node \Expr \Array_ ([], ['kind ' => Node \Expr \Array_::KIND_SHORT ]);
135
+ }
136
+ } else {
137
+ $ typeHint = $ this ->addUseStatementIfNecessary ($ mapping ->enumType );
128
138
}
129
- } elseif (null !== $ mapping -> enumType ) {
130
- $ typeHint = $ this -> addUseStatementIfNecessary ( $ mapping -> enumType );
139
+ } elseif (' array ' === $ typeHint && ! $ nullable ) {
140
+ $ defaultValue = new Node \ Expr \ Array_ ([], [ ' kind ' => Node \ Expr \Array_:: KIND_SHORT ] );
131
141
} elseif ($ typeHint && '\\' === $ typeHint [0 ] && false !== strpos ($ typeHint , '\\' , 1 )) {
132
142
$ typeHint = $ this ->addUseStatementIfNecessary (substr ($ typeHint , 1 ));
133
143
}
Original file line number Diff line number Diff line change @@ -735,6 +735,29 @@ public function getTestDetails(): \Generator
735
735
$ this ->runEntityTest ($ runner );
736
736
}),
737
737
];
738
+
739
+ yield 'it_creates_a_new_class_with_enum_field_multiple_and_nullable ' => [$ this ->createMakeEntityTest ()
740
+ ->run (function (MakerTestRunner $ runner ) {
741
+ $ this ->copyEntity ($ runner , 'Enum/Role-basic.php ' );
742
+
743
+ $ runner ->runMaker ([
744
+ // entity class name
745
+ 'User ' ,
746
+ // add additional field
747
+ 'role ' ,
748
+ 'enum ' ,
749
+ 'App \\Entity \\Enum \\Role ' ,
750
+ // multiple
751
+ 'y ' ,
752
+ // nullable
753
+ 'y ' ,
754
+ // finish adding fields
755
+ '' ,
756
+ ]);
757
+
758
+ $ this ->runEntityTest ($ runner );
759
+ }),
760
+ ];
738
761
}
739
762
740
763
/** @param array<string, mixed> $data */
You can’t perform that action at this time.
0 commit comments