File tree Expand file tree Collapse file tree 4 files changed +17
-12
lines changed Expand file tree Collapse file tree 4 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -555,9 +555,7 @@ use PhpSchool\CliMenu\Builder\CliMenuBuilder;
555555use PhpSchool\CliMenu\CliMenu;
556556
557557$callable = function (CliMenu $menu) {
558- $item = $menu->getSelectedItem();
559- $item->toggle();
560- $menu->redraw();
558+ echo $menu->getSelectedItem()->getText();
561559};
562560
563561$menu = (new CliMenuBuilder)
Original file line number Diff line number Diff line change 22
33use PhpSchool \CliMenu \CliMenu ;
44use PhpSchool \CliMenu \Builder \CliMenuBuilder ;
5- use PhpSchool \CliMenu \MenuItem \CheckableItem ;
65
76require_once (__DIR__ . '/../vendor/autoload.php ' );
87
98$ itemCallable = function (CliMenu $ menu ) {
10- /** @var CheckableItem $item */
11- $ item = $ menu ->getSelectedItem ();
12-
13- $ item ->toggle ();
14-
15- $ menu ->redraw ();
9+ echo $ menu ->getSelectedItem ()->getText ();
1610};
1711
1812$ menu = (new CliMenuBuilder )
Original file line number Diff line number Diff line change 22
33namespace PhpSchool \CliMenu \MenuItem ;
44
5+ use PhpSchool \CliMenu \CliMenu ;
56use PhpSchool \CliMenu \MenuStyle ;
67use PhpSchool \CliMenu \Util \StringUtil ;
78
@@ -49,7 +50,12 @@ public function __construct(
4950 */
5051 public function getSelectAction () : ?callable
5152 {
52- return $ this ->selectAction ;
53+ return function (CliMenu $ cliMenu ) {
54+ $ this ->toggle ();
55+ $ cliMenu ->redraw ();
56+
57+ return ($ this ->selectAction )($ cliMenu );
58+ };
5359 }
5460
5561 /**
Original file line number Diff line number Diff line change 22
33namespace PhpSchool \CliMenuTest \MenuItem ;
44
5+ use PhpSchool \CliMenu \CliMenu ;
56use PhpSchool \CliMenu \MenuItem \CheckableItem ;
67use PhpSchool \CliMenu \MenuStyle ;
78use PhpSchool \Terminal \Terminal ;
@@ -19,9 +20,15 @@ public function testCanSelectIsTrue() : void
1920 public function testGetSelectAction () : void
2021 {
2122 $ callable = function () {
23+ return 'callable is called ' ;
2224 };
2325 $ item = new CheckableItem ('Item ' , $ callable );
24- $ this ->assertSame ($ callable , $ item ->getSelectAction ());
26+
27+ $ cliMenu = $ this ->getMockBuilder (CLiMenu::class)
28+ ->disableOriginalConstructor ()
29+ ->getMock ();
30+
31+ $ this ->assertSame ($ callable (), $ item ->getSelectAction ()($ cliMenu ));
2532 }
2633
2734 public function testShowsItemExtra () : void
You can’t perform that action at this time.
0 commit comments