Failed Conditions
Push — master ( 48b44f...392b56 )
by Vladimir
04:42
created

AstFromValueUntypedTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 49
dl 0
loc 101
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testParsesVariables() 0 31 1
A assertTestCase() 0 4 1
A testParsesEnumValuesAsPlainStrings() 0 10 1
A testParsesSimpleValues() 0 8 1
A testParsesListsOfValues() 0 6 1
A testParsesInputObjects() 0 10 1
1
<?php
2
namespace GraphQL\Tests\Utils;
3
4
use GraphQL\Language\Parser;
5
use GraphQL\Utils\AST;
6
use PHPUnit\Framework\TestCase;
7
8
class AstFromValueUntypedTest extends TestCase
9
{
10
    // Describe: valueFromASTUntyped
11
12
    private function assertTestCase($valueText, $expected, array $variables = null) {
13
        $this->assertEquals(
14
            $expected,
15
            AST::valueFromASTUntyped(Parser::parseValue($valueText), $variables)
16
        );
17
    }
18
19
    /**
20
     * @it parses simple values
21
     */
22
    public function testParsesSimpleValues()
23
    {
24
        $this->assertTestCase('null', null);
25
        $this->assertTestCase('true', true);
26
        $this->assertTestCase('false', false);
27
        $this->assertTestCase('123', 123);
28
        $this->assertTestCase('123.456', 123.456);
29
        $this->assertTestCase('abc123', 'abc123');
30
    }
31
32
    /**
33
     * @it parses lists of values
34
     */
35
    public function testParsesListsOfValues()
36
    {
37
        $this->assertTestCase('[true, false]', [true, false]);
38
        $this->assertTestCase('[true, 123.45]', [true, 123.45]);
39
        $this->assertTestCase('[true, null]', [true, null]);
40
        $this->assertTestCase('[true, ["foo", 1.2]]', [true, ['foo', 1.2]]);
41
    }
42
43
    /**
44
     * @it parses input objects
45
     */
46
    public function testParsesInputObjects()
47
    {
48
        $this->assertTestCase(
49
            '{ int: 123, bool: false }',
50
            ['int' => 123, 'bool' => false]
51
        );
52
53
        $this->assertTestCase(
54
            '{ foo: [ { bar: "baz"} ] }',
55
            ['foo' => [['bar' => 'baz']]]
56
        );
57
    }
58
59
    /**
60
     * @it parses enum values as plain strings
61
     */
62
    public function testParsesEnumValuesAsPlainStrings()
63
    {
64
        $this->assertTestCase(
65
            'TEST_ENUM_VALUE',
66
            'TEST_ENUM_VALUE'
67
        );
68
69
        $this->assertTestCase(
70
            '[TEST_ENUM_VALUE]',
71
            ['TEST_ENUM_VALUE']
72
        );
73
    }
74
75
    /**
76
     * @it parses enum values as plain strings
77
     */
78
    public function testParsesVariables()
79
    {
80
        $this->assertTestCase(
81
            '$testVariable',
82
            'foo',
83
            ['testVariable' => 'foo']
84
        );
85
        $this->assertTestCase(
86
            '[$testVariable]',
87
            ['foo'],
88
            ['testVariable' => 'foo']
89
        );
90
        $this->assertTestCase(
91
            '{a:[$testVariable]}',
92
            ['a' => ['foo']],
93
            ['testVariable' => 'foo']
94
        );
95
        $this->assertTestCase(
96
            '$testVariable',
97
            null,
98
            ['testVariable' => null]
99
        );
100
        $this->assertTestCase(
101
            '$testVariable',
102
            null,
103
            []
104
        );
105
        $this->assertTestCase(
106
            '$testVariable',
107
            null,
108
            null
109
        );
110
    }
111
}
112