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
1a6a796e
Commit
1a6a796e
authored
Sep 05, 2015
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#869 - DBAL-1293 - abstract test case for date-based types
parent
bc0a4a47
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
264 deletions
+124
-264
BaseDateTypeTestCase.php
tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php
+94
-0
DateTest.php
tests/Doctrine/Tests/DBAL/Types/DateTest.php
+3
-76
DateTimeTest.php
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
+10
-62
DateTimeTzTest.php
tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
+9
-60
TimeTest.php
tests/Doctrine/Tests/DBAL/Types/TimeTest.php
+8
-66
No files found.
tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php
0 → 100644
View file @
1a6a796e
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
use
PHPUnit_Framework_TestCase
;
abstract
class
BaseDateTypeTestCase
extends
PHPUnit_Framework_TestCase
{
/**
* @var MockPlatform
*/
protected
$platform
;
/**
* @var \Doctrine\DBAL\Types\Type
*/
protected
$type
;
/**
* @var string
*/
private
$currentTimezone
;
/**
* {@inheritDoc}
*/
protected
function
setUp
()
{
$this
->
platform
=
new
MockPlatform
();
$this
->
currentTimezone
=
date_default_timezone_get
();
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Types\Type'
,
$this
->
type
);
}
/**
* {@inheritDoc}
*/
protected
function
tearDown
()
{
date_default_timezone_set
(
$this
->
currentTimezone
);
}
public
function
testDateConvertsToDatabaseValue
()
{
$this
->
assertInternalType
(
'string'
,
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
));
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
type
->
convertToDatabaseValue
(
$value
,
$this
->
platform
);
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
public
function
testConvertDateTimeToPHPValue
()
{
$date
=
new
\DateTime
(
'now'
);
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$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'
]],
];
}
}
tests/Doctrine/Tests/DBAL/Types/DateTest.php
View file @
1a6a796e
...
...
@@ -5,56 +5,16 @@ namespace Doctrine\Tests\DBAL\Types;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
class
DateTest
extends
\Doctrine\Tests\Dbal
TestCase
class
DateTest
Case
extends
BaseDateType
TestCase
{
/**
* @var MockPlatform
*/
private
$platform
;
/**
* @var \Doctrine\DBAL\Types\DateType
*/
private
$type
;
/**
* @var string
*/
private
$currentTimezone
;
/**
* {@inheritDoc}
*/
protected
function
setUp
()
{
$this
->
platform
=
new
MockPlatform
();
$this
->
type
=
Type
::
getType
(
'date'
);
$this
->
currentTimezone
=
date_default_timezone_get
();
}
$this
->
type
=
Type
::
getType
(
'date'
);
/**
* {@inheritDoc}
*/
protected
function
tearDown
()
{
date_default_timezone_set
(
$this
->
currentTimezone
);
}
public
function
testDateConvertsToDatabaseValue
()
{
$this
->
assertInternalType
(
'string'
,
$this
->
type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
platform
));
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
type
->
convertToDatabaseValue
(
$value
,
$this
->
platform
);
parent
::
setUp
();
}
public
function
testDateConvertsToPHPValue
()
...
...
@@ -91,37 +51,4 @@ class DateTest extends \Doctrine\Tests\DbalTestCase
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
public
function
testConvertDateTimeToPHPValue
()
{
$date
=
new
\DateTime
(
"now"
);
$this
->
assertSame
(
$date
,
$this
->
type
->
convertToPHPValue
(
$date
,
$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'
]],
];
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
View file @
1a6a796e
...
...
@@ -3,52 +3,33 @@
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
class
DateTimeTest
extends
\Doctrine\Tests\Dbal
TestCase
class
DateTimeTest
Case
extends
BaseDateType
TestCase
{
/**
*
@var MockPlatform
*
{@inheritDoc}
*/
private
$_platform
;
/**
* @var \Doctrine\DBAL\Types\DateTimeType
*/
private
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'datetime'
);
$this
->
type
=
Type
::
getType
(
'datetime'
);
parent
::
setUp
();
}
public
function
testDateTimeConvertsToDatabaseValue
()
{
$date
=
new
\DateTime
(
'1985-09-01 10:10:10'
);
$expected
=
$date
->
format
(
$this
->
_
platform
->
getDateTimeTzFormatString
());
$actual
=
$this
->
_type
->
convertToDatabaseValue
(
$date
,
$this
->
_
platform
);
$expected
=
$date
->
format
(
$this
->
platform
->
getDateTimeTzFormatString
());
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToDatabaseValue
(
$value
,
$this
->
_platform
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_
platform
);
$date
=
$this
->
type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
platform
);
$this
->
assertInstanceOf
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
...
...
@@ -56,48 +37,15 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
public
function
testInvalidDateTimeFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
}
public
function
testConvertDateTimeToPHPValue
()
{
$date
=
new
\DateTime
(
"now"
);
$this
->
assertSame
(
$date
,
$this
->
_type
->
convertToPHPValue
(
$date
,
$this
->
_platform
));
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
}
public
function
testConvertsNonMatchingFormatToPhpValueWithParser
()
{
$date
=
'1985/09/01 10:10:10.12345'
;
$actual
=
$this
->
_type
->
convertToPHPValue
(
$date
,
$this
->
_
platform
);
$actual
=
$this
->
type
->
convertToPHPValue
(
$date
,
$this
->
platform
);
$this
->
assertEquals
(
'1985-09-01 10:10:10'
,
$actual
->
format
(
'Y-m-d H:i:s'
));
}
/**
* @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'
]],
];
}
}
tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
View file @
1a6a796e
...
...
@@ -5,50 +5,32 @@ namespace Doctrine\Tests\DBAL\Types;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
class
DateTimeTzTest
extends
\Doctrine\Tests\Dbal
TestCase
class
DateTimeTzTest
Case
extends
BaseDateType
TestCase
{
/**
*
@var MockPlatform
*
{@inheritDoc}
*/
private
$_platform
;
/**
* @var \Doctrine\DBAL\Types\DateTimeTzType
*/
private
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'datetimetz'
);
$this
->
type
=
Type
::
getType
(
'datetimetz'
);
parent
::
setUp
();
}
public
function
testDateTimeConvertsToDatabaseValue
()
{
$date
=
new
\DateTime
(
'1985-09-01 10:10:10'
);
$expected
=
$date
->
format
(
$this
->
_
platform
->
getDateTimeTzFormatString
());
$actual
=
$this
->
_type
->
convertToDatabaseValue
(
$date
,
$this
->
_
platform
);
$expected
=
$date
->
format
(
$this
->
platform
->
getDateTimeTzFormatString
());
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$date
,
$this
->
platform
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToDatabaseValue
(
$value
,
$this
->
_platform
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_
platform
);
$date
=
$this
->
type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
platform
);
$this
->
assertInstanceOf
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
...
...
@@ -56,39 +38,6 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
public
function
testInvalidDateFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
}
public
function
testConvertDateTimeToPHPValue
()
{
$date
=
new
\DateTime
(
"now"
);
$this
->
assertSame
(
$date
,
$this
->
_type
->
convertToPHPValue
(
$date
,
$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'
]],
];
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
platform
);
}
}
tests/Doctrine/Tests/DBAL/Types/TimeTest.php
View file @
1a6a796e
...
...
@@ -5,52 +5,27 @@ namespace Doctrine\Tests\DBAL\Types;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
class
TimeTest
extends
\Doctrine\Tests\Dbal
TestCase
class
TimeTest
Case
extends
BaseDateType
TestCase
{
/**
*
@var MockPlatform
*
{@inheritDoc}
*/
private
$_platform
;
/**
* @var \Doctrine\DBAL\Types\TimeType
*/
private
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'time'
);
}
public
function
testTimeConvertsToDatabaseValue
()
{
$this
->
assertInternalType
(
'string'
,
$this
->
_type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
_platform
));
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public
function
testInvalidTypeConversionToDatabaseValue
(
$value
)
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
type
=
Type
::
getType
(
'time'
);
$this
->
_type
->
convertToDatabaseValue
(
$value
,
$this
->
_platform
);
parent
::
setUp
(
);
}
public
function
testTimeConvertsToPHPValue
()
{
$this
->
assertTrue
(
$this
->
_type
->
convertToPHPValue
(
'5:30:55'
,
$this
->
_platform
)
instanceof
\DateTime
);
$this
->
assertInstanceOf
(
'DateTime'
,
$this
->
type
->
convertToPHPValue
(
'5:30:55'
,
$this
->
platform
));
}
public
function
testDateFieldResetInPHPValue
()
{
$time
=
$this
->
_type
->
convertToPHPValue
(
'01:23:34'
,
$this
->
_platform
);
$time
=
$this
->
type
->
convertToPHPValue
(
'01:23:34'
,
$this
->
platform
);
$this
->
assertEquals
(
'01:23:34'
,
$time
->
format
(
'H:i:s'
));
$this
->
assertEquals
(
'1970-01-01'
,
$time
->
format
(
'Y-m-d'
));
}
...
...
@@ -58,39 +33,6 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase
public
function
testInvalidTimeFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
}
public
function
testConvertDateTimeToPHPValue
()
{
$date
=
new
\DateTime
(
"now"
);
$this
->
assertSame
(
$date
,
$this
->
_type
->
convertToPHPValue
(
$date
,
$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'
]],
];
$this
->
type
->
convertToPHPValue
(
'abcdefg'
,
$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