Skip to content

Php 7.4 support #183

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 5 commits into from
Dec 3, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
.idea
/composer.lock
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ cache:
- $HOME/.composer/cache/files

php:
- 7.1
- 7.2
- 7.3
- 7.4

install:
- composer self-update
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "^7.1",
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.2",
"phpstan/phpstan": "^0.11"
},
Expand Down
10 changes: 10 additions & 0 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public function setTitle(string $title) : void
$this->title = $title;
}

public function getTitle() : ?string
{
return $this->title;
}

public function setParent(CliMenu $parent) : void
{
$this->parent = $parent;
Expand Down Expand Up @@ -228,6 +233,11 @@ public function addCustomControlMapping(string $input, callable $callable) : voi
$this->customControlMappings[$input] = $callable;
}

public function getCustomControlMappings() : array
{
return $this->customControlMappings;
}

/**
* Shorthand function to add multiple custom control mapping at once
*/
Expand Down
10 changes: 10 additions & 0 deletions src/MenuItem/AsciiArtItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public function getArtLength() : int
return $this->artLength;
}

public function getPosition() : string
{
return $this->position;
}

public function getAlternateText() : string
{
return $this->alternateText;
}

/**
* Whether or not the menu item is showing the menustyle extra value
*/
Expand Down
5 changes: 5 additions & 0 deletions src/MenuItem/LineBreakItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function showsItemExtra() : bool
return false;
}

public function getLines() : int
{
return $this->lines;
}

/**
* Enable showing item extra
*/
Expand Down
5 changes: 5 additions & 0 deletions src/MenuItem/SplitItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function setGutter(int $gutter) : void
$this->gutter = $gutter;
}

public function getGutter() : int
{
return $this->gutter;
}

public function addItem(MenuItemInterface $item) : self
{
foreach (self::$blacklistedItems as $bl) {
Expand Down
205 changes: 106 additions & 99 deletions test/Builder/CliMenuBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PhpSchool\CliMenu\MenuItem\StaticItem;
use PhpSchool\Terminal\Terminal;
use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* @author Aydin Hassan <[email protected]>
Expand Down Expand Up @@ -69,17 +68,18 @@ public function testModifyStyles() : void
$builder->setTitleSeparator('-');

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

$this->checkStyleVariable($menu, 'bg', 'red');
$this->checkStyleVariable($menu, 'fg', 'red');
$this->checkStyleVariable($menu, 'width', 40);
$this->checkStyleVariable($menu, 'paddingTopBottom', 4);
$this->checkStyleVariable($menu, 'paddingLeftRight', 1);
$this->checkStyleVariable($menu, 'margin', 4);
$this->checkStyleVariable($menu, 'unselectedMarker', '>');
$this->checkStyleVariable($menu, 'selectedMarker', 'x');
$this->checkStyleVariable($menu, 'itemExtra', '*');
$this->checkStyleVariable($menu, 'titleSeparator', '-');
self::assertEquals('red', $style->getBg());
self::assertEquals('red', $style->getFg());
self::assertEquals(40, $style->getWidth());
self::assertEquals(4, $style->getPaddingTopBottom());
self::assertEquals(1, $style->getPaddingLeftRight());
self::assertEquals(4, $style->getMargin());
self::assertEquals('>', $style->getUnselectedMarker());
self::assertEquals('x', $style->getSelectedMarker());
self::assertEquals('*', $style->getItemExtra());
self::assertEquals('-', $style->getTitleSeparator());
}

public function testSetBorderShorthandFunction() : void
Expand All @@ -90,85 +90,93 @@ public function testSetBorderShorthandFunction() : void
->method('getWidth')
->will($this->returnValue(200));

$menu = (new CliMenuBuilder($terminal))
$style = (new CliMenuBuilder($terminal))
->setBorder(2)
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 2);
$this->checkStyleVariable($menu, 'borderBottomWidth', 2);
$this->checkStyleVariable($menu, 'borderLeftWidth', 2);
$this->checkStyleVariable($menu, 'borderColour', 'white');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(2, $style->getBorderRightWidth());
self::assertEquals(2, $style->getBorderBottomWidth());
self::assertEquals(2, $style->getBorderLeftWidth());
self::assertEquals('white', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4)
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 2);
$this->checkStyleVariable($menu, 'borderLeftWidth', 4);
$this->checkStyleVariable($menu, 'borderColour', 'white');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(2, $style->getBorderBottomWidth());
self::assertEquals(4, $style->getBorderLeftWidth());
self::assertEquals('white', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4, 6)
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 6);
$this->checkStyleVariable($menu, 'borderLeftWidth', 4);
$this->checkStyleVariable($menu, 'borderColour', 'white');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(6, $style->getBorderBottomWidth());
self::assertEquals(4, $style->getBorderLeftWidth());
self::assertEquals('white', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4, 6, 8)
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 6);
$this->checkStyleVariable($menu, 'borderLeftWidth', 8);
$this->checkStyleVariable($menu, 'borderColour', 'white');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(6, $style->getBorderBottomWidth());
self::assertEquals(8, $style->getBorderLeftWidth());
self::assertEquals('white', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4, 6, 8, 'green')
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 6);
$this->checkStyleVariable($menu, 'borderLeftWidth', 8);
$this->checkStyleVariable($menu, 'borderColour', 'green');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(6, $style->getBorderBottomWidth());
self::assertEquals(8, $style->getBorderLeftWidth());
self::assertEquals('green', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4, 6, 'green')
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 6);
$this->checkStyleVariable($menu, 'borderLeftWidth', 4);
$this->checkStyleVariable($menu, 'borderColour', 'green');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(6, $style->getBorderBottomWidth());
self::assertEquals(4, $style->getBorderLeftWidth());
self::assertEquals('green', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 4, 'green')
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 4);
$this->checkStyleVariable($menu, 'borderBottomWidth', 2);
$this->checkStyleVariable($menu, 'borderLeftWidth', 4);
$this->checkStyleVariable($menu, 'borderColour', 'green');
->build()
->getStyle();

