File tree Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,15 @@ 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
+ Assertion::lessOrEqualThan (
186
+ $ asciiArtItem ->getArtLength (),
187
+ $ this ->getMenuStyle ()->getContentWidth (),
188
+ 'The provided Ascii art does not fit in the menu '
189
+ );
190
+
191
+ $ this ->addMenuItem ($ asciiArtItem );
184
192
185
193
return $ this ;
186
194
}
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
+ /**
251
+ * @expectedException Assert\InvalidArgumentException
252
+ * @expectedExceptionMessage The provided Ascii art does not fit in the menu
253
+ */
254
+ public function testAddAsciiArtDetectsArtThatDoesNotFit ()
255
+ {
256
+ $ builder = new CliMenuBuilder ;
257
+ $ builder ->setWidth (1 );
258
+ $ builder ->addAsciiArt ("// \n// " , AsciiArtItem::POSITION_LEFT );
259
+ $ menu = $ builder ->build ();
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