Completed
Push — master ( 5d17f3...e891dc )
by Alexandr
03:56
created

InterfaceTypeTest::testApplyInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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
        $this->assertEquals(['name' => new Field(['name' => 'name', 'type' => new StringType()])],
27
            $interface->getFields());
28
29
        $object = new ObjectType([
30
            'name'       => 'Test',
31
            'fields'     => [
32
                'name' => new StringType()
33
            ],
34
            'interfaces' => [$interface],
35
        ]);
36
        $this->assertEquals([$interface], $object->getInterfaces());
37
        $this->assertTrue($interface->isValidValue($object));
38
        $this->assertFalse($interface->isValidValue('invalid object'));
39
40
        $this->assertEquals($interface->serialize($object), $object);
41
42
        $interfaceType = new InterfaceType([
43
            'name'        => 'UserInterface',
44
            'fields'      => [
45
                'name' => new StringType()
46
            ],
47
            'resolveType' => function ($object) {
48
                return $object;
49
            }
50
        ]);
51
        $this->assertEquals('UserInterface', $interfaceType->getName());
52
53
        $this->assertEquals($object, $interfaceType->resolveType($object));
54
55
        $this->assertFalse($interfaceType->isValidValue($object));
56
        $this->assertFalse($interfaceType->isValidValue('invalid object'));
57
    }
58
59
    public function testApplyInterface()
60
    {
61
        $extendedType = new TestExtendedType();
62
63
        $this->assertArrayHasKey('ownField', $extendedType->getFields());
64
        $this->assertArrayHasKey('name', $extendedType->getFields());
65
    }
66
67
}
68