Replace DefaultExceptionConverter with driver-specific implementations

parent 17e6eaed
......@@ -2,12 +2,13 @@
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\API;
namespace Doctrine\DBAL\Driver\API\IBMDB2;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception\DriverException;
final class DefaultExceptionConverter implements ExceptionConverter
final class ExceptionConverter implements ExceptionConverterInterface
{
public function convert(string $message, Exception $exception): DriverException
{
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\API\SQLSrv;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception\DriverException;
final class ExceptionConverter implements ExceptionConverterInterface
{
public function convert(string $message, Exception $exception): DriverException
{
return new DriverException($message, $exception);
}
}
......@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\DefaultExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\IBMDB2\ExceptionConverter;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers.
* Abstract base implementation of the {@link Driver} interface for IBM DB2 based drivers.
*/
abstract class AbstractDB2Driver implements Driver
{
......@@ -30,8 +30,8 @@ abstract class AbstractDB2Driver implements Driver
return new DB2SchemaManager($conn);
}
public function getExceptionConverter(): ExceptionConverter
public function getExceptionConverter(): ExceptionConverterInterface
{
return new DefaultExceptionConverter();
return new ExceptionConverter();
}
}
......@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\DefaultExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\SQLSrv\ExceptionConverter;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers.
* Abstract base implementation of the {@link Driver} interface for Microsoft SQL Server based drivers.
*/
abstract class AbstractSQLServerDriver implements Driver
{
......@@ -30,8 +30,8 @@ abstract class AbstractSQLServerDriver implements Driver
return new SQLServerSchemaManager($conn);
}
public function getExceptionConverter(): ExceptionConverter
public function getExceptionConverter(): ExceptionConverterInterface
{
return new DefaultExceptionConverter();
return new ExceptionConverter();
}
}
......@@ -4,8 +4,9 @@ namespace Doctrine\Tests\DBAL\Connection;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\DefaultExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Exception as DriverException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function chr;
......@@ -16,34 +17,43 @@ final class ExceptionHandlingTest extends TestCase
/** @var Connection */
private $connection;
/** @var ExceptionConverter&MockObject */
private $exceptionConverter;
protected function setUp(): void
{
$this->exceptionConverter = $this->createMock(ExceptionConverter::class);
$this->connection = new Connection([], $this->createConfiguredMock(Driver::class, [
'getExceptionConverter' => new DefaultExceptionConverter(),
'getExceptionConverter' => $this->exceptionConverter,
]));
}
public function testDriverExceptionDuringQueryAcceptsBinaryData(): void
{
$e = $this->connection->convertExceptionDuringQuery(
$this->exceptionConverter->expects(self::once())
->method('convert')
->with(self::stringContains('with params ["ABC", "\x80"]'));
$this->connection->convertExceptionDuringQuery(
$this->createMock(DriverException::class),
'',
['ABC', chr(128)]
);
self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage());
}
public function testDriverExceptionDuringQueryAcceptsResource(): void
{
$e = $this->connection->convertExceptionDuringQuery(
$this->exceptionConverter->expects(self::once())
->method('convert')
->with(self::stringContains('Resource'));
$this->connection->convertExceptionDuringQuery(
$this->createMock(DriverException::class),
'INSERT INTO file (`content`) VALUES (?)',
[
1 => fopen(__FILE__, 'r'),
]
);
self::assertStringContainsString('Resource', $e->getMessage());
}
}
......@@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Tests\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\AbstractDB2Driver;
use Doctrine\DBAL\Driver\API\DefaultExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\IBMDB2\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
......@@ -29,8 +29,8 @@ class AbstractDB2DriverTest extends AbstractDriverTest
return new DB2SchemaManager($connection);
}
protected function createExceptionConverter(): ExceptionConverter
protected function createExceptionConverter(): ExceptionConverterInterface
{
return new DefaultExceptionConverter();
return new ExceptionConverter();
}
}
......@@ -4,8 +4,8 @@ namespace Doctrine\DBAL\Tests\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost;
use Doctrine\DBAL\Driver\API\DefaultExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\SQLSrv\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
......@@ -23,9 +23,9 @@ abstract class AbstractSQLServerDriverTest extends AbstractDriverTest
return new SQLServerSchemaManager($connection);
}
protected function createExceptionConverter(): ExceptionConverter
protected function createExceptionConverter(): ExceptionConverterInterface
{
return new DefaultExceptionConverter();
return new ExceptionConverter();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment