Completed
Pull Request — master (#14)
by
unknown
11:52
created

TypeUtilitiesTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 6
dl 0
loc 48
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testTypeService() 0 13 1
A testNamedTypeResolverException() 0 4 1
A testIsInputType() 0 8 1
A testIsAbstractType() 0 6 1
A testGetPropertyValue() 0 6 1
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/11/16 10:25 PM
7
*/
8
9
namespace Youshido\Tests\Library\Utilities;
10
11
use Youshido\GraphQL\Type\Object\ObjectType;
12
use Youshido\GraphQL\Type\Scalar\StringType;
13
use Youshido\GraphQL\Type\TypeMap;
14
use Youshido\GraphQL\Type\TypeService;
15
use Youshido\Tests\DataProvider\TestInterfaceType;
16
use Youshido\Tests\DataProvider\TestObjectType;
17
use Youshido\Tests\Library\Type\ObjectTypeTest;
18
19
class TypeUtilitiesTest extends \PHPUnit_Framework_TestCase
20
{
21
22
    public function testTypeService()
23
    {
24
        $this->assertTrue(TypeService::isScalarType(TypeMap::TYPE_STRING));
25
        $this->assertFalse(TypeService::isScalarType('gibberish'));
26
        $this->assertFalse(TypeService::isScalarType(new TestObjectType()));
27
28
        $stringType = new StringType();
29
30
        $this->assertFalse(TypeService::isInterface($stringType));
31
        $this->assertEquals(TypeService::resolveNamedType($stringType), $stringType);
32
        $this->assertNull(TypeService::resolveNamedType(null));
33
        $this->assertEquals(TypeService::resolveNamedType(123), $stringType);
34
    }
35
36
    /**
37
     * @expectedException \Exception
38
     */
39
    public function testNamedTypeResolverException()
40
    {
41
        TypeService::resolveNamedType(['name' => 'test']);
42
    }
43
44
    public function testIsInputType()
45
    {
46
        $testType = new ObjectType(['name' => 'test', 'fields' => ['name' => new StringType()]]);
47
        $this->assertTrue(TypeService::isInputType(new StringType()));
48
        $this->assertTrue(TypeService::isInputType(TypeMap::TYPE_STRING));
49
        $this->assertFalse(TypeService::isInputType('invalid type'));
50
        $this->assertFalse(TypeService::isInputType($testType));
51
    }
52
53
    public function testIsAbstractType()
54
    {
55
        $this->assertTrue(TypeService::isAbstractType(new TestInterfaceType()));
56
        $this->assertFalse(TypeService::isAbstractType(new StringType()));
57
        $this->assertFalse(TypeService::isAbstractType('invalid type'));
58
    }
59
60
    public function testGetPropertyValue() {
61
        $arrayData = (new TestObjectType())->getData();
62
63
        $this->assertEquals('John', TypeService::getPropertyValue($arrayData, 'name'));
64
        $this->assertEquals('John', TypeService::getPropertyValue((object) $arrayData, 'name'));
65
    }
66
}
67