| 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' => 'connectionWithCORSPreflightOptions']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     public function graphQLEndpointUriProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ['/'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ['/graphql/default'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @expectedExceptionMessage Must provide query parameter | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     public function testEndpointWithEmptyQuery() | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |         $client = static::createClient(); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |         $client->request('GET', '/', []); | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @expectedExceptionMessage The request content body must not be empty when using json content type request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function testEndpointWithEmptyJsonBodyQuery() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @expectedExceptionMessage POST body sent invalid JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     public function testEndpointWithInvalidBodyQuery() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     public function testEndpointActionWithVariables() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $query = <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | query FriendsQuery($firstFriends: Int) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |   user { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     friends(first: $firstFriends) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |       totalCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |       edges { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         friendshipTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         node { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |           name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |       } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | EOF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @expectedExceptionMessage Variables are invalid JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 147 |  | View Code Duplication |     public function testEndpointActionWithInvalidVariables() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $query = <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | query { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |   user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | EOF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @expectedExceptionMessage Could not found "fake" schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 164 |  | View Code Duplication |     public function testMultipleEndpointActionWithUnknownSchemaName() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $query = <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | query { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |   user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | EOF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         $client->request('GET', '/graphql/fake', ['query' => $query]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     public function testEndpointActionWithOperationName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $result = $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $this->assertEquals(['data' => $this->expectedData], json_decode($result, true), $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * @param $uri | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @dataProvider graphQLBatchEndpointUriProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     public function testBatchEndpointAction($uri) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $data = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |                 'id' => 'friends', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                 'query' => $this->friendsQuery, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                 'id' => 'friendsTotalCount', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                 'query' => $this->friendsTotalCountQuery, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($data)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $result = $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $expected  = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |             ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $this->assertEquals($expected, json_decode($result, true), $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |     public function graphQLBatchEndpointUriProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |             ['/batch'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             ['/graphql/default/batch'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * @expectedExceptionMessage Must provide at least one valid query. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |     public function testBatchEndpointWithEmptyQuery() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |      * @expectedExceptionMessage Only request with content type "application/json" is accepted. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     public function testBatchEndpointWrongContentType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         $client->request('GET', '/batch'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      * @expectedExceptionMessage POST body sent invalid JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |     public function testBatchEndpointWithInvalidJson() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |      * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |      * @expectedExceptionMessage 1 is not a valid query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     public function testBatchEndpointWithInvalidQuery() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         $client->getResponse()->getContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     public function testPreflightedRequestWhenDisabled() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         $client = static::createClient(['test_case' => 'connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         $this->assertEquals(405, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     public function testPreflightedRequestWhenEnabled() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         $client = static::createClient(['test_case' => 'connectionWithCORSPreflightOptions']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |         $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         $response = $client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         $this->assertEquals(200, $response->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         $this->assertEquals('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         $this->assertEquals('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         $this->assertEquals('true', $response->headers->get('Access-Control-Allow-Credentials')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         $this->assertEquals('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |         $this->assertEquals(3600, $response->headers->get('Access-Control-Max-Age')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 288 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 289 |  |  |  | 
            
                        
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.