Failed Conditions
Push — master ( 356b1f...e74f9e )
by Adrien
10:44
created

ChronosTypeTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Api\Scalar;
6
7
use Application\Api\Scalar\ChronosType;
8
use PHPUnit\Framework\TestCase;
9
10
class ChronosTypeTest extends TestCase
11
{
12
    private $timezone;
13
14
    public function setUp(): void
15
    {
16
        $this->timezone = date_default_timezone_get();
17
        date_default_timezone_set('Europe/Zurich');
18
    }
19
20
    public function tearDown(): void
21
    {
22
        date_default_timezone_set($this->timezone);
23
    }
24
25
    /**
26
     * @dataProvider providerParseValue
27
     *
28
     * @param string $input
29
     * @param null|string $expected
30
     */
31
    public function testParseValue(string $input, ?string $expected): void
32
    {
33
        $type = new ChronosType();
34
        $actual = $type->parseValue($input);
35
        if ($actual) {
36
            $actual = $actual->format('c');
37
        }
38
39
        self::assertSame($expected, $actual);
40
    }
41
42
    public function providerParseValue(): array
43
    {
44
        return [
45
            'UTC' => ['2018-09-14T22:00:00.000Z', '2018-09-15T00:00:00+02:00'],
46
            'local time' => ['2018-09-15T00:00:00+02:00', '2018-09-15T00:00:00+02:00'],
47
            'other time' => ['2018-09-15T02:00:00+04:00', '2018-09-15T00:00:00+02:00'],
48
            'empty string' => ['', null],
49
        ];
50
    }
51
}
52