@@ -480,6 +480,62 @@ public function testAddCustomControlMapping() : void
480
480
static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
481
481
}
482
482
483
+ public function testAddCustomControlMappingsThrowsExceptionWhenOverwritingExistingDefaultControls () : void
484
+ {
485
+ $ this ->expectException (\InvalidArgumentException::class);
486
+ $ this ->expectExceptionMessage ('Cannot rebind this input ' );
487
+
488
+ $ menu = new CliMenu ('PHP School FTW ' , []);
489
+ $ menu ->addCustomControlMappings ([
490
+ ' ' => function () {
491
+ }
492
+ ]);
493
+ }
494
+
495
+ public function testAddCustomControlMappingsThrowsExceptionWhenAttemptingToOverwriteAddedCustomControlMap () : void
496
+ {
497
+ $ this ->expectException (\InvalidArgumentException::class);
498
+ $ this ->expectExceptionMessage ('Cannot rebind this input ' );
499
+
500
+ $ menu = new CliMenu ('PHP School FTW ' , []);
501
+ $ menu ->addCustomControlMappings ([
502
+ 'c ' => function () {
503
+ }
504
+ ]);
505
+ $ menu ->addCustomControlMappings ([
506
+ 'c ' => function () {
507
+ }
508
+ ]);
509
+ }
510
+
511
+ public function testAddCustomControlMappings () : void
512
+ {
513
+ $ first = true ;
514
+ $ this ->terminal ->expects ($ this ->any ())
515
+ ->method ('read ' )
516
+ ->willReturn ('c ' , 'x ' );
517
+
518
+ $ style = $ this ->getStyle ($ this ->terminal );
519
+
520
+ $ action = function (CliMenu $ menu ) {
521
+ $ menu ->close ();
522
+ };
523
+ $ item = new SelectableItem ('Item 1 ' , $ action );
524
+
525
+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
526
+ $ menu ->addCustomControlMappings ([
527
+ 'c ' => $ action ,
528
+ 'x ' => $ action
529
+ ]);
530
+
531
+ $ menu ->open ();
532
+ static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
533
+
534
+ $ first = false ;
535
+ $ menu ->open ();
536
+ static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
537
+ }
538
+
483
539
public function testRemoveCustomControlMappingThrowsExceptionIfNoSuchMappingExists () : void
484
540
{
485
541
$ this ->expectException (\InvalidArgumentException::class);
0 commit comments