|
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
|
|
|
|