File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ public function addAsciiArt($art, $position = AsciiArtItem::POSITION_CENTER)
180180 Assertion::string ($ art );
181181 Assertion::string ($ position );
182182
183- $ this ->addMenuItem (new AsciiArtItem ($ art , $ position ));
183+ $ asciiArtItem = new AsciiArtItem ($ art , $ position );
184+
185+ if ($ asciiArtItem ->getArtLength () <= $ this ->getMenuStyle ()->getContentWidth ()) {
186+ $ this ->addMenuItem ($ asciiArtItem );
187+ }
184188
185189 return $ this ;
186190 }
Original file line number Diff line number Diff line change @@ -116,6 +116,16 @@ public function getText()
116116 return $ this ->text ;
117117 }
118118
119+ /**
120+ * Return the length of the art
121+ *
122+ * @return int
123+ */
124+ public function getArtLength ()
125+ {
126+ return $ this ->artLength ;
127+ }
128+
119129 /**
120130 * Whether or not the menu item is showing the menustyle extra value
121131 *
Original file line number Diff line number Diff line change @@ -247,6 +247,18 @@ public function testAsciiArtWithSpecificPosition()
247247 $ this ->checkItems ($ menu , $ expected );
248248 }
249249
250+ public function testAddAsciiArtDetectsArtThatDoesNotFitAndSkipsIt ()
251+ {
252+ $ builder = new CliMenuBuilder ;
253+ $ builder ->setWidth (1 );
254+ $ builder ->addAsciiArt ("// \n// " , AsciiArtItem::POSITION_LEFT );
255+ $ menu = $ builder ->build ();
256+
257+ foreach ($ menu ->getItems () as $ menuItem ) {
258+ $ this ->assertNotInstanceOf (AsciiArtItem::class, $ menuItem );
259+ }
260+ }
261+
250262 public function testEndThrowsExceptionIfNoParentBuilder ()
251263 {
252264 $ builder = new CliMenuBuilder ;
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ public function testGetText()
5050 $ this ->assertEquals ('//// \\\\' , $ item ->getText ());
5151 }
5252
53+ public function testGetArtLength ()
54+ {
55+ $ item = new AsciiArtItem ("// \n// \n/// " );
56+ $ this ->assertEquals (3 , $ item ->getArtLength ());
57+ }
58+
5359 public function testGetRowsLeftAligned ()
5460 {
5561 $ menuStyle = $ this ->createMock (MenuStyle::class);
You can’t perform that action at this time.
0 commit comments