Skip to content

Commit 4d024ee

Browse files
committed
Test for lazy interface initialization + minor related tweak
1 parent 0a0c818 commit 4d024ee

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Type/Definition/InterfaceType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public static function addImplementationToInterfaces(ObjectType $impl)
6060
*/
6161
public static function loadImplementationToInterfaces()
6262
{
63-
foreach (self::$_lazyLoadImplementations as $i => &$lazyLoadImplementation) {
64-
call_user_func($lazyLoadImplementation);
65-
unset(self::$_lazyLoadImplementations[$i]);
63+
foreach (self::$_lazyLoadImplementations as $lazyLoadImplementation) {
64+
$lazyLoadImplementation();
6665
}
66+
self::$_lazyLoadImplementations = [];
6767
}
6868

6969
/**

tests/Type/DefinitionTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,24 @@ public function testIncludesInterfaceSubtypesInTheTypeMap()
232232
public function testIncludesInterfacesThunkSubtypesInTheTypeMap()
233233
{
234234
// includes interfaces' thunk subtypes in the type map
235-
$someInterface = new InterfaceType([
236-
'name' => 'SomeInterface',
237-
'fields' => [
238-
'f' => ['type' => Type::int()]
239-
]
240-
]);
235+
$someInterface = null;
241236

242237
$someSubtype = new ObjectType([
243238
'name' => 'SomeSubtype',
244239
'fields' => [
245240
'f' => ['type' => Type::int()]
246241
],
247-
'interfaces' => function() use ($someInterface) { return [$someInterface]; },
242+
'interfaces' => function() use (&$someInterface) { return [$someInterface]; },
248243
'isTypeOf' => function() {return true;}
249244
]);
250245

246+
$someInterface = new InterfaceType([
247+
'name' => 'SomeInterface',
248+
'fields' => [
249+
'f' => ['type' => Type::int()]
250+
]
251+
]);
252+
251253
$schema = new Schema(new ObjectType([
252254
'name' => 'Query',
253255
'fields' => [

0 commit comments

Comments
 (0)