Passed
Push — master ( 73bfc2...a878a7 )
by Adrien
13:45 queued 10:48
created

AbstractStringBasedType::testParseLiteral()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Api\Scalar;
6
7
use GraphQL\Language\AST\IntValueNode;
8
use GraphQL\Language\AST\StringValueNode;
9
use PHPUnit\Framework\TestCase;
10
11
abstract class AbstractStringBasedType extends TestCase
12
{
13
    abstract public function providerValues(): iterable;
14
15
    abstract public function createType(): \Ecodev\Felix\Api\Scalar\AbstractStringBasedType;
16
17
    abstract public function getTypeName(): string;
18
19
    /**
20
     * @dataProvider providerValues
21
     */
22
    public function testSerialize(?string $input, ?string $expected, bool $isValid): void
0 ignored issues
show
Unused Code introduced by
The parameter $isValid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function testSerialize(?string $input, ?string $expected, /** @scrutinizer ignore-unused */ bool $isValid): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        $type = $this->createType();
25
        $actual = $type->serialize($input);
26
        self::assertSame($expected, $actual);
27
    }
28
29
    /**
30
     * @dataProvider providerValues
31
     */
32
    public function testParseValue(?string $input, ?string $expected, bool $isValid): void
33
    {
34
        $type = $this->createType();
35
36
        if (!$isValid) {
37
            $this->expectExceptionMessage('Query error: Not a valid ' . $this->getTypeName());
38
        }
39
40
        $actual = $type->parseValue($input);
41
42
        self::assertSame($expected, $actual);
43
    }
44
45
    /**
46
     * @dataProvider providerValues
47
     */
48
    public function testParseLiteral(?string $input, ?string $expected, bool $isValid): void
49
    {
50
        $type = $this->createType();
51
        $ast = new StringValueNode(['value' => $input]);
52
53
        if (!$isValid) {
54
            $this->expectExceptionMessage('Query error: Not a valid ' . $this->getTypeName());
55
        }
56
57
        $actual = $type->parseLiteral($ast);
58
59
        self::assertSame($expected, $actual);
60
    }
61
62
    public function testParseInvalidNodeWillThrow(): void
63
    {
64
        $type = $this->createType();
65
        $ast = new IntValueNode(['value' => 123]);
66
67
        $this->expectExceptionMessage('Query error: Can only parse strings got: IntValue');
68
        $type->parseLiteral($ast);
69
    }
70
}
71