Fix testExceptionContainsRawQuery() in ConnectionTest class in SQLite. (#20653)

This commit is contained in:
Wilmer Arambula
2025-10-31 05:57:06 -03:00
committed by GitHub
parent 8a87a5fb25
commit c311720922
2 changed files with 18 additions and 9 deletions

View File

@@ -397,14 +397,21 @@ abstract class ConnectionTest extends DatabaseTestCase
/**
* @param Connection $connection
*/
private function runExceptionTest($connection): void
private function runExceptionTest(Connection $connection): void
{
$thrown = false;
$sqlAssertLog = 'INSERT INTO qlog1(a) VALUES(1);';
if ($connection->getDriverName() === 'sqlite') {
// SQLite shows placeholders (`:a`), other drivers show values (`1`) in error messages.
$sqlAssertLog = 'INSERT INTO qlog1(a) VALUES(:a);';
}
try {
$connection->createCommand('INSERT INTO qlog1(a) VALUES(:a);', [':a' => 1])->execute();
} catch (\yii\db\Exception $e) {
$this->assertStringContainsString(
'INSERT INTO qlog1(a) VALUES(1);',
$sqlAssertLog,
$e->getMessage(),
'Exception message should contain raw SQL query: ' . (string) $e
);
@@ -413,11 +420,18 @@ abstract class ConnectionTest extends DatabaseTestCase
$this->assertTrue($thrown, 'An exception should have been thrown by the command.');
$thrown = false;
$sqlAssertLog = 'SELECT * FROM qlog1 WHERE id=1 ORDER BY nonexistingcolumn;';
if ($connection->getDriverName() === 'sqlite') {
// SQLite shows placeholders (`:a`), other drivers show values (`1`) in error messages.
$sqlAssertLog = 'SELECT * FROM qlog1 WHERE id=:a ORDER BY nonexistingcolumn;';
}
try {
$connection->createCommand('SELECT * FROM qlog1 WHERE id=:a ORDER BY nonexistingcolumn;', [':a' => 1])->queryAll();
} catch (\yii\db\Exception $e) {
$this->assertStringContainsString(
'SELECT * FROM qlog1 WHERE id=1 ORDER BY nonexistingcolumn;',
$sqlAssertLog,
$e->getMessage(),
'Exception message should contain raw SQL query: ' . (string) $e,
);

View File

@@ -8,9 +8,9 @@
namespace yiiunit\framework\db\sqlite;
use Exception;
use Yii;
use yii\db\Connection;
use yii\db\Exception;
use yii\db\Transaction;
use yiiunit\data\ar\ActiveRecord;
use yiiunit\data\ar\Customer;
@@ -218,9 +218,4 @@ class ConnectionTest extends \yiiunit\framework\db\ConnectionTest
$connection->close();
}
public function testExceptionContainsRawQuery(): void
{
$this->markTestSkipped('This test does not work on sqlite because preparing the failing query fails');
}
}