Passed
Pull Request — master (#43)
by David
01:47
created

UnionTypeTest::testException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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