Completed
Push — master ( 1dc6e5...73a7e8 )
by Jeroen
07:06 queued 20s
created

AdminListTest::testBindRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
/**
16
 * Class AdminListTest
17
 */
18
class AdminListTest extends TestCase
19
{
20
    /** @var AdminList */
21
    protected $adminList;
22
23
    public function setUp()
24
    {
25
        /** @var AdminListConfiguratorInterface */
26
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
27
28
        $configurator->method('getFilterBuilder')->willReturn(new FilterBuilder());
29
        $configurator->method('getFields')->willReturn(['a', 'b']);
30
        $configurator->method('getExportFields')->willReturn(['c', 'd']);
31
        $configurator->method('getCount')->willReturn('666');
32
        $configurator->method('getItems')->willReturn(['item']);
33
        $configurator->method('getSortFields')->willReturn(['e']);
34
        $configurator->method('canEdit')->willReturn(true);
35
        $configurator->method('canAdd')->willReturn(true);
36
        $configurator->method('canView')->willReturn(true);
37
        $configurator->method('canDelete')->willReturn(true);
38
        $configurator->method('canExport')->willReturn(true);
39
        $configurator->method('getIndexUrl')->willReturn([]);
40
        $configurator->method('getEditUrlFor')->willReturn([]);
41
        $configurator->method('getDeleteUrlFor')->willReturn([]);
42
        $configurator->method('getAddUrlFor')->willReturn([]);
43
        $configurator->method('getExportUrl')->willReturn([]);
44
        $configurator->method('getViewUrlFor')->willReturn([]);
45
        $configurator->method('getValue')->willReturn('test');
46
        $configurator->method('getStringValue')->willReturn('stringtest');
47
        $configurator->method('getOrderBy')->willReturn('name');
48
        $configurator->method('getOrderDirection')->willReturn('up');
49
        $configurator->method('getItemActions')->willReturn([$this->createMock(ItemActionInterface::class)]);
50
        $configurator->method('hasItemActions')->willReturn(true);
51
        $configurator->method('getListActions')->willReturn([$this->createMock(ListActionInterface::class)]);
52
        $configurator->method('hasListActions')->willReturn(true);
53
        $configurator->method('getBulkActions')->willReturn([$this->createMock(BulkActionInterface::class)]);
54
        $configurator->method('hasBulkActions')->willReturn(true);
55
        $configurator->method('getPagerfanta')->willReturn($this->createMock(Pagerfanta::class));
56
57
        $this->adminList = new AdminList($configurator);
0 ignored issues
show
Documentation introduced by
$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...
58
    }
59
60
    public function testConstructor()
61
    {
62
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
63
64
        $configurator->expects($this->once())->method('buildFilters');
65
        $configurator->expects($this->once())->method('buildFields');
66
        $configurator->expects($this->once())->method('buildItemActions');
67
        $configurator->expects($this->once())->method('buildListActions');
68
69
        new AdminList($configurator);
0 ignored issues
show
Documentation introduced by
$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...
70
    }
71
72
    public function testGetConfigurator()
73
    {
74
        $this->assertInstanceOf(AdminListConfiguratorInterface::class, $this->adminList->getConfigurator());
75
    }
76
77
    public function testGetFilterBuilder()
78
    {
79
        $this->assertInstanceOf(FilterBuilder::class, $this->adminList->getFilterBuilder());
80
    }
81
82
    public function testGetColumns()
83
    {
84
        $this->assertContains('a', $this->adminList->getColumns());
85
    }
86
87
    public function testGetExportColumns()
88
    {
89
        $this->assertContains('c', $this->adminList->getExportColumns());
90
    }
91
92
    public function testGetCount()
93
    {
94
        $this->assertEquals(666, $this->adminList->getCount());
95
    }
96
97
    public function testGetItems()
98
    {
99
        $this->assertContains('item', $this->adminList->getItems());
100
    }
101
102
    public function testHasSort()
103
    {
104
        $this->assertTrue($this->adminList->hasSort());
105
        $this->assertTrue($this->adminList->hasSort('e'));
106
        $this->assertFalse($this->adminList->hasSort('x'));
107
    }
108
109
    public function testHasSortWithoutColumns()
110
    {
111
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
112
        $configurator->method('getSortFields')->willReturn([]);
113
114
        $adminList = new AdminList($configurator);
0 ignored issues
show
Documentation introduced by
$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...
115
116
        $this->assertFalse($adminList->hasSort());
117
    }
118
119
    public function testCanEdit()
120
    {
121
        $item = new \stdClass();
122
        $this->assertTrue($this->adminList->canEdit($item));
123
    }
124
125
    public function testCanAdd()
126
    {
127
        $this->assertTrue($this->adminList->canAdd());
128
    }
129
130
    public function testCanView()
131
    {
132
        $item = new \stdClass();
133
        $this->assertTrue($this->adminList->canView($item));
134
    }
135
136
    public function testCanDelete()
137
    {
138
        $item = new \stdClass();
139
        $this->assertTrue($this->adminList->canDelete($item));
140
    }
141
142
    public function testCanExport()
143
    {
144
        $this->assertTrue($this->adminList->canExport());
145
    }
146
147
    public function testGetIndexUrl()
148
    {
149
        $this->assertTrue(\is_array($this->adminList->getIndexUrl()));
150
    }
151
152
    public function testGetEditUrlFor()
153
    {
154
        $item = new \stdClass();
155
        $this->assertTrue(\is_array($this->adminList->getEditUrlFor($item)));
156
    }
157
158
    public function testGetDeleteUrlFor()
159
    {
160
        $item = new \stdClass();
161
        $this->assertTrue(\is_array($this->adminList->getDeleteUrlFor($item)));
162
    }
163
164
    public function testGetAddUrlFor()
165
    {
166
        $this->assertTrue(\is_array($this->adminList->getAddUrlFor([])));
167
    }
168
169
    public function testGetExportUrl()
170
    {
171
        $this->assertTrue(\is_array($this->adminList->getExportUrl()));
172
    }
173
174
    public function testGetViewUrl()
175
    {
176
        $item = new \stdClass();
177
        $this->assertTrue(\is_array($this->adminList->getViewUrlFor($item)));
178
    }
179
180
    public function testGetValue()
181
    {
182
        $object = new \stdClass();
183
        $this->assertEquals('test', $this->adminList->getValue($object, 'test'));
184
    }
185
186
    public function testGetStringValue()
187
    {
188
        $object = new \stdClass();
189
        $this->assertEquals('stringtest', $this->adminList->getStringValue($object, 'test'));
190
    }
191
192
    public function testGetOrderBy()
193
    {
194
        $this->assertEquals('name', $this->adminList->getOrderBy());
195
    }
196
197
    public function testGetOrderDirection()
198
    {
199
        $this->assertEquals('up', $this->adminList->getOrderDirection());
200
    }
201
202
    public function testGetItemActions()
203
    {
204
        $itemActions = $this->adminList->getItemActions();
205
        $this->assertTrue(\is_array($itemActions));
206
        $this->assertInstanceOf(ItemActionInterface::class, current($itemActions));
207
    }
208
209
    public function testHasItemActions()
210
    {
211
        $this->assertTrue($this->adminList->hasItemActions());
212
    }
213
214
    public function testHasListActions()
215
    {
216
        $this->assertTrue($this->adminList->hasListActions());
217
    }
218
219
    public function testGetListActions()
220
    {
221
        $listActions = $this->adminList->getListActions();
222
        $this->assertTrue(\is_array($listActions));
223
        $this->assertInstanceOf(ListActionInterface::class, current($listActions));
224
    }
225
226
    public function testGetBulkActions()
227
    {
228
        $bulkActions = $this->adminList->getBulkActions();
229
        $this->assertTrue(\is_array($bulkActions));
230
        $this->assertInstanceOf(BulkActionInterface::class, current($bulkActions));
231
    }
232
233
    public function testHasBulkActions()
234
    {
235
        $this->assertTrue($this->adminList->hasBulkActions());
236
    }
237
238
    public function testGetPagerfanta()
239
    {
240
        $this->assertInstanceOf(Pagerfanta::class, $this->adminList->getPagerfanta());
241
    }
242
243
    public function testBindRequest()
244
    {
245
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
246
247
        $configurator->expects($this->once())->method('bindRequest');
248
        $adminList = new AdminList($configurator);
0 ignored issues
show
Documentation introduced by
$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...
249
250
        $adminList->bindRequest(new Request());
251
    }
252
}
253