|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheCodingMachine\GraphQL\Controllers\Mappers; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use TheCodingMachine\GraphQL\Controllers\Mappers\CannotMapTypeException; |
|
7
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject; |
|
8
|
|
|
use Youshido\GraphQL\Type\InputObject\InputObjectType; |
|
9
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
|
10
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
11
|
|
|
|
|
12
|
|
|
class StaticTypeMapperTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var StaticTypeMapper |
|
16
|
|
|
*/ |
|
17
|
|
|
private $typeMapper; |
|
18
|
|
|
|
|
19
|
|
|
public function setUp(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->typeMapper = new StaticTypeMapper(); |
|
22
|
|
|
$this->typeMapper->setTypes([ |
|
23
|
|
|
TestObject::class => new ObjectType([ |
|
24
|
|
|
'name' => 'TestObject', |
|
25
|
|
|
'fields' => [ |
|
26
|
|
|
'test' => new StringType(), |
|
27
|
|
|
], |
|
28
|
|
|
]) |
|
29
|
|
|
]); |
|
30
|
|
|
$this->typeMapper->setInputTypes([ |
|
31
|
|
|
TestObject::class => new InputObjectType([ |
|
32
|
|
|
'name' => 'TestObject', |
|
33
|
|
|
'fields' => [ |
|
34
|
|
|
'test' => new StringType(), |
|
35
|
|
|
], |
|
36
|
|
|
]) |
|
37
|
|
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testStaticTypeMapper(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertTrue($this->typeMapper->canMapClassToType(TestObject::class)); |
|
43
|
|
|
$this->assertFalse($this->typeMapper->canMapClassToType(\Exception::class)); |
|
44
|
|
|
$this->assertTrue($this->typeMapper->canMapClassToInputType(TestObject::class)); |
|
45
|
|
|
$this->assertFalse($this->typeMapper->canMapClassToInputType(\Exception::class)); |
|
46
|
|
|
$this->assertInstanceOf(ObjectType::class, $this->typeMapper->mapClassToType(TestObject::class)); |
|
47
|
|
|
$this->assertInstanceOf(InputObjectType::class, $this->typeMapper->mapClassToInputType(TestObject::class)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testException1(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->expectException(CannotMapTypeException::class); |
|
53
|
|
|
$this->typeMapper->mapClassToType(\Exception::class); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testException2(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->expectException(CannotMapTypeException::class); |
|
59
|
|
|
$this->typeMapper->mapClassToInputType(\Exception::class); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|