Skip to content

Commit 31ce7de

Browse files
committed
tests for withdeleted on group by
1 parent 5a06e0e commit 31ce7de

1 file changed

Lines changed: 49 additions & 7 deletions

File tree

tests/system/Database/Live/ModelTest.php

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,23 +276,47 @@ public function testFirstWithGroupBy()
276276

277277
//--------------------------------------------------------------------
278278

279-
public function testFirstRespectsSoftDeletes()
279+
public function provideGroupBy()
280+
{
281+
return [
282+
[true],
283+
[false],
284+
];
285+
}
286+
287+
/**
288+
* @dataProvider provideGroupBy
289+
*/
290+
public function testFirstRespectsSoftDeletes($groupBy)
280291
{
281292
$this->db->table('user')
282293
->where('id', 1)
283294
->update(['deleted_at' => date('Y-m-d H:i:s')]);
284295

285296
$model = new UserModel();
286-
287-
$user = $model->first();
297+
if ($groupBy)
298+
{
299+
$user = $model->groupBy('id')->first();
300+
}
301+
else
302+
{
303+
$user = $model->first();
304+
}
288305

289306
// fix for PHP7.2
290307
$count = is_array($user) ? count($user) : 1;
291308
$this->assertEquals(1, $count);
292309
$this->assertEquals(2, $user->id);
293310

294-
$user = $model->withDeleted()
295-
->first();
311+
$user = $model->withDeleted();
312+
if ($groupBy)
313+
{
314+
$user = $model->groupBy('id')->first();
315+
}
316+
else
317+
{
318+
$user = $model->first();
319+
}
296320

297321
$this->assertEquals(1, $user->id);
298322
}
@@ -1900,13 +1924,31 @@ public function testUndefinedMethodInBuilder()
19001924
->getBindings();
19011925
}
19021926

1903-
public function testFirstRecoverTempUseSoftDeletes()
1927+
/**
1928+
* @dataProvider provideGroupBy
1929+
*/
1930+
public function testFirstRecoverTempUseSoftDeletes($groupBy)
19041931
{
19051932
$model = new UserModel($this->db);
19061933
$model->delete(1);
1907-
$user = $model->withDeleted()->first();
1934+
if ($groupBy)
1935+
{
1936+
$user = $model->groupBy('id')->withDeleted()->first();
1937+
}
1938+
else
1939+
{
1940+
$user = $model->withDeleted()->first();
1941+
}
19081942
$this->assertEquals(1, $user->id);
19091943
$user2 = $model->first();
1944+
if ($groupBy)
1945+
{
1946+
$user2 = $model->groupBy('id')->first();
1947+
}
1948+
else
1949+
{
1950+
$user2 = $model->first();
1951+
}
19101952
$this->assertEquals(2, $user2->id);
19111953
}
19121954

0 commit comments

Comments
 (0)