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
2 changes: 1 addition & 1 deletion src/MenuStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private function generatePaddingTopBottomRows() : void
"%s%s%s%s%s%s%s%s%s%s\n",
str_repeat(' ', $this->margin),
$borderColour,
str_repeat(' ', $this->borderRightWidth),
str_repeat(' ', $this->borderLeftWidth),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

$this->getColoursSetCode(),
str_repeat(' ', $this->paddingLeftRight),
str_repeat(' ', $this->contentWidth),
Expand Down
44 changes: 43 additions & 1 deletion test/CliMenuBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testModifyStyles() : void
$this->checkStyleVariable($menu, 'titleSeparator', '-');
}

public function testSetBorderShorthandFunction()
public function testSetBorderShorthandFunction() : void
{
$terminal = static::createMock(Terminal::class);
$terminal
Expand Down Expand Up @@ -679,6 +679,48 @@ public function testSetMarginManuallyOverwritesSetMarginAuto() : void

self::assertSame(10, $menu->getStyle()->getMargin());
}

public function testSetPaddingWithUniversalValue() : void
{
$builder = new CliMenuBuilder;
$builder->setPadding(3);

$style = $builder->build()->getStyle();

self::assertEquals(3, $style->getPaddingTopBottom());
self::assertEquals(3, $style->getPaddingLeftRight());
}

public function testSetPaddingWithXAndYValues() : void
{
$builder = new CliMenuBuilder;
$builder->setPadding(2, 3);

$style = $builder->build()->getStyle();

self::assertEquals(2, $style->getPaddingTopBottom());
self::assertEquals(3, $style->getPaddingLeftRight());
}

public function testSetPaddingTopAndBottom() : void
{
$builder = new CliMenuBuilder;
$builder->setPaddingTopBottom(2);

$style = $builder->build()->getStyle();

self::assertEquals(2, $style->getPaddingTopBottom());
}

public function testSetPaddingLeftAndRight() : void
{
$builder = new CliMenuBuilder;
$builder->setPaddingLeftRight(3);

$style = $builder->build()->getStyle();

self::assertEquals(3, $style->getPaddingLeftRight());
}

private function checkItems(CliMenu $menu, array $expected) : void
{
Expand Down
58 changes: 58 additions & 0 deletions test/CliMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,64 @@ public function testSimpleOpenCloseWithMarginAutoAndBorders() : void
self::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
}

public function testSimpleOpenCloseWithPaddingTopAndBottom() : void
{
$this->terminal->expects($this->once())
->method('read')
->willReturn("\n");

$style = $this->getStyle($this->terminal);
$style->setPaddingTopBottom(2);

$item = new SelectableItem('Item 1', function (CliMenu $menu) {
$menu->close();
});

$menu = new CliMenu('PHP School FTW', [$item], $this->terminal, $style);
$menu->open();

self::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
}

public function testSimpleOpenCloseWithPaddingLeftAndRight() : void
{
$this->terminal->expects($this->once())
->method('read')
->willReturn("\n");

$style = $this->getStyle($this->terminal);
$style->setPaddingLeftRight(5);

$item = new SelectableItem('Item 1', function (CliMenu $menu) {
$menu->close();
});

$menu = new CliMenu('PHP School FTW', [$item], $this->terminal, $style);
$menu->open();

self::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
}

public function testSimpleOpenCloseWithDifferentXAndYPadding() : void
{
$this->terminal->expects($this->once())
->method('read')
->willReturn("\n");

$style = $this->getStyle($this->terminal);
$style->setPaddingLeftRight(5);
$style->setPaddingTopBottom(4);

$item = new SelectableItem('Item 1', function (CliMenu $menu) {
$menu->close();
});

$menu = new CliMenu('PHP School FTW', [$item], $this->terminal, $style);
$menu->open();

self::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
}

public function testReDrawReDrawsImmediately() : void
{
$this->terminal->expects($this->once())
Expand Down
Loading