EnumTypeTest::testExtendedObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Date: 12.05.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\Library\Type;
9
10
11
use Youshido\GraphQL\Type\Enum\EnumType;
12
use Youshido\GraphQL\Type\TypeMap;
13
use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator;
14
use Youshido\Tests\DataProvider\TestEnumType;
15
16
class EnumTypeTest extends \PHPUnit_Framework_TestCase
17
{
18
19
    /**
20
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
21
     */
22
    public function testInvalidInlineCreation()
23
    {
24
        new EnumType([]);
25
    }
26
27
    /**
28
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
29
     */
30
    public function testInvalidEmptyParams()
31
    {
32
        $enumField = new EnumType([
33
            'values' => []
34
        ]);
35
        ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
36
37
    }
38
39
    /**
40
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
41
     */
42 View Code Duplication
    public function testInvalidValueParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        $enumField = new EnumType([
45
            'values' => [
46
                'test'  => 'asd',
47
                'value' => 'asdasd'
48
            ]
49
        ]);
50
        ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
51
    }
52
53
    /**
54
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
55
     */
56 View Code Duplication
    public function testExistingNameParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        $enumField = new EnumType([
59
            'values' => [
60
                [
61
                    'test'  => 'asd',
62
                    'value' => 'asdasd'
63
                ]
64
            ]
65
        ]);
66
        ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
67
    }
68
69
    /**
70
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
71
     */
72 View Code Duplication
    public function testInvalidNameParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $enumField = new EnumType([
75
            'values' => [
76
                [
77
                    'name'  => false,
78
                    'value' => 'asdasd'
79
                ]
80
            ]
81
        ]);
82
        ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
83
    }
84
85
    /**
86
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
87
     */
88 View Code Duplication
    public function testWithoutValueParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $enumField = new EnumType([
91
            'values' => [
92
                [
93
                    'name' => 'TEST_ENUM',
94
                ]
95
            ]
96
        ]);
97
        ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
98
    }
99
100
    public function testNormalCreatingParams()
101
    {
102
        $valuesData = [
103
            [
104
                'name'  => 'ENABLE',
105
                'value' => true
106
            ],
107
            [
108
                'name'  => 'DISABLE',
109
                'value' => 'disable'
110
            ]
111
        ];
112
        $enumType   = new EnumType([
113
            'name'   => 'BoolEnum',
114
            'values' => $valuesData
115
        ]);
116
117
        $this->assertEquals($enumType->getKind(), TypeMap::KIND_ENUM);
118
        $this->assertEquals($enumType->getName(), 'BoolEnum');
119
        $this->assertEquals($enumType->getType(), $enumType);
120
        $this->assertEquals($enumType->getNamedType(), $enumType);
121
122
        $this->assertFalse($enumType->isValidValue($enumType));
123
        $this->assertTrue($enumType->isValidValue(null));
124
125
        $this->assertTrue($enumType->isValidValue(true));
126
        $this->assertTrue($enumType->isValidValue('disable'));
127
128
        $this->assertNull($enumType->serialize('invalid value'));
129
        $this->assertNull($enumType->parseValue('invalid literal'));
130
        $this->assertTrue($enumType->parseValue('ENABLE'));
131
132
        $this->assertEquals($valuesData, $enumType->getValues());
133
    }
134
135
    public function testExtendedObject()
136
    {
137
        $testEnumType = new TestEnumType();
138
        $this->assertEquals('TestEnum', $testEnumType->getName());
139
    }
140
141
}
142