shlink/module/CLI/test/Util/ShlinkTableTest.php

66 lines
2.3 KiB
PHP
Raw Normal View History

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;
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
{
2019-12-30 00:27:00 +03:00
private ShlinkTable $shlinkTable;
private ObjectProphecy $baseTable;
2018-12-08 16:11:14 +03:00
2019-02-16 12:53:45 +03:00
public function setUp(): void
2018-12-08 16:11:14 +03:00
{
$this->baseTable = $this->prophesize(Table::class);
$this->shlinkTable = new ShlinkTable($this->baseTable->reveal());
}
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
{
$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));
}
}