Failed Conditions
Pull Request — master (#2849)
by Luís
63:28
created

DateTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

5 Methods

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