UnionTypeTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 28
loc 77
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInlineCreation() 0 27 1
A testObjectCreation() 0 9 1
A testInvalidTypesWithScalar() 14 14 1
A testInvalidTypes() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Date: 13.05.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\tests\Library\Type;
9
10
11
use Youshido\GraphQL\Type\Object\ObjectType;
12
use Youshido\GraphQL\Type\Scalar\IntType;
13
use Youshido\GraphQL\Type\TypeMap;
14
use Youshido\GraphQL\Type\Union\UnionType;
15
use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator;
16
use Youshido\Tests\DataProvider\TestObjectType;
17
use Youshido\Tests\DataProvider\TestUnionType;
18
19
class UnionTypeTest extends \PHPUnit_Framework_TestCase
20
{
21
22
    public function testInlineCreation()
23
    {
24
        $object = new ObjectType([
25
            'name' => 'TestObject',
26
            'fields' => ['id' => ['type' => new IntType()]]
27
        ]);
28
29
        $type = new UnionType([
30
            'name'        => 'Car',
31
            'description' => 'Union collect cars types',
32
            'types'       => [
33
                new TestObjectType(),
34
                $object
35
            ],
36
            'resolveType' => function ($type) {
37
                return $type;
38
            }
39
        ]);
40
41
        $this->assertEquals('Car', $type->getName());
42
        $this->assertEquals('Union collect cars types', $type->getDescription());
43
        $this->assertEquals([new TestObjectType(), $object], $type->getTypes());
44
        $this->assertEquals('test', $type->resolveType('test'));
45
        $this->assertEquals(TypeMap::KIND_UNION, $type->getKind());
46
        $this->assertEquals($type, $type->getNamedType());
47
        $this->assertTrue($type->isValidValue(true));
48
    }
49
50
    public function testObjectCreation()
51
    {
52
        $type = new TestUnionType();
53
54
        $this->assertEquals('TestUnion', $type->getName());
55
        $this->assertEquals('Union collect cars types', $type->getDescription());
56
        $this->assertEquals([new TestObjectType()], $type->getTypes());
57
        $this->assertEquals('test', $type->resolveType('test'));
58
    }
59
60
    /**
61
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
62
     */
63 View Code Duplication
    public function testInvalidTypesWithScalar()
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...
64
    {
65
        $type = new UnionType([
66
            'name'        => 'Car',
67
            'description' => 'Union collect cars types',
68
            'types'       => [
69
                'test', new IntType()
70
            ],
71
            'resolveType' => function ($type) {
72
                return $type;
73
            }
74
        ]);
75
        ConfigValidator::getInstance()->assertValidConfig($type->getConfig());
76
    }
77
78
    /**
79
     * @expectedException Youshido\GraphQL\Exception\ConfigurationException
80
     */
81 View Code Duplication
    public function testInvalidTypes()
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...
82
    {
83
        $type = new UnionType([
84
            'name'        => 'Car',
85
            'description' => 'Union collect cars types',
86
            'types'       => [
87
                new IntType()
88
            ],
89
            'resolveType' => function ($type) {
90
                return $type;
91
            }
92
        ]);
93
        ConfigValidator::getInstance()->assertValidConfig($type->getConfig());
94
    }
95
}
96