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
|
|
|
|