Skip to content

Commit 95af333

Browse files
committed
compact test code
1 parent a46433d commit 95af333

File tree

1 file changed

+32
-49
lines changed

1 file changed

+32
-49
lines changed

tests/ModelAggregateTest.php

+32-49
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
class ModelAggregateTest extends TestCase
1414
{
15-
/** @var array */
16-
private $init_db =
17-
[
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->setDb([
1820
'client' => [
1921
// allow of migrator to create all columns
2022
['name' => 'Vinny', 'surname' => null, 'order' => null],
@@ -29,12 +31,7 @@ class ModelAggregateTest extends TestCase
2931
['client_id' => 1, 'name' => 'prepay', 'amount' => 10.0],
3032
['client_id' => 2, 'name' => 'full pay', 'amount' => 4.0],
3133
],
32-
];
33-
34-
protected function setUp(): void
35-
{
36-
parent::setUp();
37-
$this->setDb($this->init_db);
34+
]);
3835
}
3936

4037
/**
@@ -61,7 +58,9 @@ protected function createInvoiceAggregate(): AggregateModel
6158

6259
public function testGroupBy(): void
6360
{
64-
$aggregate = (new AggregateModel($this->createInvoice()))->setGroupBy(['client_id'], [
61+
$aggregate = $this->createInvoiceAggregate();
62+
63+
$aggregate->setGroupBy(['client_id'], [
6564
'c' => ['expr' => 'count(*)', 'type' => 'integer'],
6665
]);
6766

@@ -180,12 +179,9 @@ public function testGroupSelectCondition2(): void
180179
$this->getDatabasePlatform() instanceof SqlitePlatform ? $aggregate->expr('10') : 10
181180
);
182181

183-
$this->assertSame(
184-
[
185-
['client' => 'Vinny', 'client_id' => 1, 's' => 19.0, 'amount' => 19.0, 'double' => 38.0],
186-
],
187-
$aggregate->export()
188-
);
182+
$this->assertSame([
183+
['client' => 'Vinny', 'client_id' => 1, 's' => 19.0, 'amount' => 19.0, 'double' => 38.0],
184+
], $aggregate->export());
189185
}
190186

191187
public function testGroupSelectCondition3(): void
@@ -206,12 +202,9 @@ public function testGroupSelectCondition3(): void
206202
$this->getDatabasePlatform() instanceof SqlitePlatform ? $aggregate->expr('38') : 38
207203
);
208204

209-
$this->assertSame(
210-
[
211-
['client' => 'Vinny', 'client_id' => 1, 's' => 19.0, 'amount' => 19.0, 'double' => 38.0],
212-
],
213-
$aggregate->export()
214-
);
205+
$this->assertSame([
206+
['client' => 'Vinny', 'client_id' => 1, 's' => 19.0, 'amount' => 19.0, 'double' => 38.0],
207+
], $aggregate->export());
215208
}
216209

217210
public function testGroupSelectCondition4(): void
@@ -228,12 +221,9 @@ public function testGroupSelectCondition4(): void
228221
$aggregate->addExpression('double', ['expr' => '[s] + [amount]', 'type' => 'atk4_money']);
229222
$aggregate->addCondition('client_id', 2);
230223

231-
$this->assertSame(
232-
[
233-
['client' => 'Zoe', 'client_id' => 2, 's' => 4.0, 'amount' => 4.0, 'double' => 8.0],
234-
],
235-
$aggregate->export()
236-
);
224+
$this->assertSame([
225+
['client' => 'Zoe', 'client_id' => 2, 's' => 4.0, 'amount' => 4.0, 'double' => 8.0],
226+
], $aggregate->export());
237227
}
238228

239229
public function testGroupSelectScope(): void
@@ -251,15 +241,12 @@ public function testGroupSelectScope(): void
251241
$scope = Scope::createAnd(new Condition('client_id', 2), new Condition('amount', $numExpr));
252242
$aggregate->addCondition($scope);
253243

254-
$this->assertSame(
255-
[
256-
['client' => 'Zoe', 'client_id' => 2, 'amount' => 4.0],
257-
],
258-
$aggregate->export()
259-
);
244+
$this->assertSame([
245+
['client' => 'Zoe', 'client_id' => 2, 'amount' => 4.0],
246+
], $aggregate->export());
260247
}
261248

262-
public function testGroupOrder(): void
249+
public function testGroupOrderSql(): void
263250
{
264251
$aggregate = $this->createInvoiceAggregate();
265252
$aggregate->addField('client');
@@ -295,13 +282,11 @@ public function testGroupLimit(): void
295282
]);
296283
self::fixAllNonAggregatedFieldsInGroupBy($aggregate);
297284
$aggregate->setLimit(1);
285+
$aggregate->setOrder('client_id', 'asc');
298286

299-
$this->assertSame(
300-
[
301-
['client' => 'Vinny', 'client_id' => 1, 'amount' => 19.0],
302-
],
303-
$aggregate->setOrder('client_id', 'asc')->export()
304-
);
287+
$this->assertSame([
288+
['client' => 'Vinny', 'client_id' => 1, 'amount' => 19.0],
289+
], $aggregate->export());
305290
}
306291

307292
public function testGroupLimit2(): void
@@ -314,16 +299,14 @@ public function testGroupLimit2(): void
314299
]);
315300
self::fixAllNonAggregatedFieldsInGroupBy($aggregate);
316301
$aggregate->setLimit(2, 1);
302+
$aggregate->setOrder('client_id', 'asc');
317303

318-
$this->assertSame(
319-
[
320-
['client' => 'Zoe', 'client_id' => 2, 'amount' => 4.0],
321-
],
322-
$aggregate->setOrder('client_id', 'asc')->export()
323-
);
304+
$this->assertSame([
305+
['client' => 'Zoe', 'client_id' => 2, 'amount' => 4.0],
306+
], $aggregate->export());
324307
}
325308

326-
public function testGroupCount(): void
309+
public function testGroupCountSql(): void
327310
{
328311
$aggregate = $this->createInvoiceAggregate();
329312
$aggregate->addField('client');
@@ -339,7 +322,7 @@ public function testGroupCount(): void
339322
);
340323
}
341324

342-
public function testAggregateFieldExpression(): void
325+
public function testAggregateFieldExpressionSql(): void
343326
{
344327
$aggregate = $this->createInvoiceAggregate();
345328

0 commit comments

Comments
 (0)