12
12
13
13
class ModelAggregateTest extends TestCase
14
14
{
15
- /** @var array */
16
- private $ init_db =
17
- [
15
+ protected function setUp (): void
16
+ {
17
+ parent ::setUp ();
18
+
19
+ $ this ->setDb ([
18
20
'client ' => [
19
21
// allow of migrator to create all columns
20
22
['name ' => 'Vinny ' , 'surname ' => null , 'order ' => null ],
@@ -29,12 +31,7 @@ class ModelAggregateTest extends TestCase
29
31
['client_id ' => 1 , 'name ' => 'prepay ' , 'amount ' => 10.0 ],
30
32
['client_id ' => 2 , 'name ' => 'full pay ' , 'amount ' => 4.0 ],
31
33
],
32
- ];
33
-
34
- protected function setUp (): void
35
- {
36
- parent ::setUp ();
37
- $ this ->setDb ($ this ->init_db );
34
+ ]);
38
35
}
39
36
40
37
/**
@@ -61,7 +58,9 @@ protected function createInvoiceAggregate(): AggregateModel
61
58
62
59
public function testGroupBy (): void
63
60
{
64
- $ aggregate = (new AggregateModel ($ this ->createInvoice ()))->setGroupBy (['client_id ' ], [
61
+ $ aggregate = $ this ->createInvoiceAggregate ();
62
+
63
+ $ aggregate ->setGroupBy (['client_id ' ], [
65
64
'c ' => ['expr ' => 'count(*) ' , 'type ' => 'integer ' ],
66
65
]);
67
66
@@ -180,12 +179,9 @@ public function testGroupSelectCondition2(): void
180
179
$ this ->getDatabasePlatform () instanceof SqlitePlatform ? $ aggregate ->expr ('10 ' ) : 10
181
180
);
182
181
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 ());
189
185
}
190
186
191
187
public function testGroupSelectCondition3 (): void
@@ -206,12 +202,9 @@ public function testGroupSelectCondition3(): void
206
202
$ this ->getDatabasePlatform () instanceof SqlitePlatform ? $ aggregate ->expr ('38 ' ) : 38
207
203
);
208
204
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 ());
215
208
}
216
209
217
210
public function testGroupSelectCondition4 (): void
@@ -228,12 +221,9 @@ public function testGroupSelectCondition4(): void
228
221
$ aggregate ->addExpression ('double ' , ['expr ' => '[s] + [amount] ' , 'type ' => 'atk4_money ' ]);
229
222
$ aggregate ->addCondition ('client_id ' , 2 );
230
223
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 ());
237
227
}
238
228
239
229
public function testGroupSelectScope (): void
@@ -251,15 +241,12 @@ public function testGroupSelectScope(): void
251
241
$ scope = Scope::createAnd (new Condition ('client_id ' , 2 ), new Condition ('amount ' , $ numExpr ));
252
242
$ aggregate ->addCondition ($ scope );
253
243
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 ());
260
247
}
261
248
262
- public function testGroupOrder (): void
249
+ public function testGroupOrderSql (): void
263
250
{
264
251
$ aggregate = $ this ->createInvoiceAggregate ();
265
252
$ aggregate ->addField ('client ' );
@@ -295,13 +282,11 @@ public function testGroupLimit(): void
295
282
]);
296
283
self ::fixAllNonAggregatedFieldsInGroupBy ($ aggregate );
297
284
$ aggregate ->setLimit (1 );
285
+ $ aggregate ->setOrder ('client_id ' , 'asc ' );
298
286
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 ());
305
290
}
306
291
307
292
public function testGroupLimit2 (): void
@@ -314,16 +299,14 @@ public function testGroupLimit2(): void
314
299
]);
315
300
self ::fixAllNonAggregatedFieldsInGroupBy ($ aggregate );
316
301
$ aggregate ->setLimit (2 , 1 );
302
+ $ aggregate ->setOrder ('client_id ' , 'asc ' );
317
303
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 ());
324
307
}
325
308
326
- public function testGroupCount (): void
309
+ public function testGroupCountSql (): void
327
310
{
328
311
$ aggregate = $ this ->createInvoiceAggregate ();
329
312
$ aggregate ->addField ('client ' );
@@ -339,7 +322,7 @@ public function testGroupCount(): void
339
322
);
340
323
}
341
324
342
- public function testAggregateFieldExpression (): void
325
+ public function testAggregateFieldExpressionSql (): void
343
326
{
344
327
$ aggregate = $ this ->createInvoiceAggregate ();
345
328
0 commit comments