DataTablesWrapperTest::testSetOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Model;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesColumnInterface;
15
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesMappingInterface;
16
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesOptionsInterface;
17
use WBW\Bundle\JQuery\DataTablesBundle\Model\DataTablesWrapper;
18
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface;
19
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase;
20
21
/**
22
 * DataTables wrapper test.
23
 *
24
 * @author webeweb <https://github.com/webeweb>
25
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Model
26
 */
27
class DataTablesWrapperTest extends AbstractTestCase {
28
29
    /**
30
     * Test addColumn()
31
     *
32
     * @return void
33
     */
34
    public function testAddColumn(): void {
35
36
        // Set a DataTables mapping mock.
37
        $map = $this->getMockBuilder(DataTablesMappingInterface::class)->getMock();
38
39
        // Set a DataTables column mock.
40
        $col = $this->getMockBuilder(DataTablesColumnInterface::class)->getMock();
41
        $col->expects($this->any())->method("getData")->willReturn("col");
42
        $col->expects($this->any())->method("getMapping")->willReturn($map);
43
44
        $obj = new DataTablesWrapper();
45
46
        $this->assertSame($obj, $obj->addColumn($this->dtColumn));
0 ignored issues
show
Bug introduced by
It seems like $this->dtColumn can also be of type null; however, parameter $column of WBW\Bundle\JQuery\DataTa...lesWrapper::addColumn() does only seem to accept WBW\Bundle\JQuery\DataTa...taTablesColumnInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->assertSame($obj, $obj->addColumn(/** @scrutinizer ignore-type */ $this->dtColumn));
Loading history...
47
        $this->assertCount(1, $obj->getColumns());
48
        $this->assertSame($this->dtColumn, $obj->getColumns()["data"]);
49
50
        $this->assertSame($obj, $obj->addColumn($col));
51
        $this->assertCount(2, $obj->getColumns());
52
        $this->assertSame($col, $obj->getColumns()["col"]);
53
    }
54
55
    /**
56
     * Test getColumn()
57
     *
58
     * @return void
59
     */
60
    public function testGetColumn(): void {
61
62
        $obj = new DataTablesWrapper();
63
64
        $this->assertNull($obj->getColumn("data"));
65
66
        $this->assertSame($obj, $obj->addColumn($this->dtColumn));
0 ignored issues
show
Bug introduced by
It seems like $this->dtColumn can also be of type null; however, parameter $column of WBW\Bundle\JQuery\DataTa...lesWrapper::addColumn() does only seem to accept WBW\Bundle\JQuery\DataTa...taTablesColumnInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        $this->assertSame($obj, $obj->addColumn(/** @scrutinizer ignore-type */ $this->dtColumn));
Loading history...
67
        $this->assertSame($this->dtColumn, $obj->getColumn("data"));
68
    }
69
70
    /**
71
     * Test removeColumn()
72
     *
73
     * @return void
74
     */
75
    public function testRemoveColumn(): void {
76
77
        // Set a DataTables column mock.
78
        $col = $this->getMockBuilder(DataTablesColumnInterface::class)->getMock();
79
        $col->expects($this->any())->method("getData")->willReturn("col");
80
        $col->expects($this->any())->method("getMapping")->willReturn($this->dtMapping);
81
82
        $obj = new DataTablesWrapper();
83
84
        $this->assertSame($obj, $obj->addColumn($this->dtColumn));
0 ignored issues
show
Bug introduced by
It seems like $this->dtColumn can also be of type null; however, parameter $column of WBW\Bundle\JQuery\DataTa...lesWrapper::addColumn() does only seem to accept WBW\Bundle\JQuery\DataTa...taTablesColumnInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
        $this->assertSame($obj, $obj->addColumn(/** @scrutinizer ignore-type */ $this->dtColumn));
Loading history...
85
        $this->assertSame($obj, $obj->addColumn($col));
86
        $this->assertCount(2, $obj->getColumns());
87
88
        $this->assertSame($obj, $obj->removeColumn($col));
89
        $this->assertCount(1, $obj->getColumns());
90
91
        $this->assertSame($obj, $obj->removeColumn($this->dtColumn));
0 ignored issues
show
Bug introduced by
It seems like $this->dtColumn can also be of type null; however, parameter $column of WBW\Bundle\JQuery\DataTa...Wrapper::removeColumn() does only seem to accept WBW\Bundle\JQuery\DataTa...taTablesColumnInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
        $this->assertSame($obj, $obj->removeColumn(/** @scrutinizer ignore-type */ $this->dtColumn));
Loading history...
92
        $this->assertCount(0, $obj->getColumns());
93
    }
94
95
    /**
96
     * Test setMethod()
97
     *
98
     * @return void
99
     */
100
    public function testSetMethod(): void {
101
102
        $obj = new DataTablesWrapper();
103
104
        $obj->setMethod("exception");
105
        $this->assertEquals("POST", $obj->getMethod());
106
107
        $obj->setMethod("GET");
108
        $this->assertEquals("GET", $obj->getMethod());
109
    }
110
111
    /**
112
     * Test setOptions()
113
     *
114
     * @return void
115
     */
116
    public function testSetOptions(): void {
117
118
        // Set a DataTables options mock.
119
        $arg = $this->getMockBuilder(DataTablesOptionsInterface::class)->getMock();
120
121
        $obj = new DataTablesWrapper();
122
123
        $obj->setOptions($arg);
124
        $this->assertSame($arg, $obj->getOptions());
125
    }
126
127
    /**
128
     * Test setProcessing()
129
     *
130
     * @return void
131
     */
132
    public function testSetProcessing(): void {
133
134
        $obj = new DataTablesWrapper();
135
136
        $obj->setProcessing(null);
137
        $this->assertTrue($obj->getProcessing());
138
139
        $obj->setProcessing(false);
140
        $this->assertFalse($obj->getProcessing());
141
    }
142
143
    /**
144
     * Test setProvider()
145
     *
146
     * @return void
147
     */
148
    public function testSetProvider(): void {
149
150
        // Set a DataTables provider mock.
151
        $arg = $this->getMockBuilder(DataTablesProviderInterface::class)->getMock();
152
        $arg->expects($this->any())->method("getName")->willReturn("name");
153
154
        $obj = new DataTablesWrapper();
155
156
        $obj->setProvider($arg);
157
        $this->assertSame($arg, $obj->getProvider());
158
    }
159
160
    /**
161
     * Test setRequest()
162
     *
163
     * @return void
164
     */
165
    public function testSetRequest(): void {
166
167
        $obj = new DataTablesWrapper();
168
169
        $obj->setRequest($this->dtRequest);
170
        $this->assertSame($this->dtRequest, $obj->getRequest());
171
    }
172
173
    /**
174
     * Test setResponse()
175
     *
176
     * @return void
177
     */
178
    public function testSetResponse(): void {
179
180
        $obj = new DataTablesWrapper();
181
182
        $obj->setResponse($this->dtResponse);
183
        $this->assertSame($this->dtResponse, $obj->getResponse());
184
    }
185
186
    /**
187
     * Test setServerSide()
188
     *
189
     * @return void
190
     */
191
    public function testSetServerSide(): void {
192
193
        $obj = new DataTablesWrapper();
194
195
        $obj->setServerSide(false);
196
        $this->assertFalse($obj->getServerSide());
197
198
        $obj->setServerSide(null);
199
        $this->assertTrue($obj->getServerSide());
200
    }
201
202
    /**
203
     * Test setUrl()
204
     *
205
     * @return void
206
     */
207
    public function testSetUrl(): void {
208
209
        $obj = new DataTablesWrapper();
210
211
        $obj->setUrl("anotherUrl");
212
        $this->assertEquals("anotherUrl", $obj->getUrl());
213
    }
214
215
    /**
216
     * Test __construct()
217
     *
218
     * @return void
219
     */
220
    public function test__construct(): void {
221
222
        $obj = new DataTablesWrapper();
223
224
        $this->assertEquals([], $obj->getColumns());
225
        $this->assertNull($obj->getMapping()->getPrefix());
226
        $this->assertEquals("POST", $obj->getMethod());
227
        $this->assertNull($obj->getOptions());
228
        $this->assertTrue($obj->getProcessing());
229
        $this->assertNull($obj->getProvider());
230
        $this->assertNull($obj->getRequest());
231
        $this->assertNull($obj->getResponse());
232
        $this->assertTrue($obj->getServerSide());
233
        $this->assertNull($obj->getUrl());
234
    }
235
}
236