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