function ConnectionTest::createConnection

Same name in other branches
  1. 9 core/modules/mysql/tests/src/Unit/ConnectionTest.php \Drupal\Tests\mysql\Unit\ConnectionTest::createConnection()
  2. 10 core/modules/mysql/tests/src/Unit/ConnectionTest.php \Drupal\Tests\mysql\Unit\ConnectionTest::createConnection()

Creates a Connection object for testing.

Return value

\Drupal\mysql\Driver\Database\mysql\Connection

1 call to ConnectionTest::createConnection()
ConnectionTest::testVersionAndIsMariaDb in core/modules/mysql/tests/src/Unit/ConnectionTest.php
@covers ::version @covers ::isMariaDb @dataProvider providerVersionAndIsMariaDb

File

core/modules/mysql/tests/src/Unit/ConnectionTest.php, line 48

Class

ConnectionTest
Tests MySQL database connections.

Namespace

Drupal\Tests\mysql\Unit

Code

private function createConnection() : Connection {
    $this->pdoStatement
        ->setFetchMode(Argument::any())
        ->shouldBeCalled()
        ->willReturn(TRUE);
    $this->pdoStatement
        ->execute(Argument::any())
        ->shouldBeCalled()
        ->willReturn(TRUE);
    $this->pdoConnection
        ->prepare('SELECT VERSION()', Argument::any())
        ->shouldBeCalled()
        ->willReturn($this->pdoStatement
        ->reveal());
    
    /** @var \PDO $pdo_connection */
    $pdo_connection = $this->pdoConnection
        ->reveal();
    return new class ($pdo_connection) extends Connection {
        public function __construct(\PDO $connection) {
            $this->connection = $connection;
            $this->setPrefix('');
        }

};
}

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