Passed
Pull Request — master (#78)
by David
02:09
created

TypeRegistryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRegisterTypeException() 0 12 1
A testGetType() 0 14 1
A testHasType() 0 12 1
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers;
4
5
use GraphQL\Type\Definition\ObjectType;
6
use PHPUnit\Framework\TestCase;
7
8
class TypeRegistryTest extends TestCase
9
{
10
11
    public function testRegisterTypeException()
12
    {
13
        $type = new ObjectType([
14
            'name' => 'Foo',
15
            'fields' => function() {return [];}
16
        ]);
17
18
        $registry = new TypeRegistry();
19
        $registry->registerType($type);
20
21
        $this->expectException(GraphQLException::class);
22
        $registry->registerType($type);
23
    }
24
25
    public function testGetType()
26
    {
27
        $type = new ObjectType([
28
            'name' => 'Foo',
29
            'fields' => function() {return [];}
30
        ]);
31
32
        $registry = new TypeRegistry();
33
        $registry->registerType($type);
34
35
        $this->assertSame($type, $registry->getType('Foo'));
36
37
        $this->expectException(GraphQLException::class);
38
        $registry->getType('Bar');
39
    }
40
41
    public function testHasType()
42
    {
43
        $type = new ObjectType([
44
            'name' => 'Foo',
45
            'fields' => function() {return [];}
46
        ]);
47
48
        $registry = new TypeRegistry();
49
        $registry->registerType($type);
50
51
        $this->assertTrue($registry->hasType('Foo'));
52
        $this->assertFalse($registry->hasType('Bar'));
53
54
    }
55
}
56