Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#63)
by Jérémiah
04:48
created

GraphControllerTest::testBatchEndpointAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 1
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Tests\Functional\Controller;
13
14
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
15
16
class GraphControllerTest extends TestCase
17
{
18
    private $friendsQuery = <<<EOF
19
query FriendsQuery {
20
  user {
21
    friends(first: 2) {
22
      totalCount
23
      edges {
24
        friendshipTime
25
        node {
26
          name
27
        }
28
      }
29
    }
30
  }
31
}
32
EOF;
33
34
    private $friendsTotalCountQuery = <<<EOF
35
query FriendsTotalCountQuery {
36
  user {
37
    friends {
38
      totalCount
39
    }
40
  }
41
}
42
EOF;
43
44
    private $expectedData = [
45
        'user' => [
46
            'friends' => [
47
                'totalCount' => 4,
48
                'edges' => [
49
                    [
50
                        'friendshipTime' => 'Yesterday',
51
                        'node' => [
52
                            'name' => 'Nick',
53
                        ],
54
                    ],
55
                    [
56
                        'friendshipTime' => 'Yesterday',
57
                        'node' => [
58
                            'name' => 'Lee',
59
                        ],
60
                    ],
61
                ],
62
            ],
63
        ],
64
    ];
65
66
    public function testEndpointAction()
67
    {
68
        $client = static::createClient(['test_case' => 'connection']);
69
70
        $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']);
71
        $result = $client->getResponse()->getContent();
72
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
73
    }
74
75
    /**
76
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
77
     * @expectedExceptionMessage Must provide query parameter
78
     */
79
    public function testEndpointWithEmptyQuery()
80
    {
81
        $client = static::createClient();
82
        $client->request('GET', '/', []);
83
        $client->getResponse()->getContent();
84
    }
85
86
    /**
87
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
88
     * @expectedExceptionMessage POST body sent invalid JSON
89
     */
90
    public function testEndpointWithInvalidBodyQuery()
91
    {
92
        $client = static::createClient();
93
        $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{');
94
        $client->getResponse()->getContent();
95
    }
96
97 View Code Duplication
    public function testEndpointActionWithVariables()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        $client = static::createClient(['test_case' => 'connection']);
100
101
        $query = <<<EOF
102
query FriendsQuery(\$firstFriends: Int) {
103
  user {
104
    friends(first: \$firstFriends) {
105
      totalCount
106
      edges {
107
        friendshipTime
108
        node {
109
          name
110
        }
111
      }
112
    }
113
  }
114
}
115
EOF;
116
117
        $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']));
118
        $result = $client->getResponse()->getContent();
119
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
120
    }
121
122
    /**
123
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
124
     * @expectedExceptionMessage Variables are invalid JSON
125
     */
126 View Code Duplication
    public function testEndpointActionWithInvalidVariables()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        $client = static::createClient(['test_case' => 'connection']);
129
130
        $query = <<<EOF
131
query {
132
  user
133
}
134
EOF;
135
136
        $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']);
137
        $result = $client->getResponse()->getContent();
138
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
139
    }
140
141
    public function testEndpointActionWithOperationName()
142
    {
143
        $client = static::createClient(['test_case' => 'connection']);
144
145
        $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery;
146
147
        $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
148
        $result = $client->getResponse()->getContent();
149
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
150
    }
151
152
    public function testBatchEndpointAction()
153
    {
154
        $client = static::createClient(['test_case' => 'connection']);
155
156
        $data = [
157
            [
158
                'id' => 'friends',
159
                'query' => $this->friendsQuery,
160
            ],
161
            [
162
                'id' => 'friendsTotalCount',
163
                'query' => $this->friendsTotalCountQuery,
164
            ],
165
        ];
166
167
        $client->request('POST', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($data));
168
        $result = $client->getResponse()->getContent();
169
170
        $expected  = [
171
            ['id' => 'friends', 'payload' => ['data' => $this->expectedData]],
172
            ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]],
173
        ];
174
        $this->assertEquals($expected, json_decode($result, true), $result);
175
    }
176
177
    /**
178
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
179
     * @expectedExceptionMessage Must provide at least one valid query.
180
     */
181
    public function testBatchEndpointWithEmptyQuery()
182
    {
183
        $client = static::createClient();
184
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
185
        $client->getResponse()->getContent();
186
    }
187
188
    /**
189
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
190
     * @expectedExceptionMessage Only request with content type "application/json" is accepted.
191
     */
192
    public function testBatchEndpointWrongContentType()
193
    {
194
        $client = static::createClient();
195
        $client->request('GET', '/batch');
196
        $client->getResponse()->getContent();
197
    }
198
199
    /**
200
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
201
     * @expectedExceptionMessage POST body sent invalid JSON
202
     */
203
    public function testBatchEndpointWithInvalidJson()
204
    {
205
        $client = static::createClient();
206
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{');
207
        $client->getResponse()->getContent();
208
    }
209
210
    /**
211
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
212
     * @expectedExceptionMessage No valid query found in node entry #1
213
     */
214
    public function testBatchEndpointWithInvalidQuery()
215
    {
216
        $client = static::createClient();
217
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}');
218
        $client->getResponse()->getContent();
219
    }
220
}
221