@@ -437,6 +437,93 @@ public function testThrowsExceptionWhenDisablingRootMenu() : void
437
437
438
438
(new CliMenuBuilder )->disableMenu ();
439
439
}
440
+
441
+ /**
442
+ * @dataProvider marginBelowZeroProvider
443
+ */
444
+ public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove (int $ value ) : void
445
+ {
446
+ self ::expectException (\Assert \InvalidArgumentException::class);
447
+
448
+
449
+ (new CliMenuBuilder )->setMargin ($ value );
450
+ }
451
+
452
+ public function marginBelowZeroProvider () : array
453
+ {
454
+ return [[-1 ], [-2 ], [-10 ]];
455
+ }
456
+
457
+ /**
458
+ * @dataProvider marginAboveZeroProvider
459
+ */
460
+ public function testSetMarginAcceptsZeroAndPositiveIntegers (int $ value ) : void
461
+ {
462
+ $ menu = (new CliMenuBuilder )->setMargin ($ value )->build ();
463
+
464
+ self ::assertSame ($ value , $ menu ->getStyle ()->getMargin ());
465
+ }
466
+
467
+ public function marginAboveZeroProvider () : array
468
+ {
469
+ return [[0 ], [1 ], [10 ], [50 ]];
470
+ }
471
+
472
+ public function testSetMarginAutoAutomaticallyCalculatesMarginToCenter () : void
473
+ {
474
+ $ terminal = self ::createMock (Terminal::class);
475
+ $ terminal
476
+ ->expects ($ this ->any ())
477
+ ->method ('getWidth ' )
478
+ ->will ($ this ->returnValue (200 ));
479
+
480
+ $ builder = new CliMenuBuilder ;
481
+ $ menu = $ builder
482
+ ->setTerminal ($ terminal )
483
+ ->setMarginAuto ()
484
+ ->setWidth (100 )
485
+ ->build ();
486
+
487
+ self ::assertSame (50 , $ menu ->getStyle ()->getMargin ());
488
+ }
489
+
490
+ public function testSetMarginAutoOverwritesSetMargin () : void
491
+ {
492
+ $ terminal = self ::createMock (Terminal::class);
493
+ $ terminal
494
+ ->expects ($ this ->any ())
495
+ ->method ('getWidth ' )
496
+ ->will ($ this ->returnValue (200 ));
497
+
498
+ $ builder = new CliMenuBuilder ;
499
+ $ menu = $ builder
500
+ ->setTerminal ($ terminal )
501
+ ->setMargin (10 )
502
+ ->setMarginAuto ()
503
+ ->setWidth (100 )
504
+ ->build ();
505
+
506
+ self ::assertSame (50 , $ menu ->getStyle ()->getMargin ());
507
+ }
508
+
509
+ public function testSetMarginManuallyOverwritesSetMarginAuto () : void
510
+ {
511
+ $ terminal = self ::createMock (Terminal::class);
512
+ $ terminal
513
+ ->expects ($ this ->any ())
514
+ ->method ('getWidth ' )
515
+ ->will ($ this ->returnValue (200 ));
516
+
517
+ $ builder = new CliMenuBuilder ;
518
+ $ menu = $ builder
519
+ ->setTerminal ($ terminal )
520
+ ->setMarginAuto ()
521
+ ->setMargin (10 )
522
+ ->setWidth (100 )
523
+ ->build ();
524
+
525
+ self ::assertSame (10 , $ menu ->getStyle ()->getMargin ());
526
+ }
440
527
441
528
private function checkItems (CliMenu $ menu , array $ expected ) : void
442
529
{
0 commit comments