Completed
Push — master ( 8e6ca0...1e6eb5 )
by David
17s queued 11s
created

UnionTypeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 7 1
A testException2() 0 4 1
A testException() 0 5 1
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Types;
4
5
use GraphQL\Type\Definition\ResolveInfo;
6
use GraphQL\Type\Definition\StringType;
7
use PHPUnit\Framework\TestCase;
8
use TheCodingMachine\GraphQL\Controllers\AbstractQueryProviderTest;
9
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject;
10
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject2;
11
12
class UnionTypeTest extends AbstractQueryProviderTest
13
{
14
    public function testConstructor()
15
    {
16
        $unionType = new UnionType([$this->getTestObjectType(), $this->getTestObjectType2()], $this->getTypeMapper());
17
        $type = $unionType->resolveType(new TestObject('foo'), null, new ResolveInfo([]));
18
        $this->assertSame($this->getTestObjectType(), $type);
19
        $type = $unionType->resolveType(new TestObject2('foo'), null, new ResolveInfo([]));
20
        $this->assertSame($this->getTestObjectType2(), $type);
21
    }
22
23
    public function testException()
24
    {
25
        $unionType = new UnionType([$this->getTestObjectType(), $this->getTestObjectType2()], $this->getTypeMapper());
26
        $this->expectException(\InvalidArgumentException::class);
27
        $unionType->resolveType('foo', null, new ResolveInfo([]));
28
    }
29
30
    public function testException2()
31
    {
32
        $this->expectException(\InvalidArgumentException::class);
33
        new UnionType([new StringType()], $this->getTypeMapper());
34
    }
35
}
36