Skip to content

Remove the mandatory space after markers #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 17, 2018
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/MenuItem/SelectableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait SelectableTrait
*/
public function getRows(MenuStyle $style, bool $selected = false) : array
{
$marker = sprintf("%s ", $style->getMarker($selected));
$marker = sprintf("%s", $style->getMarker($selected));

$length = $style->getDisplaysExtra()
? $style->getContentWidth() - (mb_strlen($style->getItemExtra()) + 2)
Expand Down
2 changes: 1 addition & 1 deletion src/MenuItem/SplitItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getRows(MenuStyle $style, bool $selected = false) : array
array_map(function ($index, $item) use ($selected, $length, $style) {
$isSelected = $selected && $index === $this->selectedItemIndex;
$marker = $item->canSelect()
? sprintf('%s ', $style->getMarker($isSelected))
? sprintf('%s', $style->getMarker($isSelected))
: '';

$itemExtra = '';
Expand Down
4 changes: 2 additions & 2 deletions src/MenuStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class MenuStyle
'paddingTopBottom' => 1,
'paddingLeftRight' => 2,
'margin' => 2,
'selectedMarker' => '●',
'unselectedMarker' => '○',
'selectedMarker' => '● ',
'unselectedMarker' => '○ ',
'itemExtra' => '✔',
'displaysExtra' => false,
'titleSeparator' => '=',
Expand Down
48 changes: 23 additions & 25 deletions test/MenuItem/MenuMenuItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\MenuItem\MenuMenuItem;
use PhpSchool\CliMenu\MenuStyle;
use PhpSchool\Terminal\Terminal;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -51,33 +52,29 @@ public function testGetText() : void

public function testGetRows() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(10);
$menuStyle->setUnselectedMarker('* ');

$subMenu = $this->createMock(CliMenu::class);

$item = new MenuMenuItem('Item', $subMenu);
$this->assertEquals([' Item'], $item->getRows($menuStyle));
$this->assertEquals(['* Item'], $item->getRows($menuStyle));
}

public function testGetRowsWithUnSelectedMarker() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));

$menuStyle
->expects($this->exactly(2))
->method('getMarker')
->with(false)
->will($this->returnValue('*'));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(10);
$menuStyle->setUnselectedMarker('* ');

$subMenu = $this->createMock(CliMenu::class);

Expand All @@ -99,7 +96,7 @@ public function testGetRowsWithSelectedMarker() : void
->expects($this->once())
->method('getMarker')
->with(true)
->will($this->returnValue('='));
->will($this->returnValue('= '));

$subMenu = $this->getMockBuilder(CliMenu::class)
->disableOriginalConstructor()
Expand All @@ -112,20 +109,21 @@ public function testGetRowsWithSelectedMarker() : void

public function testGetRowsWithMultipleLines() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(10);
$menuStyle->setUnselectedMarker('* ');

$subMenu = $this->createMock(CliMenu::class);

$item = new MenuMenuItem('LONG ITEM LINE', $subMenu);
$this->assertEquals(
[
" LONG ITEM",
" LINE",
"* LONG",
" ITEM LINE",
],
$item->getRows($menuStyle)
);
Expand Down
81 changes: 39 additions & 42 deletions test/MenuItem/SelectableItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpSchool\CliMenu\MenuItem\SelectableItem;
use PhpSchool\CliMenu\MenuStyle;
use PhpSchool\Terminal\Terminal;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -46,35 +47,35 @@ public function testGetText() : void

public function testGetRows() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(10);

$item = new SelectableItem('Item', function () {
});
$this->assertEquals([' Item'], $item->getRows($menuStyle));
$this->assertEquals([' Item'], $item->getRows($menuStyle, false));
$this->assertEquals([' Item'], $item->getRows($menuStyle, true));
$this->assertEquals([' Item'], $item->getRows($menuStyle));
$this->assertEquals([' Item'], $item->getRows($menuStyle, false));
$this->assertEquals([' Item'], $item->getRows($menuStyle, true));
}

public function testSetText() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(10);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));

$item = new SelectableItem('Item', function () {
});
$item->setText('New Text');
$this->assertEquals([' New Text'], $item->getRows($menuStyle));
$this->assertEquals([' New Text'], $item->getRows($menuStyle, false));
$this->assertEquals([' New Text'], $item->getRows($menuStyle, true));
$this->assertEquals([' New Text'], $item->getRows($menuStyle));
$this->assertEquals([' New Text'], $item->getRows($menuStyle, false));
$this->assertEquals([' New Text'], $item->getRows($menuStyle, true));
}

public function testGetRowsWithUnSelectedMarker() : void
Expand All @@ -90,7 +91,7 @@ public function testGetRowsWithUnSelectedMarker() : void
->expects($this->exactly(2))
->method('getMarker')
->with(false)
->will($this->returnValue('*'));
->will($this->returnValue('* '));

$item = new SelectableItem('Item', function () {
});
Expand All @@ -111,7 +112,7 @@ public function testGetRowsWithSelectedMarker() : void
->expects($this->once())
->method('getMarker')
->with(true)
->will($this->returnValue('='));
->will($this->returnValue('= '));

$item = new SelectableItem('Item', function () {
});
Expand All @@ -120,43 +121,39 @@ public function testGetRowsWithSelectedMarker() : void

public function testGetRowsWithItemExtra() : void
{
$menuStyle = $this->createMock(MenuStyle::class);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->once())
->method('getItemExtra')
->will($this->returnValue('[EXTRA]'));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(20);
$menuStyle->setItemExtra('[EXTRA]');
$menuStyle->setDisplaysExtra(true);
$menuStyle->setUnselectedMarker('* ');

$item = new SelectableItem('Item', function () {
}, true);
$this->assertEquals([' Item [EXTRA]'], $item->getRows($menuStyle));
$this->assertEquals(['* Item [EXTRA]'], $item->getRows($menuStyle));
}

public function testGetRowsWithMultipleLinesWithItemExtra() : void
{
$menuStyle = $this->createMock(MenuStyle::class);
$terminal = $this->createMock(Terminal::class);
$terminal->expects($this->any())->method('getWidth')->willReturn(100);

$menuStyle
->expects($this->any())
->method('getContentWidth')
->will($this->returnValue(10));

$menuStyle
->expects($this->once())
->method('getItemExtra')
->will($this->returnValue('[EXTRA]'));
$menuStyle = new MenuStyle($terminal);
$menuStyle->setPaddingLeftRight(0);
$menuStyle->setWidth(20);
$menuStyle->setItemExtra('[EXTRA]');
$menuStyle->setDisplaysExtra(true);
$menuStyle->setUnselectedMarker('* ');

$item = new SelectableItem('LONG ITEM LINE', function () {
}, true);
$this->assertEquals(
[
" LONG ITEM [EXTRA]",
" LINE",
"* LONG ITEM [EXTRA]",
" LINE",
],
$item->getRows($menuStyle)
);
Expand Down
Loading