Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ExceptionConverterDriver #4129

Merged
merged 1 commit into from
Jun 29, 2020
Merged
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
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 3.0

## The `ExceptionConverterDriver` interface is removed

All drivers must implement the `convertException()` method which is now part of the `Driver` interface.

## The `PingableConnection` interface is removed

The functionality of pinging the server is no longer supported.
Expand Down
3 changes: 1 addition & 2 deletions src/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Doctrine\DBAL;

use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -169,7 +168,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin
return $driverEx;
}

if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof TheDriverException) {
if ($driverEx instanceof TheDriverException) {
return $driver->convertException($msg, $driverEx);
}

Expand Down
14 changes: 14 additions & 0 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;

Expand Down Expand Up @@ -39,4 +40,17 @@ public function getDatabasePlatform();
* @return AbstractSchemaManager
*/
public function getSchemaManager(Connection $conn);

/**
* Converts a given driver-level exception into a DBAL-level driver exception.
*
* Implementors should use the vendor-specific error code and SQLSTATE of the exception
* and instantiate the most appropriate specialized {@link DriverException} subclass.
*
* @param string $message The exception message to use.
* @param Exception $exception The driver exception to convert.
*
* @return DriverException An instance of {@link DriverException} or one of its subclasses.
*/
public function convertException($message, Exception $exception);
}
3 changes: 1 addition & 2 deletions src/Driver/AbstractDB2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
Expand Down Expand Up @@ -35,7 +34,7 @@ public function getSchemaManager(Connection $conn)
*
* @return DriverException
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
return new DriverException($message, $exception);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\DeadlockException;
Expand Down Expand Up @@ -32,15 +31,15 @@
/**
* Abstract base implementation of the {@link Driver} interface for MySQL based drivers.
*/
abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionAwarePlatformDriver
abstract class AbstractMySQLDriver implements VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
* @link https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
switch ($exception->getCode()) {
case 1213:
Expand Down
5 changes: 2 additions & 3 deletions src/Driver/AbstractOracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
Expand All @@ -22,12 +21,12 @@
/**
* Abstract base implementation of the {@link Driver} interface for Oracle based drivers.
*/
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
abstract class AbstractOracleDriver implements Driver
{
/**
* {@inheritdoc}
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
switch ($exception->getCode()) {
case 1:
Expand Down
5 changes: 2 additions & 3 deletions src/Driver/AbstractPostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\DeadlockException;
use Doctrine\DBAL\Exception\DriverException;
Expand All @@ -28,14 +27,14 @@
/**
* Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers.
*/
abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, VersionAwarePlatformDriver
abstract class AbstractPostgreSQLDriver implements VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
switch ($exception->getSQLState()) {
case '40001':
Expand Down
3 changes: 1 addition & 2 deletions src/Driver/AbstractSQLServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
Expand Down Expand Up @@ -35,7 +34,7 @@ public function getSchemaManager(Connection $conn)
*
* @return DriverException
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
return new DriverException($message, $exception);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Driver/AbstractSQLiteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception as TheDriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
Expand All @@ -25,14 +24,14 @@
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers.
*/
abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
abstract class AbstractSQLiteDriver implements Driver
{
/**
* {@inheritdoc}
*
* @link http://www.sqlite.org/c3ref/c_abort.html
*/
public function convertException($message, TheDriverException $exception)
public function convertException($message, Exception $exception)
{
if (strpos($exception->getMessage(), 'database is locked') !== false) {
return new LockWaitTimeoutException($message, $exception);
Expand Down
28 changes: 0 additions & 28 deletions src/Driver/ExceptionConverterDriver.php

This file was deleted.

22 changes: 13 additions & 9 deletions tests/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception as DriverExceptionInterface;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Driver\AbstractException;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\ConstraintViolationException;
use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
Expand Down Expand Up @@ -78,15 +79,18 @@ public function testConvertsException(
?string $sqlState = null,
string $message = ''
): void {
if (! $this->driver instanceof ExceptionConverterDriver) {
self::markTestSkipped('This test is only intended for exception converter drivers.');
if ($this->driver instanceof IBMDB2\Driver) {
self::markTestSkipped("The IBM DB2 driver currently doesn't instantiate specialized exceptions");
}

$driverException = $this->getMockBuilder(DriverExceptionInterface::class)
->setConstructorArgs([$message, $errorCode])
->getMock();
$driverException->method('getSQLState')
->willReturn($sqlState);
if ($this->driver instanceof AbstractSQLServerDriver) {
self::markTestSkipped("The SQL Server drivers currently don't instantiate specialized exceptions");
}

$driverException = $this->getMockForAbstractClass(
AbstractException::class,
[$message, $sqlState, $errorCode]
);

$dbalMessage = 'DBAL exception message';
$dbalException = $this->driver->convertException($dbalMessage, $driverException);
Expand Down
13 changes: 10 additions & 3 deletions tests/Functional/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Doctrine\DBAL\Tests\Functional;

use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
Expand Down Expand Up @@ -35,11 +36,17 @@ protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof ExceptionConverterDriver) {
$driver = $this->connection->getDriver();

if ($driver instanceof IBMDB2\Driver) {
self::markTestSkipped("The IBM DB2 driver currently doesn't instantiate specialized exceptions");
}

if (! $driver instanceof AbstractSQLServerDriver) {
return;
}

self::markTestSkipped('Driver does not support special exception handling.');
self::markTestSkipped("The SQL Server drivers currently don't instantiate specialized exceptions");
}

public function testPrimaryConstraintViolationException(): void
Expand Down