Skip to content

Commit 32c1ffc

Browse files
committed
fix: Builder update() does not accept an object
1 parent 6cd8356 commit 32c1ffc

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

system/Database/BaseBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,11 +2014,12 @@ public function getCompiledUpdate(bool $reset = true)
20142014
/**
20152015
* Compiles an update string and runs the query.
20162016
*
2017-
* @param mixed $where
2017+
* @param null|array|object $set
2018+
* @param array|RawSql|string|null $where
20182019
*
20192020
* @throws DatabaseException
20202021
*/
2021-
public function update(?array $set = null, $where = null, ?int $limit = null): bool
2022+
public function update($set = null, $where = null, ?int $limit = null): bool
20222023
{
20232024
if ($set !== null) {
20242025
$this->set($set);

tests/system/Database/Builder/UpdateTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,35 @@ protected function setUp(): void
3434
$this->db = new MockConnection([]);
3535
}
3636

37-
public function testUpdate()
37+
public function testUpdateArray()
3838
{
3939
$builder = new BaseBuilder('jobs', $this->db);
4040

41-
$builder->testMode()->where('id', 1)->update(['name' => 'Programmer'], null, null);
41+
$data = ['name' => 'Programmer'];
42+
$builder->testMode()->where('id', 1)->update($data, null, null);
43+
44+
$expectedSQL = 'UPDATE "jobs" SET "name" = \'Programmer\' WHERE "id" = 1';
45+
$expectedBinds = [
46+
'id' => [
47+
1,
48+
true,
49+
],
50+
'name' => [
51+
'Programmer',
52+
true,
53+
],
54+
];
55+
56+
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledUpdate()));
57+
$this->assertSame($expectedBinds, $builder->getBinds());
58+
}
59+
60+
public function testUpdateObject()
61+
{
62+
$builder = new BaseBuilder('jobs', $this->db);
63+
64+
$data = (object) ['name' => 'Programmer'];
65+
$builder->testMode()->where('id', 1)->update($data, null, null);
4266

4367
$expectedSQL = 'UPDATE "jobs" SET "name" = \'Programmer\' WHERE "id" = 1';
4468
$expectedBinds = [

0 commit comments

Comments
 (0)