Scrutinizer GitHub App not installed

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

Install GitHub App

Completed
Pull Request — master (#64)
by Adrian
05:08
created

testCustomExceptions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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