DateFieldTest::testWithDateTime()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Dsn\Field;
6
7
use PHPUnit\Framework\TestCase;
8
9
class DateFieldTest extends TestCase
10
{
11
    public function testWithDateTime(): void
12
    {
13
        $timeZone = new \DateTimeZone('Europe/Zurich');
14
15
        $dateTimeFirst = (new \DateTime('2019-02-25 09:15:30'))->setTimezone($timeZone);
16
        $dateTimeSecond = (clone $dateTimeFirst)->modify('+2 hour');
17
18
        $dateField = new DateField('name', $dateTimeFirst);
19
        $this->assertEquals($dateTimeFirst, $dateField->getDateTime());
20
21
        $dateField->setDateTime($dateTimeSecond);
22
        $this->assertEquals($dateTimeSecond, $dateField->getDateTime());
23
    }
24
25
    public function testWithImmutableDateTime(): void
26
    {
27
        $timeZone = new \DateTimeZone('Europe/Zurich');
28
29
        $dateTimeFirst = (new \DateTimeImmutable('2019-02-25 09:15:30'))->setTimezone($timeZone);
30
        $dateTimeSecond = $dateTimeFirst->modify('+2 hour');
31
32
        $dateField = new DateField('name', $dateTimeFirst);
33
        $this->assertEquals($dateTimeFirst, $dateField->getDateTime());
34
35
        $dateField->setDateTime($dateTimeSecond);
0 ignored issues
show
Bug introduced by
It seems like $dateTimeSecond can also be of type false; however, parameter $dateTime of Artack\Dsn\Field\DateField::setDateTime() does only seem to accept DateTimeInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $dateField->setDateTime(/** @scrutinizer ignore-type */ $dateTimeSecond);
Loading history...
36
        $this->assertEquals($dateTimeSecond, $dateField->getDateTime());
37
    }
38
}
39