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