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

TypeUtilitiesTest::testGetPropertyValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
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 6
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/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