@@ -30,7 +30,7 @@ public function testDefaultItems() : void
30
30
],
31
31
];
32
32
33
- $ this ->checkItems ($ menu , $ expected );
33
+ $ this ->checkMenuItems ($ menu , $ expected );
34
34
}
35
35
36
36
public function testModifyExitButtonText () : void
@@ -46,7 +46,7 @@ public function testModifyExitButtonText() : void
46
46
],
47
47
];
48
48
49
- $ this ->checkItems ($ menu , $ expected );
49
+ $ this ->checkMenuItems ($ menu , $ expected );
50
50
}
51
51
52
52
public function testModifyStyles () : void
@@ -324,7 +324,7 @@ public function testAddItem() : void
324
324
],
325
325
];
326
326
327
- $ this ->checkItems ($ menu , $ expected );
327
+ $ this ->checkMenuItems ($ menu , $ expected );
328
328
}
329
329
330
330
public function testAddMultipleItems () : void
@@ -351,7 +351,7 @@ public function testAddMultipleItems() : void
351
351
],
352
352
];
353
353
354
- $ this ->checkItems ($ menu , $ expected );
354
+ $ this ->checkMenuItems ($ menu , $ expected );
355
355
}
356
356
357
357
public function testAddStaticItem () : void
@@ -369,7 +369,7 @@ public function testAddStaticItem() : void
369
369
]
370
370
];
371
371
372
- $ this ->checkItems ($ menu , $ expected );
372
+ $ this ->checkMenuItems ($ menu , $ expected );
373
373
}
374
374
375
375
public function testAddLineBreakItem () : void
@@ -387,7 +387,7 @@ public function testAddLineBreakItem() : void
387
387
]
388
388
];
389
389
390
- $ this ->checkItems ($ menu , $ expected );
390
+ $ this ->checkMenuItems ($ menu , $ expected );
391
391
}
392
392
393
393
public function testAddLineBreakItemWithNumLines () : void
@@ -405,7 +405,7 @@ public function testAddLineBreakItemWithNumLines() : void
405
405
]
406
406
];
407
407
408
- $ this ->checkItems ($ menu , $ expected );
408
+ $ this ->checkMenuItems ($ menu , $ expected );
409
409
}
410
410
411
411
public function testAsciiArtWithDefaultPosition () : void
@@ -423,7 +423,7 @@ public function testAsciiArtWithDefaultPosition() : void
423
423
]
424
424
];
425
425
426
- $ this ->checkItems ($ menu , $ expected );
426
+ $ this ->checkMenuItems ($ menu , $ expected );
427
427
}
428
428
429
429
public function testAsciiArtWithSpecificPosition () : void
@@ -441,7 +441,7 @@ public function testAsciiArtWithSpecificPosition() : void
441
441
]
442
442
];
443
443
444
- $ this ->checkItems ($ menu , $ expected );
444
+ $ this ->checkMenuItems ($ menu , $ expected );
445
445
}
446
446
447
447
public function testAsciiArtWithAlt () : void
@@ -460,7 +460,7 @@ public function testAsciiArtWithAlt() : void
460
460
]
461
461
];
462
462
463
- $ this ->checkItems ($ menu , $ expected );
463
+ $ this ->checkMenuItems ($ menu , $ expected );
464
464
}
465
465
466
466
public function testAddSubMenu () : void
@@ -472,7 +472,7 @@ public function testAddSubMenu() : void
472
472
473
473
$ menu = $ builder ->build ();
474
474
475
- $ this ->checkItems ($ menu , [
475
+ $ this ->checkMenuItems ($ menu , [
476
476
[
477
477
'class ' => MenuMenuItem::class
478
478
]
@@ -489,7 +489,7 @@ public function testAddSubMenuWithBuilder() : void
489
489
490
490
$ menu = $ builder ->build ();
491
491
492
- $ this ->checkItems ($ menu , [
492
+ $ this ->checkMenuItems ($ menu , [
493
493
[
494
494
'class ' => MenuMenuItem::class
495
495
]
@@ -563,7 +563,7 @@ public function testSubMenuDefaultItems() : void
563
563
],
564
564
];
565
565
566
- $ this ->checkItems ($ menu ->getItems ()[0 ]->getSubMenu (), $ expected );
566
+ $ this ->checkMenuItems ($ menu ->getItems ()[0 ]->getSubMenu (), $ expected );
567
567
}
568
568
569
569
public function testModifyExitAndGoBackTextOnSubMenu () : void
@@ -588,7 +588,7 @@ public function testModifyExitAndGoBackTextOnSubMenu() : void
588
588
],
589
589
];
590
590
591
- $ this ->checkItems ($ menu ->getItems ()[0 ]->getSubMenu (), $ expected );
591
+ $ this ->checkMenuItems ($ menu ->getItems ()[0 ]->getSubMenu (), $ expected );
592
592
}
593
593
594
594
public function testDisableDefaultItemsDisablesExitAndGoBackOnSubMenu () : void
@@ -736,23 +736,71 @@ public function testSetPaddingLeftAndRight() : void
736
736
737
737
self ::assertEquals (3 , $ style ->getPaddingLeftRight ());
738
738
}
739
+
740
+ public function testAddSubMenuWithClosureBinding () : void
741
+ {
742
+ $ builder = new CliMenuBuilder ;
743
+ $ builder ->disableDefaultItems ();
744
+ $ builder ->addSubMenu ('My SubMenu ' , function () {
745
+ $ this ->disableDefaultItems ();
746
+ $ this ->addItem ('My Item ' , function () {
747
+ });
748
+ });
749
+
750
+ $ menu = $ builder ->build ();
751
+
752
+ $ expected = [
753
+ [
754
+ 'class ' => SelectableItem::class,
755
+ 'text ' => 'My Item ' ,
756
+ ]
757
+ ];
758
+
759
+ $ this ->checkMenuItems ($ menu ->getItems ()[0 ]->getSubMenu (), $ expected );
760
+ }
761
+
762
+ public function testAddSplitItemWithClosureBinding () : void
763
+ {
764
+ $ builder = new CliMenuBuilder ;
765
+ $ builder ->disableDefaultItems ();
766
+ $ builder ->addSplitItem (function () {
767
+ $ this ->addItem ('My Item ' , function () {
768
+ });
769
+ });
770
+
771
+ $ menu = $ builder ->build ();
772
+
773
+ $ expected = [
774
+ [
775
+ 'class ' => SelectableItem::class,
776
+ 'text ' => 'My Item ' ,
777
+ ]
778
+ ];
779
+
780
+ $ this ->checkItems ($ menu ->getItems ()[0 ]->getItems (), $ expected );
781
+ }
739
782
740
- private function checkItems (CliMenu $ menu , array $ expected ) : void
783
+ private function checkMenuItems (CliMenu $ menu , array $ expected ) : void
784
+ {
785
+ $ this ->checkItems ($ this ->readAttribute ($ menu , 'items ' ), $ expected );
786
+ }
787
+
788
+ private function checkItems (array $ actualItems , array $ expected ) : void
741
789
{
742
- $ actualItems = $ this ->readAttribute ($ menu , 'items ' );
743
790
self ::assertCount (count ($ expected ), $ actualItems );
744
-
791
+
745
792
foreach ($ expected as $ expectedItem ) {
746
793
$ actualItem = array_shift ($ actualItems );
747
-
794
+
748
795
self ::assertInstanceOf ($ expectedItem ['class ' ], $ actualItem );
749
796
unset($ expectedItem ['class ' ]);
750
-
797
+
751
798
foreach ($ expectedItem as $ property => $ value ) {
752
799
self ::assertEquals ($ this ->readAttribute ($ actualItem , $ property ), $ value );
753
800
}
754
801
}
755
802
}
803
+
756
804
757
805
private function checkVariable (CliMenu $ menu , string $ property , $ expected ) : void
758
806
{
0 commit comments