DatabaseExceptionWrapperTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/Database/DatabaseExceptionWrapperTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
class DatabaseExceptionWrapperTest extends KernelTestBase {
public function testPreparedStatement() {
$connection = Database::getConnection();
try {
$query = $connection
->prepare('bananas');
$connection
->query($query);
$this
->fail('Expected PDOException or DatabaseExceptionWrapper, none was thrown.');
} catch (\Exception $e) {
$this
->assertTrue($e instanceof \PDOException || $e instanceof DatabaseExceptionWrapper, 'Exception should be an instance of \\PDOException or DatabaseExceptionWrapper, thrown ' . get_class($e));
}
}
public function testQueryThrowsDatabaseExceptionWrapperException() {
$this
->expectException(DatabaseExceptionWrapper::class);
Database::getConnection()
->query('SELECT * FROM {does_not_exist}');
}
}