function DatabaseExceptionWrapperTest::testPrepareStatementFailOnPreparation
Same name in other branches
- 10 core/modules/mysql/tests/src/Kernel/mysql/DatabaseExceptionWrapperTest.php \Drupal\Tests\mysql\Kernel\mysql\DatabaseExceptionWrapperTest::testPrepareStatementFailOnPreparation()
- 11.x core/modules/mysql/tests/src/Kernel/mysql/DatabaseExceptionWrapperTest.php \Drupal\Tests\mysql\Kernel\mysql\DatabaseExceptionWrapperTest::testPrepareStatementFailOnPreparation()
Tests Connection::prepareStatement exceptions on preparation.
Core database drivers use PDO emulated statements or the StatementPrefetch class, which defer the statement check to the moment of the execution. In order to test a failure at preparation time, we have to force the connection not to emulate statement preparation. Still, this is only valid for the MySql driver.
File
-
core/
modules/ mysql/ tests/ src/ Kernel/ mysql/ DatabaseExceptionWrapperTest.php, line 25
Class
- DatabaseExceptionWrapperTest
- Tests exceptions thrown by queries.
Namespace
Drupal\Tests\mysql\Kernel\mysqlCode
public function testPrepareStatementFailOnPreparation() {
$connection_info = Database::getConnectionInfo('default');
$connection_info['default']['pdo'][\PDO::ATTR_EMULATE_PREPARES] = FALSE;
Database::addConnectionInfo('default', 'foo', $connection_info['default']);
$foo_connection = Database::getConnection('foo', 'default');
$this->expectException(DatabaseExceptionWrapper::class);
$stmt = $foo_connection->prepareStatement('bananas', []);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.