Skip to content

Commit 1eee3d6

Browse files
committed
Don't throw an Exception if the art doesn't fit, but skip it
1 parent bfdb70e commit 1eee3d6

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/CliMenuBuilder.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,9 @@ public function addAsciiArt($art, $position = AsciiArtItem::POSITION_CENTER)
182182

183183
$asciiArtItem = new AsciiArtItem($art, $position);
184184

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);
185+
if ($asciiArtItem->getArtLength() <= $this->getMenuStyle()->getContentWidth()) {
186+
$this->addMenuItem($asciiArtItem);
187+
}
192188

193189
return $this;
194190
}

test/CliMenuBuilderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,16 @@ public function testAsciiArtWithSpecificPosition()
247247
$this->checkItems($menu, $expected);
248248
}
249249

250-
/**
251-
* @expectedException Assert\InvalidArgumentException
252-
* @expectedExceptionMessage The provided Ascii art does not fit in the menu
253-
*/
254-
public function testAddAsciiArtDetectsArtThatDoesNotFit()
250+
public function testAddAsciiArtDetectsArtThatDoesNotFitAndSkipsIt()
255251
{
256252
$builder = new CliMenuBuilder;
257253
$builder->setWidth(1);
258254
$builder->addAsciiArt("//\n//", AsciiArtItem::POSITION_LEFT);
259255
$menu = $builder->build();
256+
257+
foreach ($menu->getItems() as $menuItem) {
258+
$this->assertNotInstanceOf(AsciiArtItem::class, $menuItem);
259+
}
260260
}
261261

262262
public function testEndThrowsExceptionIfNoParentBuilder()

0 commit comments

Comments
 (0)