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\ResolveInfo; |
15
|
|
|
use Overblog\GraphQLBundle\Resolver\Resolver; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
|
19
|
|
|
class ResolverTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
private $privatePropertyWithoutGetter = 'ImNotAccessibleFromOutside:D'; |
22
|
|
|
|
23
|
|
|
private $privatePropertyWithGetter = 'IfYouWantMeUseMyGetter'; |
24
|
|
|
|
25
|
|
|
private $private_property_with_getter2 = 'IfYouWantMeUseMyGetter2'; |
26
|
|
|
|
27
|
|
|
public $public = 'public'; |
28
|
|
|
|
29
|
|
|
public $closureProperty; |
30
|
|
|
|
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->closureProperty = function () { |
34
|
|
|
return $this->privatePropertyWithoutGetter; |
35
|
|
|
}; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $fieldName |
40
|
|
|
* @param $source |
41
|
|
|
* @param $expected |
42
|
|
|
* |
43
|
|
|
* @dataProvider resolverProvider |
44
|
|
|
*/ |
45
|
|
|
public function testDefaultResolveFn($fieldName, $source, $expected) |
46
|
|
|
{ |
47
|
|
|
$info = new ResolveInfo(['fieldName' => $fieldName]); |
48
|
|
|
|
49
|
|
|
$this->assertEquals($expected, Resolver::defaultResolveFn($source, [], $info)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function resolverProvider() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
['key', ['key' => 'toto'], 'toto'], |
56
|
|
|
['fake', ['coco'], null], |
57
|
|
|
['privatePropertyWithoutGetter', $this, null], |
58
|
|
|
['privatePropertyWithGetter', $this, $this->privatePropertyWithGetter], |
59
|
|
|
['private_property_with_getter2', $this, $this->private_property_with_getter2], |
60
|
|
|
['not_object_or_array', 'String', null], |
61
|
|
|
['public', $this, $this->public], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getPrivatePropertyWithGetter() |
69
|
|
|
{ |
70
|
|
|
return $this->privatePropertyWithGetter; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getPrivatePropertyWithGetter2() |
77
|
|
|
{ |
78
|
|
|
return $this->private_property_with_getter2; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|