Completed
Push — master ( 62fb38...736054 )
by Alejandro
13s queued 10s
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
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 24
rs 9.6666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Console;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use ReflectionObject;
10
use Shlinkio\Shlink\Common\Console\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()
23
    {
24
        $this->baseTable = $this->prophesize(Table::class);
25
        $this->shlinkTable = new ShlinkTable($this->baseTable->reveal());
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function renderMakesTableToBeRenderedWithProvidedInfo()
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
    /**
58
     * @test
59
     */
60
    public function newTableIsCreatedForFactoryMethod()
61
    {
62
        $instance = ShlinkTable::fromOutput($this->prophesize(OutputInterface::class)->reveal());
63
64
        $ref = new ReflectionObject($instance);
65
        $baseTable = $ref->getProperty('baseTable');
66
        $baseTable->setAccessible(true);
67
68
        $this->assertInstanceOf(Table::class, $baseTable->getValue($instance));
69
    }
70
}
71