|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminListBundle\Tests\AdminList\Configurator; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Doctrine\DBAL\Query\QueryBuilder; |
|
7
|
|
|
use Doctrine\DBAL\Statement; |
|
8
|
|
|
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineDBALAdminListConfigurator; |
|
9
|
|
|
use Kunstmaan\AdminListBundle\AdminList\Filter; |
|
10
|
|
|
use Kunstmaan\AdminListBundle\AdminList\FilterBuilder; |
|
11
|
|
|
use Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL\AbstractDBALFilterType; |
|
12
|
|
|
use Pagerfanta\Pagerfanta; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
16
|
|
|
|
|
17
|
|
|
class AbstractDoctrineDBALAdminListConfiguratorTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var Connection */ |
|
20
|
|
|
private $connectionMock; |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->connectionMock = $this->createMock(Connection::class); |
|
|
|
|
|
|
25
|
|
|
$this->connectionMock |
|
26
|
|
|
->expects($this->any()) |
|
27
|
|
|
->method('executeQuery') |
|
28
|
|
|
->willReturn($this->createMock(Statement::class)) |
|
29
|
|
|
; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
public function testGetEditUrl() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$abstractMock = $this->setUpAbstractMock(); |
|
35
|
|
|
|
|
36
|
|
|
$editUrl = $abstractMock->getEditUrlFor(['id' => 888]); |
|
37
|
|
|
$this->assertIsArray($editUrl); |
|
38
|
|
|
$this->assertArrayHasKey('path', $editUrl); |
|
39
|
|
|
$this->assertArrayHasKey('params', $editUrl); |
|
40
|
|
|
$this->assertEquals('bundle_admin_myentity_'.AbstractDoctrineDBALadminListConfigurator::SUFFIX_EDIT, $editUrl['path']); |
|
41
|
|
|
$this->assertContains(888, $editUrl['params']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
public function testGetDeleteUrl() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$abstractMock = $this->setUpAbstractMock(); |
|
47
|
|
|
|
|
48
|
|
|
$editUrl = $abstractMock->getDeleteUrlFor(['id' => 888]); |
|
49
|
|
|
$this->assertIsArray($editUrl); |
|
50
|
|
|
$this->assertArrayHasKey('path', $editUrl); |
|
51
|
|
|
$this->assertArrayHasKey('params', $editUrl); |
|
52
|
|
|
$this->assertEquals('bundle_admin_myentity_'.AbstractDoctrineDBALAdminListConfigurator::SUFFIX_DELETE, $editUrl['path']); |
|
53
|
|
|
$this->assertContains(888, $editUrl['params']); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetPagerFanta() |
|
57
|
|
|
{ |
|
58
|
|
|
$abstractMock = $this->setUpAbstractMock(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertInstanceOf(Pagerfanta::class, $abstractMock->getPagerfanta()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testGetQueryBuilderAndIterator() |
|
64
|
|
|
{ |
|
65
|
|
|
$abstractMock = $this->setUpAbstractMock(['getFilterBuilder']); |
|
66
|
|
|
|
|
67
|
|
|
$abstractDBALFilterTypeMock = $this->createMock(AbstractDBALFilterType::class); |
|
68
|
|
|
|
|
69
|
|
|
$filterBuilderMock = $this->createMock(FilterBuilder::class); |
|
70
|
|
|
$filterBuilderMock |
|
71
|
|
|
->expects($this->any()) |
|
72
|
|
|
->method('getCurrentFilters') |
|
73
|
|
|
->willReturn([ |
|
74
|
|
|
new Filter('foo', ['type' => $abstractDBALFilterTypeMock, 'options' => []], 'uid'), |
|
75
|
|
|
]) |
|
76
|
|
|
; |
|
77
|
|
|
|
|
78
|
|
|
$abstractMock |
|
|
|
|
|
|
79
|
|
|
->expects($this->any()) |
|
80
|
|
|
->method('getFilterBuilder') |
|
81
|
|
|
->willReturn($filterBuilderMock) |
|
82
|
|
|
; |
|
83
|
|
|
|
|
84
|
|
|
$requestMock = $this->getMockBuilder(Request::class) |
|
85
|
|
|
->setConstructorArgs([['page' => 1], [], ['_route' => 'testroute']]) |
|
86
|
|
|
->setMethods(['getSession']) |
|
87
|
|
|
->getMock() |
|
88
|
|
|
; |
|
89
|
|
|
|
|
90
|
|
|
$sessionMock = $this->createMock(Session::class); |
|
91
|
|
|
$sessionMock |
|
92
|
|
|
->expects($this->once()) |
|
93
|
|
|
->method('has') |
|
94
|
|
|
->willReturn(true) |
|
95
|
|
|
; |
|
96
|
|
|
$sessionMock |
|
97
|
|
|
->expects($this->once()) |
|
98
|
|
|
->method('get') |
|
99
|
|
|
->with('listconfig_testroute') |
|
100
|
|
|
->willReturn(['page' => 1, 'orderBy' => 'foo', 'orderDirection' => 'up']) |
|
101
|
|
|
; |
|
102
|
|
|
|
|
103
|
|
|
$requestMock |
|
104
|
|
|
->expects($this->exactly(2)) |
|
105
|
|
|
->method('getSession') |
|
106
|
|
|
->willReturn($sessionMock) |
|
107
|
|
|
; |
|
108
|
|
|
|
|
109
|
|
|
$abstractMock->bindRequest($requestMock); |
|
|
|
|
|
|
110
|
|
|
$this->assertInstanceOf(QueryBuilder::class, $abstractMock->getQueryBuilder()); |
|
111
|
|
|
$this->assertInstanceOf(\Traversable::class, $abstractMock->getIterator()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testSetGetCountField() |
|
115
|
|
|
{ |
|
116
|
|
|
$abstractMock = $this->setUpAbstractMock(); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertInstanceOf(AbstractDoctrineDBALAdminListConfigurator::class, $abstractMock->setCountField('foo')); |
|
119
|
|
|
$this->assertIsString($abstractMock->getCountField()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testSetGetDistinctCount() |
|
123
|
|
|
{ |
|
124
|
|
|
$abstractMock = $this->setUpAbstractMock(); |
|
125
|
|
|
|
|
126
|
|
|
$this->assertInstanceOf(AbstractDoctrineDBALAdminListConfigurator::class, $abstractMock->setUseDistinctCount(false)); |
|
127
|
|
|
$this->assertFalse($abstractMock->getUseDistinctCount()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
View Code Duplication |
public function setUpAbstractMock(array $methods = []) |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
/** @var AbstractDoctrineDBALAdminListConfigurator $abstractMock */ |
|
133
|
|
|
$abstractMock = $this->getMockForAbstractClass(AbstractDoctrineDBALAdminListConfigurator::class, [$this->connectionMock], '', true, true, true, $methods); |
|
134
|
|
|
$abstractMock |
|
|
|
|
|
|
135
|
|
|
->expects($this->any()) |
|
136
|
|
|
->method('getBundleName') |
|
137
|
|
|
->willReturn('Bundle') |
|
138
|
|
|
; |
|
139
|
|
|
$abstractMock |
|
|
|
|
|
|
140
|
|
|
->expects($this->any()) |
|
141
|
|
|
->method('getEntityName') |
|
142
|
|
|
->willReturn('MyEntity') |
|
143
|
|
|
; |
|
144
|
|
|
|
|
145
|
|
|
return $abstractMock; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..