1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace TheCodingMachine \GraphQLite ;
4
6
7
+ use Doctrine \Common \Annotations \AnnotationReader ;
5
8
use GraphQL \Error \DebugFlag ;
9
+ use GraphQL \Executor \ExecutionResult ;
6
10
use GraphQL \GraphQL ;
7
11
use GraphQL \Type \SchemaConfig ;
8
12
use Mouf \Composer \ClassNameMapper ;
20
24
use TheCodingMachine \GraphQLite \Fixtures \Integration \Types \ContactOtherType ;
21
25
use TheCodingMachine \GraphQLite \Fixtures \Integration \Types \ContactType ;
22
26
use TheCodingMachine \GraphQLite \Fixtures \Integration \Types \ExtendedContactType ;
23
- use TheCodingMachine \GraphQLite \Mappers \ CannotMapTypeException ;
27
+ use TheCodingMachine \GraphQLite \Fixtures \ TestSelfType ;
24
28
use TheCodingMachine \GraphQLite \Mappers \CompositeTypeMapper ;
25
29
use TheCodingMachine \GraphQLite \Mappers \DuplicateMappingException ;
30
+ use TheCodingMachine \GraphQLite \Mappers \Parameters \ParameterMiddlewarePipe ;
26
31
use TheCodingMachine \GraphQLite \Mappers \Root \VoidRootTypeMapperFactory ;
27
32
use TheCodingMachine \GraphQLite \Mappers \StaticClassListTypeMapperFactory ;
28
33
use TheCodingMachine \GraphQLite \Middlewares \FieldMiddlewarePipe ;
29
- use TheCodingMachine \GraphQLite \Mappers \Parameters \ParameterMiddlewarePipe ;
30
34
use TheCodingMachine \GraphQLite \Middlewares \InputFieldMiddlewarePipe ;
31
35
use TheCodingMachine \GraphQLite \Security \VoidAuthenticationService ;
32
36
use TheCodingMachine \GraphQLite \Security \VoidAuthorizationService ;
33
- use TheCodingMachine \GraphQLite \Fixtures \TestSelfType ;
34
-
35
37
36
38
class SchemaFactoryTest extends TestCase
37
39
{
38
-
39
40
public function testCreateSchema (): void
40
41
{
41
42
$ container = new BasicAutoWiringContainer (new EmptyContainer ());
@@ -65,7 +66,7 @@ public function testSetters(): void
65
66
66
67
$ factory ->addControllerNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration \\Controllers ' );
67
68
$ factory ->addTypeNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration ' );
68
- $ factory ->setDoctrineAnnotationReader (new \ Doctrine \ Common \ Annotations \ AnnotationReader ())
69
+ $ factory ->setDoctrineAnnotationReader (new AnnotationReader ())
69
70
->setAuthenticationService (new VoidAuthenticationService ())
70
71
->setAuthorizationService (new VoidAuthorizationService ())
71
72
->setNamingStrategy (new NamingStrategy ())
@@ -89,8 +90,8 @@ public function testClassNameMapperInjectionWithValidMapper(): void
89
90
$ factory = new SchemaFactory (
90
91
new Psr16Cache (new ArrayAdapter ()),
91
92
new BasicAutoWiringContainer (
92
- new EmptyContainer ()
93
- )
93
+ new EmptyContainer (),
94
+ ),
94
95
);
95
96
$ factory ->setAuthenticationService (new VoidAuthenticationService ())
96
97
->setAuthorizationService (new VoidAuthorizationService ())
@@ -132,17 +133,16 @@ public function testClassNameMapperInjectionWithInvalidMapper(): void
132
133
$ factory = new SchemaFactory (
133
134
new Psr16Cache (new ArrayAdapter ()),
134
135
new BasicAutoWiringContainer (
135
- new EmptyContainer ()
136
- )
136
+ new EmptyContainer (),
137
+ ),
137
138
);
138
139
$ factory ->setAuthenticationService (new VoidAuthenticationService ())
139
140
->setAuthorizationService (new VoidAuthorizationService ())
140
141
->setClassNameMapper (new ClassNameMapper ())
141
142
->addControllerNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration \\Controllers ' )
142
143
->addTypeNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration ' );
143
144
144
- $ this ->expectException (CannotMapTypeException::class);
145
- $ this ->doTestSchema ($ factory ->createSchema ());
145
+ $ this ->doTestSchemaWithError ($ factory ->createSchema ());
146
146
}
147
147
148
148
public function testException (): void
@@ -168,9 +168,8 @@ public function testException2(): void
168
168
$ factory ->createSchema ();
169
169
}
170
170
171
- private function doTestSchema (Schema $ schema ): void
171
+ private function execTestQuery (Schema $ schema ): ExecutionResult
172
172
{
173
-
174
173
$ schema ->assertValid ();
175
174
176
175
$ queryString = '
@@ -185,34 +184,50 @@ private function doTestSchema(Schema $schema): void
185
184
}
186
185
' ;
187
186
188
- $ result = GraphQL::executeQuery (
187
+ return GraphQL::executeQuery (
189
188
$ schema ,
190
- $ queryString
189
+ $ queryString,
191
190
);
191
+ }
192
+
193
+ private function doTestSchemaWithError (Schema $ schema ): void
194
+ {
195
+ $ result = $ this ->execTestQuery ($ schema );
196
+ $ resultArr = $ result ->toArray (DebugFlag::RETHROW_INTERNAL_EXCEPTIONS );
197
+ $ this ->assertArrayHasKey ('errors ' , $ resultArr );
198
+ $ this ->assertArrayNotHasKey ('data ' , $ resultArr );
199
+ $ this ->assertCount (1 , $ resultArr );
200
+ $ this ->assertSame ('Unknown type "User" ' , $ resultArr ['errors ' ][0 ]['message ' ]);
201
+ }
192
202
203
+ private function doTestSchema (Schema $ schema ): void
204
+ {
205
+ $ result = $ this ->execTestQuery ($ schema );
206
+ $ resultArr = $ result ->toArray (DebugFlag::RETHROW_INTERNAL_EXCEPTIONS );
207
+ $ this ->assertArrayHasKey ('data ' , $ resultArr );
193
208
$ this ->assertSame ([
194
209
'contacts ' => [
195
210
[
196
211
'name ' => 'Joe ' ,
197
- 'uppercaseName ' => 'JOE '
212
+ 'uppercaseName ' => 'JOE ' ,
198
213
],
199
214
[
200
215
'name ' => 'Bill ' ,
201
216
'uppercaseName ' => 'BILL ' ,
202
-
203
- ]
217
+
218
+ ],
204
219
205
- ]
206
- ], $ result -> toArray (DebugFlag:: RETHROW_INTERNAL_EXCEPTIONS ) ['data ' ]);
220
+ ],
221
+ ], $ resultArr ['data ' ]);
207
222
}
208
223
209
224
public function testDuplicateQueryException (): void
210
225
{
211
226
$ factory = new SchemaFactory (
212
227
new Psr16Cache (new ArrayAdapter ()),
213
228
new BasicAutoWiringContainer (
214
- new EmptyContainer ()
215
- )
229
+ new EmptyContainer (),
230
+ ),
216
231
);
217
232
$ factory ->setAuthenticationService (new VoidAuthenticationService ())
218
233
->setAuthorizationService (new VoidAuthorizationService ())
@@ -229,7 +244,7 @@ public function testDuplicateQueryException(): void
229
244
' ;
230
245
GraphQL::executeQuery (
231
246
$ schema ,
232
- $ queryString
247
+ $ queryString,
233
248
);
234
249
}
235
250
@@ -238,8 +253,8 @@ public function testDuplicateQueryInTwoControllersException(): void
238
253
$ factory = new SchemaFactory (
239
254
new Psr16Cache (new ArrayAdapter ()),
240
255
new BasicAutoWiringContainer (
241
- new EmptyContainer ()
242
- )
256
+ new EmptyContainer (),
257
+ ),
243
258
);
244
259
$ factory ->setAuthenticationService (new VoidAuthenticationService ())
245
260
->setAuthorizationService (new VoidAuthorizationService ())
@@ -256,7 +271,7 @@ public function testDuplicateQueryInTwoControllersException(): void
256
271
' ;
257
272
GraphQL::executeQuery (
258
273
$ schema ,
259
- $ queryString
274
+ $ queryString,
260
275
);
261
276
}
262
277
}
0 commit comments