1414 */
1515class MenuStyleTest extends TestCase
1616{
17- private function getMenuStyle (int $ colours = 8 ) : MenuStyle
17+ private function getMenuStyle (int $ colours = 8 , int $ width = 500 ) : MenuStyle
1818 {
19- return new MenuStyle ($ this ->getMockTerminal ($ colours ));
19+ return new MenuStyle ($ this ->getMockTerminal ($ colours, $ width ));
2020 }
2121
22- private function getMockTerminal (int $ colours = 8 ) : MockObject
22+ private function getMockTerminal (int $ colours, int $ width ) : MockObject
2323 {
2424 $ terminal = $ this
2525 ->getMockBuilder (UnixTerminal::class)
@@ -28,14 +28,12 @@ private function getMockTerminal(int $colours = 8) : MockObject
2828 ->getMock ();
2929
3030 $ terminal
31- ->expects (self ::any ())
3231 ->method ('getWidth ' )
33- ->will ( self :: returnValue ( 500 ) );
32+ ->willReturn ( $ width );
3433
3534 $ terminal
36- ->expects (self ::any ())
3735 ->method ('getColourSupport ' )
38- ->will ( self :: returnValue ( $ colours) );
36+ ->willReturn ( $ colours );
3937
4038 return $ terminal ;
4139 }
@@ -308,6 +306,20 @@ public function testMargin() : void
308306 self ::assertSame (5 , $ style ->getMargin ());
309307 }
310308
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+
311323 public function testMarginAutoCenters () : void
312324 {
313325 $ style = $ this ->getMenuStyle ();
@@ -320,7 +332,17 @@ public function testMarginAutoCenters() : void
320332 self ::assertSame (290 , $ style ->getContentWidth ());
321333 }
322334
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
324346 {
325347 $ style = $ this ->getMenuStyle ();
326348
@@ -658,4 +680,36 @@ public function testHasChangedFromDefaultsReturnsFalseWhenAutoShrunk() : void
658680
659681 self ::assertFalse ($ menuStyle ->hasChangedFromDefaults ());
660682 }
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+ }
661715}
0 commit comments