File tree 4 files changed +33
-1
lines changed
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)
180
180
Assertion::string ($ art );
181
181
Assertion::string ($ position );
182
182
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
+ }
184
188
185
189
return $ this ;
186
190
}
Original file line number Diff line number Diff line change @@ -116,6 +116,16 @@ public function getText()
116
116
return $ this ->text ;
117
117
}
118
118
119
+ /**
120
+ * Return the length of the art
121
+ *
122
+ * @return int
123
+ */
124
+ public function getArtLength ()
125
+ {
126
+ return $ this ->artLength ;
127
+ }
128
+
119
129
/**
120
130
* Whether or not the menu item is showing the menustyle extra value
121
131
*
Original file line number Diff line number Diff line change @@ -247,6 +247,18 @@ public function testAsciiArtWithSpecificPosition()
247
247
$ this ->checkItems ($ menu , $ expected );
248
248
}
249
249
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
+
250
262
public function testEndThrowsExceptionIfNoParentBuilder ()
251
263
{
252
264
$ builder = new CliMenuBuilder ;
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ public function testGetText()
50
50
$ this ->assertEquals ('//// \\\\' , $ item ->getText ());
51
51
}
52
52
53
+ public function testGetArtLength ()
54
+ {
55
+ $ item = new AsciiArtItem ("// \n// \n/// " );
56
+ $ this ->assertEquals (3 , $ item ->getArtLength ());
57
+ }
58
+
53
59
public function testGetRowsLeftAligned ()
54
60
{
55
61
$ menuStyle = $ this ->createMock (MenuStyle::class);
You can’t perform that action at this time.
0 commit comments