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 (#65)
by Jérémiah
32:49 queued 28:48
created

testMultipleEndpointActionWithUnknownSchemaName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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
    /**
67
     * @param $uri
68
     * @dataProvider graphQLEndpointUriProvider
69
     */
70
    public function testEndpointAction($uri)
71
    {
72
        $client = static::createClient(['test_case' => 'connection']);
73
74
        $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']);
75
        $result = $client->getResponse()->getContent();
76
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
77
    }
78
79
80
    public function graphQLEndpointUriProvider()
81
    {
82
        return [
83
            ['/'],
84
            ['/graphql/default'],
85
        ];
86
    }
87
88
    /**
89
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
90
     * @expectedExceptionMessage Must provide query parameter
91
     */
92
    public function testEndpointWithEmptyQuery()
93
    {
94
        $client = static::createClient();
95
        $client->request('GET', '/', []);
96
        $client->getResponse()->getContent();
97
    }
98
99
    /**
100
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
101
     * @expectedExceptionMessage POST body sent invalid JSON
102
     */
103
    public function testEndpointWithInvalidBodyQuery()
104
    {
105
        $client = static::createClient();
106
        $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{');
107
        $client->getResponse()->getContent();
108
    }
109
110
    public function testEndpointActionWithVariables()
111
    {
112
        $client = static::createClient(['test_case' => 'connection']);
113
114
        $query = <<<EOF
115
query FriendsQuery(\$firstFriends: Int) {
116
  user {
117
    friends(first: \$firstFriends) {
118
      totalCount
119
      edges {
120
        friendshipTime
121
        node {
122
          name
123
        }
124
      }
125
    }
126
  }
127
}
128
EOF;
129
130
        $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']));
131
    }
132
133
    /**
134
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
135
     * @expectedExceptionMessage Variables are invalid JSON
136
     */
137 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...
138
    {
139
        $client = static::createClient(['test_case' => 'connection']);
140
141
        $query = <<<EOF
142
query {
143
  user
144
}
145
EOF;
146
147
        $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']);
148
    }
149
150
    /**
151
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
152
     * @expectedExceptionMessage Could not found "fake" schema.
153
     */
154 View Code Duplication
    public function testMultipleEndpointActionWithUnknownSchemaName()
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...
155
    {
156
        $client = static::createClient(['test_case' => 'connection']);
157
158
        $query = <<<EOF
159
query {
160
  user
161
}
162
EOF;
163
164
        $client->request('GET', '/graphql/fake', ['query' => $query]);
165
    }
166
167
    public function testEndpointActionWithOperationName()
168
    {
169
        $client = static::createClient(['test_case' => 'connection']);
170
171
        $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery;
172
173
        $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
174
        $result = $client->getResponse()->getContent();
175
        $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result);
176
    }
177
178
    /**
179
     * @param $uri
180
     * @dataProvider graphQLBatchEndpointUriProvider
181
     */
182
    public function testBatchEndpointAction($uri)
183
    {
184
        $client = static::createClient(['test_case' => 'connection']);
185
186
        $data = [
187
            [
188
                'id' => 'friends',
189
                'query' => $this->friendsQuery,
190
            ],
191
            [
192
                'id' => 'friendsTotalCount',
193
                'query' => $this->friendsTotalCountQuery,
194
            ],
195
        ];
196
197
        $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($data));
198
        $result = $client->getResponse()->getContent();
199
200
        $expected  = [
201
            ['id' => 'friends', 'payload' => ['data' => $this->expectedData]],
202
            ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]],
203
        ];
204
        $this->assertEquals($expected, json_decode($result, true), $result);
205
    }
206
207
    public function graphQLBatchEndpointUriProvider()
208
    {
209
        return [
210
            ['/batch'],
211
            ['/graphql/default/batch'],
212
        ];
213
    }
214
215
    /**
216
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
217
     * @expectedExceptionMessage Must provide at least one valid query.
218
     */
219
    public function testBatchEndpointWithEmptyQuery()
220
    {
221
        $client = static::createClient();
222
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
223
        $client->getResponse()->getContent();
224
    }
225
226
    /**
227
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
228
     * @expectedExceptionMessage Only request with content type "application/json" is accepted.
229
     */
230
    public function testBatchEndpointWrongContentType()
231
    {
232
        $client = static::createClient();
233
        $client->request('GET', '/batch');
234
        $client->getResponse()->getContent();
235
    }
236
237
    /**
238
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
239
     * @expectedExceptionMessage POST body sent invalid JSON
240
     */
241
    public function testBatchEndpointWithInvalidJson()
242
    {
243
        $client = static::createClient();
244
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{');
245
        $client->getResponse()->getContent();
246
    }
247
248
    /**
249
     * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
250
     * @expectedExceptionMessage 1 is not a valid query
251
     */
252
    public function testBatchEndpointWithInvalidQuery()
253
    {
254
        $client = static::createClient();
255
        $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}');
256
        $client->getResponse()->getContent();
257
    }
258
}
259