1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\Api; |
6
|
|
|
|
7
|
|
|
use Ecodev\Felix\Api\Server; |
|
|
|
|
8
|
|
|
use GraphQL\Executor\ExecutionResult; |
9
|
|
|
use GraphQL\Type\Definition\ObjectType; |
10
|
|
|
use GraphQL\Type\Schema; |
11
|
|
|
use Laminas\Diactoros\CallbackStream; |
12
|
|
|
use Laminas\Diactoros\ServerRequest; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class ServerTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @dataProvider providerExecute |
19
|
|
|
*/ |
20
|
|
|
public function testExecute(string $body, array $expected): void |
21
|
|
|
{ |
22
|
|
|
$schema = new Schema(['query' => new ObjectType(['name' => 'Query'])]); |
23
|
|
|
$server = new Server($schema, false); |
24
|
|
|
$request = new ServerRequest(body: new CallbackStream(fn () => $body), method: 'POST'); |
25
|
|
|
$request = $request->withHeader('content-type', 'application/json'); |
26
|
|
|
|
27
|
|
|
$result = $server->execute($request); |
28
|
|
|
|
29
|
|
|
self::assertInstanceOf(ExecutionResult::class, $result); |
30
|
|
|
self::assertSame($expected, $result->jsonSerialize()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function providerExecute(): iterable |
34
|
|
|
{ |
35
|
|
|
yield 'empty body' => [ |
36
|
|
|
'', |
37
|
|
|
[ |
38
|
|
|
'errors' => [ |
39
|
|
|
[ |
40
|
|
|
'message' => 'GraphQL Request must include at least one of those two parameters: "query" or "queryId"', |
41
|
|
|
'extensions' => [ |
42
|
|
|
'category' => 'request', |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
], |
46
|
|
|
], |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
yield 'invalid json' => [ |
50
|
|
|
'foo bar', |
51
|
|
|
[ |
52
|
|
|
'errors' => [ |
53
|
|
|
[ |
54
|
|
|
'message' => 'GraphQL Request must include at least one of those two parameters: "query" or "queryId"', |
55
|
|
|
'extensions' => [ |
56
|
|
|
'category' => 'request', |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
yield 'empty query' => [ |
64
|
|
|
'{"query": ""}', |
65
|
|
|
[ |
66
|
|
|
'errors' => [ |
67
|
|
|
[ |
68
|
|
|
'message' => 'GraphQL Request must include at least one of those two parameters: "query" or "queryId"', |
69
|
|
|
'extensions' => [ |
70
|
|
|
'category' => 'request', |
71
|
|
|
], |
72
|
|
|
], |
73
|
|
|
], |
74
|
|
|
], |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
yield 'normal' => [ |
78
|
|
|
'{"query": "{ __typename }"}', |
79
|
|
|
[ |
80
|
|
|
'data' => [ |
81
|
|
|
'__typename' => 'Query', |
82
|
|
|
], |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths