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\Definition\Builder; |
13
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\ObjectType; |
15
|
|
|
use Overblog\GraphQLBundle\Definition\Builder\TypeBuilder; |
16
|
|
|
use Overblog\GraphQLBundle\Resolver\ConfigResolver; |
17
|
|
|
|
18
|
|
|
class TypeBuilderTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var TypeBuilder |
22
|
|
|
*/ |
23
|
|
|
private $typeBuilder; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->typeBuilder = new TypeBuilder(new ConfigResolver()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param $type |
32
|
|
|
* @param array $config |
33
|
|
|
* @param $expectedInstanceOf |
34
|
|
|
* |
35
|
|
|
* @dataProvider getCreateDataProvider |
36
|
|
|
*/ |
37
|
|
|
public function testCreate($type, array $config, $expectedInstanceOf) |
38
|
|
|
{ |
39
|
|
|
$type = $this->typeBuilder->create($type, $config); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf($expectedInstanceOf, $type); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @expectedException \RuntimeException |
46
|
|
|
* @expectedExceptionMessage Type "toto" is not managed. |
47
|
|
|
*/ |
48
|
|
|
public function testCreateInvalidType() |
49
|
|
|
{ |
50
|
|
|
$this->typeBuilder->create('toto', []); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getCreateDataProvider() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
[ |
57
|
|
|
'object', ['name' => 'object'], 'GraphQL\\Type\\Definition\\ObjectType', |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
'enum', ['name' => 'enum'], 'GraphQL\\Type\\Definition\\EnumType', |
61
|
|
|
], |
62
|
|
|
[ |
63
|
|
|
'interface', ['name' => 'interface'], 'GraphQL\\Type\\Definition\\InterfaceType', |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
'union', ['name' => 'union', 'types' => [new ObjectType(['name' => 'toto'])]], 'GraphQL\\Type\\Definition\\UnionType', |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'input-object', ['name' => 'input'], 'GraphQL\\Type\\Definition\\InputObjectType', |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|