14
14
*/
15
15
class MenuStyleTest extends TestCase
16
16
{
17
- private function getMenuStyle (int $ colours = 8 ) : MenuStyle
17
+ private function getMenuStyle (int $ colours = 8 , int $ width = 500 ) : MenuStyle
18
18
{
19
- return new MenuStyle ($ this ->getMockTerminal ($ colours ));
19
+ return new MenuStyle ($ this ->getMockTerminal ($ colours, $ width ));
20
20
}
21
21
22
- private function getMockTerminal (int $ colours = 8 ) : MockObject
22
+ private function getMockTerminal (int $ colours, int $ width ) : MockObject
23
23
{
24
24
$ terminal = $ this
25
25
->getMockBuilder (UnixTerminal::class)
@@ -28,14 +28,12 @@ private function getMockTerminal(int $colours = 8) : MockObject
28
28
->getMock ();
29
29
30
30
$ terminal
31
- ->expects (self ::any ())
32
31
->method ('getWidth ' )
33
- ->will ( self :: returnValue ( 500 ) );
32
+ ->willReturn ( $ width );
34
33
35
34
$ terminal
36
- ->expects (self ::any ())
37
35
->method ('getColourSupport ' )
38
- ->will ( self :: returnValue ( $ colours) );
36
+ ->willReturn ( $ colours );
39
37
40
38
return $ terminal ;
41
39
}
@@ -308,6 +306,20 @@ public function testMargin() : void
308
306
self ::assertSame (5 , $ style ->getMargin ());
309
307
}
310
308
309
+ public function testSetMarginWhenWidthIsLargerThanTerminal () : void
310
+ {
311
+ $ style = $ this ->getMenuStyle ();
312
+ $ style ->setWidth (600 );
313
+ $ style ->setMargin (20 );
314
+
315
+ self ::assertSame (20 , $ style ->getMargin ());
316
+ self ::assertSame (480 , $ style ->getWidth ());
317
+
318
+ $ style ->setMargin (35 );
319
+ self ::assertSame (35 , $ style ->getMargin ());
320
+ self ::assertSame (465 , $ style ->getWidth ());
321
+ }
322
+
311
323
public function testMarginAutoCenters () : void
312
324
{
313
325
$ style = $ this ->getMenuStyle ();
@@ -320,7 +332,17 @@ public function testMarginAutoCenters() : void
320
332
self ::assertSame (290 , $ style ->getContentWidth ());
321
333
}
322
334
323
- public function testModifyWithWhenMarginAutoIsEnabledRecalculatesMargin () : void
335
+ public function testSetMarginAutoWhenWidthIsLargerThanTerminal () : void
336
+ {
337
+ $ style = $ this ->getMenuStyle ();
338
+ $ style ->setWidth (600 );
339
+ $ style ->setMarginAuto ();
340
+
341
+ self ::assertSame (0 , $ style ->getMargin ());
342
+ self ::assertSame (500 , $ style ->getWidth ());
343
+ }
344
+
345
+ public function testModifyWidthWhenMarginAutoIsEnabledRecalculatesMargin () : void
324
346
{
325
347
$ style = $ this ->getMenuStyle ();
326
348
@@ -658,4 +680,36 @@ public function testHasChangedFromDefaultsReturnsFalseWhenAutoShrunk() : void
658
680
659
681
self ::assertFalse ($ menuStyle ->hasChangedFromDefaults ());
660
682
}
683
+
684
+ public function testDebugMode () : void
685
+ {
686
+ $ style = $ this ->getMenuStyle (8 , 40 );
687
+
688
+ $ prop = new \ReflectionProperty (MenuStyle::class, 'debugMode ' );
689
+ $ prop ->setAccessible (true );
690
+ $ prop ->setValue ($ style , true );
691
+
692
+ $ style ->setWidth (30 );
693
+
694
+ self ::assertEquals (
695
+ ["01 \033[37;44m \033[0m01234567 \n" ],
696
+ $ style ->getPaddingTopBottomRows ()
697
+ );
698
+
699
+ $ style ->setMarginAuto ();
700
+
701
+ self ::assertEquals (
702
+ ["01234 \033[37;44m \033[0m01234 \n" ],
703
+ $ style ->getPaddingTopBottomRows ()
704
+ );
705
+
706
+ $ style ->setBorderColour ('red ' );
707
+ $ style ->setBorderTopWidth (1 );
708
+ $ style ->setBorderBottomWidth (1 );
709
+
710
+ self ::assertEquals (
711
+ ["01234 \033[41m \033[0m01234 \n" ],
712
+ $ style ->getBorderTopRows ()
713
+ );
714
+ }
661
715
}
0 commit comments