Commit ae67ace8 authored by Marco Pivetta's avatar Marco Pivetta

#869 - DBAL-1293 - testing `DateIntervalType` logic with invalid type conversions

parent beb2c7cf
......@@ -7,14 +7,23 @@ use Doctrine\Tests\DBAL\Mocks\MockPlatform;
class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
{
protected
$_platform,
$_type;
/**
* @var MockPlatform
*/
private $platform;
/**
* @var \Doctrine\DBAL\Types\DateIntervalType
*/
private $type;
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->_platform = new MockPlatform();
$this->_type = Type::getType('dateinterval');
$this->platform = new MockPlatform();
$this->type = Type::getType('dateinterval');
}
public function testDateIntervalConvertsToDatabaseValue()
......@@ -22,14 +31,14 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
$interval = new \DateInterval('P2Y1DT1H2M3S');
$expected = 'P0002-00-01T01:02:03';
$actual = $this->_type->convertToDatabaseValue($interval, $this->_platform);
$actual = $this->type->convertToDatabaseValue($interval, $this->platform);
$this->assertEquals($expected, $actual);
}
public function testDateIntervalConvertsToPHPValue()
{
$date = $this->_type->convertToPHPValue('P0002-00-01T01:02:03', $this->_platform);
$date = $this->type->convertToPHPValue('P0002-00-01T01:02:03', $this->platform);
$this->assertInstanceOf('DateInterval', $date);
$this->assertEquals('P2Y0M1DT1H2M3S', $date->format('P%yY%mM%dDT%hH%iM%sS'));
}
......@@ -37,12 +46,12 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
public function testInvalidDateIntervalFormatConversion()
{
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
$this->type->convertToPHPValue('abcdefg', $this->platform);
}
public function testDateIntervalNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
$this->assertNull($this->type->convertToPHPValue(null, $this->platform));
}
/**
......@@ -50,6 +59,41 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
*/
public function testRequiresSQLCommentHint()
{
$this->assertTrue($this->_type->requiresSQLCommentHint($this->_platform));
$this->assertTrue($this->type->requiresSQLCommentHint($this->platform));
}
/**
* @dataProvider invalidPHPValuesProvider
*
* @param mixed $value
*/
public function testInvalidTypeConversionToDatabaseValue($value)
{
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->type->convertToDatabaseValue($value, $this->platform);
}
/**
* @return mixed[][]
*/
public function invalidPHPValuesProvider()
{
return [
[0],
[''],
['foo'],
['10:11:12'],
['2015-01-31'],
['2015-01-31 10:11:12'],
[new \stdClass()],
[$this],
[27],
[-1],
[1.2],
[[]],
[['an array']],
[new \DateTime()],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment