Passed
Pull Request — master (#456)
by Alejandro
06:37 queued 01:57
created

renderMakesTableToBeRenderedWithProvidedInfo()   A

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