TableTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Grid\Table;
6
7
use AbterPhp\Framework\Grid\Component\Body;
8
use AbterPhp\Framework\Grid\Component\Header;
9
use AbterPhp\Framework\TestDouble\Domain\MockEntityFactory;
10
use PHPUnit\Framework\TestCase;
11
use PHPUnit\Framework\MockObject\MockObject;
12
13
class TableTest extends TestCase
14
{
15
    /** @var Table - System Under Test */
16
    protected Table $sut;
17
18
    /** @var Body|MockObject */
19
    protected $body;
20
21
    /** @var Header|MockObject */
22
    protected $header;
23
24
    public function setUp(): void
25
    {
26
        parent::setUp();
27
28
        $this->body = $this->createMock(Body::class);
29
30
        $this->header = $this->createMock(Header::class);
31
32
        $this->sut = new Table($this->body, $this->header);
33
    }
34
35
    public function testToStringContainsHeaders(): void
36
    {
37
        $this->body->expects($this->any())->method('__toString')->willReturn('!A!');
38
        $this->header->expects($this->any())->method('__toString')->willReturn('!B!');
39
40
        $this->assertStringContainsString('B', (string)$this->sut);
41
    }
42
43
    public function testToStringContainsRows(): void
44
    {
45
        $this->body->expects($this->any())->method('__toString')->willReturn('!A!');
46
        $this->header->expects($this->any())->method('__toString')->willReturn('!B!');
47
48
        $this->assertStringContainsString('!B!', (string)$this->sut);
49
    }
50
51
    public function testSetTemplateCanChangeContent(): void
52
    {
53
        $template = '--||--';
54
55
        $this->body->expects($this->any())->method('__toString')->willReturn('!A!');
56
        $this->header->expects($this->any())->method('__toString')->willReturn('!B!');
57
58
        $this->sut->setTemplate($template);
59
60
        $actualResult = (string)$this->sut;
61
62
        $this->assertStringNotContainsString('!A!', $actualResult);
63
        $this->assertStringNotContainsString('!A!', $actualResult);
64
        $this->assertStringContainsString($template, $actualResult);
65
    }
66
67
    public function testGetSortedUrlCallsHeader(): void
68
    {
69
        $stubBaseUrl   = '/foo?';
70
        $stubSortedUrl = '/foo?bar';
71
72
        $this->header->expects($this->once())->method('getSortedUrl')->with($stubBaseUrl)->willReturn($stubSortedUrl);
73
74
        $actualResult = $this->sut->getSortedUrl($stubBaseUrl);
75
76
        $this->assertSame($stubSortedUrl, $actualResult);
77
    }
78
79
    public function testGetSortedConditionsCallsHeader(): void
80
    {
81
        $stubSortedConditions = ['foo', 'bar'];
82
83
        $this->header->expects($this->once())->method('getSortConditions')->willReturn($stubSortedConditions);
84
85
        $actualResult = $this->sut->getSortConditions();
86
87
        $this->assertSame($stubSortedConditions, $actualResult);
88
    }
89
90
    public function testGetSqlParamsCallsHeader(): void
91
    {
92
        $stubQueryParams = ['foo', 'bar'];
93
94
        $this->header->expects($this->once())->method('getQueryParams')->willReturn($stubQueryParams);
95
96
        $actualResult = $this->sut->getSqlParams();
97
98
        $this->assertSame($stubQueryParams, $actualResult);
99
    }
100
101
    public function testSetEntitiesCallsBody(): void
102
    {
103
        $stubEntity = MockEntityFactory::createEntityStub($this);
104
105
        $stubEntities = [$stubEntity];
106
107
        $this->body->expects($this->once())->method('setEntities')->with($stubEntities);
108
109
        $this->sut->setEntities($stubEntities);
110
    }
111
112
    public function testGetExtendedNodes(): void
113
    {
114
        $actualResult = $this->sut->getExtendedNodes();
115
116
        $this->assertSame([$this->header, $this->body], $actualResult);
117
    }
118
}
119