function ConnectionTest::testPDOStatementQueryDeprecation

Tests the deprecation of passing a PDOStatement object to ::query.

@group legacy

File

core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php, line 154

Class

ConnectionTest
Tests of the core database system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testPDOStatementQueryDeprecation() : void {
    $db = Database::getConnection();
    $stmt = $db->prepareStatement('SELECT * FROM {test}', []);
    if (!$stmt instanceof StatementWrapper) {
        $this->markTestSkipped("This test only runs for db drivers using StatementWrapper.");
    }
    if (!$stmt->getClientStatement() instanceof \PDOStatement) {
        $this->markTestSkipped("This test only runs for PDO-based db drivers.");
    }
    $this->expectDeprecation('Passing a \\PDOStatement object as a $query argument to Drupal\\Core\\Database\\Connection::query is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439');
    $this->assertNotNull($db->query($stmt->getClientStatement()));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.