Implement basic WPDB Doctrine driver with connection, statement, and result stubs

[MAILPOET-6142]
This commit is contained in:
Jan Jakes
2024-07-13 13:36:14 +02:00
committed by Aschepikov
parent ff6a98fae1
commit c17d8feaa4
6 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php declare(strict_types = 1);
namespace MailPoet\Doctrine\WPDB;
use MailPoetVendor\Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use MailPoetVendor\Doctrine\DBAL\ParameterType;
class Connection implements ServerInfoAwareConnection {
public function prepare(string $sql): Statement {
// TODO: Implement prepare() method.
}
public function query(string $sql): Result {
// TODO: Implement query() method.
}
public function exec(string $sql): int {
// TODO: Implement exec() method.
}
public function beginTransaction() {
// TODO: Implement beginTransaction() method.
}
public function commit() {
// TODO: Implement commit() method.
}
public function rollBack() {
// TODO: Implement rollBack() method.
}
public function quote($value, $type = ParameterType::STRING) {
// TODO: Implement quote() method.
}
public function lastInsertId($name = null) {
// TODO: Implement lastInsertId() method.
}
public function getServerVersion() {
// TODO: Implement getServerVersion() method.
}
public function __call($name, $arguments) {
// TODO: Implement @method object getNativeConnection()
}
}

View File

@ -0,0 +1,11 @@
<?php declare(strict_types = 1);
namespace MailPoet\Doctrine\WPDB;
use MailPoetVendor\Doctrine\DBAL\Driver\AbstractMySQLDriver;
class Driver extends AbstractMySQLDriver {
public function connect(array $params): Connection {
return new Connection();
}
}

View File

@ -0,0 +1,43 @@
<?php declare(strict_types = 1);
namespace MailPoet\Doctrine\WPDB;
use MailPoetVendor\Doctrine\DBAL\Driver\Result as ResultInterface;
class Result implements ResultInterface {
public function fetchNumeric() {
// TODO: Implement fetchNumeric() method.
}
public function fetchAssociative() {
// TODO: Implement fetchAssociative() method.
}
public function fetchOne() {
// TODO: Implement fetchOne() method.
}
public function fetchAllNumeric(): array {
// TODO: Implement fetchAllNumeric() method.
}
public function fetchAllAssociative(): array {
// TODO: Implement fetchAllAssociative() method.
}
public function fetchFirstColumn(): array {
// TODO: Implement fetchFirstColumn() method.
}
public function rowCount(): int {
// TODO: Implement rowCount() method.
}
public function columnCount(): int {
// TODO: Implement columnCount() method.
}
public function free(): void {
// TODO: Implement free() method.
}
}

View File

@ -0,0 +1,21 @@
<?php declare(strict_types = 1);
namespace MailPoet\Doctrine\WPDB;
use MailPoetVendor\Doctrine\DBAL\Driver\Result;
use MailPoetVendor\Doctrine\DBAL\Driver\Statement as StatementInterface;
use MailPoetVendor\Doctrine\DBAL\ParameterType;
class Statement implements StatementInterface {
public function bindValue($param, $value, $type = ParameterType::STRING) {
// TODO: Implement bindValue() method.
}
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) {
// TODO: Implement bindParam() method.
}
public function execute($params = null): Result {
// TODO: Implement execute() method.
}
}

View File

@ -0,0 +1,20 @@
<?php declare(strict_types = 1);
namespace MailPoet\Test\Doctrine\WPDB;
use MailPoet\Doctrine\WPDB\Connection;
use MailPoet\Doctrine\WPDB\Driver;
use MailPoetTest;
use MailPoetVendor\Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1052Platform;
use MailPoetVendor\Doctrine\DBAL\Platforms\MySQLPlatform;
class DriverTest extends MailPoetTest {
public function testDriverSetup(): void {
$driver = new Driver();
$this->assertInstanceOf(Connection::class, $driver->connect([]));
$this->assertInstanceOf(MySQLPlatform::class, $driver->getDatabasePlatform());
$this->assertInstanceOf(MariaDb1052Platform::class, $driver->createDatabasePlatformForVersion('10.5.8-MariaDB-1:10.5.8+maria~focal'));
$this->assertInstanceOf(ExceptionConverter::class, $driver->getExceptionConverter());
}
}

View File

@ -0,0 +1,19 @@
<?php declare(strict_types = 1);
namespace MailPoet\Doctrine\WPDB;
use MailPoetUnitTest;
use MailPoetVendor\Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use MailPoetVendor\Doctrine\DBAL\Platforms\MariaDb1052Platform;
use MailPoetVendor\Doctrine\DBAL\Platforms\MySQLPlatform;
class DriverTest extends MailPoetUnitTest {
public function testDriverSetup(): void {
$driver = $this->createPartialMock(Driver::class, ['connect']);
$this->assertInstanceOf(Connection::class, $driver->connect([]));
$this->assertInstanceOf(MySQLPlatform::class, $driver->getDatabasePlatform());
$this->assertInstanceOf(MariaDb1052Platform::class, $driver->createDatabasePlatformForVersion('10.5.8-MariaDB-1:10.5.8+maria~focal'));
$this->assertInstanceOf(ExceptionConverter::class, $driver->getExceptionConverter());
}
}