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

DateTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testDateConvertsToPHPValue() 0 6 1
A testDateRestsSummerTimeAffection() 0 11 1
A testInvalidDateFormatConversion() 0 4 1
A testDateResetsNonDatePartsToZeroUnixTimeValues() 0 5 1
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