Passed
Push — master ( c0ff8f...66dfac )
by Adrien
02:28
created

NonUniqueEmailTypeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A providerEmails() 0 10 1
A testParseValue() 0 11 2
A testSerialize() 0 5 1
A testParseLiteral() 0 12 2
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
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

16
    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...
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