GraphQL\Tests\Executor\AbstractTest::testIsTypeOfUsedToResolveRuntimeTypeForInterface PHP Method

testIsTypeOfUsedToResolveRuntimeTypeForInterface() public method

    public function testIsTypeOfUsedToResolveRuntimeTypeForInterface()
    {
        // isTypeOf used to resolve runtime type for Interface
        $petType = new InterfaceType(['name' => 'Pet', 'fields' => ['name' => ['type' => Type::string()]]]);
        // Added to interface type when defined
        $dogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$petType], 'isTypeOf' => function ($obj) {
            return $obj instanceof Dog;
        }, 'fields' => ['name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()]]]);
        $catType = new ObjectType(['name' => 'Cat', 'interfaces' => [$petType], 'isTypeOf' => function ($obj) {
            return $obj instanceof Cat;
        }, 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]]]);
        $schema = new Schema(['query' => new ObjectType(['name' => 'Query', 'fields' => ['pets' => ['type' => Type::listOf($petType), 'resolve' => function () {
            return [new Dog('Odie', true), new Cat('Garfield', false)];
        }]]]), 'types' => [$catType, $dogType]]);
        $query = '{
          pets {
            name
            ... on Dog {
              woofs
            }
            ... on Cat {
              meows
            }
          }
        }';
        $expected = new ExecutionResult(['pets' => [['name' => 'Odie', 'woofs' => true], ['name' => 'Garfield', 'meows' => false]]]);
        $this->assertEquals($expected, Executor::execute($schema, Parser::parse($query)));
    }