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

69 lines
2.3 KiB
PHP
Raw Normal View History

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