1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Tests\Resolver; |
13
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\ObjectType; |
15
|
|
|
use Overblog\GraphQLBundle\Resolver\TypeResolver; |
16
|
|
|
|
17
|
|
|
class TypeResolverTest extends AbstractResolverTest |
18
|
|
|
{ |
19
|
|
|
protected function createResolver() |
20
|
|
|
{ |
21
|
|
|
return new TypeResolver(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function getResolverSolutionsMapping() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
'Toto' => ['solution' => new ObjectType(['name' => 'Toto'])], |
28
|
|
|
'Tata' => ['solution' => new ObjectType(['name' => 'Tata'])], |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testResolveKnownType() |
33
|
|
|
{ |
34
|
|
|
$type = $this->resolver->resolve('Toto'); |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ObjectType', $type); |
37
|
|
|
$this->assertEquals('Toto', $type->name); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @expectedException \Overblog\GraphQLBundle\Resolver\UnresolvableException |
42
|
|
|
*/ |
43
|
|
|
public function testResolveUnknownType() |
44
|
|
|
{ |
45
|
|
|
$this->resolver->resolve('Fake'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testResolveWithListOfWrapper() |
49
|
|
|
{ |
50
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
51
|
|
|
$type = $this->resolver->resolve('[Tata]'); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type); |
54
|
|
|
$this->assertEquals('Tata', $type->getWrappedType()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testResolveWithNonNullWrapper() |
58
|
|
|
{ |
59
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
60
|
|
|
$type = $this->resolver->resolve('Toto!'); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\NonNull', $type); |
63
|
|
|
$this->assertEquals('Toto', $type->getWrappedType()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testResolveWithNonNullListOfWrapper() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
69
|
|
|
$type = $this->resolver->resolve('[Toto]!'); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\NonNull', $type); |
72
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type->getWrappedType()); |
73
|
|
|
$this->assertEquals('Toto', $type->getWrappedType()->getWrappedType()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function testResolveWitListOfNonNullWrapper() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
79
|
|
|
$type = $this->resolver->resolve('[Toto!]'); |
80
|
|
|
|
81
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type); |
82
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\NonNull', $type->getWrappedType()); |
83
|
|
|
$this->assertEquals('Toto', $type->getWrappedType()->getWrappedType()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testResolveWitNonNullListOfNonNullWrapper() |
87
|
|
|
{ |
88
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
89
|
|
|
$type = $this->resolver->resolve('[Toto!]!'); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\NonNull', $type); |
92
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type->getWrappedType()); |
93
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\NonNull', $type->getWrappedType()->getWrappedType()); |
94
|
|
|
$this->assertEquals('Toto', $type->getWrappedType()->getWrappedType()->getWrappedType()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
public function testResolveWitListOfListOfWrapper() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
/** @var \GraphQL\Type\Definition\WrappingType $type */ |
100
|
|
|
$type = $this->resolver->resolve('[[Toto]]'); |
101
|
|
|
|
102
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type); |
103
|
|
|
$this->assertInstanceOf('GraphQL\Type\Definition\ListOfType', $type->getWrappedType()); |
104
|
|
|
$this->assertEquals('Toto', $type->getWrappedType()->getWrappedType()); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.