diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 4332cab3cafa..c42de7d080f3 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -1785,7 +1785,9 @@ protected function batchExecute(string $renderMethod, int $batchSize = 100) } } - $this->resetWrite(); + if (! $this->testMode) { + $this->resetWrite(); + } return $this->testMode ? $savedSQL : $affectedRows; } diff --git a/tests/system/Database/Live/UpsertTest.php b/tests/system/Database/Live/UpsertTest.php index 34c3da2db794..5c3370bc9f6e 100644 --- a/tests/system/Database/Live/UpsertTest.php +++ b/tests/system/Database/Live/UpsertTest.php @@ -640,4 +640,18 @@ public function testUpsertWithMultipleSet() $this->seeInDatabase('user', ['email' => 'jarvis@example.com', 'name' => 'Jarvis', 'country' => $dt]); } + + public function testUpsertWithTestModeAndGetCompiledUpsert() + { + $userData = [ + 'email' => 'upsertone@test.com', + 'name' => 'Upsert One', + 'country' => 'US', + ]; + $builder = $this->db->table('user'); + $builder->testMode()->upsert($userData); + $sql = $builder->getCompiledUpsert(); + + $this->assertStringContainsString('upsertone@test.com', $sql); + } }