1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\Api\Scalar; |
6
|
|
|
|
7
|
|
|
use Cake\Chronos\ChronosTime; |
|
|
|
|
8
|
|
|
use Ecodev\Felix\Api\Scalar\TimeType; |
9
|
|
|
use GraphQL\Language\AST\IntValueNode; |
10
|
|
|
use GraphQL\Language\AST\StringValueNode; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
final class TimeTypeTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testSerialize(): void |
16
|
|
|
{ |
17
|
|
|
$type = new TimeType(); |
18
|
|
|
$time = new ChronosTime('14:30:25'); |
19
|
|
|
$actual = $type->serialize($time); |
20
|
|
|
self::assertSame('14h30', $actual); |
21
|
|
|
|
22
|
|
|
// Test serialize with microseconds |
23
|
|
|
$time = new ChronosTime('23:59:59.1254'); |
24
|
|
|
$actual = $type->serialize($time); |
25
|
|
|
self::assertSame('23h59', $actual); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @dataProvider providerValues |
30
|
|
|
*/ |
31
|
|
|
public function testParseValue(string $input, ?string $expected): void |
32
|
|
|
{ |
33
|
|
|
$type = new TimeType(); |
34
|
|
|
$actual = $type->parseValue($input); |
35
|
|
|
if ($actual) { |
36
|
|
|
$actual = $actual->__toString(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
self::assertSame($expected, $actual); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider providerValues |
44
|
|
|
*/ |
45
|
|
|
public function testParseLiteral(string $input, ?string $expected): void |
46
|
|
|
{ |
47
|
|
|
$type = new TimeType(); |
48
|
|
|
$ast = new StringValueNode(['value' => $input]); |
49
|
|
|
|
50
|
|
|
$actual = $type->parseLiteral($ast); |
51
|
|
|
if ($actual) { |
52
|
|
|
$actual = $actual->__toString(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
self::assertSame($expected, $actual); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testParseLiteralAsInt(): void |
59
|
|
|
{ |
60
|
|
|
$type = new TimeType(); |
61
|
|
|
$ast = new IntValueNode(['value' => '123']); |
62
|
|
|
|
63
|
|
|
$this->expectExceptionMessage('Query error: Can only parse strings got: IntValue'); |
64
|
|
|
$type->parseLiteral($ast); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function providerValues(): array |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'empty string' => ['', null], |
71
|
|
|
'normal time' => ['14:30', '14:30:00'], |
72
|
|
|
'alternative separator' => ['14h30', '14:30:00'], |
73
|
|
|
'only hour' => ['14h', '14:00:00'], |
74
|
|
|
'only hour alternative' => ['14:', '14:00:00'], |
75
|
|
|
'even shorter' => ['9', '09:00:00'], |
76
|
|
|
'spaces are fines' => [' 14h00 ', '14:00:00'], |
77
|
|
|
'a bit weird, but why not' => [' 14h6 ', '14:06:00'], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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