Completed
Push — master ( c7a187...1a4f5e )
by Alexandr
02:57
created

Issue131Test::testInternalVariableArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 62
rs 9.4743
cc 1
eloc 36
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Youshido\Tests\Issues\Issue116Test;
4
5
use Youshido\GraphQL\Execution\Processor;
6
use Youshido\GraphQL\Schema\Schema;
7
use Youshido\GraphQL\Type\InputObject\InputObjectType;
8
use Youshido\GraphQL\Type\ListType\ListType;
9
use Youshido\GraphQL\Type\NonNullType;
10
use Youshido\GraphQL\Type\Object\ObjectType;
11
use Youshido\GraphQL\Type\Scalar\IdType;
12
use Youshido\GraphQL\Type\Scalar\IntType;
13
use Youshido\GraphQL\Type\Scalar\StringType;
14
15
class Issue131Test extends \PHPUnit_Framework_TestCase
16
{
17
18
    public function testInternalVariableArgument()
19
    {
20
21
22
        $schema    = new Schema([
23
            'query'    => new ObjectType([
24
                'name'   => 'RootQuery',
25
                'fields' => [
26
                    'hello' => new StringType(),
27
                ]
28
            ]),
29
            'mutation' => new ObjectType([
30
                'name'   => 'RootMutation',
31
                'fields' => [
32
                    'createMeeting' => [
33
                        'type'    => new ObjectType([
34
                            'name'   => 'Meeting',
35
                            'fields' => [
36
                                'id'   => new IdType(),
37
                                'name' => new StringType(),
38
                            ]
39
                        ]),
40
                        'args'    => [
41
                            'name'          => new StringType(),
42
                            'related_beans' => new ListType(new ObjectType([
43
                                'name'   => 'RelatedBeanInputType',
44
                                'fields' => [
45
                                    'id'     => new IntType(),
46
                                    'module' => new StringType(),
47
                                ]
48
                            ]))
49
                        ],
50
                        'resolve' => function ($source, $args) {
51
                            return [
52
                                'id' => '1',
53
                                'name' => sprintf('Meeting with %d beans', count($args['related_beans'])),
54
                            ];
55
                        }
56
                    ]
57
                ]
58
            ])
59
        ]);
60
        $processor = new Processor($schema);
61
        $response  = $processor->processPayload('
62
mutation ($related_beans: RelatedBeanInputType) {
63
  createMeeting(name: "Meeting 1", related_beans: $related_beans) {
64
    id,
65
    name
66
  }
67
}',
68
            [
69
                "related_beans" => [
70
                    ["module" => "contacts", "id" => "5cc6be5b-fb86-2671-e2c0-55e749882d29"],
71
                    ["module" => "contacts", "id" => "2a135003-3765-af3f-bc54-55e7497e77aa"],
72
73
                ]
74
            ])->getResponseData();
75
        $this->assertEquals(['data' => ['createMeeting' => [
76
            'id' => '1',
77
            'name' => 'Meeting with 2 beans'
78
        ]]], $response);
79
    }
80
}