You are here

private function ConnectionTest::createConnection in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/Driver/mysql/ConnectionTest.php \Drupal\Tests\Core\Database\Driver\mysql\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/tests/Drupal/Tests/Core/Database/Driver/mysql/ConnectionTest.php
@covers ::version @covers ::isMariaDb @dataProvider providerVersionAndIsMariaDb

File

core/tests/Drupal/Tests/Core/Database/Driver/mysql/ConnectionTest.php, line 44

Class

ConnectionTest
Tests MySQL database connections.

Namespace

Drupal\Tests\Core\Database\Driver\mysql

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('');
    }

  };
}