Skip to content

Commit 21addfd

Browse files
committed
Fix tests
1 parent cc0f38f commit 21addfd

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

system/Database/BaseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,10 +2537,10 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
25372537

25382538
if ($constraints === []) {
25392539
if ($this->db->DBDebug) {
2540-
throw new DatabaseException('You must specify a constraint to match on for batch updates.');
2540+
throw new DatabaseException('You must specify a constraint to match on for batch updates.'); // @codeCoverageIgnore
25412541
}
25422542

2543-
return ''; // @codeCoverageIgnor
2543+
return ''; // @codeCoverageIgnore
25442544
}
25452545

25462546
$updateFields = $this->QBOptions['updateFields'] ??

system/Database/MySQLi/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
6969

7070
if ($constraints === []) {
7171
if ($this->db->DBDebug) {
72-
throw new DatabaseException('You must specify a constraint to match on for batch updates.');
72+
throw new DatabaseException('You must specify a constraint to match on for batch updates.'); // @codeCoverageIgnore
7373
}
7474

75-
return ''; // @codeCoverageIgnor
75+
return ''; // @codeCoverageIgnore
7676
}
7777

7878
$updateFields = $this->QBOptions['updateFields'] ??

system/Database/OCI8/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
357357
throw new DatabaseException('You must specify a constraint to match on for batch updates.');
358358
}
359359

360-
return ''; // @codeCoverageIgnor
360+
return ''; // @codeCoverageIgnore
361361
}
362362

363363
$updateFields = $this->QBOptions['updateFields'] ??

tests/system/Database/Live/SclubricantsTest.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Database\Live;
1313

14+
use CodeIgniter\Database\Exceptions\DatabaseException;
1415
use CodeIgniter\Database\Forge;
1516
use CodeIgniter\Database\RawSql;
1617
use CodeIgniter\Test\CIUnitTestCase;
@@ -39,10 +40,6 @@ final class SclubricantsTest extends CIUnitTestCase
3940
protected function setUp(): void
4041
{
4142
parent::setUp();
42-
43-
if ($this->db->DBDriver === 'SQLite3' && ! (version_compare($this->db->getVersion(), '3.33.0') >= 0)) {
44-
$this->markTestSkipped('Only SQLite 3.33 and newer can complete this test.');
45-
}
4643
}
4744

4845
public function setupTable()
@@ -150,6 +147,10 @@ public function setupTable()
150147

151148
public function testUpdateBatchUpdateFieldsAndAlias()
152149
{
150+
if ($this->db->DBDriver === 'SQLite3' && ! (version_compare($this->db->getVersion(), '3.33.0') >= 0)) {
151+
$this->markTestSkipped('Only SQLite 3.33 and newer can complete this test.');
152+
}
153+
153154
$data = [
154155
[
155156
'email' => '[email protected]',
@@ -238,6 +239,10 @@ public function testUpdateBatchUpdateFieldsAndAlias()
238239

239240
public function testUpdateBatchWithoutOnConstraint()
240241
{
242+
if ($this->db->DBDriver === 'SQLite3' && ! (version_compare($this->db->getVersion(), '3.33.0') >= 0)) {
243+
$this->markTestSkipped('Only SQLite 3.33 and newer can complete this test.');
244+
}
245+
241246
$data = [
242247
[
243248
'name' => 'Derek Nothing', // won't update
@@ -274,8 +279,20 @@ public function testUpdateBatchWithoutOnConstraint()
274279
}
275280
}
276281

282+
public function testUpsertNoData()
283+
{
284+
$this->expectException(DatabaseException::class);
285+
$this->expectExceptionMessage('No data availble to process.');
286+
287+
$this->db->table('user')->onConstraint('email')->upsertBatch();
288+
}
289+
277290
public function testUpdateWithQuery()
278291
{
292+
if ($this->db->DBDriver === 'SQLite3' && ! (version_compare($this->db->getVersion(), '3.33.0') >= 0)) {
293+
$this->markTestSkipped('Only SQLite 3.33 and newer can complete this test.');
294+
}
295+
279296
$this->setupTable();
280297

281298
$updateFields = ['country', 'updated_at' => new RawSql('CURRENT_TIMESTAMP')];
@@ -380,12 +397,33 @@ public function testSetBatchOneRow()
380397
$evenMoreData->email = '[email protected]';
381398
$evenMoreData->country = 'Netherlands';
382399

383-
$builder->updateBatch($evenMoreData, 'email');
400+
$builder->onConstraint('email')->upsertBatch($evenMoreData, true, 2);
384401

385402
$result = $this->db->table('user')->get()->getResultArray();
386403

387404
foreach ($result as $row) {
388405
$this->assertSame('Netherlands', $row['country']);
389406
}
390407
}
408+
409+
public function testRawSqlConstraint()
410+
{
411+
if ($this->db->DBDriver === 'SQLite3' && ! (version_compare($this->db->getVersion(), '3.33.0') >= 0)) {
412+
$this->markTestSkipped('Only SQLite 3.33 and newer can complete this test.');
413+
}
414+
415+
$data = [
416+
[
417+
'name' => 'Derek Jones',
418+
'email' => '[email protected]',
419+
'country' => 'Germany',
420+
],
421+
];
422+
423+
$builder = $this->db->table('user');
424+
425+
$builder->setBatch($data, true, 'db_myalias')->updateFields('name, country')->onConstraint(new RawSql($this->db->protectIdentifiers('user.email') . ' = ' . $this->db->protectIdentifiers('myalias.email')))->updateBatch();
426+
427+
$this->seeInDatabase('user', ['email' => '[email protected]', 'country' => 'Germany']);
428+
}
391429
}

0 commit comments

Comments
 (0)