InterfaceTypeTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInterfaceMethods() 0 39 1
A testApplyInterface() 0 7 1
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/12/16 5:02 PM
7
*/
8
9
namespace Youshido\Tests\Library\Type;
10
11
12
use Youshido\GraphQL\Field\Field;
13
use Youshido\GraphQL\Type\InterfaceType\InterfaceType;
14
use Youshido\GraphQL\Type\Object\ObjectType;
15
use Youshido\GraphQL\Type\Scalar\StringType;
16
use Youshido\Tests\DataProvider\TestExtendedType;
17
use Youshido\Tests\DataProvider\TestInterfaceType;
18
19
class InterfaceTypeTest extends \PHPUnit_Framework_TestCase
20
{
21
22
    public function testInterfaceMethods()
23
    {
24
        $interface = new TestInterfaceType();
25
        $this->assertEquals($interface->getNamedType(), $interface->getType());
26
        $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
27
        $nameField->getName();
28
29
        $this->assertEquals(['name' => $nameField],
30
            $interface->getFields());
31
32
        $object = new ObjectType([
33
            'name'       => 'Test',
34
            'fields'     => [
35
                'name' => new StringType()
36
            ],
37
            'interfaces' => [$interface],
38
        ]);
39
        $this->assertEquals([$interface], $object->getInterfaces());
40
        $this->assertTrue($interface->isValidValue($object));
41
        $this->assertFalse($interface->isValidValue('invalid object'));
42
43
        $this->assertEquals($interface->serialize($object), $object);
44
45
        $interfaceType = new InterfaceType([
46
            'name'        => 'UserInterface',
47
            'fields'      => [
48
                'name' => new StringType()
49
            ],
50
            'resolveType' => function ($object) {
51
                return $object;
52
            }
53
        ]);
54
        $this->assertEquals('UserInterface', $interfaceType->getName());
55
56
        $this->assertEquals($object, $interfaceType->resolveType($object));
57
58
        $this->assertTrue($interfaceType->isValidValue($object));
59
        $this->assertFalse($interfaceType->isValidValue('invalid object'));
60
    }
61
62
    public function testApplyInterface()
63
    {
64
        $extendedType = new TestExtendedType();
65
66
        $this->assertArrayHasKey('ownField', $extendedType->getFields());
67
        $this->assertArrayHasKey('name', $extendedType->getFields());
68
    }
69
70
}
71