Skip to content

Commit 4ac0e5a

Browse files
committed
use data provider for group by aggregate first
1 parent 31ce7de commit 4ac0e5a

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

tests/system/Database/Live/ModelTest.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,39 +251,40 @@ public function testFirst()
251251

252252
//--------------------------------------------------------------------
253253

254-
public function testFirstWithoutGroupBy()
254+
public function provideGroupBy()
255255
{
256-
$model = new UserModel();
257-
258-
$user = $model->select('SUM(id) as total')
259-
->where('id >', 2)
260-
->first();
261-
$this->assertEquals(7, $user->total);
256+
return [
257+
[true],
258+
[false],
259+
];
262260
}
263261

264-
//--------------------------------------------------------------------
265-
266-
public function testFirstWithGroupBy()
262+
/**
263+
* @dataProvider provideGroupBy
264+
*/
265+
public function testFirstAggregate($groupBy)
267266
{
268267
$model = new UserModel();
269268

270-
$user = $model->select('SUM(id) as total')
269+
if ($groupBy)
270+
{
271+
$user = $model->select('SUM(id) as total')
271272
->where('id >', 2)
272273
->groupBy('id')
273274
->first();
274-
$this->assertEquals(3, $user->total);
275+
$this->assertEquals(3, $user->total);
276+
}
277+
else
278+
{
279+
$user = $model->select('SUM(id) as total')
280+
->where('id >', 2)
281+
->first();
282+
$this->assertEquals(7, $user->total);
283+
}
275284
}
276285

277286
//--------------------------------------------------------------------
278287

279-
public function provideGroupBy()
280-
{
281-
return [
282-
[true],
283-
[false],
284-
];
285-
}
286-
287288
/**
288289
* @dataProvider provideGroupBy
289290
*/

0 commit comments

Comments
 (0)