Failed Conditions
Push — master ( 9355a2...379085 )
by Sergei
26s queued 12s
created

DateTest::testDateRestsSummerTimeAffection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use DateTime;
6
use Doctrine\DBAL\Types\ConversionException;
7
use Doctrine\DBAL\Types\Type;
8
use function date_default_timezone_set;
9
10
class DateTest extends BaseDateTypeTestCase
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15
    protected function setUp()
16
    {
17
        $this->type = Type::getType('date');
18
19
        parent::setUp();
20
    }
21
22
    public function testDateConvertsToPHPValue()
23
    {
24
        // Birthday of jwage and also birthday of Doctrine. Send him a present ;)
25
        self::assertInstanceOf(
26
            DateTime::class,
27
            $this->type->convertToPHPValue('1985-09-01', $this->platform)
28
        );
29
    }
30
31
    public function testDateResetsNonDatePartsToZeroUnixTimeValues()
32
    {
33
        $date = $this->type->convertToPHPValue('1985-09-01', $this->platform);
34
35
        self::assertEquals('00:00:00', $date->format('H:i:s'));
36
    }
37
38
    public function testDateRestsSummerTimeAffection()
39
    {
40
        date_default_timezone_set('Europe/Berlin');
41
42
        $date = $this->type->convertToPHPValue('2009-08-01', $this->platform);
43
        self::assertEquals('00:00:00', $date->format('H:i:s'));
44
        self::assertEquals('2009-08-01', $date->format('Y-m-d'));
45
46
        $date = $this->type->convertToPHPValue('2009-11-01', $this->platform);
47
        self::assertEquals('00:00:00', $date->format('H:i:s'));
48
        self::assertEquals('2009-11-01', $date->format('Y-m-d'));
49
    }
50
51
    public function testInvalidDateFormatConversion()
52
    {
53
        $this->expectException(ConversionException::class);
54
        $this->type->convertToPHPValue('abcdefg', $this->platform);
55
    }
56
}
57