|
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 Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage; |
|
15
|
|
|
use Overblog\GraphQLBundle\Resolver\ConfigResolver; |
|
16
|
|
|
|
|
17
|
|
|
class ConfigResolverTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var ConfigResolver */ |
|
20
|
|
|
private static $configResolver; |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container') |
|
25
|
|
|
->getMock(); |
|
26
|
|
|
$container |
|
27
|
|
|
->method('get') |
|
28
|
|
|
->will($this->returnValue(new \stdClass())); |
|
29
|
|
|
|
|
30
|
|
|
$expressionLanguage = new ExpressionLanguage(); |
|
31
|
|
|
$expressionLanguage->setContainer($container); |
|
32
|
|
|
|
|
33
|
|
|
$typeResolver = $this->getMockBuilder('Overblog\GraphQLBundle\Resolver\TypeResolver') |
|
34
|
|
|
->disableOriginalConstructor() |
|
35
|
|
|
->getMock(); |
|
36
|
|
|
$typeResolver |
|
37
|
|
|
->method('resolve') |
|
38
|
|
|
->will($this->returnValue(new \stdClass())); |
|
39
|
|
|
|
|
40
|
|
|
$fieldResolver = $this->getMockBuilder('Overblog\GraphQLBundle\Resolver\FieldResolver') |
|
41
|
|
|
->disableOriginalConstructor() |
|
42
|
|
|
->getMock(); |
|
43
|
|
|
$fieldResolver |
|
44
|
|
|
->method('resolve') |
|
45
|
|
|
->will($this->returnValue(new \stdClass())); |
|
46
|
|
|
|
|
47
|
|
|
$argResolver = $this->getMockBuilder('Overblog\GraphQLBundle\Resolver\ArgResolver') |
|
48
|
|
|
->disableOriginalConstructor() |
|
49
|
|
|
->getMock(); |
|
50
|
|
|
$argResolver |
|
51
|
|
|
->method('resolve') |
|
52
|
|
|
->will($this->returnValue(new \stdClass())); |
|
53
|
|
|
|
|
54
|
|
|
self::$configResolver = new ConfigResolver( |
|
55
|
|
|
$typeResolver, |
|
56
|
|
|
$fieldResolver, |
|
57
|
|
|
$argResolver, |
|
58
|
|
|
$expressionLanguage, |
|
59
|
|
|
true |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @expectedException \RuntimeException |
|
65
|
|
|
* @expectedExceptionMessage Config must be an array or implement \ArrayAccess interface |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testConfigNotArrayOrImplementArrayAccess() |
|
68
|
|
|
{ |
|
69
|
|
|
self::$configResolver->resolve('Not Array'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testResolveValues() |
|
73
|
|
|
{ |
|
74
|
|
|
$config = self::$configResolver->resolve( |
|
75
|
|
|
[ |
|
76
|
|
|
'values' => [ |
|
77
|
|
|
'test' => ['value' => 'my test value'], |
|
78
|
|
|
'toto' => ['value' => 'my toto value'], |
|
79
|
|
|
'expression-language-test' => ['value' => '@=["my", "test"]'], |
|
80
|
|
|
], |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$expected = [ |
|
85
|
|
|
'values' => [ |
|
86
|
|
|
'test' => ['value' => 'my test value'], |
|
87
|
|
|
'toto' => ['value' => 'my toto value'], |
|
88
|
|
|
'expression-language-test' => ['value' => ['my', 'test']], |
|
89
|
|
|
], |
|
90
|
|
|
]; |
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals($expected, $config); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|