Completed
Pull Request — master (#204)
by Ryan
11:34
created

NonNullTypeTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2015–2018 Alexandr Viniychuk <http://youshido.com>.
4
 * Copyright (c) 2015–2018 Portey Vasil <https://github.com/portey>.
5
 * Copyright (c) 2018 Ryan Parman <https://github.com/skyzyx>.
6
 * Copyright (c) 2018 Ashley Hutson <https://github.com/asheliahut>.
7
 * Copyright (c) 2015–2018 Contributors.
8
 *
9
 * http://opensource.org/licenses/MIT
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is a part of GraphQL project.
15
 *
16
 * @author Alexandr Viniychuk <[email protected]>
17
 * created: 5/11/16 9:31 PM
18
 */
19
20
namespace Youshido\Tests\Library\Type;
21
22
use Youshido\GraphQL\Type\NonNullType;
23
use Youshido\GraphQL\Type\Scalar\StringType;
24
use Youshido\GraphQL\Type\TypeMap;
25
use Youshido\GraphQL\Type\TypeService;
26
27
class NonNullTypeTest extends \PHPUnit_Framework_TestCase
28
{
29
    public function testInvalidParams(): void
30
    {
31
        $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class);
32
33
        new NonNullType('invalid param');
34
    }
35
36
    public function testNonNullType(): void
37
    {
38
        $stringType      = new StringType();
39
        $nonNullType     = new NonNullType(new StringType());
40
        $nonNullOnString = new NonNullType(TypeMap::TYPE_STRING);
41
        $testArray       = ['a' => 'b'];
42
43
        $this->assertEquals($nonNullType->getName(), null, 'Empty non-null name');
44
        $this->assertEquals($nonNullType->getKind(), TypeMap::KIND_NON_NULL);
45
        $this->assertEquals($nonNullType->getType(), new NonNullType($stringType));
46
        $this->assertEquals($nonNullType->getNullableType(), $stringType);
47
        $this->assertEquals($nonNullType->getNullableType(), $nonNullOnString->getNullableType());
48
        $this->assertEquals($nonNullType->getNamedType(), $stringType);
49
        $this->assertEquals($nonNullType->getTypeOf(), $stringType);
50
        $this->assertEquals($nonNullType->isCompositeType(), true);
51
        $this->assertEquals(TypeService::isAbstractType($nonNullType), false);
52
        $this->assertFalse($nonNullType->isValidValue(null));
53
        $this->assertTrue($nonNullType->isValidValue($stringType));
54
        $this->assertFalse($nonNullType->isValidValue(new \stdClass()));
55
        $this->assertEquals($nonNullType->parseValue($testArray), '');
56
        $this->assertEquals($nonNullType->resolve($testArray), $testArray);
57
    }
58
}
59