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
|
|
|
$customExceptions = [ |
91
|
|
|
'warnings' => [ |
92
|
|
|
'Symfony\Component\Routing\Exception\ResourceNotFoundException' |
93
|
|
|
], |
94
|
|
|
'errors' => [ |
95
|
|
|
'InvalidArgumentException' |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$ext = new OverblogGraphQLExtension(); |
100
|
|
|
$ext->load( |
101
|
|
|
[ |
102
|
|
|
[ |
103
|
|
|
'definitions' => [ |
104
|
|
|
'exceptions' => $customExceptions |
105
|
|
|
], |
106
|
|
|
], |
107
|
|
|
], |
108
|
|
|
$this->container |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$definition = $this->container->getDefinition('overblog_graphql.error_handler'); |
112
|
|
|
$this->assertEquals($customExceptions, $definition->getArgument(2)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @runInSeparateProcess |
117
|
|
|
*/ |
118
|
|
|
public function testCustomBuilders() |
119
|
|
|
{ |
120
|
|
|
$ext = new OverblogGraphQLExtension(); |
121
|
|
|
$ext->load( |
122
|
|
|
[ |
123
|
|
|
[ |
124
|
|
|
'definitions' => [ |
125
|
|
|
'builders' => [ |
126
|
|
|
'field' => [ |
127
|
|
|
[ |
128
|
|
|
'alias' => 'RawId', |
129
|
|
|
'class' => 'Overblog\\GraphQLBundle\\Tests\\DependencyInjection\\Builder\\RawIdField', |
130
|
|
|
], |
131
|
|
|
], |
132
|
|
|
'args' => [ |
133
|
|
|
[ |
134
|
|
|
'alias' => 'Pager', |
135
|
|
|
'class' => 'Overblog\\GraphQLBundle\\Tests\\DependencyInjection\\Builder\\PagerArgs', |
136
|
|
|
], |
137
|
|
|
], |
138
|
|
|
], |
139
|
|
|
], |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
$this->container |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$this->extension->load( |
146
|
|
|
[ |
147
|
|
|
[ |
148
|
|
|
'foo' => [ |
149
|
|
|
'type' => 'object', |
150
|
|
|
'config' => [ |
151
|
|
|
'fields' => [ |
152
|
|
|
'rawIDWithDescriptionOverride' => [ |
153
|
|
|
'builder' => 'RawId', |
154
|
|
|
'description' => 'rawIDWithDescriptionOverride description', |
155
|
|
|
], |
156
|
|
|
'rawID' => 'RawId', |
157
|
|
|
'rawIDs' => [ |
158
|
|
|
'type' => '[RawID!]!', |
159
|
|
|
'argsBuilder' => 'Pager', |
160
|
|
|
], |
161
|
|
|
'categories' => [ |
162
|
|
|
'type' => '[String!]!', |
163
|
|
|
'argsBuilder' => ['builder' => 'Pager'], |
164
|
|
|
], |
165
|
|
|
], |
166
|
|
|
], |
167
|
|
|
], |
168
|
|
|
], |
169
|
|
|
], |
170
|
|
|
$this->container |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$this->assertEquals( |
174
|
|
|
[ |
175
|
|
|
'foo' => [ |
176
|
|
|
'type' => 'object', |
177
|
|
|
'config' => [ |
178
|
|
|
'name' => 'foo', |
179
|
|
|
'fields' => [ |
180
|
|
|
'rawIDWithDescriptionOverride' => [ |
181
|
|
|
'description' => 'rawIDWithDescriptionOverride description', |
182
|
|
|
'type' => 'Int!', |
183
|
|
|
'resolve' => '@=value.id', |
184
|
|
|
'args' => [], |
185
|
|
|
], |
186
|
|
|
'rawID' => [ |
187
|
|
|
'description' => 'The raw ID of an object', |
188
|
|
|
'type' => 'Int!', |
189
|
|
|
'resolve' => '@=value.id', |
190
|
|
|
'args' => [], |
191
|
|
|
], |
192
|
|
|
'rawIDs' => [ |
193
|
|
|
'type' => '[RawID!]!', |
194
|
|
|
'args' => [ |
195
|
|
|
'limit' => [ |
196
|
|
|
'type' => 'Int!', |
197
|
|
|
'defaultValue' => 20, |
198
|
|
|
], |
199
|
|
|
'offset' => [ |
200
|
|
|
'type' => 'Int!', |
201
|
|
|
'defaultValue' => 0, |
202
|
|
|
], |
203
|
|
|
], |
204
|
|
|
], |
205
|
|
|
'categories' => [ |
206
|
|
|
'type' => '[String!]!', |
207
|
|
|
'args' => [ |
208
|
|
|
'limit' => [ |
209
|
|
|
'type' => 'Int!', |
210
|
|
|
'defaultValue' => 20, |
211
|
|
|
], |
212
|
|
|
'offset' => [ |
213
|
|
|
'type' => 'Int!', |
214
|
|
|
'defaultValue' => 0, |
215
|
|
|
], |
216
|
|
|
], |
217
|
|
|
], |
218
|
|
|
], |
219
|
|
|
'interfaces' => [], |
220
|
|
|
], |
221
|
|
|
], |
222
|
|
|
|
223
|
|
|
], |
224
|
|
|
$this->container->getParameter('overblog_graphql_types.config') |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function internalConfigKeys() |
229
|
|
|
{ |
230
|
|
|
return [ |
231
|
|
|
['_object_config'], |
232
|
|
|
['_enum_config'], |
233
|
|
|
['_interface_config'], |
234
|
|
|
['_union_config'], |
235
|
|
|
['_input_object_config'], |
236
|
|
|
]; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
private function getBrokenMappingConfig($type) |
240
|
|
|
{ |
241
|
|
|
$config = [ |
242
|
|
|
'definitions' => [ |
243
|
|
|
'mappings' => [ |
244
|
|
|
'types' => [ |
245
|
|
|
[ |
246
|
|
|
'type' => $type, |
247
|
|
|
'dir' => __DIR__.'/mapping/'.$type, |
248
|
|
|
], |
249
|
|
|
], |
250
|
|
|
], |
251
|
|
|
], |
252
|
|
|
]; |
253
|
|
|
|
254
|
|
|
return $config; |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|