Failed Conditions
Pull Request — master (#62)
by Adrien
06:30 queued 04:20
created

php$0 ➔ providerDefaultFieldResolver()   A

Complexity

Conditions 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A DefaultFieldResolverTest.php$0 ➔ __construct() 0 2 1
A DefaultFieldResolverTest.php$0 ➔ getEntity() 0 3 1
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;
1 ignored issue
show
Bug introduced by
The type GraphQL\Doctrine\Definition\EntityID was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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