Skip to content

Commit b166875

Browse files
authored
Merge pull request #6697 from sclubricants/FixTestModeWithUpsert
Fix testMode() with upsert() and getCompiledUpsert()
2 parents ebb8e26 + f7ef247 commit b166875

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

system/Database/BaseBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,9 @@ protected function batchExecute(string $renderMethod, int $batchSize = 100)
17851785
}
17861786
}
17871787

1788-
$this->resetWrite();
1788+
if (! $this->testMode) {
1789+
$this->resetWrite();
1790+
}
17891791

17901792
return $this->testMode ? $savedSQL : $affectedRows;
17911793
}

tests/system/Database/Live/UpsertTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,18 @@ public function testUpsertWithMultipleSet()
640640

641641
$this->seeInDatabase('user', ['email' => '[email protected]', 'name' => 'Jarvis', 'country' => $dt]);
642642
}
643+
644+
public function testUpsertWithTestModeAndGetCompiledUpsert()
645+
{
646+
$userData = [
647+
'email' => '[email protected]',
648+
'name' => 'Upsert One',
649+
'country' => 'US',
650+
];
651+
$builder = $this->db->table('user');
652+
$builder->testMode()->upsert($userData);
653+
$sql = $builder->getCompiledUpsert();
654+
655+
$this->assertStringContainsString('[email protected]', $sql);
656+
}
643657
}

0 commit comments

Comments
 (0)