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
ae67ace8
Commit
ae67ace8
authored
Sep 06, 2015
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#869 - DBAL-1293 - testing `DateIntervalType` logic with invalid type conversions
parent
beb2c7cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
10 deletions
+54
-10
DateIntervalTest.php
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
+54
-10
No files found.
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
View file @
ae67ace8
...
...
@@ -7,14 +7,23 @@ use Doctrine\Tests\DBAL\Mocks\MockPlatform;
class
DateIntervalTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
/**
* @var MockPlatform
*/
private
$platform
;
/**
* @var \Doctrine\DBAL\Types\DateIntervalType
*/
private
$type
;
/**
* {@inheritDoc}
*/
protected
function
setUp
()
{
$this
->
_
platform
=
new
MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'dateinterval'
);
$this
->
platform
=
new
MockPlatform
();
$this
->
type
=
Type
::
getType
(
'dateinterval'
);
}
public
function
testDateIntervalConvertsToDatabaseValue
()
...
...
@@ -22,14 +31,14 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
$expected
=
'P0002-00-01T01:02:03'
;
$actual
=
$this
->
_type
->
convertToDatabaseValue
(
$interval
,
$this
->
_
platform
);
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$interval
,
$this
->
platform
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testDateIntervalConvertsToPHPValue
()
{
$date
=
$this
->
_type
->
convertToPHPValue
(
'P0002-00-01T01:02:03'
,
$this
->
_
platform
);
$date
=
$this
->
type
->
convertToPHPValue
(
'P0002-00-01T01:02:03'
,
$this
->
platform
);
$this
->
assertInstanceOf
(
'DateInterval'
,
$date
);
$this
->
assertEquals
(
'P2Y0M1DT1H2M3S'
,
$date
->
format
(
'P%yY%mM%dDT%hH%iM%sS'
));
}
...
...
@@ -37,12 +46,12 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
public
function
testInvalidDateIntervalFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_
platform
);
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
}
public
function
testDateIntervalNullConversion
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_
platform
));
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
/**
...
...
@@ -50,6 +59,41 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
*/
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
_type
->
requiresSQLCommentHint
(
$this
->
_platform
));
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
type
->
convertToDatabaseValue
(
$value
,
$this
->
platform
);
}
/**
* @return mixed[][]
*/
public
function
invalidPHPValuesProvider
()
{
return
[
[
0
],
[
''
],
[
'foo'
],
[
'10:11:12'
],
[
'2015-01-31'
],
[
'2015-01-31 10:11:12'
],
[
new
\stdClass
()],
[
$this
],
[
27
],
[
-
1
],
[
1.2
],
[[]],
[[
'an array'
]],
[
new
\DateTime
()],
];
}
}
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