Skip to content

Commit

Permalink
fix: Builder update() does not accept an object
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 1, 2022
1 parent 6cd8356 commit 32c1ffc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2014,11 +2014,12 @@ public function getCompiledUpdate(bool $reset = true)
/**
* Compiles an update string and runs the query.
*
* @param mixed $where
* @param null|array|object $set
* @param array|RawSql|string|null $where
*
* @throws DatabaseException
*/
public function update(?array $set = null, $where = null, ?int $limit = null): bool
public function update($set = null, $where = null, ?int $limit = null): bool
{
if ($set !== null) {
$this->set($set);
Expand Down
28 changes: 26 additions & 2 deletions tests/system/Database/Builder/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,35 @@ protected function setUp(): void
$this->db = new MockConnection([]);
}

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

$builder->testMode()->where('id', 1)->update(['name' => 'Programmer'], null, null);
$data = ['name' => 'Programmer'];
$builder->testMode()->where('id', 1)->update($data, null, null);

$expectedSQL = 'UPDATE "jobs" SET "name" = \'Programmer\' WHERE "id" = 1';
$expectedBinds = [
'id' => [
1,
true,
],
'name' => [
'Programmer',
true,
],
];

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledUpdate()));
$this->assertSame($expectedBinds, $builder->getBinds());
}

public function testUpdateObject()
{
$builder = new BaseBuilder('jobs', $this->db);

$data = (object) ['name' => 'Programmer'];
$builder->testMode()->where('id', 1)->update($data, null, null);

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

0 comments on commit 32c1ffc

Please sign in to comment.