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
|
|||
60 | $info = new ResolveInfo($fieldDefinition, [], new ObjectType(['name' => 'foo']), [], new Schema([]), [], null, null, []); |
||
61 | $actual = $resolver($source, $args, null, $info); |
||
62 | self::assertSame($expected, $actual); |
||
63 | } |
||
64 | } |
||
65 |
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.