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
|
|
|
|
2022-10-22 15:40:35 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-12-08 16:11:14 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
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
|
|
|
|
{
|
2019-12-30 00:27:00 +03:00
|
|
|
private ShlinkTable $shlinkTable;
|
2022-10-22 15:40:35 +03:00
|
|
|
private MockObject $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
|
|
|
{
|
2022-10-22 15:40:35 +03:00
|
|
|
$this->baseTable = $this->createMock(Table::class);
|
|
|
|
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable);
|
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';
|
|
|
|
|
2022-10-22 15:40:35 +03:00
|
|
|
$this->baseTable->expects($this->once())->method('setStyle')->with(
|
2022-10-22 15:41:42 +03:00
|
|
|
$this->isInstanceOf(TableStyle::class),
|
2022-10-22 15:40:35 +03:00
|
|
|
)->willReturnSelf();
|
|
|
|
$this->baseTable->expects($this->once())->method('setHeaders')->with(
|
|
|
|
$this->equalTo($headers),
|
|
|
|
)->willReturnSelf();
|
|
|
|
$this->baseTable->expects($this->once())->method('setRows')->with($this->equalTo($rows))->willReturnSelf();
|
|
|
|
$this->baseTable->expects($this->once())->method('setFooterTitle')->with(
|
|
|
|
$this->equalTo($footerTitle),
|
|
|
|
)->willReturnSelf();
|
|
|
|
$this->baseTable->expects($this->once())->method('setHeaderTitle')->with(
|
|
|
|
$this->equalTo($headerTitle),
|
|
|
|
)->willReturnSelf();
|
|
|
|
$this->baseTable->expects($this->once())->method('render')->with()->willReturnSelf();
|
2018-12-08 16:11:14 +03:00
|
|
|
|
|
|
|
$this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2022-10-22 15:40:35 +03:00
|
|
|
$instance = ShlinkTable::default($this->createMock(OutputInterface::class));
|
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
|
|
|
}
|
|
|
|
}
|