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