forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTest.php
More file actions
62 lines (48 loc) · 1.8 KB
/
DateTest.php
File metadata and controls
62 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Types;
use DateTime;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateType;
use function date_default_timezone_set;
class DateTest extends BaseDateTypeTestCase
{
protected function setUp(): void
{
$this->type = new DateType();
parent::setUp();
$this->platform->method('getDateFormatString')
->willReturn('Y-m-d');
}
public function testDateConvertsToPHPValue(): void
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
self::assertInstanceOf(
DateTime::class,
$this->type->convertToPHPValue('1985-09-01', $this->platform),
);
}
public function testDateResetsNonDatePartsToZeroUnixTimeValues(): void
{
/** @var DateTime $date */
$date = $this->type->convertToPHPValue('1985-09-01', $this->platform);
self::assertEquals('00:00:00', $date->format('H:i:s'));
}
public function testDateRestsSummerTimeAffection(): void
{
date_default_timezone_set('Europe/Berlin');
/** @var DateTime $date */
$date = $this->type->convertToPHPValue('2009-08-01', $this->platform);
self::assertEquals('00:00:00', $date->format('H:i:s'));
self::assertEquals('2009-08-01', $date->format('Y-m-d'));
/** @var DateTime $date */
$date = $this->type->convertToPHPValue('2009-11-01', $this->platform);
self::assertEquals('00:00:00', $date->format('H:i:s'));
self::assertEquals('2009-11-01', $date->format('Y-m-d'));
}
public function testInvalidDateFormatConversion(): void
{
$this->expectException(ConversionException::class);
$this->type->convertToPHPValue('abcdefg', $this->platform);
}
}