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
9e880d97
Unverified
Commit
9e880d97
authored
Mar 03, 2020
by
Grégoire Paris
Committed by
GitHub
Mar 03, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3222 from peter-gribanov/PreviousConversionException
Allow add previous exception in ConversionException
parents
d67347c7
9a214ffb
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 @
9e880d97
...
@@ -26,11 +26,11 @@ class ConversionException extends DBALException
...
@@ -26,11 +26,11 @@ class ConversionException extends DBALException
*
*
* @return \Doctrine\DBAL\Types\ConversionException
* @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
;
$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
...
@@ -64,8 +64,12 @@ class ConversionException extends DBALException
*
*
* @return \Doctrine\DBAL\Types\ConversionException
* @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
);
$actualType
=
is_object
(
$value
)
?
get_class
(
$value
)
:
gettype
(
$value
);
if
(
is_scalar
(
$value
))
{
if
(
is_scalar
(
$value
))
{
...
@@ -75,7 +79,7 @@ class ConversionException extends DBALException
...
@@ -75,7 +79,7 @@ class ConversionException extends DBALException
$actualType
,
$actualType
,
$toType
,
$toType
,
implode
(
', '
,
$possibleTypes
)
implode
(
', '
,
$possibleTypes
)
));
)
,
0
,
$previous
);
}
}
return
new
self
(
sprintf
(
return
new
self
(
sprintf
(
...
@@ -83,7 +87,7 @@ class ConversionException extends DBALException
...
@@ -83,7 +87,7 @@ class ConversionException extends DBALException
$actualType
,
$actualType
,
$toType
,
$toType
,
implode
(
', '
,
$possibleTypes
)
implode
(
', '
,
$possibleTypes
)
));
)
,
0
,
$previous
);
}
}
public
static
function
conversionFailedSerialization
(
$value
,
$format
,
$error
)
public
static
function
conversionFailedSerialization
(
$value
,
$format
,
$error
)
...
...
tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php
View file @
9e880d97
...
@@ -3,13 +3,23 @@
...
@@ -3,13 +3,23 @@
namespace
Doctrine\Tests\DBAL\Types
;
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Exception
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
stdClass
;
use
stdClass
;
use
Throwable
;
use
function
tmpfile
;
use
function
tmpfile
;
class
ConversionExceptionTest
extends
TestCase
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
* @param mixed $scalarValue
*
*
...
@@ -44,9 +54,19 @@ class ConversionExceptionTest extends TestCase
...
@@ -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
public
function
testConversionFailedFormatPreservesPreviousException
()
:
void
{
{
$previous
=
new
Exception
(
);
$previous
=
$this
->
createMock
(
Throwable
::
class
);
$exception
=
ConversionException
::
conversionFailedFormat
(
'foo'
,
'bar'
,
'baz'
,
$previous
);
$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