@@ -261,13 +261,15 @@ public function testNonBinaryInputOptions(array $parameters, array $expected)
261
261
{
262
262
$ command =new Command ('foo ' );
263
263
$ command ->setCode (function (
264
- #[Option] ?string $ a =null ,
265
- #[Option] ?string $ b ='b ' ,
266
- #[Option] ?array $ c = [],
264
+ #[Option]string $ a ='' ,
265
+ #[Option] ?string $ b ='' ,
266
+ #[Option]array $ c = [],
267
+ #[Option]array $ d = ['a ' ,'b ' ],
267
268
)use ($ expected ):int {
268
269
$ this ->assertSame ($ expected [0 ],$ a );
269
270
$ this ->assertSame ($ expected [1 ],$ b );
270
271
$ this ->assertSame ($ expected [2 ],$ c );
272
+ $ this ->assertSame ($ expected [3 ],$ d );
271
273
272
274
return 0 ;
273
275
});
@@ -277,22 +279,45 @@ public function testNonBinaryInputOptions(array $parameters, array $expected)
277
279
278
280
public static function provideNonBinaryInputOptions ():\Generator
279
281
{
280
- yield 'defaults ' => [[], [null ,'b ' , []]];
281
- yield 'with-value ' => [['--a ' =>'x ' ,'--b ' =>'y ' ,'--c ' => ['z ' ]] , ['x ' ,'y ' , ['z ' ]]];
282
- yield 'without-value ' => [['--a ' =>null , ' --b ' => null ,' --c ' => null ], [null , null , null ]];
282
+ yield 'defaults ' => [[], ['' ,'' , [], [ ' a ' , ' b ' ]]];
283
+ yield 'with-value ' => [['--a ' =>'x ' ,'--b ' =>'y ' ,'--c ' => ['z ' ], ' --d ' => [ ' c ' , ' d ' ]] , ['x ' ,'y ' , ['z ' ], [ ' c ' , ' d ' ]]];
284
+ yield 'without-value ' => [['--b ' =>null ], [ '' , null ,[ ], [' a ' , ' b ' ] ]];
283
285
}
284
286
285
- public function testInvalidOptionDefinition ()
287
+ /**
288
+ * @dataProvider provideInvalidOptionDefinitions
289
+ */
290
+ public function testInvalidOptionDefinition (callable $ code ,string $ expectedMessage )
286
291
{
287
292
$ command =new Command ('foo ' );
288
- $ command ->setCode (function (#[Option] string $ a ) {} );
293
+ $ command ->setCode ($ code );
289
294
290
295
$ this ->expectException (LogicException::class);
291
- $ this ->expectExceptionMessage (' The option parameter "$a" must declare a default value. ' );
296
+ $ this ->expectExceptionMessage ($ expectedMessage );
292
297
293
298
$ command ->getDefinition ();
294
299
}
295
300
301
+ public static function provideInvalidOptionDefinitions ():\Generator
302
+ {
303
+ yield 'no-default ' => [
304
+ function (#[Option]string $ a ) {},
305
+ 'The option parameter "$a" must declare a default value. ' ,
306
+ ];
307
+ yield 'nullable-bool-default-true ' => [
308
+ function (#[Option] ?bool $ a =true ) {},
309
+ 'The option parameter "$a" must not be nullable when it has a default boolean value. ' ,
310
+ ];
311
+ yield 'nullable-bool-default-false ' => [
312
+ function (#[Option] ?bool $ a =false ) {},
313
+ 'The option parameter "$a" must not be nullable when it has a default boolean value. ' ,
314
+ ];
315
+ yield 'nullable-string ' => [
316
+ function (#[Option] ?string $ a =null ) {},
317
+ 'The option parameter "$a" must not have a default of null. ' ,
318
+ ];
319
+ }
320
+
296
321
public function testInvalidRequiredValueOptionEvenWithDefault ()
297
322
{
298
323
$ command =new Command ('foo ' );