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\TimeImmutableType; |
11
|
|
|
use Doctrine\DBAL\Types\Type; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
14
|
|
|
use function get_class; |
15
|
|
|
|
16
|
|
|
class TimeImmutableTypeTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** @var AbstractPlatform|ObjectProphecy */ |
19
|
|
|
private $platform; |
20
|
|
|
|
21
|
|
|
/** @var TimeImmutableType */ |
22
|
|
|
private $type; |
23
|
|
|
|
24
|
|
|
protected function setUp() : void |
25
|
|
|
{ |
26
|
|
|
$this->type = Type::getType('time_immutable'); |
27
|
|
|
$this->platform = $this->prophesize(AbstractPlatform::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testFactoryCreatesCorrectType() |
31
|
|
|
{ |
32
|
|
|
self::assertSame(TimeImmutableType::class, get_class($this->type)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testReturnsName() |
36
|
|
|
{ |
37
|
|
|
self::assertSame('time_immutable', $this->type->getName()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testReturnsBindingType() |
41
|
|
|
{ |
42
|
|
|
self::assertSame(ParameterType::STRING, $this->type->getBindingType()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() |
46
|
|
|
{ |
47
|
|
|
$date = $this->prophesize(DateTimeImmutable::class); |
48
|
|
|
|
49
|
|
|
$this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); |
50
|
|
|
$date->format('H:i:s')->willReturn('15:58:59')->shouldBeCalled(); |
51
|
|
|
|
52
|
|
|
self::assertSame( |
53
|
|
|
'15:58:59', |
54
|
|
|
$this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testConvertsNullToDatabaseValue() |
59
|
|
|
{ |
60
|
|
|
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() |
64
|
|
|
{ |
65
|
|
|
$this->expectException(ConversionException::class); |
66
|
|
|
|
67
|
|
|
$this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testNormalizesInstanceToPHPValue() |
71
|
|
|
{ |
72
|
|
|
$date = new DateTimeImmutable(); |
73
|
|
|
|
74
|
|
|
self::assertSame($date, $this->type->normalizeToPHPValue($date, $this->platform->reveal())); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testConvertsNullToPHPValue() |
78
|
|
|
{ |
79
|
|
|
self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testConvertsTimeStringToPHPValue() |
83
|
|
|
{ |
84
|
|
|
$this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); |
85
|
|
|
|
86
|
|
|
$date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); |
87
|
|
|
|
88
|
|
|
self::assertInstanceOf(DateTimeImmutable::class, $date); |
89
|
|
|
self::assertSame('15:58:59', $date->format('H:i:s')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testResetDateFractionsWhenConvertingToPHPValue() |
93
|
|
|
{ |
94
|
|
|
$this->platform->getTimeFormatString()->willReturn('H:i:s'); |
95
|
|
|
|
96
|
|
|
$date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); |
97
|
|
|
|
98
|
|
|
self::assertSame('1970-01-01 15:58:59', $date->format('Y-m-d H:i:s')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeString() |
102
|
|
|
{ |
103
|
|
|
$this->expectException(ConversionException::class); |
104
|
|
|
|
105
|
|
|
$this->type->convertToPHPValue('invalid time string', $this->platform->reveal()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testRequiresSQLCommentHint() |
109
|
|
|
{ |
110
|
|
|
self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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.