From 97a9289d5f5675917bca156f2f771366f02a3606 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 8 Dec 2018 14:11:14 +0100 Subject: [PATCH] Created ShlinkTableTest --- .../Paginator/Util/PaginatorUtilsTrait.php | 2 +- .../Common/test/Console/ShlinkTableTest.php | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 module/Common/test/Console/ShlinkTableTest.php diff --git a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php index c031db21..a98568d3 100644 --- a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php +++ b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Paginator\Util; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; -use function sprintf; use Zend\Paginator\Paginator; use Zend\Stdlib\ArrayUtils; use function array_map; +use function sprintf; trait PaginatorUtilsTrait { diff --git a/module/Common/test/Console/ShlinkTableTest.php b/module/Common/test/Console/ShlinkTableTest.php new file mode 100644 index 00000000..d38fb5bb --- /dev/null +++ b/module/Common/test/Console/ShlinkTableTest.php @@ -0,0 +1,70 @@ +baseTable = $this->prophesize(Table::class); + $this->shlinkTable = new ShlinkTable($this->baseTable->reveal()); + } + + /** + * @test + */ + public function renderMakesTableToBeRenderedWithProvidedInfo() + { + $headers = []; + $rows = [[]]; + $headerTitle = 'Header'; + $footerTitle = 'Footer'; + + $setStyle = $this->baseTable->setStyle(Argument::type(TableStyle::class))->willReturn( + $this->baseTable->reveal() + ); + $setHeaders = $this->baseTable->setHeaders($headers)->willReturn($this->baseTable->reveal()); + $setRows = $this->baseTable->setRows($rows)->willReturn($this->baseTable->reveal()); + $setFooterTitle = $this->baseTable->setFooterTitle($footerTitle)->willReturn($this->baseTable->reveal()); + $setHeaderTitle = $this->baseTable->setHeaderTitle($headerTitle)->willReturn($this->baseTable->reveal()); + $render = $this->baseTable->render()->willReturn($this->baseTable->reveal()); + + $this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle); + + $setStyle->shouldHaveBeenCalledOnce(); + $setHeaders->shouldHaveBeenCalledOnce(); + $setRows->shouldHaveBeenCalledOnce(); + $setFooterTitle->shouldHaveBeenCalledOnce(); + $setHeaderTitle->shouldHaveBeenCalledOnce(); + $render->shouldHaveBeenCalledOnce(); + } + + /** + * @test + */ + public function newTableIsCreatedForFactoryMethod() + { + $instance = ShlinkTable::fromOutput($this->prophesize(OutputInterface::class)->reveal()); + + $ref = new ReflectionObject($instance); + $baseTable = $ref->getProperty('baseTable'); + $baseTable->setAccessible(true); + + $this->assertInstanceOf(Table::class, $baseTable->getValue($instance)); + } +}