|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Youshido\Tests\Schema; |
|
4
|
|
|
|
|
5
|
|
|
use Youshido\GraphQL\Execution\Processor; |
|
6
|
|
|
use Youshido\GraphQL\Schema\Schema; |
|
7
|
|
|
use Youshido\GraphQL\Type\Enum\EnumType; |
|
8
|
|
|
use Youshido\GraphQL\Type\InputObject\InputObjectType; |
|
9
|
|
|
use Youshido\GraphQL\Type\NonNullType; |
|
10
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
|
11
|
|
|
use Youshido\GraphQL\Type\Scalar\DateTimeType; |
|
12
|
|
|
use Youshido\GraphQL\Type\Scalar\DateTimeTzType; |
|
13
|
|
|
use Youshido\GraphQL\Type\Scalar\IntType; |
|
14
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
15
|
|
|
|
|
16
|
|
|
class InputObjectDefaultValuesTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public function testDefaultEnum() |
|
20
|
|
|
{ |
|
21
|
|
|
$enumType = new EnumType([ |
|
22
|
|
|
'name' => 'InternalStatus', |
|
23
|
|
|
'values' => [ |
|
24
|
|
|
[ |
|
25
|
|
|
'name' => 1, |
|
26
|
|
|
'value' => 'ACTIVE' |
|
27
|
|
|
], |
|
28
|
|
|
[ |
|
29
|
|
|
'name' => 0, |
|
30
|
|
|
'value' => 'DISABLED' |
|
31
|
|
|
], |
|
32
|
|
|
] |
|
33
|
|
|
]); |
|
34
|
|
|
$schema = new Schema([ |
|
35
|
|
|
'query' => new ObjectType([ |
|
36
|
|
|
'name' => 'RootQuery', |
|
37
|
|
|
'fields' => [ |
|
38
|
|
|
'stringQuery' => [ |
|
39
|
|
|
'type' => new StringType(), |
|
40
|
|
|
'args' => [ |
|
41
|
|
|
'statObject' => new InputObjectType([ |
|
42
|
|
|
'name' => 'StatObjectType', |
|
43
|
|
|
'fields' => [ |
|
44
|
|
|
'status' => [ |
|
45
|
|
|
'type' => $enumType, |
|
46
|
|
|
'default' => 1 |
|
47
|
|
|
], |
|
48
|
|
|
'level' => new NonNullType(new IntType()) |
|
49
|
|
|
] |
|
50
|
|
|
]) |
|
51
|
|
|
], |
|
52
|
|
|
'resolve' => function ($source, $args) { |
|
53
|
|
|
return sprintf('Result with level %s and status %s', |
|
54
|
|
|
$args['statObject']['level'], $args['statObject']['status'] |
|
55
|
|
|
); |
|
56
|
|
|
}, |
|
57
|
|
|
], |
|
58
|
|
|
] |
|
59
|
|
|
]) |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$processor = new Processor($schema); |
|
63
|
|
|
$processor->processPayload('{ stringQuery(statObject: { level: 1 }) }'); |
|
64
|
|
|
$result = $processor->getResponseData(); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals(['data' => [ |
|
67
|
|
|
'stringQuery' => 'Result with level 1 and status ACTIVE' |
|
68
|
|
|
]], $result); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |