1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\Api\Scalar; |
6
|
|
|
|
7
|
|
|
use Ecodev\Felix\Api\Scalar\NonUniqueEmailType; |
8
|
|
|
use GraphQL\Language\AST\StringValueNode; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
final class NonUniqueEmailTypeTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider providerEmails |
15
|
|
|
*/ |
16
|
|
|
public function testSerialize(?string $input, ?string $expected, bool $isValid): void |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$type = new NonUniqueEmailType(); |
19
|
|
|
$actual = $type->serialize($input); |
20
|
|
|
self::assertSame($expected, $actual); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @dataProvider providerEmails |
25
|
|
|
*/ |
26
|
|
|
public function testParseValue(?string $input, ?string $expected, bool $isValid): void |
27
|
|
|
{ |
28
|
|
|
$type = new NonUniqueEmailType(); |
29
|
|
|
|
30
|
|
|
if (!$isValid) { |
31
|
|
|
$this->expectExceptionMessage('Query error: Not a valid NonUniqueEmail'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$actual = $type->parseValue($input); |
35
|
|
|
|
36
|
|
|
self::assertSame($expected, $actual); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider providerEmails |
41
|
|
|
*/ |
42
|
|
|
public function testParseLiteral(?string $input, ?string $expected, bool $isValid): void |
43
|
|
|
{ |
44
|
|
|
$type = new NonUniqueEmailType(); |
45
|
|
|
$ast = new StringValueNode(['value' => $input]); |
46
|
|
|
|
47
|
|
|
if (!$isValid) { |
48
|
|
|
$this->expectExceptionMessage('Query error: Not a valid NonUniqueEmail'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$actual = $type->parseLiteral($ast); |
52
|
|
|
|
53
|
|
|
self::assertSame($expected, $actual); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function providerEmails(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
['[email protected]', '[email protected]', true], |
60
|
|
|
['josé@example.com', 'josé@example.com', true], |
61
|
|
|
['josé@example.non-existing-tld', 'josé@example.non-existing-tld', false], |
62
|
|
|
['root@localhost', 'root@localhost', false], |
63
|
|
|
['foo', 'foo', false], |
64
|
|
|
[null, null, false], |
65
|
|
|
['', '', true], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.