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
e9552089
Commit
e9552089
authored
Jul 15, 2016
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add immutable date types
Closes #1882
parent
c48effb6
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1066 additions
and
27 deletions
+1066
-27
known-vendor-issues.rst
docs/en/reference/known-vendor-issues.rst
+13
-5
types.rst
docs/en/reference/types.rst
+45
-1
DateImmutableType.php
lib/Doctrine/DBAL/Types/DateImmutableType.php
+89
-0
DateTimeImmutableType.php
lib/Doctrine/DBAL/Types/DateTimeImmutableType.php
+93
-0
DateTimeTzImmutableType.php
lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php
+89
-0
TimeImmutableType.php
lib/Doctrine/DBAL/Types/TimeImmutableType.php
+89
-0
Type.php
lib/Doctrine/DBAL/Types/Type.php
+29
-21
VarDateTimeImmutableType.php
lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php
+85
-0
DateImmutableTypeTest.php
tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php
+110
-0
DateTimeImmutableTypeTest.php
...s/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
+113
-0
DateTimeTzImmutableTypeTest.php
...Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php
+101
-0
TimeImmutableTypeTest.php
tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php
+110
-0
VarDateTimeImmutableTypeTest.php
...octrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php
+100
-0
No files found.
docs/en/reference/known-vendor-issues.rst
View file @
e9552089
...
@@ -26,7 +26,7 @@ full representation:
...
@@ -26,7 +26,7 @@ full representation:
2010-10-10 10:10:10.123456 (Y-m-d H:i:s.u)
2010-10-10 10:10:10.123456 (Y-m-d H:i:s.u)
Using the DateTime, DateTimeTz or Time type with microseconds
Using the DateTime, DateTimeTz or Time type
(and immutable variants)
with microseconds
enabled columns can lead to errors because internally types expect
enabled columns can lead to errors because internally types expect
the exact format 'Y-m-d H:i:s' in combination with
the exact format 'Y-m-d H:i:s' in combination with
``DateTime::createFromFormat()``. This method is twice a fast as
``DateTime::createFromFormat()``. This method is twice a fast as
...
@@ -42,8 +42,8 @@ without microseconds:
...
@@ -42,8 +42,8 @@ without microseconds:
If you do not let Doctrine create the date column types and rather
If you do not let Doctrine create the date column types and rather
use types with microseconds you have replace the "DateTime",
use types with microseconds you have replace the "DateTime",
"DateTimeTz" and "Time" types
with a more liberal DateTime parser
"DateTimeTz" and "Time" types
(and immutable variants) with a more
that detects the format automatically:
liberal DateTime parser
that detects the format automatically:
::
::
...
@@ -53,6 +53,10 @@ that detects the format automatically:
...
@@ -53,6 +53,10 @@ that detects the format automatically:
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('time', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('time', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('datetime_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
Type::overrideType('datetimetz_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
Type::overrideType('time_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
Timezones and DateTimeTz
Timezones and DateTimeTz
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~
...
@@ -191,8 +195,8 @@ a value with microseconds = 0.
...
@@ -191,8 +195,8 @@ a value with microseconds = 0.
If you do not let Doctrine create the date column types and rather
If you do not let Doctrine create the date column types and rather
use types with microseconds you have replace the "DateTime",
use types with microseconds you have replace the "DateTime",
"DateTimeTz" and "Time" types
with a more liberal DateTime parser
"DateTimeTz" and "Time" types
(and immutable variants) with a more
that detects the format automatically:
liberal DateTime parser
that detects the format automatically:
::
::
...
@@ -202,6 +206,10 @@ that detects the format automatically:
...
@@ -202,6 +206,10 @@ that detects the format automatically:
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTime');
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTime');
Type::overrideType('time', 'Doctrine\DBAL\Types\VarDateTime');
Type::overrideType('time', 'Doctrine\DBAL\Types\VarDateTime');
Type::overrideType('datetime_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
Type::overrideType('datetimetz_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
Type::overrideType('time_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType');
PDO_SQLSRV: VARBINARY/BLOB columns
PDO_SQLSRV: VARBINARY/BLOB columns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
docs/en/reference/types.rst
View file @
e9552089
...
@@ -248,6 +248,17 @@ without time and timezone information, you should consider using this type.
...
@@ -248,6 +248,17 @@ without time and timezone information, you should consider using this type.
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
or ``null`` if no data is present.
or ``null`` if no data is present.
date_immutable
^^^^^^^^^^^^^^
The immutable variant of the ``date`` type.
Values retrieved from the database are always converted to PHP's ``\DateTimeImmutable``
object or ``null`` if no data is present.
.. note::
Available since version ``2.6``.
datetime
datetime
^^^^^^^^
^^^^^^^^
...
@@ -271,6 +282,17 @@ or ``null`` if no data is present.
...
@@ -271,6 +282,17 @@ or ``null`` if no data is present.
and not parsed correctly by ``date_create()``, however since
and not parsed correctly by ``date_create()``, however since
databases are rather strict on dates there should be no problem.
databases are rather strict on dates there should be no problem.
datetime_immutable
^^^^^^^^^^^^^^^^^^
The immutable variant of the ``datetime`` type.
Values retrieved from the database are always converted to PHP's ``\DateTimeImmutable``
object or ``null`` if no data is present.
.. note::
Available since version ``2.6``.
datetimetz
datetimetz
^^^^^^^^^^
^^^^^^^^^^
...
@@ -280,6 +302,17 @@ information, you should consider using this type.
...
@@ -280,6 +302,17 @@ information, you should consider using this type.
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
or ``null`` if no data is present.
or ``null`` if no data is present.
datetimetz_immutable
^^^^^^^^^^^^^^^^^^^^
The immutable variant of the ``datetimetz`` type.
Values retrieved from the database are always converted to PHP's ``\DateTimeImmutable``
object or ``null`` if no data is present.
.. note::
Available since version ``2.6``.
time
time
^^^^
^^^^
...
@@ -289,6 +322,17 @@ without date, time and timezone information, you should consider using this type
...
@@ -289,6 +322,17 @@ without date, time and timezone information, you should consider using this type
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
Values retrieved from the database are always converted to PHP's ``\DateTime`` object
or ``null`` if no data is present.
or ``null`` if no data is present.
time_immutable
^^^^^^^^^^^^^^
The immutable variant of the ``time`` type.
Values retrieved from the database are always converted to PHP's ``\DateTimeImmutable``
object or ``null`` if no data is present.
.. note::
Available since version ``2.6``.
dateinterval
dateinterval
^^^^^^^^^^^^
^^^^^^^^^^^^
...
...
lib/Doctrine/DBAL/Types/DateImmutableType.php
0 → 100644
View file @
e9552089
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Immutable type of {@see DateType}.
*
* @since 2.6
* @author Steve Müller <deeky666@googlemail.com>
*/
class
DateImmutableType
extends
DateType
{
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
Type
::
DATE_IMMUTABLE
;
}
/**
* {@inheritdoc}
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
$value
;
}
if
(
$value
instanceof
\DateTimeImmutable
)
{
return
$value
->
format
(
$platform
->
getDateFormatString
());
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
\DateTimeImmutable
::
class
]
);
}
/**
* {@inheritdoc}
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
||
$value
instanceof
\DateTimeImmutable
)
{
return
$value
;
}
$dateTime
=
\DateTimeImmutable
::
createFromFormat
(
'!'
.
$platform
->
getDateFormatString
(),
$value
);
if
(
!
$dateTime
)
{
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
$platform
->
getDateFormatString
()
);
}
return
$dateTime
;
}
/**
* {@inheritdoc}
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/DateTimeImmutableType.php
0 → 100644
View file @
e9552089
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Immutable type of {@see DateTimeType}.
*
* @since 2.6
* @author Steve Müller <deeky666@googlemail.com>
*/
class
DateTimeImmutableType
extends
DateTimeType
{
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
Type
::
DATETIME_IMMUTABLE
;
}
/**
* {@inheritdoc}
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
$value
;
}
if
(
$value
instanceof
\DateTimeImmutable
)
{
return
$value
->
format
(
$platform
->
getDateTimeFormatString
());
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
\DateTimeImmutable
::
class
]
);
}
/**
* {@inheritdoc}
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
||
$value
instanceof
\DateTimeImmutable
)
{
return
$value
;
}
$dateTime
=
\DateTimeImmutable
::
createFromFormat
(
$platform
->
getDateTimeFormatString
(),
$value
);
if
(
!
$dateTime
)
{
$dateTime
=
\date_create_immutable
(
$value
);
}
if
(
!
$dateTime
)
{
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
$platform
->
getDateTimeFormatString
()
);
}
return
$dateTime
;
}
/**
* {@inheritdoc}
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php
0 → 100644
View file @
e9552089
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Immutable type of {@see DateTimeTzType}.
*
* @since 2.6
* @author Steve Müller <deeky666@googlemail.com>
*/
class
DateTimeTzImmutableType
extends
DateTimeTzType
{
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
Type
::
DATETIMETZ_IMMUTABLE
;
}
/**
* {@inheritdoc}
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
$value
;
}
if
(
$value
instanceof
\DateTimeImmutable
)
{
return
$value
->
format
(
$platform
->
getDateTimeTzFormatString
());
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
\DateTimeImmutable
::
class
]
);
}
/**
* {@inheritdoc}
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
||
$value
instanceof
\DateTimeImmutable
)
{
return
$value
;
}
$dateTime
=
\DateTimeImmutable
::
createFromFormat
(
$platform
->
getDateTimeTzFormatString
(),
$value
);
if
(
!
$dateTime
)
{
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
$platform
->
getDateTimeTzFormatString
()
);
}
return
$dateTime
;
}
/**
* {@inheritdoc}
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/TimeImmutableType.php
0 → 100644
View file @
e9552089
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Immutable type of {@see TimeType}.
*
* @since 2.6
* @author Steve Müller <deeky666@googlemail.com>
*/
class
TimeImmutableType
extends
TimeType
{
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
Type
::
TIME_IMMUTABLE
;
}
/**
* {@inheritdoc}
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
$value
;
}
if
(
$value
instanceof
\DateTimeImmutable
)
{
return
$value
->
format
(
$platform
->
getTimeFormatString
());
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
\DateTimeImmutable
::
class
]
);
}
/**
* {@inheritdoc}
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
||
$value
instanceof
\DateTimeImmutable
)
{
return
$value
;
}
$dateTime
=
\DateTimeImmutable
::
createFromFormat
(
'!'
.
$platform
->
getTimeFormatString
(),
$value
);
if
(
!
$dateTime
)
{
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
$platform
->
getTimeFormatString
()
);
}
return
$dateTime
;
}
/**
* {@inheritdoc}
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/Type.php
View file @
e9552089
...
@@ -40,9 +40,13 @@ abstract class Type
...
@@ -40,9 +40,13 @@ abstract class Type
const
BIGINT
=
'bigint'
;
const
BIGINT
=
'bigint'
;
const
BOOLEAN
=
'boolean'
;
const
BOOLEAN
=
'boolean'
;
const
DATETIME
=
'datetime'
;
const
DATETIME
=
'datetime'
;
const
DATETIME_IMMUTABLE
=
'datetime_immutable'
;
const
DATETIMETZ
=
'datetimetz'
;
const
DATETIMETZ
=
'datetimetz'
;
const
DATETIMETZ_IMMUTABLE
=
'datetimetz_immutable'
;
const
DATE
=
'date'
;
const
DATE
=
'date'
;
const
DATE_IMMUTABLE
=
'date_immutable'
;
const
TIME
=
'time'
;
const
TIME
=
'time'
;
const
TIME_IMMUTABLE
=
'time_immutable'
;
const
DECIMAL
=
'decimal'
;
const
DECIMAL
=
'decimal'
;
const
INTEGER
=
'integer'
;
const
INTEGER
=
'integer'
;
const
OBJECT
=
'object'
;
const
OBJECT
=
'object'
;
...
@@ -68,27 +72,31 @@ abstract class Type
...
@@ -68,27 +72,31 @@ abstract class Type
* @var array
* @var array
*/
*/
private
static
$_typesMap
=
array
(
private
static
$_typesMap
=
array
(
self
::
TARRAY
=>
'Doctrine\DBAL\Types\ArrayType'
,
self
::
TARRAY
=>
ArrayType
::
class
,
self
::
SIMPLE_ARRAY
=>
'Doctrine\DBAL\Types\SimpleArrayType'
,
self
::
SIMPLE_ARRAY
=>
SimpleArrayType
::
class
,
self
::
JSON_ARRAY
=>
'Doctrine\DBAL\Types\JsonArrayType'
,
self
::
JSON_ARRAY
=>
JsonArrayType
::
class
,
self
::
JSON
=>
'Doctrine\DBAL\Types\JsonType'
,
self
::
JSON
=>
JsonType
::
class
,
self
::
OBJECT
=>
'Doctrine\DBAL\Types\ObjectType'
,
self
::
OBJECT
=>
ObjectType
::
class
,
self
::
BOOLEAN
=>
'Doctrine\DBAL\Types\BooleanType'
,
self
::
BOOLEAN
=>
BooleanType
::
class
,
self
::
INTEGER
=>
'Doctrine\DBAL\Types\IntegerType'
,
self
::
INTEGER
=>
IntegerType
::
class
,
self
::
SMALLINT
=>
'Doctrine\DBAL\Types\SmallIntType'
,
self
::
SMALLINT
=>
SmallIntType
::
class
,
self
::
BIGINT
=>
'Doctrine\DBAL\Types\BigIntType'
,
self
::
BIGINT
=>
BigIntType
::
class
,
self
::
STRING
=>
'Doctrine\DBAL\Types\StringType'
,
self
::
STRING
=>
StringType
::
class
,
self
::
TEXT
=>
'Doctrine\DBAL\Types\TextType'
,
self
::
TEXT
=>
TextType
::
class
,
self
::
DATETIME
=>
'Doctrine\DBAL\Types\DateTimeType'
,
self
::
DATETIME
=>
DateTimeType
::
class
,
self
::
DATETIMETZ
=>
'Doctrine\DBAL\Types\DateTimeTzType'
,
self
::
DATETIME_IMMUTABLE
=>
DateTimeImmutableType
::
class
,
self
::
DATE
=>
'Doctrine\DBAL\Types\DateType'
,
self
::
DATETIMETZ
=>
DateTimeTzType
::
class
,
self
::
TIME
=>
'Doctrine\DBAL\Types\TimeType'
,
self
::
DATETIMETZ_IMMUTABLE
=>
DateTimeTzImmutableType
::
class
,
self
::
DECIMAL
=>
'Doctrine\DBAL\Types\DecimalType'
,
self
::
DATE
=>
DateType
::
class
,
self
::
FLOAT
=>
'Doctrine\DBAL\Types\FloatType'
,
self
::
DATE_IMMUTABLE
=>
DateImmutableType
::
class
,
self
::
BINARY
=>
'Doctrine\DBAL\Types\BinaryType'
,
self
::
TIME
=>
TimeType
::
class
,
self
::
BLOB
=>
'Doctrine\DBAL\Types\BlobType'
,
self
::
TIME_IMMUTABLE
=>
TimeImmutableType
::
class
,
self
::
GUID
=>
'Doctrine\DBAL\Types\GuidType'
,
self
::
DECIMAL
=>
DecimalType
::
class
,
self
::
DATEINTERVAL
=>
'Doctrine\DBAL\Types\DateIntervalType'
,
self
::
FLOAT
=>
FloatType
::
class
,
self
::
BINARY
=>
BinaryType
::
class
,
self
::
BLOB
=>
BlobType
::
class
,
self
::
GUID
=>
GuidType
::
class
,
self
::
DATEINTERVAL
=>
DateIntervalType
::
class
,
);
);
/**
/**
...
...
lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php
0 → 100644
View file @
e9552089
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Immutable type of {@see VarDateTimeType}.
*
* @since 2.6
* @author Steve Müller <deeky666@googlemail.com>
*/
class
VarDateTimeImmutableType
extends
VarDateTimeType
{
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
Type
::
DATETIME_IMMUTABLE
;
}
/**
* {@inheritdoc}
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
$value
;
}
if
(
$value
instanceof
\DateTimeImmutable
)
{
return
$value
->
format
(
$platform
->
getDateTimeFormatString
());
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
\DateTimeImmutable
::
class
]
);
}
/**
* {@inheritdoc}
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
||
$value
instanceof
\DateTimeImmutable
)
{
return
$value
;
}
$dateTime
=
date_create_immutable
(
$value
);
if
(
!
$dateTime
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$dateTime
;
}
/**
* {@inheritdoc}
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php
0 → 100644
View file @
e9552089
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateImmutableType
;
use
Doctrine\DBAL\Types\Type
;
class
DateImmutableTypeTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy
*/
private
$platform
;
/**
* @var DateImmutableType
*/
private
$type
;
protected
function
setUp
()
{
$this
->
type
=
Type
::
getType
(
'date_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
}
public
function
testFactoryCreatesCorrectType
()
{
$this
->
assertSame
(
DateImmutableType
::
class
,
get_class
(
$this
->
type
));
}
public
function
testReturnsName
()
{
$this
->
assertSame
(
'date_immutable'
,
$this
->
type
->
getName
());
}
public
function
testReturnsBindingType
()
{
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$this
->
type
->
getBindingType
());
}
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
{
$date
=
$this
->
prophesize
(
\DateTimeImmutable
::
class
);
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
)
->
shouldBeCalled
();
$date
->
format
(
'Y-m-d'
)
->
willReturn
(
'2016-01-01'
)
->
shouldBeCalled
();
$this
->
assertSame
(
'2016-01-01'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
())
);
}
public
function
testConvertsNullToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
->
reveal
());
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
{
$date
=
new
\DateTimeImmutable
();
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsNullToPHPValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsDateStringToPHPValue
()
{
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
)
->
shouldBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
->
reveal
());
$this
->
assertInstanceOf
(
\DateTimeImmutable
::
class
,
$date
);
$this
->
assertSame
(
'2016-01-01'
,
$date
->
format
(
'Y-m-d'
));
}
public
function
testResetTimeFractionsWhenConvertingToPHPValue
()
{
$this
->
platform
->
getDateFormatString
()
->
willReturn
(
'Y-m-d'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01'
,
$this
->
platform
->
reveal
());
$this
->
assertSame
(
'2016-01-01 00:00:00.000000'
,
$date
->
format
(
'Y-m-d H:i:s.u'
));
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateString
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid date string'
,
$this
->
platform
->
reveal
());
}
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()));
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
0 → 100644
View file @
e9552089
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateTimeImmutableType
;
use
Doctrine\DBAL\Types\Type
;
class
DateTimeImmutableTypeTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy
*/
private
$platform
;
/**
* @var DateTimeImmutableType
*/
private
$type
;
protected
function
setUp
()
{
$this
->
type
=
Type
::
getType
(
'datetime_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
}
public
function
testFactoryCreatesCorrectType
()
{
$this
->
assertSame
(
DateTimeImmutableType
::
class
,
get_class
(
$this
->
type
));
}
public
function
testReturnsName
()
{
$this
->
assertSame
(
'datetime_immutable'
,
$this
->
type
->
getName
());
}
public
function
testReturnsBindingType
()
{
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$this
->
type
->
getBindingType
());
}
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
{
$date
=
$this
->
prophesize
(
\DateTimeImmutable
::
class
);
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$date
->
format
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
)
->
shouldBeCalled
();
$this
->
assertSame
(
'2016-01-01 15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
())
);
}
public
function
testConvertsNullToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
->
reveal
());
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
{
$date
=
new
\DateTimeImmutable
();
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsNullToPHPValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsDateTimeStringToPHPValue
()
{
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59'
,
$this
->
platform
->
reveal
());
$this
->
assertInstanceOf
(
\DateTimeImmutable
::
class
,
$date
);
$this
->
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
/**
* @group DBAL-415
*/
public
function
testConvertsDateTimeStringWithMicrosecondsToPHPValue
()
{
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456'
,
$this
->
platform
->
reveal
());
$this
->
assertSame
(
'2016-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime string'
,
$this
->
platform
->
reveal
());
}
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()));
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php
0 → 100644
View file @
e9552089
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\DateTimeTzImmutableType
;
use
Doctrine\DBAL\Types\Type
;
class
DateTimeTzImmutableTypeTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy
*/
private
$platform
;
/**
* @var DateTimeTzImmutableType
*/
private
$type
;
protected
function
setUp
()
{
$this
->
type
=
Type
::
getType
(
'datetimetz_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
}
public
function
testFactoryCreatesCorrectType
()
{
$this
->
assertSame
(
DateTimeTzImmutableType
::
class
,
get_class
(
$this
->
type
));
}
public
function
testReturnsName
()
{
$this
->
assertSame
(
'datetimetz_immutable'
,
$this
->
type
->
getName
());
}
public
function
testReturnsBindingType
()
{
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$this
->
type
->
getBindingType
());
}
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
{
$date
=
$this
->
prophesize
(
\DateTimeImmutable
::
class
);
$this
->
platform
->
getDateTimeTzFormatString
()
->
willReturn
(
'Y-m-d H:i:s T'
)
->
shouldBeCalled
();
$date
->
format
(
'Y-m-d H:i:s T'
)
->
willReturn
(
'2016-01-01 15:58:59 UTC'
)
->
shouldBeCalled
();
$this
->
assertSame
(
'2016-01-01 15:58:59 UTC'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
())
);
}
public
function
testConvertsNullToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
->
reveal
());
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
{
$date
=
new
\DateTimeImmutable
();
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsNullToPHPValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsDateTimeWithTimezoneStringToPHPValue
()
{
$this
->
platform
->
getDateTimeTzFormatString
()
->
willReturn
(
'Y-m-d H:i:s T'
)
->
shouldBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59 UTC'
,
$this
->
platform
->
reveal
());
$this
->
assertInstanceOf
(
\DateTimeImmutable
::
class
,
$date
);
$this
->
assertSame
(
'2016-01-01 15:58:59 UTC'
,
$date
->
format
(
'Y-m-d H:i:s T'
));
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid datetime with timezone string'
,
$this
->
platform
->
reveal
());
}
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()));
}
}
tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php
0 → 100644
View file @
e9552089
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\TimeImmutableType
;
use
Doctrine\DBAL\Types\Type
;
class
TimeImmutableTypeTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy
*/
private
$platform
;
/**
* @var TimeImmutableType
*/
private
$type
;
protected
function
setUp
()
{
$this
->
type
=
Type
::
getType
(
'time_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
}
public
function
testFactoryCreatesCorrectType
()
{
$this
->
assertSame
(
TimeImmutableType
::
class
,
get_class
(
$this
->
type
));
}
public
function
testReturnsName
()
{
$this
->
assertSame
(
'time_immutable'
,
$this
->
type
->
getName
());
}
public
function
testReturnsBindingType
()
{
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$this
->
type
->
getBindingType
());
}
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
{
$date
=
$this
->
prophesize
(
\DateTimeImmutable
::
class
);
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
)
->
shouldBeCalled
();
$date
->
format
(
'H:i:s'
)
->
willReturn
(
'15:58:59'
)
->
shouldBeCalled
();
$this
->
assertSame
(
'15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
())
);
}
public
function
testConvertsNullToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
->
reveal
());
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
{
$date
=
new
\DateTimeImmutable
();
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsNullToPHPValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsTimeStringToPHPValue
()
{
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
)
->
shouldBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
->
reveal
());
$this
->
assertInstanceOf
(
\DateTimeImmutable
::
class
,
$date
);
$this
->
assertSame
(
'15:58:59'
,
$date
->
format
(
'H:i:s'
));
}
public
function
testResetDateFractionsWhenConvertingToPHPValue
()
{
$this
->
platform
->
getTimeFormatString
()
->
willReturn
(
'H:i:s'
);
$date
=
$this
->
type
->
convertToPHPValue
(
'15:58:59'
,
$this
->
platform
->
reveal
());
$this
->
assertSame
(
'1970-01-01 15:58:59'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeString
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid time string'
,
$this
->
platform
->
reveal
());
}
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()));
}
}
tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php
0 → 100644
View file @
e9552089
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\ConversionException
;
use
Doctrine\DBAL\Types\VarDateTimeImmutableType
;
use
Doctrine\DBAL\Types\Type
;
class
VarDateTimeImmutableTypeTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy
*/
private
$platform
;
/**
* @var VarDateTimeImmutableType
*/
private
$type
;
protected
function
setUp
()
{
if
(
!
Type
::
hasType
(
'vardatetime_immutable'
))
{
Type
::
addType
(
'vardatetime_immutable'
,
VarDateTimeImmutableType
::
class
);
}
$this
->
type
=
Type
::
getType
(
'vardatetime_immutable'
);
$this
->
platform
=
$this
->
prophesize
(
AbstractPlatform
::
class
);
}
public
function
testReturnsName
()
{
$this
->
assertSame
(
'datetime_immutable'
,
$this
->
type
->
getName
());
}
public
function
testReturnsBindingType
()
{
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$this
->
type
->
getBindingType
());
}
public
function
testConvertsDateTimeImmutableInstanceToDatabaseValue
()
{
$date
=
$this
->
prophesize
(
\DateTimeImmutable
::
class
);
$this
->
platform
->
getDateTimeFormatString
()
->
willReturn
(
'Y-m-d H:i:s'
)
->
shouldBeCalled
();
$date
->
format
(
'Y-m-d H:i:s'
)
->
willReturn
(
'2016-01-01 15:58:59'
)
->
shouldBeCalled
();
$this
->
assertSame
(
'2016-01-01 15:58:59'
,
$this
->
type
->
convertToDatabaseValue
(
$date
->
reveal
(),
$this
->
platform
->
reveal
())
);
}
public
function
testConvertsNullToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToDatabaseValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testDoesNotSupportMutableDateTimeToDatabaseValueConversion
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
->
reveal
());
}
public
function
testConvertsDateTimeImmutableInstanceToPHPValue
()
{
$date
=
new
\DateTimeImmutable
();
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsNullToPHPValue
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
->
reveal
()));
}
public
function
testConvertsDateishStringToPHPValue
()
{
$this
->
platform
->
getDateTimeFormatString
()
->
shouldNotBeCalled
();
$date
=
$this
->
type
->
convertToPHPValue
(
'2016-01-01 15:58:59.123456 UTC'
,
$this
->
platform
->
reveal
());
$this
->
assertInstanceOf
(
\DateTimeImmutable
::
class
,
$date
);
$this
->
assertSame
(
'2016-01-01 15:58:59.123456 UTC'
,
$date
->
format
(
'Y-m-d H:i:s.u T'
));
}
public
function
testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishString
()
{
$this
->
expectException
(
ConversionException
::
class
);
$this
->
type
->
convertToPHPValue
(
'invalid date-ish string'
,
$this
->
platform
->
reveal
());
}
public
function
testRequiresSQLCommentHint
()
{
$this
->
assertTrue
(
$this
->
type
->
requiresSQLCommentHint
(
$this
->
platform
->
reveal
()));
}
}
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