23
23
use PHPUnit \Framework \Error \Error ;
24
24
use PHPUnit \Framework \TestCase ;
25
25
26
- class ExecutorLazySchemaTest extends TestCase
26
+ final class ExecutorLazySchemaTest extends TestCase
27
27
{
28
28
public ScalarType $ someScalarType ;
29
29
@@ -54,40 +54,32 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema(): void
54
54
// isTypeOf used to resolve runtime type for Interface
55
55
$ petType = new InterfaceType ([
56
56
'name ' => 'Pet ' ,
57
- 'fields ' => static function (): array {
58
- return [
59
- 'name ' => [ ' type ' => Type::string ()] ,
60
- ];
61
- } ,
57
+ 'fields ' => static fn (): array => [
58
+ ' name ' => [
59
+ 'type ' => Type::string (),
60
+ ],
61
+ ] ,
62
62
]);
63
63
64
64
// Added to interface type when defined
65
65
$ dogType = new ObjectType ([
66
66
'name ' => 'Dog ' ,
67
67
'interfaces ' => [$ petType ],
68
- 'isTypeOf ' => static function ($ obj ): bool {
69
- return $ obj instanceof Dog;
70
- },
71
- 'fields ' => static function (): array {
72
- return [
73
- 'name ' => ['type ' => Type::string ()],
74
- 'woofs ' => ['type ' => Type::boolean ()],
75
- ];
76
- },
68
+ 'isTypeOf ' => static fn ($ obj ): bool => $ obj instanceof Dog,
69
+ 'fields ' => static fn (): array => [
70
+ 'name ' => ['type ' => Type::string ()],
71
+ 'woofs ' => ['type ' => Type::boolean ()],
72
+ ],
77
73
]);
78
74
79
75
$ catType = new ObjectType ([
80
76
'name ' => 'Cat ' ,
81
77
'interfaces ' => [$ petType ],
82
- 'isTypeOf ' => static function ($ obj ): bool {
83
- return $ obj instanceof Cat;
84
- },
85
- 'fields ' => static function (): array {
86
- return [
87
- 'name ' => ['type ' => Type::string ()],
88
- 'meows ' => ['type ' => Type::boolean ()],
89
- ];
90
- },
78
+ 'isTypeOf ' => static fn ($ obj ): bool => $ obj instanceof Cat,
79
+ 'fields ' => static fn (): array => [
80
+ 'name ' => ['type ' => Type::string ()],
81
+ 'meows ' => ['type ' => Type::boolean ()],
82
+ ],
91
83
]);
92
84
93
85
$ schema = new Schema ([
@@ -96,23 +88,20 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema(): void
96
88
'fields ' => [
97
89
'pets ' => [
98
90
'type ' => Type::listOf ($ petType ),
99
- 'resolve ' => static function (): array {
100
- return [new Dog ('Odie ' , true ), new Cat ('Garfield ' , false )];
101
- },
91
+ 'resolve ' => static fn (): array => [
92
+ new Dog ('Odie ' , true ),
93
+ new Cat ('Garfield ' , false ),
94
+ ],
102
95
],
103
96
],
104
97
]),
105
98
'types ' => [$ catType , $ dogType ],
106
- 'typeLoader ' => static function ($ name ) use ($ dogType , $ petType , $ catType ) {
99
+ 'typeLoader ' => static function ($ name ) use ($ dogType , $ petType , $ catType ): ? Type {
107
100
switch ($ name ) {
108
- case 'Dog ' :
109
- return $ dogType ;
110
-
111
- case 'Pet ' :
112
- return $ petType ;
113
-
114
- case 'Cat ' :
115
- return $ catType ;
101
+ case 'Dog ' : return $ dogType ;
102
+ case 'Pet ' : return $ petType ;
103
+ case 'Cat ' : return $ catType ;
104
+ default : return null ;
116
105
}
117
106
},
118
107
]);
@@ -160,28 +149,21 @@ public function testHintsOnConflictingTypeInstancesInDefinitions(): void
160
149
$ typeLoader = static function ($ name ) use (&$ calls ): ?ObjectType {
161
150
$ calls [] = $ name ;
162
151
switch ($ name ) {
163
- case 'Test ' :
164
- return new ObjectType ([
165
- 'name ' => 'Test ' ,
166
- 'fields ' => static function (): array {
167
- return [
168
- 'test ' => Type::string (),
169
- ];
170
- },
171
- ]);
172
-
173
- default :
174
- return null ;
152
+ case 'Test ' : return new ObjectType ([
153
+ 'name ' => 'Test ' ,
154
+ 'fields ' => static fn (): array => [
155
+ 'test ' => Type::string (),
156
+ ],
157
+ ]);
158
+ default : return null ;
175
159
}
176
160
};
177
161
178
162
$ query = new ObjectType ([
179
163
'name ' => 'Query ' ,
180
- 'fields ' => static function () use ($ typeLoader ): array {
181
- return [
182
- 'test ' => $ typeLoader ('Test ' ),
183
- ];
184
- },
164
+ 'fields ' => static fn (): array => [
165
+ 'test ' => $ typeLoader ('Test ' ),
166
+ ],
185
167
]);
186
168
187
169
$ schema = new Schema ([
@@ -215,9 +197,7 @@ public function testSimpleQuery(): void
215
197
{
216
198
$ schema = new Schema ([
217
199
'query ' => $ this ->loadType ('Query ' ),
218
- 'typeLoader ' => function ($ name ) {
219
- return $ this ->loadType ($ name , true );
220
- },
200
+ 'typeLoader ' => fn (string $ name ): ?Type => $ this ->loadType ($ name , true ),
221
201
]);
222
202
223
203
$ query = '{ object { string } } ' ;
@@ -275,8 +255,8 @@ public function loadType(string $name, bool $isExecutorCall = false): ?Type
275
255
'interfaces ' => function (): array {
276
256
$ this ->calls [] = 'SomeObject.interfaces ' ;
277
257
278
- /** @var InterfaceType $someInterface */
279
258
$ someInterface = $ this ->loadType ('SomeInterface ' );
259
+ assert ($ someInterface instanceof InterfaceType);
280
260
281
261
return [
282
262
$ someInterface ,
@@ -290,10 +270,11 @@ public function loadType(string $name, bool $isExecutorCall = false): ?Type
290
270
'fields ' => function (): array {
291
271
$ this ->calls [] = 'OtherObject.fields ' ;
292
272
293
- /** @var UnionType $someUnion */
294
273
$ someUnion = $ this ->loadType ('SomeUnion ' );
295
- /** @var InterfaceType $someInterface */
274
+ assert ($ someUnion instanceof UnionType);
275
+
296
276
$ someInterface = $ this ->loadType ('SomeInterface ' );
277
+ assert ($ someInterface instanceof InterfaceType);
297
278
298
279
return [
299
280
'union ' => ['type ' => $ someUnion ],
@@ -324,16 +305,16 @@ public function loadType(string $name, bool $isExecutorCall = false): ?Type
324
305
'resolveType ' => function () {
325
306
$ this ->calls [] = 'SomeUnion.resolveType ' ;
326
307
327
- /** @var ObjectType $deeperObject */
328
308
$ deeperObject = $ this ->loadType ('DeeperObject ' );
309
+ assert ($ deeperObject instanceof ObjectType);
329
310
330
311
return $ deeperObject ;
331
312
},
332
313
'types ' => function (): array {
333
314
$ this ->calls [] = 'SomeUnion.types ' ;
334
315
335
- /** @var ObjectType $deeperObject */
336
316
$ deeperObject = $ this ->loadType ('DeeperObject ' );
317
+ assert ($ deeperObject instanceof ObjectType);
337
318
338
319
return [$ deeperObject ];
339
320
},
@@ -345,16 +326,18 @@ public function loadType(string $name, bool $isExecutorCall = false): ?Type
345
326
'resolveType ' => function () {
346
327
$ this ->calls [] = 'SomeInterface.resolveType ' ;
347
328
348
- /** @var ObjectType $someObject */
349
329
$ someObject = $ this ->loadType ('SomeObject ' );
330
+ assert ($ someObject instanceof ObjectType);
350
331
351
332
return $ someObject ;
352
333
},
353
334
'fields ' => function (): array {
354
335
$ this ->calls [] = 'SomeInterface.fields ' ;
355
336
356
337
return [
357
- 'string ' => ['type ' => Type::string ()],
338
+ 'string ' => [
339
+ 'type ' => Type::string (),
340
+ ],
358
341
];
359
342
},
360
343
]);
@@ -406,9 +389,7 @@ public function testResolveUnion(): void
406
389
{
407
390
$ schema = new Schema ([
408
391
'query ' => $ this ->loadType ('Query ' ),
409
- 'typeLoader ' => function ($ name ) {
410
- return $ this ->loadType ($ name , true );
411
- },
392
+ 'typeLoader ' => fn (string $ name ): ?Type => $ this ->loadType ($ name , true ),
412
393
]);
413
394
414
395
$ query = '
0 commit comments