-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstTest.php
144 lines (134 loc) · 4.58 KB
/
AstTest.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace Jerowork\GraphqlAttributeSchema\Test;
use Jerowork\GraphqlAttributeSchema\Ast;
use Jerowork\GraphqlAttributeSchema\Node\Child\ArgNode;
use Jerowork\GraphqlAttributeSchema\Node\Child\EnumValueNode;
use Jerowork\GraphqlAttributeSchema\Node\EnumNode;
use Jerowork\GraphqlAttributeSchema\Node\InputTypeNode;
use Jerowork\GraphqlAttributeSchema\Node\MutationNode;
use Jerowork\GraphqlAttributeSchema\Node\QueryNode;
use Jerowork\GraphqlAttributeSchema\Node\TypeNode;
use Jerowork\GraphqlAttributeSchema\Node\TypeReference\ObjectTypeReference;
use Jerowork\GraphqlAttributeSchema\Node\TypeReference\ScalarTypeReference;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\Enum\TestAnotherEnumType;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\Enum\TestEnumType;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\InputType\TestInputType;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\Mutation\TestMutation;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\Query\TestQuery;
use Jerowork\GraphqlAttributeSchema\Test\Doubles\Type\TestType;
use Override;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
final class AstTest extends TestCase
{
private Ast $ast;
private EnumNode $enumNode1;
private EnumNode $enumNode2;
private TypeNode $typeNode;
#[Override]
protected function setUp(): void
{
parent::setUp();
$this->ast = new Ast(
$this->enumNode1 = new EnumNode(
TestEnumType::class,
'enum1',
null,
[
new EnumValueNode('case1', null, null),
new EnumValueNode('case2', null, null),
],
),
$this->typeNode = new TypeNode(
TestType::class,
'type',
null,
[],
null,
[],
),
$this->enumNode2 =new EnumNode(
TestAnotherEnumType::class,
'enum2',
null,
[
new EnumValueNode('case3', null, null),
new EnumValueNode('case4', null, null),
],
),
new InputTypeNode(
TestInputType::class,
'inputType',
null,
[],
),
);
}
#[Test]
public function itShouldGetNodesByType(): void
{
self::assertSame([$this->enumNode1, $this->enumNode2], $this->ast->getNodesByNodeType(EnumNode::class));
self::assertSame([$this->typeNode], $this->ast->getNodesByNodeType(TypeNode::class));
}
#[Test]
public function itShouldGetNodeByTypeId(): void
{
self::assertSame($this->typeNode, $this->ast->getNodeByClassName(TestType::class));
self::assertSame($this->enumNode2, $this->ast->getNodeByClassName(TestAnotherEnumType::class));
}
#[Test]
public function itShouldSerializeAndDeserialize(): void
{
$ast = new Ast(
new MutationNode(
TestMutation::class,
'name',
'description',
[
new ArgNode(
ScalarTypeReference::create('int'),
'name',
'a description',
'aPropertyName',
),
new ArgNode(
ScalarTypeReference::create('string'),
'name 2',
'b description',
'bPropertyName',
),
],
ObjectTypeReference::create(TestType::class),
'method',
'deprecated',
),
new QueryNode(
TestQuery::class,
'name',
'description',
[
new ArgNode(
ScalarTypeReference::create('int'),
'name',
'a description',
'aPropertyName',
),
new ArgNode(
ScalarTypeReference::create('string'),
'name 2',
'b description',
'bPropertyName',
),
],
ObjectTypeReference::create(TestType::class),
'method',
'deprecated',
),
);
self::assertEquals(Ast::fromArray($ast->toArray()), $ast);
}
}