1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Types; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DateTimeImmutable; |
7
|
|
|
use Doctrine\DBAL\ParameterType; |
8
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
9
|
|
|
use Doctrine\DBAL\Types\ConversionException; |
10
|
|
|
use Doctrine\DBAL\Types\Type; |
11
|
|
|
use Doctrine\DBAL\Types\VarDateTimeImmutableType; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
14
|
|
|
|
15
|
|
|
class VarDateTimeImmutableTypeTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var AbstractPlatform|ObjectProphecy */ |
18
|
|
|
private $platform; |
19
|
|
|
|
20
|
|
|
/** @var VarDateTimeImmutableType */ |
21
|
|
|
private $type; |
22
|
|
|
|
23
|
|
|
protected function setUp() : void |
24
|
|
|
{ |
25
|
|
|
if (! Type::hasType('vardatetime_immutable')) { |
26
|
|
|
Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$this->type = Type::getType('vardatetime_immutable'); |
30
|
|
|
$this->platform = $this->prophesize(AbstractPlatform::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testReturnsName() |
34
|
|
|
{ |
35
|
|
|
self::assertSame('datetime_immutable', $this->type->getName()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testReturnsBindingType() |
39
|
|
|
{ |
40
|
|
|
self::assertSame(ParameterType::STRING, $this->type->getBindingType()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() |
44
|
|
|
{ |
45
|
|
|
$date = $this->prophesize(DateTimeImmutable::class); |
46
|
|
|
|
47
|
|
|
$this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); |
48
|
|
|
$date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); |
49
|
|
|
|
50
|
|
|
self::assertSame( |
51
|
|
|
'2016-01-01 15:58:59', |
52
|
|
|
$this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testConvertsNullToDatabaseValue() |
57
|
|
|
{ |
58
|
|
|
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() |
62
|
|
|
{ |
63
|
|
|
$this->expectException(ConversionException::class); |
64
|
|
|
|
65
|
|
|
$this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testNormalizesInstanceToPHPValue() |
69
|
|
|
{ |
70
|
|
|
$date = new DateTimeImmutable(); |
71
|
|
|
|
72
|
|
|
self::assertSame($date, $this->type->normalizeToPHPValue($date, $this->platform->reveal())); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testConvertsNullToPHPValue() |
76
|
|
|
{ |
77
|
|
|
self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testConvertsDateishStringToPHPValue() |
81
|
|
|
{ |
82
|
|
|
$this->platform->getDateTimeFormatString()->shouldNotBeCalled(); |
83
|
|
|
|
84
|
|
|
$date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform->reveal()); |
85
|
|
|
|
86
|
|
|
self::assertInstanceOf(DateTimeImmutable::class, $date); |
87
|
|
|
self::assertSame('2016-01-01 15:58:59.123456 UTC', $date->format('Y-m-d H:i:s.u T')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishString() |
91
|
|
|
{ |
92
|
|
|
$this->expectException(ConversionException::class); |
93
|
|
|
|
94
|
|
|
$this->type->convertToPHPValue('invalid date-ish string', $this->platform->reveal()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testRequiresSQLCommentHint() |
98
|
|
|
{ |
99
|
|
|
self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.