Failed Conditions
Push — master ( e75200...fab761 )
by Adrien
02:43
created

TimeTypeTest::testParseLiteral()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Api\Scalar;
6
7
use Cake\Chronos\ChronosTime;
1 ignored issue
show
Bug introduced by
The type Cake\Chronos\ChronosTime was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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('14:30:25.000000', $actual);
21
22
        // Test serialize with microseconds
23
        $time = new ChronosTime('23:59:59.1254');
24
        $actual = $type->serialize($time);
25
        self::assertSame('23:59:59.001254', $actual);
26
    }
27
28
    /**
29
     * @dataProvider providerValues
30
     */
31
    public function testParseLiteral(string $input, ?string $expected): void
32
    {
33
        $type = new TimeType();
34
        $ast = new StringValueNode(['value' => $input]);
35
36
        $actual = $type->parseLiteral($ast);
37
        self::assertInstanceOf(ChronosTime::class, $actual);
38
        self::assertSame($expected, $actual->format('H:i:s.u'));
39
    }
40
41
    public function testParseLiteralAsInt(): void
42
    {
43
        $type = new TimeType();
44
        $ast = new IntValueNode(['value' => '123']);
45
46
        $this->expectExceptionMessage('Query error: Can only parse strings got: IntValue');
47
        $type->parseLiteral($ast);
48
    }
49
50
    public static function providerValues(): array
51
    {
52
        return [
53
            'normal timr' => ['14:30:25', '14:30:25.000000'],
54
            'time with milliseconds' => ['23:45:13.300', '23:45:13.000300'],
55
        ];
56
    }
57
}
58