Completed
Push — master ( 6fa888...1dfddd )
by Patrick
02:15
created

DateFieldTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testWithDateTime() 0 12 1
A testWithImmutableDateTime() 0 12 1
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);
1 ignored issue
show
Bug introduced by
It seems like $dateTimeFirst can also be of type false; however, parameter $date of Artack\Dsn\Field\DateField::__construct() 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

32
        $dateField = new DateField('name', /** @scrutinizer ignore-type */ $dateTimeFirst);
Loading history...
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