Completed
Push — master ( 6c2ef1...d70f56 )
by David
15s queued 10s
created

MutableObjectTypeTest::testGetFieldError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Types;
4
5
use GraphQL\Type\Definition\Type;
6
use PHPUnit\Framework\TestCase;
7
use RuntimeException;
8
9
class MutableObjectTypeTest extends TestCase
10
{
11
    /**
12
     * @var MutableObjectType
13
     */
14
    private $type;
15
16
    public function setUp()
17
    {
18
        $this->type = new MutableObjectType([
19
            'name'    => 'TestObject',
20
            'fields'  => [
21
                'test'   => Type::string(),
22
            ],
23
        ]);
24
    }
25
26
    public function testGetStatus()
27
    {
28
        $this->assertSame(MutableObjectType::STATUS_PENDING, $this->type->getStatus());
29
        $this->type->freeze();
30
        $this->assertSame(MutableObjectType::STATUS_FROZEN, $this->type->getStatus());
31
    }
32
33
    public function testAddFields()
34
    {
35
        $this->type->addFields(function() {
36
            return [
37
                'test'   => Type::int(),
38
                'test2'   => Type::string(),
39
            ];
40
        });
41
        $this->type->addFields(function() {
42
            return [
43
                'test3'   => Type::int(),
44
            ];
45
        });
46
        $this->type->freeze();
47
        $fields = $this->type->getFields();
48
        $this->assertCount(3, $fields);
49
        $this->assertArrayHasKey('test', $fields);
50
        $this->assertSame(Type::int(), $fields['test']->getType());
51
    }
52
53
    public function testHasField()
54
    {
55
        $this->type->freeze();
56
        $this->assertTrue($this->type->hasField('test'));
57
    }
58
59
    public function testGetField()
60
    {
61
        $this->type->freeze();
62
        $this->assertSame(Type::string(), $this->type->getField('test')->getType());
63
    }
64
65
    public function testHasFieldError()
66
    {
67
        $this->expectException(RuntimeException::class);
68
        $this->type->hasField('test');
69
    }
70
71
    public function testGetFieldError()
72
    {
73
        $this->expectException(RuntimeException::class);
74
        $this->type->getField('test');
75
    }
76
77
    public function testGetFieldsError()
78
    {
79
        $this->expectException(RuntimeException::class);
80
        $this->type->getFields();
81
    }
82
83
    public function testAddFieldsError()
84
    {
85
        $this->type->freeze();
86
        $this->expectException(RuntimeException::class);
87
        $this->type->addFields(function() {});
88
    }
89
}
90