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
Push — master ( 1b39d6...2f4c50 )
by Jérémiah
28:00 queued 07:52
created

OverblogGraphQLTypesExtensionTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 252
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 252
rs 10

10 Methods

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