Test for lazy interface initialization + minor related tweak

This commit is contained in:
vladar 2016-04-20 18:04:11 +06:00
parent 0a0c8181ea
commit 4d024ee85e
2 changed files with 12 additions and 10 deletions

View File

@ -60,10 +60,10 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
*/ */
public static function loadImplementationToInterfaces() public static function loadImplementationToInterfaces()
{ {
foreach (self::$_lazyLoadImplementations as $i => &$lazyLoadImplementation) { foreach (self::$_lazyLoadImplementations as $lazyLoadImplementation) {
call_user_func($lazyLoadImplementation); $lazyLoadImplementation();
unset(self::$_lazyLoadImplementations[$i]);
} }
self::$_lazyLoadImplementations = [];
} }
/** /**

View File

@ -232,22 +232,24 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
public function testIncludesInterfacesThunkSubtypesInTheTypeMap() public function testIncludesInterfacesThunkSubtypesInTheTypeMap()
{ {
// includes interfaces' thunk subtypes in the type map // includes interfaces' thunk subtypes in the type map
$someInterface = new InterfaceType([ $someInterface = null;
'name' => 'SomeInterface',
'fields' => [
'f' => ['type' => Type::int()]
]
]);
$someSubtype = new ObjectType([ $someSubtype = new ObjectType([
'name' => 'SomeSubtype', 'name' => 'SomeSubtype',
'fields' => [ 'fields' => [
'f' => ['type' => Type::int()] 'f' => ['type' => Type::int()]
], ],
'interfaces' => function() use ($someInterface) { return [$someInterface]; }, 'interfaces' => function() use (&$someInterface) { return [$someInterface]; },
'isTypeOf' => function() {return true;} 'isTypeOf' => function() {return true;}
]); ]);
$someInterface = new InterfaceType([
'name' => 'SomeInterface',
'fields' => [
'f' => ['type' => Type::int()]
]
]);
$schema = new Schema(new ObjectType([ $schema = new Schema(new ObjectType([
'name' => 'Query', 'name' => 'Query',
'fields' => [ 'fields' => [