GraphQL\Tests\Type\DefinitionTest::testProhibitsPuttingNonObjectTypesInUnions PHP Method

testProhibitsPuttingNonObjectTypesInUnions() public method

    public function testProhibitsPuttingNonObjectTypesInUnions()
    {
        $int = Type::int();
        $badUnionTypes = [$int, new NonNull($int), new ListOfType($int), $this->interfaceType, $this->unionType, $this->enumType, $this->inputObjectType];
        // TODO: extract config validation to separate test
        Config::enableValidation();
        foreach ($badUnionTypes as $type) {
            try {
                new UnionType(['name' => 'BadUnion', 'types' => [$type]]);
                $this->fail('Expected exception not thrown');
            } catch (\Exception $e) {
                $this->assertSame('Error in "BadUnion" type definition: expecting callable or ObjectType definition at "types:0", but got "' . Utils::getVariableType($type) . '"', $e->getMessage());
            }
        }
        Config::disableValidation();
    }