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

Passed
Pull Request — master (#277)
by Jérémiah
14:57
created

OverblogGraphQLTypesExtensionTest::testCustomBuilders()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 124
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 124
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 77
nc 1
nop 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\DependencyInjection;
4
5
use GraphQL\Error\UserError;
6
use Overblog\GraphQLBundle\Config\Processor\InheritanceProcessor;
7
use Overblog\GraphQLBundle\DependencyInjection\OverblogGraphQLExtension;
8
use Overblog\GraphQLBundle\DependencyInjection\OverblogGraphQLTypesExtension;
9
use Overblog\GraphQLBundle\Error\UserWarning;
10
use Overblog\GraphQLBundle\Tests\DependencyInjection\Builder\PagerArgs;
11
use Overblog\GraphQLBundle\Tests\DependencyInjection\Builder\RawIdField;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
15
16
class OverblogGraphQLTypesExtensionTest extends TestCase
17
{
18
    /** @var ContainerBuilder */
19
    private $container;
20
21
    /** @var OverblogGraphQLTypesExtension */
22
    private $extension;
23
24
    public function setUp()
25
    {
26
        $this->container = new ContainerBuilder();
27
        $this->container->setParameter('kernel.bundles', []);
28
        $this->container->setParameter('kernel.debug', false);
29
        $this->extension = new OverblogGraphQLTypesExtension();
30
    }
31
32
    public function tearDown()
33
    {
34
        unset($this->container, $this->extension);
35
    }
36
37
    /**
38
     * @expectedException \Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException
39
     */
40
    public function testDuplicatedType()
41
    {
42
        $type = ['foo' => []];
43
        $configs = [$type, $type];
44
        $this->extension->load($configs, $this->container);
45
    }
46
47
    /**
48
     * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
49
     * @expectedExceptionMessageRegExp #The file "(.*)/broken.types.yml" does not contain valid YAML\.#
50
     */
51
    public function testBrokenYmlOnPrepend()
52
    {
53
        $this->extension->containerPrependExtensionConfig($this->getMappingConfig('yaml'), $this->container);
54
    }
55
56
    /**
57
     * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
58
     * @expectedExceptionMessageRegExp #Unable to parse file "(.*)/broken.types.xml"\.#
59
     */
60
    public function testBrokenXmlOnPrepend()
61
    {
62
        $this->extension->containerPrependExtensionConfig($this->getMappingConfig('xml'), $this->container);
63
    }
64
65
    /**
66
     * @param $internalConfigKey
67
     * @dataProvider internalConfigKeys
68
     * @expectedException \InvalidArgumentException
69
     * @expectedExceptionMessage Don't use internal config keys _object_config, _enum_config, _interface_config, _union_config, _input_object_config, _custom_scalar_config, replace it by "config" instead.
70
     */
71
    public function testInternalConfigKeysShouldNotBeUsed($internalConfigKey)
72
    {
73
        $configs = [
74
            ['bar' => [$internalConfigKey => []]],
75
        ];
76
77
        $this->extension->load($configs, $this->container);
78
    }
79
80
    /**
81
     * @runInSeparateProcess
82
     */
83
    public function testCustomExceptions()
84
    {
85
        $ext = new OverblogGraphQLExtension();
86
        $ext->load(
87
            [
88
                [
89
                    'errors_handler' => [
90
                        'exceptions' => [
91
                            'warnings' => [
92
                                ResourceNotFoundException::class,
93
                            ],
94
                            'errors' => [
95
                                \InvalidArgumentException::class,
96
                            ],
97
                        ],
98
                    ],
99
                ],
100
            ],
101
            $this->container
102
        );
103
104
        $expectedExceptionMap = [
105
            ResourceNotFoundException::class => UserWarning::class,
106
            \InvalidArgumentException::class => UserError::class,
107
        ];
108
109
        $definition = $this->container->getDefinition('overblog_graphql.error_handler');
110
        $this->assertEquals($expectedExceptionMap, $definition->getArgument(2));
111
    }
112
113
    /**
114
     * @runInSeparateProcess
115
     */
116
    public function testCustomBuilders()
117
    {
118
        $ext = new OverblogGraphQLExtension();
119
        $ext->load(
120
            [
121
                [
122
                    'definitions' => [
123
                        'builders' => [
124
                            'field' => [
125
                                'RawId' => RawIdField::class,
126
                            ],
127
                            'args' => [
128
                                [
129
                                    'alias' => 'Pager',
130
                                    'class' => PagerArgs::class,
131
                                ],
132
                            ],
133
                        ],
134
                    ],
135
                ],
136
            ],
137
            $this->container
138
        );
139
140
        $this->extension->load(
141
            [
142
                [
143
                    'foo' => [
144
                        'type' => 'object',
145
                        'config' => [
146
                            'fields' => [
147
                                'rawIDWithDescriptionOverride' => [
148
                                    'builder' => 'RawId',
149
                                    'description' => 'rawIDWithDescriptionOverride description',
150
                                ],
151
                                'rawID' => 'RawId',
152
                                'rawIDs' => [
153
                                    'type' => '[RawID!]!',
154
                                    'argsBuilder' => 'Pager',
155
                                ],
156
                                'categories' => [
157
                                    'type' => '[String!]!',
158
                                    'argsBuilder' => ['builder' => 'Pager'],
159
                                ],
160
                                'categories2' => [
161
                                    'type' => '[String!]!',
162
                                    'argsBuilder' => ['builder' => 'Pager', 'config' => ['defaultLimit' => 50]],
163
                                ],
164
                            ],
165
                        ],
166
                    ],
167
                ],
168
            ],
169
            $this->container
170
        );
171
172
        $this->assertEquals(
173
            [
174
                'foo' => [
175
                    'type' => 'object',
176
                    InheritanceProcessor::INHERITS_KEY => [],
177
                    'decorator' => false,
178
                    'config' => [
179
                        'name' => 'foo',
180
                        'fields' => [
181
                            'rawIDWithDescriptionOverride' => [
182
                                'description' => 'rawIDWithDescriptionOverride description',
183
                                'type' => 'Int!',
184
                                'resolve' => '@=value.id',
185
                                'args' => [],
186
                            ],
187
                            'rawID' => [
188
                                'description' => 'The raw ID of an object',
189
                                'type' => 'Int!',
190
                                'resolve' => '@=value.id',
191
                                'args' => [],
192
                            ],
193
                            'rawIDs' => [
194
                                'type' => '[RawID!]!',
195
                                'args' => [
196
                                    'limit' => [
197
                                        'type' => 'Int!',
198
                                        'defaultValue' => 20,
199
                                    ],
200
                                    'offset' => [
201
                                        'type' => 'Int!',
202
                                        'defaultValue' => 0,
203
                                    ],
204
                                ],
205
                            ],
206
                            'categories' => [
207
                                'type' => '[String!]!',
208
                                'args' => [
209
                                    'limit' => [
210
                                        'type' => 'Int!',
211
                                        'defaultValue' => 20,
212
                                    ],
213
                                    'offset' => [
214
                                        'type' => 'Int!',
215
                                        'defaultValue' => 0,
216
                                    ],
217
                                ],
218
                            ],
219
                            'categories2' => [
220
                                'type' => '[String!]!',
221
                                'args' => [
222
                                    'limit' => [
223
                                        'type' => 'Int!',
224
                                        'defaultValue' => 50,
225
                                    ],
226
                                    'offset' => [
227
                                        'type' => 'Int!',
228
                                        'defaultValue' => 0,
229
                                    ],
230
                                ],
231
                            ],
232
                        ],
233
                        'interfaces' => [],
234
                    ],
235
                ],
236
            ],
237
            $this->container->getParameter('overblog_graphql_types.config')
238
        );
239
    }
240
241
    public function internalConfigKeys()
242
    {
243
        return [
244
            ['_object_config'],
245
            ['_enum_config'],
246
            ['_interface_config'],
247
            ['_union_config'],
248
            ['_input_object_config'],
249
        ];
250
    }
251
252
    private function getMappingConfig($type)
253
    {
254
        $config = [
255
            'definitions' => [
256
                'mappings' => [
257
                    'types' => [
258
                        [
259
                            'types' => [$type],
260
                            'dir' => __DIR__.'/mapping/'.$type,
261
                        ],
262
                    ],
263
                ],
264
            ],
265
        ];
266
267
        return $config;
268
    }
269
}
270