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
070684af
Unverified
Commit
070684af
authored
Jun 14, 2019
by
Sergei Morozov
Committed by
GitHub
Jun 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3609 from morozov/remove-prophecy
Reworked the mocks generated by Prophecy using PHPUnit
parents
2d10d9f1
8004701a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
82 deletions
+124
-82
DateImmutableTypeTest.php
tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php
+26
-17
DateTimeImmutableTypeTest.php
...s/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
+30
-17
DateTimeTzImmutableTypeTest.php
...Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php
+26
-15
TimeImmutableTypeTest.php
tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php
+26
-17
VarDateTimeImmutableTypeTest.php
...octrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php
+16
-16
No files found.
tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php
View file @
070684af
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateImmutableType
;
use
Doctrine\DBAL\Types\DateImmutableType
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
Prophecy\Prophecy\ObjectProphecy
;
use
function
get_class
;
use
function
get_class
;
class
DateImmutableTypeTest
extends
TestCase
class
DateImmutableTypeTest
extends
TestCase
{
{
/** @var AbstractPlatform|
ObjectProphecy
*/
/** @var AbstractPlatform|
MockObject
*/
private
$platform
;
private
$platform
;
/** @var DateImmutableType */
/** @var DateImmutableType */
...
@@ -24,7 +24,7 @@ class DateImmutableTypeTest extends TestCase
...
@@ -24,7 +24,7 @@ class DateImmutableTypeTest extends TestCase
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$this
->
type
=
Type
::
getType
(
'date_immutable'
);
$this
->
type
=
Type
::
getType
(
'date_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
$this
->
platform
=
$this
->
createMock
(
AbstractPlatform
::
class
);
}
}
public
function
testFactoryCreatesCorrectType
()
:
void
public
function
testFactoryCreatesCorrectType
()
:
void
...
@@ -44,46 +44,53 @@ class DateImmutableTypeTest extends TestCase
...
@@ -44,46 +44,53 @@ class DateImmutableTypeTest extends TestCase
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
{
{
$date
=
$this
->
prophesize
(
DateTimeImmutable
::
class
);
$date
=
$this
->
createMock
(
DateTimeImmutable
::
class
);
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
$date
->
format
(
'Y-m-d'
)
->
willReturn
(
'2016-01-01'
)
->
shouldBeCalled
();
->
method
(
'getDateFormatString'
)
->
willReturn
(
'Y-m-d'
);
$date
->
expects
(
$this
->
once
())
->
method
(
'format'
)
->
with
(
'Y-m-d'
)
->
willReturn
(
'2016-01-01'
);
self
::
assertSame
(
self
::
assertSame
(
'2016-01-01'
,
'2016-01-01'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
()
)
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
)
);
);
}
}
public
function
testConvertsNullToDatabaseValue
()
:
void
public
function
testConvertsNullToDatabaseValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
));
}
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
);
}
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
{
{
$date
=
new
DateTimeImmutable
();
$date
=
new
DateTimeImmutable
();
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()
));
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
));
}
}
public
function
testConvertsNullToPHPValue
()
:
void
public
function
testConvertsNullToPHPValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
public
function
testConvertsDateStringToPHPValue
()
:
void
public
function
testConvertsDateStringToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
->
method
(
'getDateFormatString'
)
->
willReturn
(
'Y-m-d'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertSame
(
'2016-01-01'
,
$date
->
format
(
'Y-m-d'
));
self
::
assertSame
(
'2016-01-01'
,
$date
->
format
(
'Y-m-d'
));
...
@@ -91,9 +98,11 @@ class DateImmutableTypeTest extends TestCase
...
@@ -91,9 +98,11 @@ class DateImmutableTypeTest extends TestCase
public
function
testResetTimeFractionsWhenConvertingToPHPValue
()
:
void
public
function
testResetTimeFractionsWhenConvertingToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
);
$this
->
platform
->
expects
(
$this
->
any
())
->
method
(
'getDateFormatString'
)
->
willReturn
(
'Y-m-d'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
);
self
::
assertSame
(
'2016-01-01 00:00:00.000000'
,
$date
->
format
(
'Y-m-d H:i:s.u'
));
self
::
assertSame
(
'2016-01-01 00:00:00.000000'
,
$date
->
format
(
'Y-m-d H:i:s.u'
));
}
}
...
@@ -102,11 +111,11 @@ class DateImmutableTypeTest extends TestCase
...
@@ -102,11 +111,11 @@ class DateImmutableTypeTest extends TestCase
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid date string'
,
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToPHPValue
(
'invalid date string'
,
$this
->
platform
);
}
}
public
function
testRequiresSQLCommentHint
()
:
void
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
View file @
070684af
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateTimeImmutableType
;
use
Doctrine\DBAL\Types\DateTimeImmutableType
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
Prophecy\Prophecy\ObjectProphecy
;
use
function
get_class
;
use
function
get_class
;
class
DateTimeImmutableTypeTest
extends
TestCase
class
DateTimeImmutableTypeTest
extends
TestCase
{
{
/** @var AbstractPlatform|
ObjectProphecy
*/
/** @var AbstractPlatform|
MockObject
*/
private
$platform
;
private
$platform
;
/** @var DateTimeImmutableType */
/** @var DateTimeImmutableType */
...
@@ -24,7 +24,7 @@ class DateTimeImmutableTypeTest extends TestCase
...
@@ -24,7 +24,7 @@ class DateTimeImmutableTypeTest extends TestCase
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$this
->
type
=
Type
::
getType
(
'datetime_immutable'
);
$this
->
type
=
Type
::
getType
(
'datetime_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
$this
->
platform
=
$this
->
getMockBuilder
(
AbstractPlatform
::
class
)
->
getMock
(
);
}
}
public
function
testFactoryCreatesCorrectType
()
:
void
public
function
testFactoryCreatesCorrectType
()
:
void
...
@@ -44,46 +44,53 @@ class DateTimeImmutableTypeTest extends TestCase
...
@@ -44,46 +44,53 @@ class DateTimeImmutableTypeTest extends TestCase
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
{
{
$date
=
$this
->
prophesize
(
DateTimeImmutable
::
class
);
$date
=
$this
->
getMockBuilder
(
DateTimeImmutable
::
class
)
->
getMock
(
);
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
$date
->
format
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
)
->
shouldBeCalled
();
->
method
(
'getDateTimeFormatString'
)
->
willReturn
(
'Y-m-d H:i:s'
);
$date
->
expects
(
$this
->
once
())
->
method
(
'format'
)
->
with
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
);
self
::
assertSame
(
self
::
assertSame
(
'2016-01-01 15:58:59'
,
'2016-01-01 15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
()
)
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
)
);
);
}
}
public
function
testConvertsNullToDatabaseValue
()
:
void
public
function
testConvertsNullToDatabaseValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
));
}
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
);
}
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
{
{
$date
=
new
DateTimeImmutable
();
$date
=
new
DateTimeImmutable
();
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()
));
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
));
}
}
public
function
testConvertsNullToPHPValue
()
:
void
public
function
testConvertsNullToPHPValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
public
function
testConvertsDateTimeStringToPHPValue
()
:
void
public
function
testConvertsDateTimeStringToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
->
method
(
'getDateTimeFormatString'
)
->
willReturn
(
'Y-m-d H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59'
,
$this
->
platform
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
self
::
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
...
@@ -94,22 +101,28 @@ class DateTimeImmutableTypeTest extends TestCase
...
@@ -94,22 +101,28 @@ class DateTimeImmutableTypeTest extends TestCase
*/
*/
public
function
testConvertsDateTimeStringWithMicrosecondsToPHPValue
()
:
void
public
function
testConvertsDateTimeStringWithMicrosecondsToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
);
$this
->
platform
->
expects
(
$this
->
any
())
->
method
(
'getDateTimeFormatString'
)
->
willReturn
(
'Y-m-d H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456'
,
$this
->
platform
);
self
::
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
self
::
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString
()
:
void
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString
()
:
void
{
{
$this
->
platform
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'getDateTimeFormatString'
)
->
willReturn
(
'Y-m-d H:i:s'
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime string'
,
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime string'
,
$this
->
platform
);
}
}
public
function
testRequiresSQLCommentHint
()
:
void
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php
View file @
070684af
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateTimeTzImmutableType
;
use
Doctrine\DBAL\Types\DateTimeTzImmutableType
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
Prophecy\Prophecy\ObjectProphecy
;
use
function
get_class
;
use
function
get_class
;
class
DateTimeTzImmutableTypeTest
extends
TestCase
class
DateTimeTzImmutableTypeTest
extends
TestCase
{
{
/** @var AbstractPlatform|
ObjectProphecy
*/
/** @var AbstractPlatform|
MockObject
*/
private
$platform
;
private
$platform
;
/** @var DateTimeTzImmutableType */
/** @var DateTimeTzImmutableType */
...
@@ -24,7 +24,7 @@ class DateTimeTzImmutableTypeTest extends TestCase
...
@@ -24,7 +24,7 @@ class DateTimeTzImmutableTypeTest extends TestCase
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$this
->
type
=
Type
::
getType
(
'datetimetz_immutable'
);
$this
->
type
=
Type
::
getType
(
'datetimetz_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
$this
->
platform
=
$this
->
createMock
(
AbstractPlatform
::
class
);
}
}
public
function
testFactoryCreatesCorrectType
()
:
void
public
function
testFactoryCreatesCorrectType
()
:
void
...
@@ -44,46 +44,53 @@ class DateTimeTzImmutableTypeTest extends TestCase
...
@@ -44,46 +44,53 @@ class DateTimeTzImmutableTypeTest extends TestCase
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
{
{
$date
=
$this
->
prophesize
(
DateTimeImmutable
::
class
);
$date
=
$this
->
createMock
(
DateTimeImmutable
::
class
);
$this
->
platform
->
getDateTimeTzFormatString
()
->
willReturn
(
'Y-m-d H:i:s T'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
$date
->
format
(
'Y-m-d H:i:s T'
)
->
willReturn
(
'2016-01-01 15:58:59 UTC'
)
->
shouldBeCalled
();
->
method
(
'getDateTimeTzFormatString'
)
->
willReturn
(
'Y-m-d H:i:s T'
);
$date
->
expects
(
$this
->
once
())
->
method
(
'format'
)
->
with
(
'Y-m-d H:i:s T'
)
->
willReturn
(
'2016-01-01 15:58:59 UTC'
);
self
::
assertSame
(
self
::
assertSame
(
'2016-01-01 15:58:59 UTC'
,
'2016-01-01 15:58:59 UTC'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
()
)
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
)
);
);
}
}
public
function
testConvertsNullToDatabaseValue
()
:
void
public
function
testConvertsNullToDatabaseValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
));
}
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
);
}
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
{
{
$date
=
new
DateTimeImmutable
();
$date
=
new
DateTimeImmutable
();
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()
));
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
));
}
}
public
function
testConvertsNullToPHPValue
()
:
void
public
function
testConvertsNullToPHPValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
public
function
testConvertsDateTimeWithTimezoneStringToPHPValue
()
:
void
public
function
testConvertsDateTimeWithTimezoneStringToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateTimeTzFormatString
()
->
willReturn
(
'Y-m-d H:i:s T'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
->
method
(
'getDateTimeTzFormatString'
)
->
willReturn
(
'Y-m-d H:i:s T'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59 UTC'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59 UTC'
,
$this
->
platform
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertSame
(
'2016-01-01 15:58:59 UTC'
,
$date
->
format
(
'Y-m-d H:i:s T'
));
self
::
assertSame
(
'2016-01-01 15:58:59 UTC'
,
$date
->
format
(
'Y-m-d H:i:s T'
));
...
@@ -91,13 +98,17 @@ class DateTimeTzImmutableTypeTest extends TestCase
...
@@ -91,13 +98,17 @@ class DateTimeTzImmutableTypeTest extends TestCase
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString
()
:
void
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString
()
:
void
{
{
$this
->
platform
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'getDateTimeTzFormatString'
)
->
willReturn
(
'Y-m-d H:i:s T'
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime with timezone string'
,
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime with timezone string'
,
$this
->
platform
);
}
}
public
function
testRequiresSQLCommentHint
()
:
void
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
}
}
tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php
View file @
070684af
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -9,13 +9,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\TimeImmutableType
;
use
Doctrine\DBAL\Types\TimeImmutableType
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
Prophecy\Prophecy\ObjectProphecy
;
use
function
get_class
;
use
function
get_class
;
class
TimeImmutableTypeTest
extends
TestCase
class
TimeImmutableTypeTest
extends
TestCase
{
{
/** @var AbstractPlatform|
ObjectProphecy
*/
/** @var AbstractPlatform|
MockObject
*/
private
$platform
;
private
$platform
;
/** @var TimeImmutableType */
/** @var TimeImmutableType */
...
@@ -24,7 +24,7 @@ class TimeImmutableTypeTest extends TestCase
...
@@ -24,7 +24,7 @@ class TimeImmutableTypeTest extends TestCase
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$this
->
type
=
Type
::
getType
(
'time_immutable'
);
$this
->
type
=
Type
::
getType
(
'time_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
$this
->
platform
=
$this
->
getMockBuilder
(
AbstractPlatform
::
class
)
->
getMock
(
);
}
}
public
function
testFactoryCreatesCorrectType
()
:
void
public
function
testFactoryCreatesCorrectType
()
:
void
...
@@ -44,46 +44,53 @@ class TimeImmutableTypeTest extends TestCase
...
@@ -44,46 +44,53 @@ class TimeImmutableTypeTest extends TestCase
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
{
{
$date
=
$this
->
prophesize
(
DateTimeImmutable
::
class
);
$date
=
$this
->
getMockBuilder
(
DateTimeImmutable
::
class
)
->
getMock
(
);
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
$date
->
format
(
'H:i:s'
)
->
willReturn
(
'15:58:59'
)
->
shouldBeCalled
();
->
method
(
'getTimeFormatString'
)
->
willReturn
(
'H:i:s'
);
$date
->
expects
(
$this
->
once
())
->
method
(
'format'
)
->
with
(
'H:i:s'
)
->
willReturn
(
'15:58:59'
);
self
::
assertSame
(
self
::
assertSame
(
'15:58:59'
,
'15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
()
)
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
)
);
);
}
}
public
function
testConvertsNullToDatabaseValue
()
:
void
public
function
testConvertsNullToDatabaseValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
));
}
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
);
}
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
{
{
$date
=
new
DateTimeImmutable
();
$date
=
new
DateTimeImmutable
();
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()
));
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
));
}
}
public
function
testConvertsNullToPHPValue
()
:
void
public
function
testConvertsNullToPHPValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
public
function
testConvertsTimeStringToPHPValue
()
:
void
public
function
testConvertsTimeStringToPHPValue
()
:
void
{
{
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
)
->
shouldBeCalled
();
$this
->
platform
->
expects
(
$this
->
once
())
->
method
(
'getTimeFormatString'
)
->
willReturn
(
'H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertSame
(
'15:58:59'
,
$date
->
format
(
'H:i:s'
));
self
::
assertSame
(
'15:58:59'
,
$date
->
format
(
'H:i:s'
));
...
@@ -91,9 +98,11 @@ class TimeImmutableTypeTest extends TestCase
...
@@ -91,9 +98,11 @@ class TimeImmutableTypeTest extends TestCase
public
function
testResetDateFractionsWhenConvertingToPHPValue
()
:
void
public
function
testResetDateFractionsWhenConvertingToPHPValue
()
:
void
{
{
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
);
$this
->
platform
->
expects
(
$this
->
any
())
->
method
(
'getTimeFormatString'
)
->
willReturn
(
'H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
->
reveal
()
);
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
);
self
::
assertSame
(
'1970-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
self
::
assertSame
(
'1970-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
}
...
@@ -102,11 +111,11 @@ class TimeImmutableTypeTest extends TestCase
...
@@ -102,11 +111,11 @@ class TimeImmutableTypeTest extends TestCase
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid time string'
,
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToPHPValue
(
'invalid time string'
,
$this
->
platform
);
}
}
public
function
testRequiresSQLCommentHint
()
:
void
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
}
}
tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php
View file @
070684af
...
@@ -9,12 +9,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -9,12 +9,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\VarDateTimeImmutableType
;
use
Doctrine\DBAL\Types\VarDateTimeImmutableType
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
use
Prophecy\Prophecy\ObjectProphecy
;
class
VarDateTimeImmutableTypeTest
extends
TestCase
class
VarDateTimeImmutableTypeTest
extends
TestCase
{
{
/** @var AbstractPlatform|
ObjectProphecy
*/
/** @var AbstractPlatform|
MockObject
*/
private
$platform
;
private
$platform
;
/** @var VarDateTimeImmutableType */
/** @var VarDateTimeImmutableType */
...
@@ -27,7 +27,7 @@ class VarDateTimeImmutableTypeTest extends TestCase
...
@@ -27,7 +27,7 @@ class VarDateTimeImmutableTypeTest extends TestCase
}
}
$this
->
type
=
Type
::
getType
(
'vardatetime_immutable'
);
$this
->
type
=
Type
::
getType
(
'vardatetime_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
$this
->
platform
=
$this
->
getMockForAbstractClass
(
AbstractPlatform
::
class
);
}
}
public
function
testReturnsName
()
:
void
public
function
testReturnsName
()
:
void
...
@@ -42,46 +42,46 @@ class VarDateTimeImmutableTypeTest extends TestCase
...
@@ -42,46 +42,46 @@ class VarDateTimeImmutableTypeTest extends TestCase
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
:
void
{
{
$date
=
$this
->
prophesize
(
DateTimeImmutable
::
class
);
$date
=
$this
->
getMockBuilder
(
DateTimeImmutable
::
class
)
->
getMock
(
);
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$date
->
expects
(
$this
->
once
())
$date
->
format
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
)
->
shouldBeCalled
();
->
method
(
'format'
)
->
with
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
);
self
::
assertSame
(
self
::
assertSame
(
'2016-01-01 15:58:59'
,
'2016-01-01 15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
()
)
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
)
);
);
}
}
public
function
testConvertsNullToDatabaseValue
()
:
void
public
function
testConvertsNullToDatabaseValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
));
}
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
:
void
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToDatabaseValue
(
new
DateTime
(),
$this
->
platform
);
}
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
:
void
{
{
$date
=
new
DateTimeImmutable
();
$date
=
new
DateTimeImmutable
();
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()
));
self
::
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
));
}
}
public
function
testConvertsNullToPHPValue
()
:
void
public
function
testConvertsNullToPHPValue
()
:
void
{
{
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()
));
self
::
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
}
public
function
testConvertsDateishStringToPHPValue
()
:
void
public
function
testConvertsDateishStringToPHPValue
()
:
void
{
{
$this
->
platform
->
getDateTimeFormatString
()
->
shouldNotBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456 UTC'
,
$this
->
platform
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456 UTC'
,
$this
->
platform
->
reveal
());
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertInstanceOf
(
DateTimeImmutable
::
class
,
$date
);
self
::
assertSame
(
'2016-01-01 15:58:59.123456 UTC'
,
$date
->
format
(
'Y-m-d H:i:s.u T'
));
self
::
assertSame
(
'2016-01-01 15:58:59.123456 UTC'
,
$date
->
format
(
'Y-m-d H:i:s.u T'
));
...
@@ -91,11 +91,11 @@ class VarDateTimeImmutableTypeTest extends TestCase
...
@@ -91,11 +91,11 @@ class VarDateTimeImmutableTypeTest extends TestCase
{
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid date-ish string'
,
$this
->
platform
->
reveal
()
);
$this
->
type
->
convertToPHPValue
(
'invalid date-ish string'
,
$this
->
platform
);
}
}
public
function
testRequiresSQLCommentHint
()
:
void
public
function
testRequiresSQLCommentHint
()
:
void
{
{
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()
));
self
::
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
));
}
}
}
}
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