2018-12-08 16:11:14 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2018-12-08 16:11:14 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-08-11 00:16:34 +03:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Util;
|
2018-12-08 16:11:14 +03:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
2020-11-02 13:50:19 +03:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
2018-12-08 16:11:14 +03:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use ReflectionObject;
|
2019-08-11 00:16:34 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
|
2018-12-08 16:11:14 +03:00
|
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
use Symfony\Component\Console\Helper\TableStyle;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class ShlinkTableTest extends TestCase
|
|
|
|
{
|
2020-11-02 13:50:19 +03:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2019-12-30 00:27:00 +03:00
|
|
|
private ShlinkTable $shlinkTable;
|
|
|
|
private ObjectProphecy $baseTable;
|
2018-12-08 16:11:14 +03:00
|
|
|
|
2022-09-11 13:02:49 +03:00
|
|
|
protected function setUp(): void
|
2018-12-08 16:11:14 +03:00
|
|
|
{
|
|
|
|
$this->baseTable = $this->prophesize(Table::class);
|
2021-08-03 11:21:42 +03:00
|
|
|
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable->reveal());
|
2018-12-08 16:11:14 +03:00
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-08-11 00:16:34 +03:00
|
|
|
public function renderMakesTableToBeRenderedWithProvidedInfo(): void
|
2018-12-08 16:11:14 +03:00
|
|
|
{
|
|
|
|
$headers = [];
|
|
|
|
$rows = [[]];
|
|
|
|
$headerTitle = 'Header';
|
|
|
|
$footerTitle = 'Footer';
|
|
|
|
|
|
|
|
$setStyle = $this->baseTable->setStyle(Argument::type(TableStyle::class))->willReturn(
|
2020-01-01 22:48:31 +03:00
|
|
|
$this->baseTable->reveal(),
|
2018-12-08 16:11:14 +03:00
|
|
|
);
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-08-11 00:16:34 +03:00
|
|
|
public function newTableIsCreatedForFactoryMethod(): void
|
2018-12-08 16:11:14 +03:00
|
|
|
{
|
2021-08-03 11:21:42 +03:00
|
|
|
$instance = ShlinkTable::default($this->prophesize(OutputInterface::class)->reveal());
|
2018-12-08 16:11:14 +03:00
|
|
|
|
|
|
|
$ref = new ReflectionObject($instance);
|
|
|
|
$baseTable = $ref->getProperty('baseTable');
|
|
|
|
$baseTable->setAccessible(true);
|
|
|
|
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertInstanceOf(Table::class, $baseTable->getValue($instance));
|
2018-12-08 16:11:14 +03:00
|
|
|
}
|
|
|
|
}
|