public function testProhibitsPuttingNonObjectTypesInUnions() { $int = Type::int(); $badUnionTypes = [$int, new NonNull($int), new ListOfType($int), $this->interfaceType, $this->unionType, $this->enumType, $this->inputObjectType]; Config::enableValidation(); foreach ($badUnionTypes as $type) { try { new UnionType(['name' => 'BadUnion', 'types' => [$type]]); $this->fail('Expected exception not thrown'); } catch (\Exception $e) { $this->assertSame('Expecting callable or instance of GraphQL\\Type\\Definition\\ObjectType at "types:0", but got "' . get_class($type) . '"', $e->getMessage()); } } Config::disableValidation(); }
/** * @it prohibits putting non-Object types in unions */ 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(); }