Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/var
/composer.lock
/.php_cs.cache
/.phpunit.result.cache
/.phpunit.result.cache
/.idea
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
],
"require": {
"php": "^7.4 || ^8.0",
"doctrine/dbal": "^3",
"doctrine/dbal": "^3|^4",
"react/event-loop": "^1"
},
"require-dev": {
"phpunit/phpunit": "^9",
"clue/block-react": "^1",
"react/mysql": "^0.5",
"react/mysql": "^0.6",
"clue/reactphp-sqlite": "^1",
"voryx/pgasync": "^2"
},
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,14 @@ private function releaseConnection(SingleConnection $connection): PromiseInterfa
/** @var \Drift\DBAL\ConnectionWorker $worker */
$worker = $this->connections[$connection];
$worker->setLeased(false);
return resolve();
return resolve(null);
}

$deferred = $this->deferreds->current();
$this->deferreds->detach($deferred);

$deferred->resolve($this->connections[$connection]);
return resolve();
return resolve(null);
}

}
2 changes: 1 addition & 1 deletion src/Driver/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($message, $sqlState = null, $code = 0, ?Throwable $p
$this->sqlState = $sqlState;
}

public function getSQLState()
public function getSQLState(): ?string
{
return $this->sqlState;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Driver/PostgreSQL/PostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

namespace Drift\DBAL\Driver\PostgreSQL;

use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query;
use Doctrine\DBAL\Query\QueryBuilder;
use Drift\DBAL\Credentials;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function query(
array $parameters
): PromiseInterface {
if ($this->isClosed) {
return reject(new Exception('Connection closed'));
return reject(new ConnectionException('Connection closed'));
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ public function query(
public function insert(QueryBuilder $queryBuilder, string $table, array $values): PromiseInterface
{
if ($this->isClosed) {
return reject(new Exception('Connection closed'));
return reject(new ConnectionException('Connection closed'));
}

$queryBuilder = $this->createInsertQuery($queryBuilder, $table, $values);
Expand Down
137 changes: 1 addition & 136 deletions src/Mock/MockedDBALConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,142 +15,7 @@

namespace Drift\DBAL\Mock;

use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Type;
use Exception;

/**
* Class MockedDBALConnection.
*/
class MockedDBALConnection extends Connection
final class MockedDBALConnection extends Connection
{
/**
* Prepares an SQL statement.
*
* @param string $sql the SQL statement to prepare
*
* @throws \Doctrine\DBAL\Exception
*/
public function prepare(string $sql): Statement
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs.
*
* @deprecated This API is deprecated and will be removed after 2022
*/
public function query(string $sql): Result
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*
* @return mixed
*/
public function quote($input, $type = ParameterType::STRING)/*: mixed // <--- from php 8*/
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs.
*
* @deprecated This API is deprecated and will be removed after 2022
*/
public function exec(string $sql): int
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*
* @return string|int|false A string representation of the last inserted ID.
*/
public function lastInsertId($name = null)/*: string|int|false // <--- from php 8 */
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function beginTransaction(): bool
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function commit(): bool
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function rollBack(): bool
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function errorCode()
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function errorInfo()
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* Executes an, optionally parametrized, SQL query.
*
* If the query is parametrized, a prepared statement is used.
* If an SQLLogger is configured, the execution is logged.
*
* @param string $sql SQL query
* @param list<mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @throws \Doctrine\DBAL\Exception
*/
public function executeQuery(
string $sql,
array $params = [],
$types = [],
?QueryCacheProfile $qcp = null
): Result {
throw new Exception('Mocked method. Unable to be used');
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs.
*
* @deprecated This API is deprecated and will be removed after 2022
*
* @param array<mixed> $params The query parameters
* @param array<int|string|null> $types The parameter types
*/
public function executeUpdate(string $sql, array $params = [], array $types = []): int
{
throw new Exception('Mocked method. Unable to be used');
}
}
107 changes: 59 additions & 48 deletions src/Mock/MockedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,76 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Exception;

/**
* Class MockedDriver.
*/
class MockedDriver implements Driver
{
/**
* {@inheritdoc}
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = []): DriverConnection
if ((new \ReflectionMethod(Driver::class, 'getDatabasePlatform'))->getNumberOfParameters() === 1) {
final class MockedDriver implements Driver
{
throw new Exception('Mocked method. Unable to be used');
}
private AbstractPlatform $platform;

/**
* {@inheritdoc}
*/
public function getDatabasePlatform(): AbstractPlatform
{
throw new Exception('Mocked method. Unable to be used');
}
public function __construct(AbstractPlatform $platform)
{
$this->platform = $platform;
}

/**
* Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to.
*
* @return AbstractSchemaManager
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
throw new Exception('Mocked method. Unable to be used');
}
public function connect(array $params): DriverConnection
{
throw new Exception('Mocked method. Unable to be used');
}

/**
* {@inheritdoc}
*/
public function getName()
{
throw new Exception('Mocked method. Unable to be used');
}
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
{
return $this->platform;
}

/**
* {@inheritdoc}
*/
public function getDatabase(Connection $conn)
{
throw new Exception('Mocked method. Unable to be used');
public function getExceptionConverter(): ExceptionConverter
{
throw new Exception('Mocked method. Unable to be used');
}
}

/**
* {@inheritdoc}
*/
public function getExceptionConverter(): ExceptionConverter
} else {
final class MockedDriver implements Driver
{
throw new Exception('Mocked method. Unable to be used');
private AbstractPlatform $platform;

public function __construct(AbstractPlatform $platform)
{
$this->platform = $platform;
}

public function connect(array $params, $username = null, $password = null, array $driverOptions = []): DriverConnection
{
throw new Exception('Mocked method. Unable to be used');
}

public function getDatabasePlatform(): AbstractPlatform
{
return $this->platform;
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
throw new Exception('Mocked method. Unable to be used');
}

public function getName()
{
throw new Exception('Mocked method. Unable to be used');
}

public function getDatabase(Connection $conn)
{
throw new Exception('Mocked method. Unable to be used');
}

public function getExceptionConverter(): ExceptionConverter
{
throw new Exception('Mocked method. Unable to be used');
}
}
}
Loading