Skip to content

Commit 2841f01

Browse files
committed
Restructure tests to improve readability
1 parent cc6abaf commit 2841f01

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

tests/Unit/DataTableTest.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
*/
1010

1111
declare(strict_types=1);
12-
/*
13-
* Symfony DataTables Bundle
14-
* (c) Omines Internetbureau B.V. - https://omines.nl/
15-
*
16-
* For the full copyright and license information, please view the LICENSE
17-
* file that was distributed with this source code.
18-
*/
1912

2013
namespace Tests\Unit;
2114

@@ -78,7 +71,7 @@ public function testFactoryRemembersInstances()
7871

7972
public function testDataTableState()
8073
{
81-
$datatable = new DataTable($this->createMock(EventDispatcher::class));
74+
$datatable = $this->createMockDataTable();
8275
$datatable->add('foo', TextColumn::class)->setMethod(Request::METHOD_GET);
8376
$datatable->handleRequest(Request::create('/?_dt=' . $datatable->getName()));
8477
$state = $datatable->getState();
@@ -104,7 +97,7 @@ public function testDataTableState()
10497

10598
public function testPostMethod()
10699
{
107-
$datatable = new DataTable($this->createMock(EventDispatcher::class));
100+
$datatable = $this->createMockDataTable();
108101
$datatable->handleRequest(Request::create('/foo', Request::METHOD_POST, ['_dt' => $datatable->getName(), 'draw' => 684]));
109102

110103
$this->assertSame(684, $datatable->getState()->getDraw());
@@ -129,23 +122,23 @@ public function testFactoryFailsOnInvalidType()
129122
*/
130123
public function testInvalidOption()
131124
{
132-
new DataTable($this->createMock(EventDispatcher::class), ['option' => 'bar']);
125+
$this->createMockDataTable(['option' => 'bar']);
133126
}
134127

135128
/**
136129
* @expectedException \InvalidArgumentException
137130
*/
138131
public function testDataTableInvalidColumn()
139132
{
140-
(new DataTable($this->createMock(EventDispatcher::class)))->getColumn(5);
133+
$this->createMockDataTable()->getColumn(5);
141134
}
142135

143136
/**
144137
* @expectedException \InvalidArgumentException
145138
*/
146139
public function testDataTableInvalidColumnByName()
147140
{
148-
(new DataTable($this->createMock(EventDispatcher::class)))->getColumnByName('foo');
141+
$this->createMockDataTable()->getColumnByName('foo');
149142
}
150143

151144
/**
@@ -154,7 +147,7 @@ public function testDataTableInvalidColumnByName()
154147
*/
155148
public function testDuplicateColumnNameThrows()
156149
{
157-
(new DataTable($this->createMock(EventDispatcher::class)))
150+
$this->createMockDataTable()
158151
->add('foo', TextColumn::class)
159152
->add('foo', TextColumn::class)
160153
;
@@ -166,9 +159,7 @@ public function testDuplicateColumnNameThrows()
166159
*/
167160
public function testInvalidAdapterThrows()
168161
{
169-
(new DataTable($this->createMock(EventDispatcher::class)))
170-
->createAdapter('foo\bar')
171-
;
162+
$this->createMockDataTable()->createAdapter('foo\bar');
172163
}
173164

174165
/**
@@ -177,8 +168,7 @@ public function testInvalidAdapterThrows()
177168
*/
178169
public function testInvalidColumnThrows()
179170
{
180-
(new DataTable($this->createMock(EventDispatcher::class)))
181-
->add('foo', 'bar');
171+
$this->createMockDataTable()->add('foo', 'bar');
182172
}
183173

184174
/**
@@ -187,7 +177,7 @@ public function testInvalidColumnThrows()
187177
*/
188178
public function testMissingAdapterThrows()
189179
{
190-
$datatable = new DataTable($this->createMock(EventDispatcher::class));
180+
$datatable = $this->createMockDataTable();
191181
$datatable
192182
->setMethod(Request::METHOD_GET)
193183
->handleRequest(Request::create('/?_dt=' . $datatable->getName()))
@@ -201,7 +191,7 @@ public function testMissingAdapterThrows()
201191
*/
202192
public function testEmptyNameThrows()
203193
{
204-
(new DataTable($this->createMock(EventDispatcher::class)))->setName('');
194+
$this->createMockDataTable()->setName('');
205195
}
206196

207197
/**
@@ -210,7 +200,7 @@ public function testEmptyNameThrows()
210200
*/
211201
public function testStateWillNotProcessInvalidMethod()
212202
{
213-
$datatable = new DataTable($this->createMock(EventDispatcher::class));
203+
$datatable = $this->createMockDataTable();
214204
$datatable->setMethod(Request::METHOD_OPTIONS);
215205
$datatable->handleRequest(Request::create('/foo'));
216206
}
@@ -221,8 +211,7 @@ public function testStateWillNotProcessInvalidMethod()
221211
*/
222212
public function testMissingStateThrows()
223213
{
224-
(new DataTable($this->createMock(EventDispatcher::class)))
225-
->getResponse();
214+
$this->createMockDataTable()->getResponse();
226215
}
227216

228217
/**
@@ -234,4 +223,9 @@ public function testInvalidDataTableTypeThrows()
234223
(new DataTableFactory([], $this->createMock(DataTableRendererInterface::class), new Instantiator(), $this->createMock(EventDispatcher::class)))
235224
->createFromType('foo');
236225
}
226+
227+
private function createMockDataTable(array $options = [])
228+
{
229+
return new DataTable($this->createMock(EventDispatcher::class), $options);
230+
}
237231
}

0 commit comments

Comments
 (0)