Completed
Push — master ( 3853ec...f78c46 )
by Adrien
07:49
created

EmailTypeTest::providerEmails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
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

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