TimeTest.php 944 Bytes
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Tests\Types;
4

Sergei Morozov's avatar
Sergei Morozov committed
5
use Doctrine\DBAL\Types\ConversionException;
6 7
use Doctrine\DBAL\Types\Type;

8
class TimeTest extends BaseDateTypeTestCase
9
{
10
    protected function setUp() : void
11
    {
12
        $this->type = Type::getType('time');
13

14
        parent::setUp();
15 16
    }

17
    public function testTimeConvertsToPHPValue() : void
18
    {
19
        self::assertInstanceOf('DateTime', $this->type->convertToPHPValue('5:30:55', $this->platform));
20
    }
21

22
    public function testDateFieldResetInPHPValue() : void
23
    {
24 25
        $time = $this->type->convertToPHPValue('01:23:34', $this->platform);

26 27
        self::assertEquals('01:23:34', $time->format('H:i:s'));
        self::assertEquals('1970-01-01', $time->format('Y-m-d'));
28 29
    }

30
    public function testInvalidTimeFormatConversion() : void
31
    {
Sergei Morozov's avatar
Sergei Morozov committed
32
        $this->expectException(ConversionException::class);
33
        $this->type->convertToPHPValue('abcdefg', $this->platform);
34
    }
35
}