FieldAwareConfigTraitTest::testAddField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/12/16 7:46 PM
7
*/
8
9
namespace Youshido\Tests\Library\Field;
10
11
12
use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
13
use Youshido\GraphQL\Field\Field;
14
use Youshido\GraphQL\Type\Scalar\IntType;
15
use Youshido\GraphQL\Type\Scalar\StringType;
16
17
class FieldAwareConfigTraitTest extends \PHPUnit_Framework_TestCase
18
{
19
20
    public function testAddField()
21
    {
22
        $fieldsData = [
23
            'id' => [
24
                'type' => new IntType()
25
            ]
26
        ];
27
        $config     = new ObjectTypeConfig([
28
            'name'   => 'UserType',
29
            'fields' => $fieldsData
30
        ]);
31
32
        $this->assertTrue($config->hasFields());
33
        $idField = new Field(['name' => 'id', 'type' => new IntType()]);
34
        $idField->getName();
35
        $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
36
37
        $this->assertEquals([
38
            'id' => $idField,
39
        ], $config->getFields());
40
41
        $config->addField($nameField);
42
        $this->assertEquals([
43
            'id'   => $idField,
44
            'name' => $nameField
45
        ], $config->getFields());
46
47
        $config->removeField('id');
48
        $this->assertEquals([
49
            'name' => $nameField
50
        ], $config->getFields());
51
52
        $config->addFields([
53
            'id' => $idField
54
        ]);
55
        $this->assertEquals([
56
            'name' => $nameField,
57
            'id'   => $idField,
58
        ], $config->getFields());
59
60
        $levelField = new Field(['name' => 'level', 'type' => new IntType()]);
61
        $config->addFields([
62
            $levelField
63
        ]);
64
        $this->assertEquals([
65
            'name'  => $nameField,
66
            'id'    => $idField,
67
            'level' => $levelField,
68
        ], $config->getFields());
69
70
    }
71
72
}
73