From 31ce7dea8130e86e6bebdc56d4714aa5fe558304 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 1 May 2020 03:09:42 +0700 Subject: [PATCH] tests for withdeleted on group by --- tests/system/Database/Live/ModelTest.php | 56 +++++++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index b47a116a0ba7..9f65cfd1e95c 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -276,23 +276,47 @@ public function testFirstWithGroupBy() //-------------------------------------------------------------------- - public function testFirstRespectsSoftDeletes() + public function provideGroupBy() + { + return [ + [true], + [false], + ]; + } + + /** + * @dataProvider provideGroupBy + */ + public function testFirstRespectsSoftDeletes($groupBy) { $this->db->table('user') ->where('id', 1) ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model = new UserModel(); - - $user = $model->first(); + if ($groupBy) + { + $user = $model->groupBy('id')->first(); + } + else + { + $user = $model->first(); + } // fix for PHP7.2 $count = is_array($user) ? count($user) : 1; $this->assertEquals(1, $count); $this->assertEquals(2, $user->id); - $user = $model->withDeleted() - ->first(); + $user = $model->withDeleted(); + if ($groupBy) + { + $user = $model->groupBy('id')->first(); + } + else + { + $user = $model->first(); + } $this->assertEquals(1, $user->id); } @@ -1900,13 +1924,31 @@ public function testUndefinedMethodInBuilder() ->getBindings(); } - public function testFirstRecoverTempUseSoftDeletes() + /** + * @dataProvider provideGroupBy + */ + public function testFirstRecoverTempUseSoftDeletes($groupBy) { $model = new UserModel($this->db); $model->delete(1); - $user = $model->withDeleted()->first(); + if ($groupBy) + { + $user = $model->groupBy('id')->withDeleted()->first(); + } + else + { + $user = $model->withDeleted()->first(); + } $this->assertEquals(1, $user->id); $user2 = $model->first(); + if ($groupBy) + { + $user2 = $model->groupBy('id')->first(); + } + else + { + $user2 = $model->first(); + } $this->assertEquals(2, $user2->id); }