TimeTest.php 981 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
    /**
11
     * {@inheritDoc}
12
     */
13
    protected function setUp() : void
14
    {
15
        $this->type = Type::getType('time');
16

17
        parent::setUp();
18 19
    }

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

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

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

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