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