UnionTypeTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 8 1
A testException2() 0 4 1
A testException() 0 6 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
        $resolveInfo = $this->getMockBuilder(ResolveInfo::class)->disableOriginalConstructor()->getMock();
18
        $type = $unionType->resolveType(new TestObject('foo'), null, $resolveInfo);
19
        $this->assertSame($this->getTestObjectType(), $type);
20
        $type = $unionType->resolveType(new TestObject2('foo'), null, $resolveInfo);
21
        $this->assertSame($this->getTestObjectType2(), $type);
22
    }
23
24
    public function testException()
25
    {
26
        $unionType = new UnionType([$this->getTestObjectType(), $this->getTestObjectType2()], $this->getTypeMapper());
27
        $this->expectException(\InvalidArgumentException::class);
28
        $resolveInfo = $this->getMockBuilder(ResolveInfo::class)->disableOriginalConstructor()->getMock();
29
        $unionType->resolveType('foo', null, $resolveInfo);
0 ignored issues
show
Bug introduced by
'foo' of type string is incompatible with the type object expected by parameter $objectValue of GraphQL\Type\Definition\UnionType::resolveType(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        $unionType->resolveType(/** @scrutinizer ignore-type */ 'foo', null, $resolveInfo);
Loading history...
30
    }
31
32
    public function testException2()
33
    {
34
        $this->expectException(\InvalidArgumentException::class);
35
        new UnionType([new StringType()], $this->getTypeMapper());
36
    }
37
}
38