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

59 lines
2 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\Attributes\Test;
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-24 20:53:13 +03:00
private MockObject & Table $baseTable;
2018-12-08 16:11:14 +03:00
protected function setUp(): void
2018-12-08 16:11:14 +03:00
{
$this->baseTable = $this->createMock(Table::class);
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable);
2018-12-08 16:11:14 +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';
$this->baseTable->expects($this->once())->method('setStyle')->with(
2022-10-22 15:41:42 +03:00
$this->isInstanceOf(TableStyle::class),
)->willReturnSelf();
$this->baseTable->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
$this->baseTable->expects($this->once())->method('setRows')->with($rows)->willReturnSelf();
$this->baseTable->expects($this->once())->method('setFooterTitle')->with($footerTitle)->willReturnSelf();
$this->baseTable->expects($this->once())->method('setHeaderTitle')->with($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);
}
#[Test]
2019-08-11 00:16:34 +03:00
public function newTableIsCreatedForFactoryMethod(): void
2018-12-08 16:11:14 +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
}
}