From 4d024ee85ee55b46c6337b405ba9612d4613dc80 Mon Sep 17 00:00:00 2001 From: vladar Date: Wed, 20 Apr 2016 18:04:11 +0600 Subject: [PATCH] Test for lazy interface initialization + minor related tweak --- src/Type/Definition/InterfaceType.php | 6 +++--- tests/Type/DefinitionTest.php | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Type/Definition/InterfaceType.php b/src/Type/Definition/InterfaceType.php index 8ba859b..7bf37c5 100644 --- a/src/Type/Definition/InterfaceType.php +++ b/src/Type/Definition/InterfaceType.php @@ -60,10 +60,10 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT */ public static function loadImplementationToInterfaces() { - foreach (self::$_lazyLoadImplementations as $i => &$lazyLoadImplementation) { - call_user_func($lazyLoadImplementation); - unset(self::$_lazyLoadImplementations[$i]); + foreach (self::$_lazyLoadImplementations as $lazyLoadImplementation) { + $lazyLoadImplementation(); } + self::$_lazyLoadImplementations = []; } /** diff --git a/tests/Type/DefinitionTest.php b/tests/Type/DefinitionTest.php index 1dd9b8a..ef0de37 100644 --- a/tests/Type/DefinitionTest.php +++ b/tests/Type/DefinitionTest.php @@ -232,22 +232,24 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase public function testIncludesInterfacesThunkSubtypesInTheTypeMap() { // includes interfaces' thunk subtypes in the type map - $someInterface = new InterfaceType([ - 'name' => 'SomeInterface', - 'fields' => [ - 'f' => ['type' => Type::int()] - ] - ]); + $someInterface = null; $someSubtype = new ObjectType([ 'name' => 'SomeSubtype', 'fields' => [ 'f' => ['type' => Type::int()] ], - 'interfaces' => function() use ($someInterface) { return [$someInterface]; }, + 'interfaces' => function() use (&$someInterface) { return [$someInterface]; }, 'isTypeOf' => function() {return true;} ]); + $someInterface = new InterfaceType([ + 'name' => 'SomeInterface', + 'fields' => [ + 'f' => ['type' => Type::int()] + ] + ]); + $schema = new Schema(new ObjectType([ 'name' => 'Query', 'fields' => [