Unverified Commit 7c975933 authored by Luís Cobucci's avatar Luís Cobucci Committed by Sergei Morozov

Add type declarations to DateIntervalTest

parent ff369310
......@@ -3,13 +3,14 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function substr;
/**
* Type that maps interval string to a PHP DateInterval Object.
*/
class DateIntervalType extends Type
{
const FORMAT = '%RP%YY%MM%DDT%HH%IM%SS';
public const FORMAT = '%RP%YY%MM%DDT%HH%IM%SS';
/**
* {@inheritdoc}
......
......@@ -2,10 +2,13 @@
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateIntervalType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase;
class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
final class DateIntervalTest extends DbalTestCase
{
/**
* @var MockPlatform
......@@ -20,15 +23,15 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$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');
......@@ -38,40 +41,40 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
self::assertEquals($expected, $actual);
}
public function testDateIntervalConvertsToPHPValue()
public function testDateIntervalConvertsToPHPValue() : void
{
$interval = $this->type->convertToPHPValue('+P02Y00M01DT01H02M03S', $this->platform);
self::assertInstanceOf('DateInterval', $interval);
self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format('%RP%YY%MM%DDT%HH%IM%SS'));
self::assertInstanceOf(\DateInterval::class, $interval);
self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT));
}
public function testNegativeDateIntervalConvertsToDatabaseValue()
public function testNegativeDateIntervalConvertsToDatabaseValue() : void
{
$interval = new \DateInterval('P2Y1DT1H2M3S');
$interval->invert = 1;
$expected = '-P02Y00M01DT01H02M03S';
$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);
self::assertInstanceOf('DateInterval', $interval);
self::assertEquals('-P02Y00M01DT01H02M03S', $interval->format('%RP%YY%MM%DDT%HH%IM%SS'));
self::assertInstanceOf(\DateInterval::class, $interval);
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);
}
public function testDateIntervalNullConversion()
public function testDateIntervalNullConversion() : void
{
self::assertNull($this->type->convertToPHPValue(null, $this->platform));
}
......@@ -79,19 +82,17 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
* @group DBAL-1288
*/
public function testRequiresSQLCommentHint()
public function testRequiresSQLCommentHint() : void
{
self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
}
/**
* @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);
}
......@@ -99,7 +100,7 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
/**
* @return mixed[][]
*/
public function invalidPHPValuesProvider()
public function invalidPHPValuesProvider() : array
{
return [
[0],
......
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