$menu = (new CliMenuBuilder($terminal))
self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(4, $style->getBorderRightWidth());
self::assertEquals(2, $style->getBorderBottomWidth());
self::assertEquals(4, $style->getBorderLeftWidth());
self::assertEquals('green', $style->getBorderColour());

$style = (new CliMenuBuilder($terminal))
->setBorder(2, 'green')
->build();

$this->checkStyleVariable($menu, 'borderTopWidth', 2);
$this->checkStyleVariable($menu, 'borderRightWidth', 2);
$this->checkStyleVariable($menu, 'borderBottomWidth', 2);
$this->checkStyleVariable($menu, 'borderLeftWidth', 2);
$this->checkStyleVariable($menu, 'borderColour', 'green');
->build()
->getStyle();

self::assertEquals(2, $style->getBorderTopWidth());
self::assertEquals(2, $style->getBorderRightWidth());
self::assertEquals(2, $style->getBorderBottomWidth());
self::assertEquals(2, $style->getBorderLeftWidth());
self::assertEquals('green', $style->getBorderColour());
}

public function testSetBorderTopWidth() : void
Expand Down Expand Up @@ -232,10 +240,11 @@ public function test256ColoursCodes() : void
$builder = new CliMenuBuilder($terminal);
$builder->setBackgroundColour(16, 'white');
$builder->setForegroundColour(206, 'red');
$menu = $builder->build();
$style = $builder->build()
->getStyle();

$this->checkStyleVariable($menu, 'bg', 16);
$this->checkStyleVariable($menu, 'fg', 206);
self::assertEquals(16, $style->getBg());
self::assertEquals(206, $style->getFg());

$terminal = static::createMock(Terminal::class);
$terminal
Expand All @@ -246,10 +255,11 @@ public function test256ColoursCodes() : void
$builder = new CliMenuBuilder($terminal);
$builder->setBackgroundColour(16, 'white');
$builder->setForegroundColour(206, 'red');
$menu = $builder->build();
$style = $builder->build()
->getStyle();

$this->checkStyleVariable($menu, 'bg', 'white');
$this->checkStyleVariable($menu, 'fg', 'red');
self::assertEquals('white', $style->getBg());
self::assertEquals('red', $style->getFg());
}

public function testSetFgThrowsExceptionWhenColourCodeIsNotInRange() : void
Expand Down Expand Up @@ -288,8 +298,8 @@ public function testDisableDefaultItems() : void
$builder->disableDefaultItems();

$menu = $builder->build();
$this->checkVariable($menu, 'items', []);

self::assertEquals([], $menu->getItems());
}

public function testSetTitle() : void
Expand All @@ -299,7 +309,7 @@ public function testSetTitle() : void

$menu = $builder->build();

$this->checkVariable($menu, 'title', 'title');
self::assertEquals('title', $menu->getTitle());
}

public function testAddItem() : void
Expand Down Expand Up @@ -782,11 +792,15 @@ public function testAddSplitItemWithClosureBinding() : void

private function checkMenuItems(CliMenu $menu, array $expected) : void
{
$this->checkItems($this->readAttribute($menu, 'items'), $expected);
$this->checkItems($menu->getItems(), $expected);
}

private function checkItems(array $actualItems, array $expected) : void
{
$propMap = [
'breakChar' => 'getText',
];

self::assertCount(count($expected), $actualItems);

foreach ($expected as $expectedItem) {
Expand All @@ -796,21 +810,14 @@ private function checkItems(array $actualItems, array $expected) : void
unset($expectedItem['class']);

foreach ($expectedItem as $property => $value) {
self::assertEquals($this->readAttribute($actualItem, $property), $value);
if (isset($propMap[$property])) {
$getter = $propMap[$property];
} else {
$getter = 'get'. ucfirst($property);
}

self::assertEquals($actualItem->{$getter}(), $value);
}
}
}


private function checkVariable(CliMenu $menu, string $property, $expected) : void
{
$actual = $this->readAttribute($menu, $property);
self::assertEquals($expected, $actual);
}

private function checkStyleVariable(CliMenu $menu, string $property, $expected) : void
{
$style = $this->readAttribute($menu, 'style');
self::assertEquals($this->readAttribute($style, $property), $expected);
}
}
4 changes: 2 additions & 2 deletions test/Builder/SplitItemBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testSetGutter() : void
$builder->setGutter(4);

$item = $builder->build();
self::assertEquals(4, self::readAttribute($item, 'gutter'));
self::assertEquals(4, $item->getGutter());
}

public function testAddSubMenuWithClosureBinding() : void
Expand Down Expand Up @@ -134,7 +134,7 @@ private function checkItems(array $actualItems, array $expected) : void
unset($expectedItem['class']);

foreach ($expectedItem as $property => $value) {
self::assertEquals($this->readAttribute($actualItem, $property), $value);
self::assertEquals($actualItem->{'get'. ucfirst($property)}(), $value);
}
}
}
Expand Down
Loading