Skip to content

Commit cb546aa

Browse files
committed
Fix a few things to increase code coverage
Removed unused code, added some tests to increase code coverage
1 parent 9d17d4a commit cb546aa

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

system/Database/OCI8/Builder.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,6 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
356356

357357
$updateFields = $this->QBOptions['updateFields'] ?? $this->updateFields($keys, false, $constraints)->QBOptions['updateFields'] ?? [];
358358

359-
if (empty($updateFields)) {
360-
$updateFields = array_filter(
361-
$keys,
362-
static fn ($columnName) => ! (in_array($columnName, $constraints, true))
363-
);
364-
365-
$this->QBOptions['updateFields'] = $updateFields;
366-
}
367-
368359
$sql = 'MERGE INTO ' . $table . "\nUSING (\n{:_table_:}";
369360

370361
$sql .= ') "_upsert"' . "\nON (";

system/Database/SQLSRV/Builder.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
637637
$tableIdentity = $this->QBOptions['tableIdentity'] ?? '';
638638
$sql = "SELECT name from syscolumns where id = Object_ID('" . $table . "') and colstat = 1";
639639
if (($query = $this->db->query($sql)) === false) {
640-
throw new DatabaseException('Failed to get table identity');
640+
throw new DatabaseException('Failed to get table identity'); // @codeCoverageIgnore
641641
}
642642
$query = $query->getResultObject();
643643

@@ -687,15 +687,6 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
687687

688688
$updateFields = $this->QBOptions['updateFields'] ?? $this->updateFields($keys, false, $constraints)->QBOptions['updateFields'] ?? [];
689689

690-
if (empty($updateFields)) {
691-
$updateFields = array_filter(
692-
$fieldNames,
693-
static fn ($columnName) => ! (in_array($columnName, $constraints, true))
694-
);
695-
696-
$this->QBOptions['updateFields'] = $updateFields;
697-
}
698-
699690
$sql = 'MERGE INTO ' . $fullTableName . "\nUSING (\n";
700691

701692
$sql .= '{:_table_:}';

tests/system/Database/Live/UpdateTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,19 @@ public function testRawSqlConstraint()
482482

483483
$this->seeInDatabase('user', ['email' => '[email protected]', 'country' => 'Germany']);
484484
}
485+
486+
public function testNoConstraintFound()
487+
{
488+
$jobData = [
489+
'name' => 'Programmer',
490+
'description' => 'General PHP Coding',
491+
];
492+
493+
$this->expectException(DatabaseException::class);
494+
$this->expectExceptionMessage('You must specify a constraint to match on for batch updates.');
495+
496+
$this->db->table('job')
497+
->updateBatch($jobData);
498+
499+
}
485500
}

tests/system/Database/Live/UpsertTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ public function testUpsertCauseConstraintError()
253253

254254
$this->expectException(DatabaseException::class);
255255

256+
$esc = $this->db->escapeChar;
257+
256258
$this->db->table('user')
257-
->onConstraint('id')
259+
->onConstraint(new RawSql($esc . 'user' . $esc . '.' . $esc. 'id' . $esc))
258260
->updateFields('name, email, country')
259261
->upsert($userData);
260262
}

0 commit comments

Comments
 (0)