|
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 |
|
|
|
|
|
|
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
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.