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() : void |
||
31 | { |
||
32 | self::assertSame(TimeImmutableType::class, get_class($this->type)); |
||
33 | } |
||
34 | |||
35 | public function testReturnsName() : void |
||
36 | { |
||
37 | self::assertSame('time_immutable', $this->type->getName()); |
||
38 | } |
||
39 | |||
40 | public function testReturnsBindingType() : void |
||
41 | { |
||
42 | self::assertSame(ParameterType::STRING, $this->type->getBindingType()); |
||
43 | } |
||
44 | |||
45 | public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void |
||
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() : void |
||
59 | { |
||
60 | self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); |
||
0 ignored issues
–
show
|
|||
61 | } |
||
62 | |||
63 | public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() : void |
||
64 | { |
||
65 | $this->expectException(ConversionException::class); |
||
66 | |||
67 | $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); |
||
68 | } |
||
69 | |||
70 | public function testConvertsDateTimeImmutableInstanceToPHPValue() : void |
||
71 | { |
||
72 | $date = new DateTimeImmutable(); |
||
73 | |||
74 | self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); |
||
75 | } |
||
76 | |||
77 | public function testConvertsNullToPHPValue() : void |
||
78 | { |
||
79 | self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->type->convertToPH...is->platform->reveal()) targeting Doctrine\DBAL\Types\Time...pe::convertToPHPValue() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||
80 | } |
||
81 | |||
82 | public function testConvertsTimeStringToPHPValue() : void |
||
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() : void |
||
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() : void |
||
102 | { |
||
103 | $this->expectException(ConversionException::class); |
||
104 | |||
105 | $this->type->convertToPHPValue('invalid time string', $this->platform->reveal()); |
||
106 | } |
||
107 | |||
108 | public function testRequiresSQLCommentHint() : void |
||
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.