renderMakesTableToBeRenderedWithProvidedInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 24
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\CLI\Util;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Argument;
9
use Prophecy\PhpUnit\ProphecyTrait;
10
use Prophecy\Prophecy\ObjectProphecy;
11
use ReflectionObject;
12
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Helper\TableStyle;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class ShlinkTableTest extends TestCase
18
{
19
    use ProphecyTrait;
20
21
    private ShlinkTable $shlinkTable;
22
    private ObjectProphecy $baseTable;
23
24
    public function setUp(): void
25
    {
26
        $this->baseTable = $this->prophesize(Table::class);
27
        $this->shlinkTable = new ShlinkTable($this->baseTable->reveal());
28
    }
29
30
    /** @test */
31
    public function renderMakesTableToBeRenderedWithProvidedInfo(): void
32
    {
33
        $headers = [];
34
        $rows = [[]];
35
        $headerTitle = 'Header';
36
        $footerTitle = 'Footer';
37
38
        $setStyle = $this->baseTable->setStyle(Argument::type(TableStyle::class))->willReturn(
39
            $this->baseTable->reveal(),
40
        );
41
        $setHeaders = $this->baseTable->setHeaders($headers)->willReturn($this->baseTable->reveal());
42
        $setRows = $this->baseTable->setRows($rows)->willReturn($this->baseTable->reveal());
43
        $setFooterTitle = $this->baseTable->setFooterTitle($footerTitle)->willReturn($this->baseTable->reveal());
44
        $setHeaderTitle = $this->baseTable->setHeaderTitle($headerTitle)->willReturn($this->baseTable->reveal());
45
        $render = $this->baseTable->render()->willReturn($this->baseTable->reveal());
46
47
        $this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle);
48
49
        $setStyle->shouldHaveBeenCalledOnce();
50
        $setHeaders->shouldHaveBeenCalledOnce();
51
        $setRows->shouldHaveBeenCalledOnce();
52
        $setFooterTitle->shouldHaveBeenCalledOnce();
53
        $setHeaderTitle->shouldHaveBeenCalledOnce();
54
        $render->shouldHaveBeenCalledOnce();
55
    }
56
57
    /** @test */
58
    public function newTableIsCreatedForFactoryMethod(): void
59
    {
60
        $instance = ShlinkTable::fromOutput($this->prophesize(OutputInterface::class)->reveal());
61
62
        $ref = new ReflectionObject($instance);
63
        $baseTable = $ref->getProperty('baseTable');
64
        $baseTable->setAccessible(true);
65
66
        self::assertInstanceOf(Table::class, $baseTable->getValue($instance));
67
    }
68
}
69