Completed
Push — master ( 8f4b0a...3474c6 )
by Alexandr
02:52
created

VariablesTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 0
cbo 5
dl 0
loc 71
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testVariables() 0 25 2
B queries() 0 33 1
1
<?php
2
3
namespace Youshido\Tests\Schema;
4
5
use Youshido\GraphQL\Execution\Processor;
6
use Youshido\GraphQL\Schema\Schema;
7
use Youshido\GraphQL\Type\ListType\ListType;
8
use Youshido\GraphQL\Type\NonNullType;
9
use Youshido\GraphQL\Type\Object\ObjectType;
10
use Youshido\GraphQL\Type\Scalar\IdType;
11
use Youshido\GraphQL\Type\Scalar\IntType;
12
use Youshido\GraphQL\Type\Scalar\StringType;
13
14
class VariablesTest extends \PHPUnit_Framework_TestCase
15
{
16
17
    /**
18
     * @dataProvider queries
19
     *
20
     * @param $query
21
     * @param $expected
22
     * @param $variables
23
     */
24
    public function testVariables($query, $expected, $variables)
25
    {
26
        $schema = new Schema([
27
            'query' => new ObjectType([
28
                'name'   => 'RootQuery',
29
                'fields' => [
30
                    'stringQuery' => [
31
                        'type'    => new StringType(),
32
                        'args'    => [
33
                            'sortOrder' => new StringType(),
34
                        ],
35
                        'resolve' => function ($args) {
36
                            return sprintf('Result with %s order', empty($args['sortOrder']) ? 'default' : $args['sortOrder']);
37
                        },
38
                    ],
39
                ]
40
            ])
41
        ]);
42
43
        $processor = new Processor($schema);
44
        $processor->processPayload($query, $variables);
45
        $result = $processor->getResponseData();
46
47
        $this->assertEquals($expected, $result);
48
    }
49
50
    public function queries()
51
    {
52
        return [
53
            [
54
                'query ListQuery($sort:String) {
55
                  stringQuery(sortOrder: $sort)
56
                }',
57
                [
58
                    'data' => [
59
                        'stringQuery' => 'Result with default order'
60
                    ],
61
                ],
62
                [
63
                    'sort' => null
64
                ]
65
            ],
66
            [
67
                'query queryWithVariable($abc:String) {
68
                  stringQuery {
69
                    ...someFragment
70
                  }
71
                }',
72
                [
73
                    'errors' => [
74
                        ['message' => 'Fragment "someFragment" not defined in query']
75
                    ],
76
                ],
77
                [
78
                    'abc' => null
79
                ]
80
            ],
81
        ];
82
    }
83
84
}