|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\Api\Scalar; |
|
6
|
|
|
|
|
7
|
|
|
use Cake\Chronos\Chronos; |
|
|
|
|
|
|
8
|
|
|
use Ecodev\Felix\Api\Scalar\ChronosType; |
|
9
|
|
|
use GraphQL\Language\AST\IntValueNode; |
|
10
|
|
|
use GraphQL\Language\AST\StringValueNode; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
final class ChronosTypeTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private string $timezone; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->timezone = date_default_timezone_get(); |
|
20
|
|
|
date_default_timezone_set('Europe/Zurich'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function tearDown(): void |
|
24
|
|
|
{ |
|
25
|
|
|
date_default_timezone_set($this->timezone); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testSerialize(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$type = new ChronosType(); |
|
31
|
|
|
$date = new Chronos('2018-09-15T00:00:00+02:00'); |
|
32
|
|
|
$actual = $type->serialize($date); |
|
33
|
|
|
self::assertSame('2018-09-15T00:00:00+02:00', $actual); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @dataProvider providerValues |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testParseValue(string $input, ?string $expected): void |
|
40
|
|
|
{ |
|
41
|
|
|
$type = new ChronosType(); |
|
42
|
|
|
$actual = $type->parseValue($input); |
|
43
|
|
|
if ($actual) { |
|
44
|
|
|
$actual = $actual->format('c'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
self::assertSame($expected, $actual); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @dataProvider providerValues |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testParseLiteral(string $input, ?string $expected): void |
|
54
|
|
|
{ |
|
55
|
|
|
$type = new ChronosType(); |
|
56
|
|
|
$ast = new StringValueNode(['value' => $input]); |
|
57
|
|
|
|
|
58
|
|
|
$actual = $type->parseLiteral($ast); |
|
59
|
|
|
if ($actual) { |
|
60
|
|
|
$actual = $actual->format('c'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
self::assertSame($expected, $actual); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testParseLiteralAsInt(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$type = new ChronosType(); |
|
69
|
|
|
$ast = new IntValueNode(['value' => '123']); |
|
70
|
|
|
|
|
71
|
|
|
$this->expectExceptionMessage('Query error: Can only parse strings got: IntValue'); |
|
72
|
|
|
$type->parseLiteral($ast); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function providerValues(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
'UTC' => ['2018-09-14T22:00:00.000Z', '2018-09-15T00:00:00+02:00'], |
|
79
|
|
|
'local time' => ['2018-09-15T00:00:00+02:00', '2018-09-15T00:00:00+02:00'], |
|
80
|
|
|
'other time' => ['2018-09-15T02:00:00+04:00', '2018-09-15T00:00:00+02:00'], |
|
81
|
|
|
'empty string' => ['', null], |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths