From 20a2e91a07a35deb2444b71d29e22ac7c2a713b1 Mon Sep 17 00:00:00 2001 From: michalsn Date: Thu, 2 Jan 2025 11:25:24 +0100 Subject: [PATCH] fix failing tests for mysqli - enable strict mode --- tests/system/Database/Live/InsertTest.php | 12 ++++++++++- .../system/Database/Live/TransactionTest.php | 20 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/system/Database/Live/InsertTest.php b/tests/system/Database/Live/InsertTest.php index 01cc74e9c26b..4db8e8868468 100644 --- a/tests/system/Database/Live/InsertTest.php +++ b/tests/system/Database/Live/InsertTest.php @@ -102,7 +102,17 @@ public function testInsertBatchFailed(): void ], ]; - $this->db->table('job')->insertBatch($data); + $db = $this->db; + + if ($this->db->DBDriver === 'MySQLi') { + // strict mode is required for MySQLi to throw an exception here + $config = config('Database'); + $config->tests['strictOn'] = true; + + $db = Database::connect($config->tests); + } + + $db->table('job')->insertBatch($data); } public function testReplaceWithNoMatchingData(): void diff --git a/tests/system/Database/Live/TransactionTest.php b/tests/system/Database/Live/TransactionTest.php index aced7767bcca..610306f2fd22 100644 --- a/tests/system/Database/Live/TransactionTest.php +++ b/tests/system/Database/Live/TransactionTest.php @@ -254,12 +254,24 @@ public function testTransInsertBatchFailed(): void ], ]; - $this->db->transStrict(false)->transBegin(); - $this->db->table('job')->insertBatch($data); + $db = $this->db; - $this->assertFalse($this->db->transStatus()); + if ($this->db->DBDriver === 'MySQLi') { + // strict mode is required for MySQLi to throw an exception here + $config = config('Database'); + $config->tests['strictOn'] = true; - $this->db->transComplete(); + $db = Database::connect($config->tests); + } + + $db->transStrict(false)->transBegin(); + $db->table('job')->insertBatch($data); + + $this->assertFalse($db->transStatus()); + + $db->transComplete(); + + $db->transStrict(); $this->dontSeeInDatabase('job', ['name' => 'Grocery Sales']); }