Failed Conditions
Pull Request — master (#69)
by
unknown
28:27 queued 13:44
created

DefaultFieldResolverTest.php$0 ➔ __construct()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 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;
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 GraphQLTests\Doctrine\Blog\Model\User;
17
use PHPUnit\Framework\TestCase;
18
19
final class DefaultFieldResolverTest extends TestCase
20
{
21
    public function providerDefaultFieldResolver(): array
22
    {
23
        $fakeEntity = new User();
24
        $entityID = new class($fakeEntity) extends EntityID {
25
            public function __construct(private readonly User $fakeEntity)
26
            {
27
            }
28
29
            public function getEntity(): User
30
            {
31
                return $this->fakeEntity;
32
            }
33
        };
34
35
        return [
36
            [null, new IgnoredGetter(), 'privateProperty'],
37
            [null, new IgnoredGetter(), 'protectedProperty'],
38
            ['publicProperty', new IgnoredGetter(), 'publicProperty'],
39
            [null, new IgnoredGetter(), 'private'],
40
            [null, new IgnoredGetter(), 'protected'],
41
            ['getPublic', new IgnoredGetter(), 'public'],
42
            [[$fakeEntity, 2, ['foo']], new IgnoredGetter(), 'publicWithArgs', ['arg2' => 2, 'arg1' => $entityID]],
43
            [null, new IgnoredGetter(), 'nonExisting'],
44
            [null, new IgnoredGetter(), '__call'],
45
            [true, new IgnoredGetter(), 'isValid'],
46
            [true, new IgnoredGetter(), 'hasMoney'],
47
            ['john', new DefaultValue(), 'nameWithDefaultValueOnArgument'],
48
            ['jane', new DefaultValue(), 'nameWithDefaultValueOnArgument', ['name' => 'jane']],
49
            ['bar', ['foo' => 'bar'], 'foo'],
50
        ];
51
    }
52
53
    /**
54
     * @dataProvider providerDefaultFieldResolver
55
     */
56
    public function testDefaultFieldResolver(mixed $expected, array|object $source, string $fieldName, array $args = []): void
57
    {
58
        $resolver = new DefaultFieldResolver();
59
        $fieldDefinition = FieldDefinition::create(['name' => $fieldName, 'type' => Type::boolean()]);
0 ignored issues
show
Bug introduced by
The method create() does not exist on GraphQL\Type\Definition\FieldDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        $fieldDefinition = FieldDefinition::create(['name' => $fieldName, 'type' => Type::boolean()]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        $info = new ResolveInfo($fieldDefinition, [], new ObjectType(['name' => 'foo']), [], new Schema([]), [], null, null, []);
2 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type ArrayObject expected by parameter $fieldNodes of GraphQL\Type\Definition\ResolveInfo::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $info = new ResolveInfo($fieldDefinition, /** @scrutinizer ignore-type */ [], new ObjectType(['name' => 'foo']), [], new Schema([]), [], null, null, []);
Loading history...
Bug introduced by
null of type null is incompatible with the type GraphQL\Language\AST\OperationDefinitionNode expected by parameter $operation of GraphQL\Type\Definition\ResolveInfo::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $info = new ResolveInfo($fieldDefinition, [], new ObjectType(['name' => 'foo']), [], new Schema([]), [], null, /** @scrutinizer ignore-type */ null, []);
Loading history...
61
        $actual = $resolver($source, $args, null, $info);
62
        self::assertSame($expected, $actual);
63
    }
64
}
65