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
7c975933
Unverified
Commit
7c975933
authored
Jul 23, 2017
by
Luís Cobucci
Committed by
Sergei Morozov
Mar 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add type declarations to DateIntervalTest
parent
ff369310
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
24 deletions
+26
-24
DateIntervalType.php
lib/Doctrine/DBAL/Types/DateIntervalType.php
+2
-1
DateIntervalTest.php
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
+24
-23
No files found.
lib/Doctrine/DBAL/Types/DateIntervalType.php
View file @
7c975933
...
@@ -3,13 +3,14 @@
...
@@ -3,13 +3,14 @@
namespace
Doctrine\DBAL\Types
;
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
function
substr
;
/**
/**
* Type that maps interval string to a PHP DateInterval Object.
* Type that maps interval string to a PHP DateInterval Object.
*/
*/
class
DateIntervalType
extends
Type
class
DateIntervalType
extends
Type
{
{
const
FORMAT
=
'%RP%YY%MM%DDT%HH%IM%SS'
;
public
const
FORMAT
=
'%RP%YY%MM%DDT%HH%IM%SS'
;
/**
/**
* {@inheritdoc}
* {@inheritdoc}
...
...
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
View file @
7c975933
...
@@ -2,10 +2,13 @@
...
@@ -2,10 +2,13 @@
namespace
Doctrine\Tests\DBAL\Types
;
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateIntervalType
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
use
Doctrine\Tests\DbalTestCase
;
class
DateIntervalTest
extends
\Doctrine\Tests\
DbalTestCase
final
class
DateIntervalTest
extends
DbalTestCase
{
{
/**
/**
* @var MockPlatform
* @var MockPlatform
...
@@ -20,15 +23,15 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
...
@@ -20,15 +23,15 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
protected
function
setUp
()
protected
function
setUp
()
:
void
{
{
$this
->
platform
=
new
MockPlatform
();
$this
->
platform
=
new
MockPlatform
();
$this
->
type
=
Type
::
getType
(
'dateinterval'
);
$this
->
type
=
Type
::
getType
(
'dateinterval'
);
self
::
assertInstanceOf
(
'Doctrine\DBAL\Types\DateIntervalType'
,
$this
->
type
);
self
::
assertInstanceOf
(
DateIntervalType
::
class
,
$this
->
type
);
}
}
public
function
testDateIntervalConvertsToDatabaseValue
()
public
function
testDateIntervalConvertsToDatabaseValue
()
:
void
{
{
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
...
@@ -38,40 +41,40 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
...
@@ -38,40 +41,40 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
self
::
assertEquals
(
$expected
,
$actual
);
self
::
assertEquals
(
$expected
,
$actual
);
}
}
public
function
testDateIntervalConvertsToPHPValue
()
public
function
testDateIntervalConvertsToPHPValue
()
:
void
{
{
$interval
=
$this
->
type
->
convertToPHPValue
(
'+P02Y00M01DT01H02M03S'
,
$this
->
platform
);
$interval
=
$this
->
type
->
convertToPHPValue
(
'+P02Y00M01DT01H02M03S'
,
$this
->
platform
);
self
::
assertInstanceOf
(
'DateInterval'
,
$interval
);
self
::
assertInstanceOf
(
\DateInterval
::
class
,
$interval
);
self
::
assertEquals
(
'+P02Y00M01DT01H02M03S'
,
$interval
->
format
(
'%RP%YY%MM%DDT%HH%IM%SS'
));
self
::
assertEquals
(
'+P02Y00M01DT01H02M03S'
,
$interval
->
format
(
DateIntervalType
::
FORMAT
));
}
}
public
function
testNegativeDateIntervalConvertsToDatabaseValue
()
public
function
testNegativeDateIntervalConvertsToDatabaseValue
()
:
void
{
{
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
$interval
->
invert
=
1
;
$interval
->
invert
=
1
;
$expected
=
'-P02Y00M01DT01H02M03S'
;
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$interval
,
$this
->
platform
);
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$interval
,
$this
->
platform
);
self
::
assertEquals
(
$expected
,
$actual
);
self
::
assertEquals
(
'-P02Y00M01DT01H02M03S'
,
$actual
);
}
}
public
function
testNegativeDateIntervalConvertsToPHPValue
()
public
function
testNegativeDateIntervalConvertsToPHPValue
()
:
void
{
{
$interval
=
$this
->
type
->
convertToPHPValue
(
'-P02Y00M01DT01H02M03S'
,
$this
->
platform
);
$interval
=
$this
->
type
->
convertToPHPValue
(
'-P02Y00M01DT01H02M03S'
,
$this
->
platform
);
self
::
assertInstanceOf
(
'DateInterval'
,
$interval
);
self
::
assertInstanceOf
(
\DateInterval
::
class
,
$interval
);
self
::
assertEquals
(
'-P02Y00M01DT01H02M03S'
,
$interval
->
format
(
'%RP%YY%MM%DDT%HH%IM%SS'
));
self
::
assertEquals
(
'-P02Y00M01DT01H02M03S'
,
$interval
->
format
(
DateIntervalType
::
FORMAT
));
}
}
public
function
testInvalidDateIntervalFormatConversion
()
public
function
testInvalidDateIntervalFormatConversion
()
:
void
{
{
$this
->
expectException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
}
}
public
function
testDateIntervalNullConversion
()
public
function
testDateIntervalNullConversion
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
...
@@ -79,19 +82,17 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
...
@@ -79,19 +82,17 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
/**
* @group DBAL-1288
* @group DBAL-1288
*/
*/
public
function
testRequiresSQLCommentHint
()
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
/**
/**
* @dataProvider invalidPHPValuesProvider
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
:
void
{
{
$this
->
expectException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
$value
,
$this
->
platform
);
$this
->
type
->
convertToDatabaseValue
(
$value
,
$this
->
platform
);
}
}
...
@@ -99,7 +100,7 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
...
@@ -99,7 +100,7 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
/**
* @return mixed[][]
* @return mixed[][]
*/
*/
public
function
invalidPHPValuesProvider
()
public
function
invalidPHPValuesProvider
()
:
array
{
{
return
[
return
[
[
0
],
[
0
],
...
...
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