@@ -63,46 +63,46 @@ public static function childProvider(): iterable
63
63
$ scriptPath ,
64
64
$ commandName
65
65
) {
66
- $ input = new ArrayInput ([
67
- ' item ' => ' item3 ' ,
68
- ' groupId ' => 'group2 ' ,
69
- ' --child ' => null ,
70
- '--processes ' => ' 2 ' ,
71
- '--opt ' => 'val ' ,
72
- ]);
73
-
74
- $ commandDefinition = new InputDefinition ( [
75
- new InputArgument (
76
- 'item ' ,
77
- InputArgument::REQUIRED ,
78
- ),
79
- new InputArgument (
80
- 'groupId ' ,
81
- InputArgument::REQUIRED ,
82
- ),
83
- new InputArgument (
84
- 'optArg ' ,
85
- InputArgument::OPTIONAL ,
86
- '' ,
87
- '' ,
88
- ),
89
- new InputOption (
90
- 'opt ' ,
91
- null ,
92
- InputOption::VALUE_REQUIRED ,
93
- ),
94
- new InputOption (
95
- 'child ' ,
96
- null ,
97
- InputOption::VALUE_NONE ,
98
- ),
99
- new InputOption (
100
- 'processes ' ,
101
- null ,
102
- InputOption::VALUE_REQUIRED ,
103
- ),
104
- ]);
105
- $ input -> bind ( $ commandDefinition );
66
+ [ $ input, $ commandDefinition ] = self :: createInput (
67
+ [
68
+ ' item ' => 'item3 ' ,
69
+ ' groupId ' => ' group2 ' ,
70
+ '--child ' => null ,
71
+ '--processes ' => '2 ' ,
72
+ ' --opt ' => ' val ' ,
73
+ ],
74
+ [
75
+ new InputArgument (
76
+ 'item ' ,
77
+ InputArgument::REQUIRED ,
78
+ ),
79
+ new InputArgument (
80
+ 'groupId ' ,
81
+ InputArgument::REQUIRED ,
82
+ ),
83
+ new InputArgument (
84
+ 'optArg ' ,
85
+ InputArgument::OPTIONAL ,
86
+ '' ,
87
+ '' ,
88
+ ),
89
+ new InputOption (
90
+ 'opt ' ,
91
+ null ,
92
+ InputOption::VALUE_REQUIRED ,
93
+ ),
94
+ new InputOption (
95
+ 'child ' ,
96
+ null ,
97
+ InputOption::VALUE_NONE ,
98
+ ),
99
+ new InputOption (
100
+ 'processes ' ,
101
+ null ,
102
+ InputOption::VALUE_REQUIRED ,
103
+ ),
104
+ ],
105
+ );
106
106
107
107
return [
108
108
$ phpExecutable ,
@@ -120,6 +120,131 @@ public static function childProvider(): iterable
120
120
],
121
121
];
122
122
})();
123
+
124
+ yield 'it removes the command & item argument ' => (static function () use (
125
+ $ phpExecutable ,
126
+ $ scriptPath ,
127
+ $ commandName
128
+ ) {
129
+ [$ input , $ commandDefinition ] = self ::createInput (
130
+ [
131
+ 'command ' => 'import:something ' ,
132
+ 'groupId ' => 'group2 ' ,
133
+ 'categoryId ' => 10 ,
134
+ 'item ' => 'item3 ' ,
135
+ 'tagIds ' => 'tag1 tag2 tag3 ' ,
136
+ ],
137
+ [
138
+ new InputArgument (
139
+ 'groupId ' ,
140
+ InputArgument::REQUIRED ,
141
+ ),
142
+ new InputArgument (
143
+ 'categoryId ' ,
144
+ InputArgument::REQUIRED ,
145
+ ),
146
+ // Inverse the order to break with the old code which was
147
+ // relying on item/command being the first argument.
148
+ new InputArgument (
149
+ 'item ' ,
150
+ InputArgument::REQUIRED ,
151
+ ),
152
+ new InputArgument (
153
+ 'command ' ,
154
+ InputArgument::OPTIONAL ,
155
+ ),
156
+ new InputArgument (
157
+ 'tagIds ' ,
158
+ InputArgument::IS_ARRAY ,
159
+ ),
160
+ ],
161
+ );
162
+
163
+ return [
164
+ $ phpExecutable ,
165
+ $ scriptPath ,
166
+ $ commandName ,
167
+ $ commandDefinition ,
168
+ $ input ,
169
+ [
170
+ $ phpExecutable ,
171
+ $ scriptPath ,
172
+ $ commandName ,
173
+ 'group2 ' ,
174
+ '10 ' ,
175
+ 'tag1 tag2 tag3 ' ,
176
+ '--child ' ,
177
+ ],
178
+ ];
179
+ })();
180
+
181
+ yield 'it does not forward the parallel input ' => (static function () use (
182
+ $ phpExecutable ,
183
+ $ scriptPath ,
184
+ $ commandName
185
+ ) {
186
+ [$ input , $ commandDefinition ] = self ::createInput (
187
+ [
188
+ '--processes ' => '10 ' ,
189
+ '--main-process ' => null ,
190
+ '--child ' => null ,
191
+ ],
192
+ [
193
+ new InputOption (
194
+ ParallelizationInput::PROCESSES_OPTION ,
195
+ null ,
196
+ InputOption::VALUE_OPTIONAL ,
197
+ ),
198
+ new InputOption (
199
+ ParallelizationInput::MAIN_PROCESS_OPTION ,
200
+ null ,
201
+ InputOption::VALUE_NONE ,
202
+ ),
203
+ new InputOption (
204
+ ParallelizationInput::CHILD_OPTION ,
205
+ null ,
206
+ InputOption::VALUE_NONE ,
207
+ ),
208
+ ],
209
+ );
210
+
211
+ return [
212
+ $ phpExecutable ,
213
+ $ scriptPath ,
214
+ $ commandName ,
215
+ $ commandDefinition ,
216
+ $ input ,
217
+ [
218
+ $ phpExecutable ,
219
+ $ scriptPath ,
220
+ $ commandName ,
221
+ '--child ' ,
222
+ ],
223
+ ];
224
+ })();
225
+
226
+ yield 'no PHP executable ' => (static function () use (
227
+ $ scriptPath ,
228
+ $ commandName
229
+ ) {
230
+ [$ input , $ commandDefinition ] = self ::createInput (
231
+ [],
232
+ [],
233
+ );
234
+
235
+ return [
236
+ '' ,
237
+ $ scriptPath ,
238
+ $ commandName ,
239
+ $ commandDefinition ,
240
+ $ input ,
241
+ [
242
+ $ scriptPath ,
243
+ $ commandName ,
244
+ '--child ' ,
245
+ ],
246
+ ];
247
+ })();
123
248
}
124
249
125
250
public function test_it_cannot_create_a_factory_with_an_invalid_script_path (): void
@@ -136,4 +261,16 @@ public function test_it_cannot_create_a_factory_with_an_invalid_script_path(): v
136
261
new InputDefinition (),
137
262
);
138
263
}
264
+
265
+ private static function createInput (
266
+ array $ input ,
267
+ array $ definition
268
+ ): array {
269
+ $ input = new ArrayInput ($ input );
270
+ $ inputDefinition = new InputDefinition ($ definition );
271
+
272
+ $ input ->bind ($ inputDefinition );
273
+
274
+ return [$ input , $ inputDefinition ];
275
+ }
139
276
}
0 commit comments