Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
597da178
Unverified
Commit
597da178
authored
Jul 04, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace DefaultExceptionConverter with driver-specific implementations
parent
17e6eaed
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
28 deletions
+56
-28
ExceptionConverter.php
src/Driver/API/IBMDB2/ExceptionConverter.php
+3
-2
ExceptionConverter.php
src/Driver/API/SQLSrv/ExceptionConverter.php
+17
-0
AbstractDB2Driver.php
src/Driver/AbstractDB2Driver.php
+5
-5
AbstractSQLServerDriver.php
src/Driver/AbstractSQLServerDriver.php
+5
-5
ExceptionHandlingTest.php
tests/Connection/ExceptionHandlingTest.php
+18
-8
AbstractDB2DriverTest.php
tests/Driver/AbstractDB2DriverTest.php
+4
-4
AbstractSQLServerDriverTest.php
tests/Driver/AbstractSQLServerDriverTest.php
+4
-4
No files found.
src/Driver/API/
Default
ExceptionConverter.php
→
src/Driver/API/
IBMDB2/
ExceptionConverter.php
View file @
597da178
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
declare
(
strict_types
=
1
);
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\Driver\Exception
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Exception\DriverException
;
final
class
DefaultExceptionConverter
implements
ExceptionConverter
final
class
ExceptionConverter
implements
ExceptionConverterInterface
{
{
public
function
convert
(
string
$message
,
Exception
$exception
)
:
DriverException
public
function
convert
(
string
$message
,
Exception
$exception
)
:
DriverException
{
{
...
...
src/Driver/API/SQLSrv/ExceptionConverter.php
0 → 100644
View file @
597da178
<?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
);
}
}
src/Driver/AbstractDB2Driver.php
View file @
597da178
...
@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
...
@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\API\
DefaultExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
ExceptionConverter
as
ExceptionConverterInterface
;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
IBMDB2\
ExceptionConverter
;
use
Doctrine\DBAL\Platforms\DB2Platform
;
use
Doctrine\DBAL\Platforms\DB2Platform
;
use
Doctrine\DBAL\Schema\DB2SchemaManager
;
use
Doctrine\DBAL\Schema\DB2SchemaManager
;
/**
/**
* Abstract base implementation of the {@link D
octrine\DBAL\D
river} interface for IBM DB2 based drivers.
* Abstract base implementation of the {@link Driver} interface for IBM DB2 based drivers.
*/
*/
abstract
class
AbstractDB2Driver
implements
Driver
abstract
class
AbstractDB2Driver
implements
Driver
{
{
...
@@ -30,8 +30,8 @@ abstract class AbstractDB2Driver implements Driver
...
@@ -30,8 +30,8 @@ abstract class AbstractDB2Driver implements Driver
return
new
DB2SchemaManager
(
$conn
);
return
new
DB2SchemaManager
(
$conn
);
}
}
public
function
getExceptionConverter
()
:
ExceptionConverter
public
function
getExceptionConverter
()
:
ExceptionConverter
Interface
{
{
return
new
Default
ExceptionConverter
();
return
new
ExceptionConverter
();
}
}
}
}
src/Driver/AbstractSQLServerDriver.php
View file @
597da178
...
@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
...
@@ -4,13 +4,13 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\API\
DefaultExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
ExceptionConverter
as
ExceptionConverterInterface
;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
SQLSrv\
ExceptionConverter
;
use
Doctrine\DBAL\Platforms\SQLServer2012Platform
;
use
Doctrine\DBAL\Platforms\SQLServer2012Platform
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
/**
/**
* Abstract base implementation of the {@link D
octrine\DBAL\D
river} 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
abstract
class
AbstractSQLServerDriver
implements
Driver
{
{
...
@@ -30,8 +30,8 @@ abstract class AbstractSQLServerDriver implements Driver
...
@@ -30,8 +30,8 @@ abstract class AbstractSQLServerDriver implements Driver
return
new
SQLServerSchemaManager
(
$conn
);
return
new
SQLServerSchemaManager
(
$conn
);
}
}
public
function
getExceptionConverter
()
:
ExceptionConverter
public
function
getExceptionConverter
()
:
ExceptionConverter
Interface
{
{
return
new
Default
ExceptionConverter
();
return
new
ExceptionConverter
();
}
}
}
}
tests/Connection/ExceptionHandlingTest.php
View file @
597da178
...
@@ -4,8 +4,9 @@ namespace Doctrine\Tests\DBAL\Connection;
...
@@ -4,8 +4,9 @@ namespace Doctrine\Tests\DBAL\Connection;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\API\
Default
ExceptionConverter
;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\Exception
as
DriverException
;
use
Doctrine\DBAL\Driver\Exception
as
DriverException
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
function
chr
;
use
function
chr
;
...
@@ -16,34 +17,43 @@ final class ExceptionHandlingTest extends TestCase
...
@@ -16,34 +17,43 @@ final class ExceptionHandlingTest extends TestCase
/** @var Connection */
/** @var Connection */
private
$connection
;
private
$connection
;
/** @var ExceptionConverter&MockObject */
private
$exceptionConverter
;
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$this
->
exceptionConverter
=
$this
->
createMock
(
ExceptionConverter
::
class
);
$this
->
connection
=
new
Connection
([],
$this
->
createConfiguredMock
(
Driver
::
class
,
[
$this
->
connection
=
new
Connection
([],
$this
->
createConfiguredMock
(
Driver
::
class
,
[
'getExceptionConverter'
=>
new
DefaultExceptionConverter
()
,
'getExceptionConverter'
=>
$this
->
exceptionConverter
,
]));
]));
}
}
public
function
testDriverExceptionDuringQueryAcceptsBinaryData
()
:
void
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
),
$this
->
createMock
(
DriverException
::
class
),
''
,
''
,
[
'ABC'
,
chr
(
128
)]
[
'ABC'
,
chr
(
128
)]
);
);
self
::
assertStringContainsString
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
}
}
public
function
testDriverExceptionDuringQueryAcceptsResource
()
:
void
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
),
$this
->
createMock
(
DriverException
::
class
),
'INSERT INTO file (`content`) VALUES (?)'
,
'INSERT INTO file (`content`) VALUES (?)'
,
[
[
1
=>
fopen
(
__FILE__
,
'r'
),
1
=>
fopen
(
__FILE__
,
'r'
),
]
]
);
);
self
::
assertStringContainsString
(
'Resource'
,
$e
->
getMessage
());
}
}
}
}
tests/Driver/AbstractDB2DriverTest.php
View file @
597da178
...
@@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Tests\Driver;
...
@@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Tests\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\AbstractDB2Driver
;
use
Doctrine\DBAL\Driver\AbstractDB2Driver
;
use
Doctrine\DBAL\Driver\API\
DefaultExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
ExceptionConverter
as
ExceptionConverterInterface
;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
IBMDB2\
ExceptionConverter
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\DB2Platform
;
use
Doctrine\DBAL\Platforms\DB2Platform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
...
@@ -29,8 +29,8 @@ class AbstractDB2DriverTest extends AbstractDriverTest
...
@@ -29,8 +29,8 @@ class AbstractDB2DriverTest extends AbstractDriverTest
return
new
DB2SchemaManager
(
$connection
);
return
new
DB2SchemaManager
(
$connection
);
}
}
protected
function
createExceptionConverter
()
:
ExceptionConverter
protected
function
createExceptionConverter
()
:
ExceptionConverter
Interface
{
{
return
new
Default
ExceptionConverter
();
return
new
ExceptionConverter
();
}
}
}
}
tests/Driver/AbstractSQLServerDriverTest.php
View file @
597da178
...
@@ -4,8 +4,8 @@ namespace Doctrine\DBAL\Tests\Driver;
...
@@ -4,8 +4,8 @@ namespace Doctrine\DBAL\Tests\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost
;
use
Doctrine\DBAL\Driver\API\
DefaultExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
ExceptionConverter
as
ExceptionConverterInterface
;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\API\
SQLSrv\
ExceptionConverter
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\SQLServer2012Platform
;
use
Doctrine\DBAL\Platforms\SQLServer2012Platform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
...
@@ -23,9 +23,9 @@ abstract class AbstractSQLServerDriverTest extends AbstractDriverTest
...
@@ -23,9 +23,9 @@ abstract class AbstractSQLServerDriverTest extends AbstractDriverTest
return
new
SQLServerSchemaManager
(
$connection
);
return
new
SQLServerSchemaManager
(
$connection
);
}
}
protected
function
createExceptionConverter
()
:
ExceptionConverter
protected
function
createExceptionConverter
()
:
ExceptionConverter
Interface
{
{
return
new
Default
ExceptionConverter
();
return
new
ExceptionConverter
();
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment