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
9a214ffb
Commit
9a214ffb
authored
Feb 03, 2020
by
Peter Gribanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow add previous exception in ConversionException
parent
a0e23739
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
8 deletions
+32
-8
ConversionException.php
lib/Doctrine/DBAL/Types/ConversionException.php
+10
-6
ConversionExceptionTest.php
tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php
+22
-2
No files found.
lib/Doctrine/DBAL/Types/ConversionException.php
View file @
9a214ffb
...
...
@@ -26,11 +26,11 @@ class ConversionException extends DBALException
*
* @return \Doctrine\DBAL\Types\ConversionException
*/
public
static
function
conversionFailed
(
$value
,
$toType
)
public
static
function
conversionFailed
(
$value
,
$toType
,
?
Throwable
$previous
=
null
)
{
$value
=
strlen
(
$value
)
>
32
?
substr
(
$value
,
0
,
20
)
.
'...'
:
$value
;
return
new
self
(
'Could not convert database value "'
.
$value
.
'" to Doctrine Type '
.
$toType
);
return
new
self
(
'Could not convert database value "'
.
$value
.
'" to Doctrine Type '
.
$toType
,
0
,
$previous
);
}
/**
...
...
@@ -64,8 +64,12 @@ class ConversionException extends DBALException
*
* @return \Doctrine\DBAL\Types\ConversionException
*/
public
static
function
conversionFailedInvalidType
(
$value
,
$toType
,
array
$possibleTypes
)
{
public
static
function
conversionFailedInvalidType
(
$value
,
$toType
,
array
$possibleTypes
,
?
Throwable
$previous
=
null
)
{
$actualType
=
is_object
(
$value
)
?
get_class
(
$value
)
:
gettype
(
$value
);
if
(
is_scalar
(
$value
))
{
...
...
@@ -75,7 +79,7 @@ class ConversionException extends DBALException
$actualType
,
$toType
,
implode
(
', '
,
$possibleTypes
)
));
)
,
0
,
$previous
);
}
return
new
self
(
sprintf
(
...
...
@@ -83,7 +87,7 @@ class ConversionException extends DBALException
$actualType
,
$toType
,
implode
(
', '
,
$possibleTypes
)
));
)
,
0
,
$previous
);
}
public
static
function
conversionFailedSerialization
(
$value
,
$format
,
$error
)
...
...
tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php
View file @
9a214ffb
...
...
@@ -3,13 +3,23 @@
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Exception
;
use
PHPUnit\Framework\TestCase
;
use
stdClass
;
use
Throwable
;
use
function
tmpfile
;
class
ConversionExceptionTest
extends
TestCase
{
public
function
testConversionFailedPreviousException
()
:
void
{
$previous
=
$this
->
createMock
(
Throwable
::
class
);
$exception
=
ConversionException
::
conversionFailed
(
'foo'
,
'foo'
,
$previous
);
self
::
assertInstanceOf
(
ConversionException
::
class
,
$exception
);
self
::
assertSame
(
$previous
,
$exception
->
getPrevious
());
}
/**
* @param mixed $scalarValue
*
...
...
@@ -44,9 +54,19 @@ class ConversionExceptionTest extends TestCase
);
}
public
function
testConversionFailedInvalidTypePreviousException
()
:
void
{
$previous
=
$this
->
createMock
(
Throwable
::
class
);
$exception
=
ConversionException
::
conversionFailedInvalidType
(
'foo'
,
'foo'
,
[
'bar'
,
'baz'
],
$previous
);
self
::
assertInstanceOf
(
ConversionException
::
class
,
$exception
);
self
::
assertSame
(
$previous
,
$exception
->
getPrevious
());
}
public
function
testConversionFailedFormatPreservesPreviousException
()
:
void
{
$previous
=
new
Exception
(
);
$previous
=
$this
->
createMock
(
Throwable
::
class
);
$exception
=
ConversionException
::
conversionFailedFormat
(
'foo'
,
'bar'
,
'baz'
,
$previous
);
...
...
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