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

testIsTypeOfUsedToResolveRuntimeTypeForUnion() public method

    public function testIsTypeOfUsedToResolveRuntimeTypeForUnion()
    {
        $dogType = new ObjectType(['name' => 'Dog', 'isTypeOf' => function ($obj) {
            return $obj instanceof Dog;
        }, 'fields' => ['name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()]]]);
        $catType = new ObjectType(['name' => 'Cat', 'isTypeOf' => function ($obj) {
            return $obj instanceof Cat;
        }, 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]]]);
        $petType = new UnionType(['name' => 'Pet', 'types' => [$dogType, $catType]]);
        $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)];
        }]]])]);
        $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)));
    }