Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ public function open() : void
if ($this->isOpen()) {
return;
}

if (count($this->items) === 0) {
throw new \RuntimeException('Menu must have at least 1 item before it can be opened');
}

$this->configureTerminal();
$this->open = true;
Expand Down
10 changes: 9 additions & 1 deletion test/CliMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,19 @@ public function testThrowsExceptionIfTerminalIsNotValidTTY() : void
->method('isInteractive')
->willReturn(false);

$menu = new CliMenu('PHP School FTW', [], $terminal);
$menu = new CliMenu('PHP School FTW', [new StaticItem('One')], $terminal);

$menu->open();
}

public function testOpenThrowsExceptionIfNoItemsInMenu() : void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Menu must have at least 1 item before it can be opened');

(new CliMenu('PHP School FTW', [], $this->terminal))->open();
}

public function testGetTerminal() : void
{
$menu = new CliMenu('PHP School FTW', []);
Expand Down