public function DatabaseExceptionWrapperTest::testPrepareStatementFailOnExecution in Drupal 10
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/DatabaseExceptionWrapperTest.php \Drupal\KernelTests\Core\Database\DatabaseExceptionWrapperTest::testPrepareStatementFailOnExecution()
Tests Connection::prepareStatement exceptions on execution.
Core database drivers use PDO emulated statements or the StatementPrefetch class, which defer the statement check to the moment of the execution.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseExceptionWrapperTest.php, line 22
Class
- DatabaseExceptionWrapperTest
- Tests exceptions thrown by queries.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testPrepareStatementFailOnExecution() {
$connection = Database::getConnection();
$connection_reflection_class = new \ReflectionClass($connection);
$client_connection_property = $connection_reflection_class
->getProperty('connection');
$client_connection = $client_connection_property
->getValue($connection);
if (!$client_connection instanceof \PDO) {
$this
->markTestSkipped("This tests can only run for drivers wrapping \\PDO connections.");
}
$this
->expectException(\PDOException::class);
$stmt = $connection
->prepareStatement('bananas', []);
$stmt
->execute();
}