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
8a3a81f9
Commit
8a3a81f9
authored
Nov 20, 2015
by
Mathieu Rochette
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid rewrapping Docrine\DBAL\Exception\DriverException
parent
c83a43c3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+17
-8
DBALExceptionTest.php
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
+9
-0
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
8a3a81f9
...
...
@@ -19,7 +19,8 @@
namespace
Doctrine\DBAL
;
use
Doctrine\DBAL\Driver\DriverException
;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
class
DBALException
extends
\Exception
...
...
@@ -112,11 +113,7 @@ class DBALException extends \Exception
}
$msg
.=
":
\n\n
"
.
$driverEx
->
getMessage
();
if
(
$driver
instanceof
ExceptionConverterDriver
&&
$driverEx
instanceof
DriverException
)
{
return
$driver
->
convertException
(
$msg
,
$driverEx
);
}
return
new
self
(
$msg
,
0
,
$driverEx
);
return
static
::
wrapException
(
$driver
,
$driverEx
,
$msg
);
}
/**
...
...
@@ -127,9 +124,21 @@ class DBALException extends \Exception
*/
public
static
function
driverException
(
Driver
$driver
,
\Exception
$driverEx
)
{
$msg
=
"An exception occurred in driver: "
.
$driverEx
->
getMessage
();
return
static
::
wrapException
(
$driver
,
$driverEx
,
"An exception occurred in driver: "
.
$driverEx
->
getMessage
());
}
if
(
$driver
instanceof
ExceptionConverterDriver
&&
$driverEx
instanceof
DriverException
)
{
/**
* @param \Doctrine\DBAL\Driver $driver
* @param \Exception $driverEx
*
* @return \Doctrine\DBAL\DBALException
*/
private
static
function
wrapException
(
Driver
$driver
,
\Exception
$driverEx
,
$msg
)
{
if
(
$driverEx
instanceof
Exception\DriverException
)
{
return
$driverEx
;
}
if
(
$driver
instanceof
ExceptionConverterDriver
&&
$driverEx
instanceof
Driver\DriverException
)
{
return
$driver
->
convertException
(
$msg
,
$driverEx
);
}
...
...
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
View file @
8a3a81f9
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Exception\DriverException
;
class
DBALExceptionTest
extends
\Doctrine\Tests\DbalTestCase
{
...
...
@@ -12,4 +13,12 @@ class DBALExceptionTest extends \Doctrine\Tests\DbalTestCase
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$this
->
assertContains
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
}
public
function
testAvoidOverWrappingOnDriverException
()
{
$driver
=
$this
->
getMock
(
'\Doctrine\DBAL\Driver'
);
$ex
=
new
DriverException
(
''
,
$this
->
getMock
(
'\Doctrine\DBAL\Driver\DriverException'
));
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
$ex
,
''
);
$this
->
assertSame
(
$ex
,
$e
);
}
}
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