1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQLTests\Doctrine; |
6
|
|
|
|
7
|
|
|
use GraphQL\Doctrine\DefaultFieldResolver; |
8
|
|
|
use GraphQL\Doctrine\Definition\EntityID; |
9
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
10
|
|
|
use GraphQLTests\Doctrine\Blog\Model\Special\DefaultValue; |
11
|
|
|
use GraphQLTests\Doctrine\Blog\Model\Special\IgnoredGetter; |
12
|
|
|
|
13
|
|
|
class DefaultFieldResolverTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
public function providerDefaultFieldResolver(): array |
16
|
|
|
{ |
17
|
|
|
$entityID = new class() extends EntityID { |
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getEntity() |
23
|
|
|
{ |
24
|
|
|
return 'real entity'; |
25
|
|
|
} |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
return [ |
29
|
|
|
[null, new IgnoredGetter(), 'privateProperty'], |
30
|
|
|
[null, new IgnoredGetter(), 'protectedProperty'], |
31
|
|
|
['publicProperty', new IgnoredGetter(), 'publicProperty'], |
32
|
|
|
[null, new IgnoredGetter(), 'private'], |
33
|
|
|
[null, new IgnoredGetter(), 'protected'], |
34
|
|
|
['getPublic', new IgnoredGetter(), 'public'], |
35
|
|
|
[['real entity', 2, ['foo']], new IgnoredGetter(), 'publicWithArgs', ['arg2' => 2, 'arg1' => $entityID]], |
36
|
|
|
[null, new IgnoredGetter(), 'nonExisting'], |
37
|
|
|
[null, new IgnoredGetter(), '__call'], |
38
|
|
|
[true, new IgnoredGetter(), 'isValid'], |
39
|
|
|
[true, new IgnoredGetter(), 'hasMoney'], |
40
|
|
|
['john', new DefaultValue(), 'nameWithDefaultValueOnArgument'], |
41
|
|
|
['jane', new DefaultValue(), 'nameWithDefaultValueOnArgument', ['name' => 'jane']], |
42
|
|
|
['bar', ['foo' => 'bar'], 'foo'], |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @dataProvider providerDefaultFieldResolver |
48
|
|
|
* |
49
|
|
|
* @param mixed $expected |
50
|
|
|
* @param array|object $source |
51
|
|
|
* @param string $fieldName |
52
|
|
|
* @param null|array $args |
53
|
|
|
*/ |
54
|
|
|
public function testDefaultFieldResolver($expected, $source, string $fieldName, ?array $args = null): void |
55
|
|
|
{ |
56
|
|
|
$resolver = new DefaultFieldResolver(); |
57
|
|
|
$info = new ResolveInfo(['fieldName' => $fieldName]); |
58
|
|
|
$actual = $resolver($source, $args, null, $info); |
59
|
|
|
self::assertSame($expected, $actual); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|