Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

AdminListBundle/Tests/AdminList/AdminListTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\AdminList;
4
5
use Kunstmaan\AdminListBundle\AdminList\AdminList;
6
use Kunstmaan\AdminListBundle\AdminList\BulkAction\BulkActionInterface;
7
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
8
use Kunstmaan\AdminListBundle\AdminList\FilterBuilder;
9
use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface;
10
use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface;
11
use Pagerfanta\Pagerfanta;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\HttpFoundation\Request;
14
15
class AdminListTest extends TestCase
16
{
17
    /** @var AdminList */
18
    protected $adminList;
19
20
    public function setUp()
21
    {
22
        /** @var AdminListConfiguratorInterface */
23
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
24
25
        $configurator->method('getFilterBuilder')->willReturn(new FilterBuilder());
26
        $configurator->method('getFields')->willReturn(['a', 'b']);
27
        $configurator->method('getExportFields')->willReturn(['c', 'd']);
28
        $configurator->method('getCount')->willReturn('666');
29
        $configurator->method('getItems')->willReturn(['item']);
30
        $configurator->method('getSortFields')->willReturn(['e']);
31
        $configurator->method('canEdit')->willReturn(true);
32
        $configurator->method('canAdd')->willReturn(true);
33
        $configurator->method('canView')->willReturn(true);
34
        $configurator->method('canDelete')->willReturn(true);
35
        $configurator->method('canExport')->willReturn(true);
36
        $configurator->method('getIndexUrl')->willReturn([]);
37
        $configurator->method('getEditUrlFor')->willReturn([]);
38
        $configurator->method('getDeleteUrlFor')->willReturn([]);
39
        $configurator->method('getAddUrlFor')->willReturn([]);
40
        $configurator->method('getExportUrl')->willReturn([]);
41
        $configurator->method('getViewUrlFor')->willReturn([]);
42
        $configurator->method('getValue')->willReturn('test');
43
        $configurator->method('getStringValue')->willReturn('stringtest');
44
        $configurator->method('getOrderBy')->willReturn('name');
45
        $configurator->method('getOrderDirection')->willReturn('up');
46
        $configurator->method('getItemActions')->willReturn([$this->createMock(ItemActionInterface::class)]);
47
        $configurator->method('hasItemActions')->willReturn(true);
48
        $configurator->method('getListActions')->willReturn([$this->createMock(ListActionInterface::class)]);
49
        $configurator->method('hasListActions')->willReturn(true);
50
        $configurator->method('getBulkActions')->willReturn([$this->createMock(BulkActionInterface::class)]);
51
        $configurator->method('hasBulkActions')->willReturn(true);
52
        $configurator->method('getPagerfanta')->willReturn($this->createMock(Pagerfanta::class));
53
54
        $this->adminList = new AdminList($configurator);
0 ignored issues
show
$configurator is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminLi...tConfiguratorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
    }
56
57
    public function testConstructor()
58
    {
59
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
60
61
        $configurator->expects($this->once())->method('buildFilters');
62
        $configurator->expects($this->once())->method('buildFields');
63
        $configurator->expects($this->once())->method('buildItemActions');
64
        $configurator->expects($this->once())->method('buildListActions');
65
66
        new AdminList($configurator);
67
    }
68
69
    public function testGetConfigurator()
70
    {
71
        $this->assertInstanceOf(AdminListConfiguratorInterface::class, $this->adminList->getConfigurator());
72
    }
73
74
    public function testGetFilterBuilder()
75
    {
76
        $this->assertInstanceOf(FilterBuilder::class, $this->adminList->getFilterBuilder());
77
    }
78
79
    public function testGetColumns()
80
    {
81
        $this->assertContains('a', $this->adminList->getColumns());
82
    }
83
84
    public function testGetExportColumns()
85
    {
86
        $this->assertContains('c', $this->adminList->getExportColumns());
87
    }
88
89
    public function testGetCount()
90
    {
91
        $this->assertEquals(666, $this->adminList->getCount());
92
    }
93
94
    public function testGetItems()
95
    {
96
        $this->assertContains('item', $this->adminList->getItems());
97
    }
98
99
    public function testHasSort()
100
    {
101
        $this->assertTrue($this->adminList->hasSort());
102
        $this->assertTrue($this->adminList->hasSort('e'));
103
        $this->assertFalse($this->adminList->hasSort('x'));
104
    }
105
106
    public function testHasSortWithoutColumns()
107
    {
108
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
109
        $configurator->method('getSortFields')->willReturn([]);
110
111
        $adminList = new AdminList($configurator);
112
113
        $this->assertFalse($adminList->hasSort());
114
    }
115
116
    public function testCanEdit()
117
    {
118
        $item = new \stdClass();
119
        $this->assertTrue($this->adminList->canEdit($item));
120
    }
121
122
    public function testCanAdd()
123
    {
124
        $this->assertTrue($this->adminList->canAdd());
125
    }
126
127
    public function testCanView()
128
    {
129
        $item = new \stdClass();
130
        $this->assertTrue($this->adminList->canView($item));
131
    }
132
133
    public function testCanDelete()
134
    {
135
        $item = new \stdClass();
136
        $this->assertTrue($this->adminList->canDelete($item));
137
    }
138
139
    public function testCanExport()
140
    {
141
        $this->assertTrue($this->adminList->canExport());
142
    }
143
144
    public function testGetIndexUrl()
145
    {
146
        $this->assertTrue(\is_array($this->adminList->getIndexUrl()));
147
    }
148
149
    public function testGetEditUrlFor()
150
    {
151
        $item = new \stdClass();
152
        $this->assertTrue(\is_array($this->adminList->getEditUrlFor($item)));
153
    }
154
155
    public function testGetDeleteUrlFor()
156
    {
157
        $item = new \stdClass();
158
        $this->assertTrue(\is_array($this->adminList->getDeleteUrlFor($item)));
159
    }
160
161
    public function testGetAddUrlFor()
162
    {
163
        $this->assertTrue(\is_array($this->adminList->getAddUrlFor([])));
164
    }
165
166
    public function testGetExportUrl()
167
    {
168
        $this->assertTrue(\is_array($this->adminList->getExportUrl()));
169
    }
170
171
    public function testGetViewUrl()
172
    {
173
        $item = new \stdClass();
174
        $this->assertTrue(\is_array($this->adminList->getViewUrlFor($item)));
175
    }
176
177
    public function testGetValue()
178
    {
179
        $object = new \stdClass();
180
        $this->assertEquals('test', $this->adminList->getValue($object, 'test'));
181
    }
182
183
    public function testGetStringValue()
184
    {
185
        $object = new \stdClass();
186
        $this->assertEquals('stringtest', $this->adminList->getStringValue($object, 'test'));
187
    }
188
189
    public function testGetOrderBy()
190
    {
191
        $this->assertEquals('name', $this->adminList->getOrderBy());
192
    }
193
194
    public function testGetOrderDirection()
195
    {
196
        $this->assertEquals('up', $this->adminList->getOrderDirection());
197
    }
198
199
    public function testGetItemActions()
200
    {
201
        $itemActions = $this->adminList->getItemActions();
202
        $this->assertTrue(\is_array($itemActions));
203
        $this->assertInstanceOf(ItemActionInterface::class, current($itemActions));
204
    }
205
206
    public function testHasItemActions()
207
    {
208
        $this->assertTrue($this->adminList->hasItemActions());
209
    }
210
211
    public function testHasListActions()
212
    {
213
        $this->assertTrue($this->adminList->hasListActions());
214
    }
215
216
    public function testGetListActions()
217
    {
218
        $listActions = $this->adminList->getListActions();
219
        $this->assertTrue(\is_array($listActions));
220
        $this->assertInstanceOf(ListActionInterface::class, current($listActions));
221
    }
222
223
    public function testGetBulkActions()
224
    {
225
        $bulkActions = $this->adminList->getBulkActions();
226
        $this->assertTrue(\is_array($bulkActions));
227
        $this->assertInstanceOf(BulkActionInterface::class, current($bulkActions));
228
    }
229
230
    public function testHasBulkActions()
231
    {
232
        $this->assertTrue($this->adminList->hasBulkActions());
233
    }
234
235
    public function testGetPagerfanta()
236
    {
237
        $this->assertInstanceOf(Pagerfanta::class, $this->adminList->getPagerfanta());
238
    }
239
240
    public function testBindRequest()
241
    {
242
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
243
244
        $configurator->expects($this->once())->method('bindRequest');
245
        $adminList = new AdminList($configurator);
246
247
        $adminList->bindRequest(new Request());
248
    }
249
}
250