1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\GraphQL\Controllers; |
4
|
|
|
|
5
|
|
|
use GraphQL\Type\Definition\ObjectType; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use TheCodingMachine\GraphQL\Controllers\Types\MutableObjectType; |
8
|
|
|
|
9
|
|
|
class TypeRegistryTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public function testRegisterTypeException() |
13
|
|
|
{ |
14
|
|
|
$type = new ObjectType([ |
15
|
|
|
'name' => 'Foo', |
16
|
|
|
'fields' => function() {return [];} |
17
|
|
|
]); |
18
|
|
|
|
19
|
|
|
$registry = new TypeRegistry(); |
20
|
|
|
$registry->registerType($type); |
21
|
|
|
|
22
|
|
|
$this->expectException(GraphQLException::class); |
23
|
|
|
$registry->registerType($type); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetType() |
27
|
|
|
{ |
28
|
|
|
$type = new ObjectType([ |
29
|
|
|
'name' => 'Foo', |
30
|
|
|
'fields' => function() {return [];} |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
$registry = new TypeRegistry(); |
34
|
|
|
$registry->registerType($type); |
35
|
|
|
|
36
|
|
|
$this->assertSame($type, $registry->getType('Foo')); |
37
|
|
|
|
38
|
|
|
$this->expectException(GraphQLException::class); |
39
|
|
|
$registry->getType('Bar'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testHasType() |
43
|
|
|
{ |
44
|
|
|
$type = new ObjectType([ |
45
|
|
|
'name' => 'Foo', |
46
|
|
|
'fields' => function() {return [];} |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$registry = new TypeRegistry(); |
50
|
|
|
$registry->registerType($type); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($registry->hasType('Foo')); |
53
|
|
|
$this->assertFalse($registry->hasType('Bar')); |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetMutableObjectType() |
58
|
|
|
{ |
59
|
|
|
$type = new MutableObjectType([ |
60
|
|
|
'name' => 'Foo', |
61
|
|
|
'fields' => function() {return [];} |
62
|
|
|
]); |
63
|
|
|
$type2 = new ObjectType([ |
64
|
|
|
'name' => 'FooBar', |
65
|
|
|
'fields' => function() {return [];} |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$registry = new TypeRegistry(); |
69
|
|
|
$registry->registerType($type); |
70
|
|
|
$registry->registerType($type2); |
71
|
|
|
|
72
|
|
|
$this->assertSame($type, $registry->getMutableObjectType('Foo')); |
73
|
|
|
|
74
|
|
|
$this->expectException(GraphQLException::class); |
75
|
|
|
$this->assertSame($type, $registry->getMutableObjectType('FooBar')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|