@@ -205,7 +205,7 @@ public function testSimpleOpenCloseWithDifferentXAndYPadding() : void
205
205
206
206
self ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
207
207
}
208
-
208
+
209
209
public function testReDrawReDrawsImmediately () : void
210
210
{
211
211
$ this ->terminal ->expects ($ this ->once ())
@@ -242,11 +242,11 @@ public function testRedrawClearsTerminalFirstIfOptionIsPassed() : void
242
242
->will ($ this ->returnCallback (function ($ buffer ) {
243
243
$ this ->output ->write ($ buffer );
244
244
}));
245
-
245
+
246
246
$ terminal ->expects ($ this ->exactly (3 ))
247
247
->method ('read ' )
248
248
->willReturn ("\n" , "\n" , "\n" );
249
-
249
+
250
250
$ terminal ->expects ($ this ->atLeast (2 ))
251
251
->method ('clear ' );
252
252
@@ -264,11 +264,11 @@ public function testRedrawClearsTerminalFirstIfOptionIsPassed() : void
264
264
$ menu ->getStyle ()->setWidth (70 );
265
265
$ menu ->redraw (true );
266
266
}
267
-
267
+
268
268
if ($ hits === 2 ) {
269
269
$ menu ->close ();
270
270
}
271
-
271
+
272
272
$ hits ++;
273
273
});
274
274
@@ -371,7 +371,7 @@ public function testOpenThrowsExceptionIfNoItemsInMenu() : void
371
371
{
372
372
$ this ->expectException (\RuntimeException::class);
373
373
$ this ->expectExceptionMessage ('Menu must have at least 1 item before it can be opened ' );
374
-
374
+
375
375
(new CliMenu ('PHP School FTW ' , [], $ this ->terminal ))->open ();
376
376
}
377
377
@@ -440,7 +440,7 @@ public function testSetItems() : void
440
440
$ menu ->addItems ([$ item1 , $ item2 ]);
441
441
442
442
$ this ->assertCount (2 , $ menu ->getItems ());
443
-
443
+
444
444
$ menu ->setItems ([$ item3 , $ item4 ]);
445
445
446
446
$ this ->assertCount (2 , $ menu ->getItems ());
@@ -603,6 +603,27 @@ public function testAddCustomControlMapping() : void
603
603
self ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
604
604
}
605
605
606
+
607
+ public function testAddCustomControlMappingWithControlChar () : void
608
+ {
609
+ $ this ->terminal ->expects ($ this ->once ())
610
+ ->method ('read ' )
611
+ ->willReturn ("\e" );
612
+
613
+ $ style = $ this ->getStyle ($ this ->terminal );
614
+
615
+ $ action = function (CliMenu $ menu ) {
616
+ $ menu ->close ();
617
+ };
618
+ $ item = new SelectableItem ('Item 1 ' , $ action );
619
+
620
+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
621
+ $ menu ->addCustomControlMapping ('ESC ' , $ action );
622
+ $ menu ->open ();
623
+
624
+ self ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
625
+ }
626
+
606
627
public function testAddCustomControlMappingsThrowsExceptionWhenOverwritingExistingDefaultControls () : void
607
628
{
608
629
$ this ->expectException (\InvalidArgumentException::class);
@@ -675,7 +696,7 @@ public function testRemoveCustomControlMapping() : void
675
696
$ menu = new CliMenu ('PHP School FTW ' , [], $ this ->terminal );
676
697
$ menu ->addCustomControlMapping ('c ' , $ action );
677
698
self ::assertSame (['c ' => $ action ], $ menu ->getCustomControlMappings ());
678
-
699
+
679
700
$ menu ->removeCustomControlMapping ('c ' );
680
701
self ::assertSame ([], $ menu ->getCustomControlMappings ());
681
702
}
@@ -685,16 +706,16 @@ public function testSplitItemWithNoSelectableItemsScrollingVertically() : void
685
706
$ this ->terminal ->expects ($ this ->exactly (3 ))
686
707
->method ('read ' )
687
708
->willReturn ("\033[B " , "\033[B " , "\n" );
688
-
709
+
689
710
$ action = function (CliMenu $ menu ) {
690
711
$ menu ->close ();
691
712
};
692
-
713
+
693
714
$ menu = new CliMenu ('PHP School FTW ' , [], $ this ->terminal );
694
715
$ menu ->addItem (new SelectableItem ('One ' , $ action ));
695
716
$ menu ->addItem (new SplitItem ([new StaticItem ('Two ' ), new StaticItem ('Three ' )]));
696
717
$ menu ->addItem (new SelectableItem ('Four ' , $ action ));
697
-
718
+
698
719
$ menu ->open ();
699
720
700
721
self ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
@@ -841,7 +862,7 @@ public function testSelectableCallableReceivesSelectableAndNotSplitItem() : void
841
862
)
842
863
);
843
864
$ menu ->open ();
844
-
865
+
845
866
self ::assertSame ($ expectedSelectedItem , $ actualSelectedItem );
846
867
}
847
868
0 commit comments