-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathIssue238Test.php
More file actions
57 lines (52 loc) · 1.92 KB
/
Copy pathIssue238Test.php
File metadata and controls
57 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Youshido\Tests\Issue238;
use PHPUnit\Framework\TestCase;
use Youshido\GraphQL\Schema\Schema;
use Youshido\GraphQL\Execution\Processor;
use Youshido\GraphQL\Type\Scalar\IntType;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\StringType;
class Issue238Test extends TestCase
{
public function testNotDefinedVariableThrowsException()
{
$schema = new Schema([
'query' => new ObjectType([
'name' => 'RootQuery',
'fields' => [
'currentUser' => [
'type' => new StringType(),
'args' => [
'age' => [
'type' => new IntType(),
'defaultValue' => 20,
],
],
'resolve' => static function ($source, $args, ResolveInfo $info) {
return 'Alex age ' . $args['age'];
},
],
],
]),
]);
$processor = new Processor($schema);
/**
* If using a variable in a query, it must be defined in the operation
* $properQuery = 'query GetUserAge($age:Int) { currentUser(age:$age) }';
* When not declaring the variable in the operation, it must return a nice error message
* (instead of throwing a RuntimeException)
*/
$unproperQuery = '{ currentUser(age:$age) }';
$response = $processor->processPayload($unproperQuery)->getResponseData();
if ($this->assertArrayHasKey(
'errors',
$response
)) {
$this->assertArraySubset(
['message' => 'Variable age hasn\'t been declared'],
$response['errors']
);
}
}
}