-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathTypeRegistryTest.php
98 lines (76 loc) · 2.63 KB
/
TypeRegistryTest.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
<?php
namespace TheCodingMachine\GraphQLite;
use GraphQL\Type\Definition\ObjectType;
use PHPUnit\Framework\TestCase;
use TheCodingMachine\GraphQLite\Types\MutableObjectType;
class TypeRegistryTest extends TestCase
{
public function testRegisterTypeException(): void
{
$type = new ObjectType([
'name' => 'Foo',
'fields' => function() {return [];}
]);
$registry = new TypeRegistry();
$registry->registerType($type);
$this->expectException(GraphQLRuntimeException::class);
$registry->registerType($type);
}
public function testGetType(): void
{
$type = new ObjectType([
'name' => 'Foo',
'fields' => function() {return [];}
]);
$registry = new TypeRegistry();
$registry->registerType($type);
$this->assertSame($type, $registry->getType('Foo'));
$this->expectException(GraphQLRuntimeException::class);
$registry->getType('Bar');
}
public function testHasType(): void
{
$type = new ObjectType([
'name' => 'Foo',
'fields' => function() {return [];}
]);
$registry = new TypeRegistry();
$registry->registerType($type);
$this->assertTrue($registry->hasType('Foo'));
$this->assertFalse($registry->hasType('Bar'));
}
public function testGetMutableObjectType(): void
{
$type = new MutableObjectType([
'name' => 'Foo',
'fields' => function() {return [];}
]);
$type2 = new ObjectType([
'name' => 'FooBar',
'fields' => function() {return [];}
]);
$registry = new TypeRegistry();
$registry->registerType($type);
$registry->registerType($type2);
$this->assertSame($type, $registry->getMutableObjectType('Foo'));
$this->expectException(GraphQLRuntimeException::class);
$this->assertSame($type, $registry->getMutableObjectType('FooBar'));
}
public function testGetMutableInterface(): void
{
$type = new MutableObjectType([
'name' => 'Foo',
'fields' => function() {return [];}
]);
$type2 = new ObjectType([
'name' => 'FooBar',
'fields' => function() {return [];}
]);
$registry = new TypeRegistry();
$registry->registerType($type);
$registry->registerType($type2);
$this->assertSame($type, $registry->getMutableInterface('Foo'));
$this->expectException(GraphQLRuntimeException::class);
$this->assertSame($type, $registry->getMutableInterface('FooBar'));
}
}