UnionTypeTest::testConstructor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
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
        $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