diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8565ae099..8598378fa 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -865,11 +865,6 @@ parameters: count: 1 path: src/Validator/Rules/KnownTypeNames.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/LoneAnonymousOperation.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 @@ -1115,71 +1110,6 @@ parameters: count: 1 path: src/Validator/ValidationContext.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 5 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 7 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Deferred\"\\.$#" - count: 2 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Deferred\"\\.$#" - count: 1 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Executor/AbstractPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 4 - path: tests/Executor/AbstractTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 7 - path: tests/Executor/AbstractTest.php - - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: tests/Executor/AbstractTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Executor/AbstractTest.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 4 - path: tests/Executor/DeferredFieldsTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 4 - path: tests/Executor/DeferredFieldsTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 2 - path: tests/Executor/DeferredFieldsTest.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Schema given\\.$#" count: 1 @@ -1190,286 +1120,36 @@ parameters: count: 1 path: tests/Executor/DirectivesTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 13 - path: tests/Executor/ExecutorLazySchemaTest.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 2 - path: tests/Executor/ExecutorLazySchemaTest.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 7 path: tests/Executor/ExecutorLazySchemaTest.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: tests/Executor/ExecutorLazySchemaTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 3 - path: tests/Executor/ExecutorSchemaTest.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Deferred\"\\.$#" - count: 1 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 19 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 6 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 12 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Error\\\\UserError\"\\.$#" - count: 1 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Deferred\"\\.$#" - count: 7 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 1 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Executor/ExecutorTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Executor/LazyInterfaceTest.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\InterfaceType given\\.$#" count: 1 path: tests/Executor/LazyInterfaceTest.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Executor/LazyInterfaceTest.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\ObjectType given\\.$#" count: 1 path: tests/Executor/LazyInterfaceTest.php - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Executor/LazyInterfaceTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 9 - path: tests/Executor/ListsTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Deferred\"\\.$#" - count: 4 - path: tests/Executor/ListsTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 8 - path: tests/Executor/ListsTest.php - - - - message: "#^Anonymous function should have native return typehint \"int\"\\.$#" - count: 24 - path: tests/Executor/ListsTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Tests\\\\Executor\\\\TestClasses\\\\NumberHolder\"\\.$#" - count: 1 - path: tests/Executor/MutationsTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Deferred\"\\.$#" - count: 2 - path: tests/Executor/MutationsTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: tests/Executor/MutationsTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 4 - path: tests/Executor/NonNullTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Deferred\"\\.$#" - count: 2 - path: tests/Executor/NonNullTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 9 - path: tests/Executor/NonNullTest.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Deferred\"\\.$#" - count: 2 - path: tests/Executor/NonNullTest.php - - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: tests/Executor/NonNullTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 9 - path: tests/Executor/Promise/ReactPromiseAdapterTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 7 - path: tests/Executor/Promise/SyncPromiseAdapterTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Executor/Promise/SyncPromiseAdapterTest.php - - - - message: "#^Anonymous function should have native return typehint \"int\"\\.$#" - count: 4 - path: tests/Executor/Promise/SyncPromiseAdapterTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 3 - path: tests/Executor/Promise/SyncPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 10 - path: tests/Executor/Promise/SyncPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"int\"\\.$#" - count: 1 - path: tests/Executor/Promise/SyncPromiseTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Executor/ResolveTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Executor/SyncTest.php - - - - message: "#^Anonymous function should have native return typehint \"float\"\\.$#" - count: 1 - path: tests/Executor/TestClasses/Adder.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Tests\\\\Executor\\\\TestClasses\\\\NumberHolder\"\\.$#" - count: 1 - path: tests/Executor/TestClasses/Root.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: tests/Executor/TestClasses/Root.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 3 - path: tests/Executor/UnionInterfaceTest.php - - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: tests/Executor/UnionInterfaceTest.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Schema given\\.$#" count: 1 path: tests/Executor/ValuesTest.php - - - message: "#^Anonymous function should have native return typehint \"\\?string\"\\.$#" - count: 1 - path: tests/Executor/VariablesTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 6 path: tests/Experimental/Executor/CollectorTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Experimental/Executor/CollectorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Executor\\\\Promise\\\\Promise\"\\.$#" - count: 1 - path: tests/GraphQLTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: tests/Language/LexerTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Language/ParserTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 20 - path: tests/Language/SchemaParserTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 31 - path: tests/Language/VisitorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\OperationDefinitionNode\"\\.$#" - count: 2 - path: tests/Language/VisitorTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\DocumentNode\"\\.$#" - count: 1 - path: tests/Language/VisitorTest.php - - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 18 - path: tests/Language/VisitorTest.php - - message: "#^Only booleans are allowed in a ternary operator condition, \\(GraphQL\\\\Type\\\\Definition\\\\CompositeType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|null given\\.$#" count: 4 @@ -1485,131 +1165,26 @@ parameters: count: 4 path: tests/Language/VisitorTest.php - - - message: "#^Anonymous function should return GraphQL\\\\Type\\\\Definition\\\\Type but return statement is missing\\.$#" - count: 1 - path: tests/Regression/Issue396Test.php - - - - message: "#^Anonymous function should return GraphQL\\\\Type\\\\Definition\\\\Type\\|null but return statement is missing\\.$#" - count: 1 - path: tests/Regression/Issue396Test.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 path: tests/Server/Psr7/PsrStreamStub.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 7 - path: tests/Server/QueryExecutionTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 4 - path: tests/Server/QueryExecutionTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 3 - path: tests/Server/QueryExecutionTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\DocumentNode\"\\.$#" - count: 1 - path: tests/Server/QueryExecutionTest.php - - - - message: "#^Anonymous function should have native return typehint \"stdClass\"\\.$#" - count: 1 - path: tests/Server/QueryExecutionTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Server/RequestParsingTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: tests/Server/RequestParsingTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: tests/Server/RequestValidationTest.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 10 - path: tests/Server/ServerConfigTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Server/ServerConfigTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: tests/Server/ServerTestCase.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 4 - path: tests/StarWarsSchema.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: tests/StarWarsSchema.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 7 path: tests/StarWarsValidationTest.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 16 - path: tests/Type/DefinitionTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 16 - path: tests/Type/DefinitionTest.php - - - - message: "#^Anonymous function should have native return typehint \"stdClass\"\\.$#" - count: 1 - path: tests/Type/DefinitionTest.php - - - - message: "#^Anonymous function should have native return typehint \"int\"\\.$#" - count: 1 - path: tests/Type/DefinitionTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: tests/Type/EnumTypeTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 4 path: tests/Type/EnumTypeTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Type/QueryPlanTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Type/QueryPlanTest.php - - message: "#^Variable property access on \\$this\\(GraphQL\\\\Tests\\\\Type\\\\TypeLoaderTest\\)\\.$#" count: 1 diff --git a/src/Validator/Rules/LoneAnonymousOperation.php b/src/Validator/Rules/LoneAnonymousOperation.php index f0a68cf6e..facc895a3 100644 --- a/src/Validator/Rules/LoneAnonymousOperation.php +++ b/src/Validator/Rules/LoneAnonymousOperation.php @@ -39,7 +39,7 @@ static function (Node $definition) : bool { NodeKind::OPERATION_DEFINITION => static function (OperationDefinitionNode $node) use ( &$operationCount, $context - ) { + ) : void { if ($node->name !== null || $operationCount <= 1) { return; } diff --git a/tests/Executor/AbstractPromiseTest.php b/tests/Executor/AbstractPromiseTest.php index c5fd7935a..04013e476 100644 --- a/tests/Executor/AbstractPromiseTest.php +++ b/tests/Executor/AbstractPromiseTest.php @@ -41,7 +41,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void 'name' => 'Dog', 'interfaces' => [$petType], 'isTypeOf' => static function ($obj) { - return new Deferred(static function () use ($obj) { + return new Deferred(static function () use ($obj) : bool { return $obj instanceof Dog; }); }, @@ -55,7 +55,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void 'name' => 'Cat', 'interfaces' => [$petType], 'isTypeOf' => static function ($obj) { - return new Deferred(static function () use ($obj) { + return new Deferred(static function () use ($obj) : bool { return $obj instanceof Cat; }); }, @@ -71,7 +71,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($petType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -124,8 +124,8 @@ public function testIsTypeOfCanBeRejected() : void $DogType = new ObjectType([ 'name' => 'Dog', 'interfaces' => [$PetType], - 'isTypeOf' => static function () { - return new Deferred(static function () { + 'isTypeOf' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('We are testing this error'); }); }, @@ -139,7 +139,7 @@ public function testIsTypeOfCanBeRejected() : void 'name' => 'Cat', 'interfaces' => [$PetType], 'isTypeOf' => static function ($obj) { - return new Deferred(static function () use ($obj) { + return new Deferred(static function () use ($obj) : bool { return $obj instanceof Cat; }); }, @@ -155,7 +155,7 @@ public function testIsTypeOfCanBeRejected() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -210,7 +210,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void $dogType = new ObjectType([ 'name' => 'Dog', 'isTypeOf' => static function ($obj) { - return new Deferred(static function () use ($obj) { + return new Deferred(static function () use ($obj) : bool { return $obj instanceof Dog; }); }, @@ -223,7 +223,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void $catType = new ObjectType([ 'name' => 'Cat', 'isTypeOf' => static function ($obj) { - return new Deferred(static function () use ($obj) { + return new Deferred(static function () use ($obj) : bool { return $obj instanceof Cat; }); }, @@ -244,7 +244,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($petType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [new Dog('Odie', true), new Cat('Garfield', false)]; }, ], @@ -286,8 +286,8 @@ public function testResolveTypeOnInterfaceYieldsUsefulError() : void { $PetType = new InterfaceType([ 'name' => 'Pet', - 'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) { - return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) { + 'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) : Deferred { + return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) : ?Type { if ($obj instanceof Dog) { return $DogType; } @@ -338,7 +338,7 @@ public function testResolveTypeOnInterfaceYieldsUsefulError() : void 'pets' => [ 'type' => Type::listOf($PetType), 'resolve' => static function () { - return new Deferred(static function () { + return new Deferred(static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -417,7 +417,7 @@ public function testResolveTypeOnUnionYieldsUsefulError() : void $PetType = new UnionType([ 'name' => 'Pet', 'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) { - return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) { + return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) : ?Type { if ($obj instanceof Dog) { return $DogType; } @@ -440,7 +440,7 @@ public function testResolveTypeOnUnionYieldsUsefulError() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -535,7 +535,7 @@ public function testResolveTypeAllowsResolvingWithTypeName() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -579,8 +579,8 @@ public function testResolveTypeCanBeCaught() : void { $PetType = new InterfaceType([ 'name' => 'Pet', - 'resolveType' => static function () { - return new Deferred(static function () { + 'resolveType' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('We are testing this error'); }); }, @@ -613,7 +613,7 @@ public function testResolveTypeCanBeCaught() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), diff --git a/tests/Executor/AbstractTest.php b/tests/Executor/AbstractTest.php index 60f5b793f..fe25b4656 100644 --- a/tests/Executor/AbstractTest.php +++ b/tests/Executor/AbstractTest.php @@ -4,6 +4,7 @@ namespace GraphQL\Tests\Executor; +use GraphQL\Error\InvariantViolation; use GraphQL\Executor\ExecutionResult; use GraphQL\Executor\Executor; use GraphQL\GraphQL; @@ -43,7 +44,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void $dogType = new ObjectType([ 'name' => 'Dog', 'interfaces' => [$petType], - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Dog; }, 'fields' => [ @@ -55,7 +56,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void $catType = new ObjectType([ 'name' => 'Cat', 'interfaces' => [$petType], - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Cat; }, 'fields' => [ @@ -70,7 +71,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForInterface() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($petType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [new Dog('Odie', true), new Cat('Garfield', false)]; }, ], @@ -109,7 +110,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void { $dogType = new ObjectType([ 'name' => 'Dog', - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Dog; }, 'fields' => [ @@ -120,7 +121,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void $catType = new ObjectType([ 'name' => 'Cat', - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Cat; }, 'fields' => [ @@ -140,7 +141,7 @@ public function testIsTypeOfUsedToResolveRuntimeTypeForUnion() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($petType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [new Dog('Odie', true), new Cat('Garfield', false)]; }, ], @@ -230,7 +231,7 @@ public function testResolveTypeOnInterfaceYieldsUsefulError() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -305,7 +306,7 @@ public function testResolveTypeOnUnionYieldsUsefulError() : void $PetType = new UnionType([ 'name' => 'Pet', - 'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) { + 'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) : Type { if ($obj instanceof Dog) { return $DogType; } @@ -315,6 +316,8 @@ public function testResolveTypeOnUnionYieldsUsefulError() : void if ($obj instanceof Human) { return $HumanType; } + + throw new InvariantViolation('Invalid type'); }, 'types' => [$DogType, $CatType], ]); @@ -325,7 +328,7 @@ public function testResolveTypeOnUnionYieldsUsefulError() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -383,7 +386,7 @@ public function testReturningInvalidValueFromResolveTypeYieldsUsefulError() : vo $fooInterface = new InterfaceType([ 'name' => 'FooInterface', 'fields' => ['bar' => ['type' => Type::string()]], - 'resolveType' => static function () { + 'resolveType' => static function () : array { return []; }, ]); @@ -400,7 +403,7 @@ public function testReturningInvalidValueFromResolveTypeYieldsUsefulError() : vo 'fields' => [ 'foo' => [ 'type' => $fooInterface, - 'resolve' => static function () { + 'resolve' => static function () : string { return 'dummy'; }, ], @@ -476,7 +479,7 @@ public function testResolveTypeAllowsResolvingWithTypeName() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($PetType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [ new Dog('Odie', true), new Cat('Garfield', false), @@ -523,7 +526,7 @@ public function testHintsOnConflictingTypeInstancesInResolveType() : void 'fields' => [ 'a' => Type::string(), ], - 'interfaces' => static function () use ($iface) { + 'interfaces' => static function () use ($iface) : array { return [$iface]; }, ]); diff --git a/tests/Executor/DeferredFieldsTest.php b/tests/Executor/DeferredFieldsTest.php index a897614a0..2f301c5af 100644 --- a/tests/Executor/DeferredFieldsTest.php +++ b/tests/Executor/DeferredFieldsTest.php @@ -144,7 +144,7 @@ public function setUp() : void return Utils::filter( $this->storyDataSource, - static function ($story) use ($category) { + static function ($story) use ($category) : bool { return in_array($category['id'], $story['categoryIds'], true); } ); @@ -192,7 +192,7 @@ static function ($story) use ($category) { return Utils::filter( $this->storyDataSource, - static function ($story) { + static function ($story) : bool { return $story['id'] % 2 === 1; } ); @@ -200,7 +200,7 @@ static function ($story) { ], 'featuredCategory' => [ 'type' => $this->categoryType, - 'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) { + 'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) : array { $this->paths[] = $info->path; return $this->categoryDataSource[0]; @@ -208,7 +208,7 @@ static function ($story) { ], 'categories' => [ 'type' => Type::listOf($this->categoryType), - 'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) { + 'resolve' => function ($rootValue, $args, $context, ResolveInfo $info) : array { $this->paths[] = $info->path; return $this->categoryDataSource; @@ -403,7 +403,7 @@ public function testComplexRecursiveDeferredFields() : void return [ 'sync' => [ 'type' => Type::string(), - 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) { + 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) : string { $this->paths[] = $info->path; return 'sync'; @@ -414,7 +414,7 @@ public function testComplexRecursiveDeferredFields() : void 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) { $this->paths[] = $info->path; - return new Deferred(function () use ($info) { + return new Deferred(function () use ($info) : string { $this->paths[] = ['!dfd for: ', $info->path]; return 'deferred'; @@ -423,7 +423,7 @@ public function testComplexRecursiveDeferredFields() : void ], 'nest' => [ 'type' => $complexType, - 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) { + 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) : array { $this->paths[] = $info->path; return []; @@ -434,7 +434,7 @@ public function testComplexRecursiveDeferredFields() : void 'resolve' => function ($complexType, $args, $context, ResolveInfo $info) { $this->paths[] = $info->path; - return new Deferred(function () use ($info) { + return new Deferred(function () use ($info) : array { $this->paths[] = ['!dfd nest for: ', $info->path]; return []; @@ -635,7 +635,7 @@ private function findStoryById($id) { return Utils::find( $this->storyDataSource, - static function ($story) use ($id) { + static function ($story) use ($id) : bool { return $story['id'] === $id; } ); @@ -645,7 +645,7 @@ private function findUserById($id) { return Utils::find( $this->userDataSource, - static function ($user) use ($id) { + static function ($user) use ($id) : bool { return $user['id'] === $id; } ); diff --git a/tests/Executor/ExecutorLazySchemaTest.php b/tests/Executor/ExecutorLazySchemaTest.php index 245b95df4..9d9878531 100644 --- a/tests/Executor/ExecutorLazySchemaTest.php +++ b/tests/Executor/ExecutorLazySchemaTest.php @@ -64,7 +64,7 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema() : void // isTypeOf used to resolve runtime type for Interface $petType = new InterfaceType([ 'name' => 'Pet', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => ['type' => Type::string()], ]; @@ -75,10 +75,10 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema() : void $dogType = new ObjectType([ 'name' => 'Dog', 'interfaces' => [$petType], - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Dog; }, - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()], @@ -89,10 +89,10 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema() : void $catType = new ObjectType([ 'name' => 'Cat', 'interfaces' => [$petType], - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Cat; }, - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()], @@ -106,7 +106,7 @@ public function testWarnsAboutSlowIsTypeOfForLazySchema() : void 'fields' => [ 'pets' => [ 'type' => Type::listOf($petType), - 'resolve' => static function () { + 'resolve' => static function () : array { return [new Dog('Odie', true), new Cat('Garfield', false)]; }, ], @@ -171,7 +171,7 @@ public function testHintsOnConflictingTypeInstancesInDefinitions() : void case 'Test': return new ObjectType([ 'name' => 'Test', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'test' => Type::string(), ]; @@ -184,7 +184,7 @@ public function testHintsOnConflictingTypeInstancesInDefinitions() : void $query = new ObjectType([ 'name' => 'Query', - 'fields' => static function () use ($typeLoader) { + 'fields' => static function () use ($typeLoader) : array { return [ 'test' => $typeLoader('Test'), ]; @@ -259,7 +259,7 @@ public function loadType($name, $isExecutorCall = false) case 'Query': return $this->queryType ?: $this->queryType = new ObjectType([ 'name' => 'Query', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'Query.fields'; return [ @@ -271,7 +271,7 @@ public function loadType($name, $isExecutorCall = false) case 'SomeObject': return $this->someObjectType ?: $this->someObjectType = new ObjectType([ 'name' => 'SomeObject', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'SomeObject.fields'; return [ @@ -279,7 +279,7 @@ public function loadType($name, $isExecutorCall = false) 'object' => ['type' => $this->someObjectType], ]; }, - 'interfaces' => function () { + 'interfaces' => function () : array { $this->calls[] = 'SomeObject.interfaces'; return [ @@ -290,7 +290,7 @@ public function loadType($name, $isExecutorCall = false) case 'OtherObject': return $this->otherObjectType ?: $this->otherObjectType = new ObjectType([ 'name' => 'OtherObject', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'OtherObject.fields'; return [ @@ -302,7 +302,7 @@ public function loadType($name, $isExecutorCall = false) case 'DeeperObject': return $this->deeperObjectType ?: $this->deeperObjectType = new ObjectType([ 'name' => 'DeeperObject', - 'fields' => function () { + 'fields' => function () : array { return [ 'scalar' => ['type' => $this->loadType('SomeScalar')], ]; @@ -317,7 +317,7 @@ public function loadType($name, $isExecutorCall = false) 'parseValue' => static function ($value) { return $value; }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]); case 'SomeUnion': @@ -328,7 +328,7 @@ public function loadType($name, $isExecutorCall = false) return $this->loadType('DeeperObject'); }, - 'types' => function () { + 'types' => function () : array { $this->calls[] = 'SomeUnion.types'; return [$this->loadType('DeeperObject')]; @@ -342,7 +342,7 @@ public function loadType($name, $isExecutorCall = false) return $this->loadType('SomeObject'); }, - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'SomeInterface.fields'; return [ diff --git a/tests/Executor/ExecutorSchemaTest.php b/tests/Executor/ExecutorSchemaTest.php index 494d49301..4a35291a2 100644 --- a/tests/Executor/ExecutorSchemaTest.php +++ b/tests/Executor/ExecutorSchemaTest.php @@ -82,7 +82,7 @@ public function testExecutesUsingASchema() : void ], 'feed' => [ 'type' => Type::listOf($BlogArticle), - 'resolve' => function () { + 'resolve' => function () : array { return [ $this->article(1), $this->article(2), @@ -213,7 +213,7 @@ public function testExecutesUsingASchema() : void private function article($id) { $johnSmith = null; - $article = static function ($id) use (&$johnSmith) { + $article = static function ($id) use (&$johnSmith) : array { return [ 'id' => $id, 'isPublished' => 'true', @@ -226,7 +226,7 @@ private function article($id) ]; }; - $getPic = static function ($uid, $width, $height) { + $getPic = static function ($uid, $width, $height) : array { return [ 'url' => sprintf('cdn://%s', $uid), 'width' => $width, @@ -237,7 +237,7 @@ private function article($id) $johnSmith = [ 'id' => 123, 'name' => 'John Smith', - 'pic' => static function ($width, $height) use ($getPic) { + 'pic' => static function ($width, $height) use ($getPic) : array { return $getPic(123, $width, $height); }, 'recentArticle' => $article(1), diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 28b36f9ed..33ae342b7 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -45,33 +45,33 @@ public function testExecutesArbitraryCode() : void $deepData = null; $data = null; - $promiseData = static function () use (&$data) { + $promiseData = static function () use (&$data) : Deferred { return new Deferred(static function () use (&$data) { return $data; }); }; $data = [ - 'a' => static function () { + 'a' => static function () : string { return 'Apple'; }, - 'b' => static function () { + 'b' => static function () : string { return 'Banana'; }, - 'c' => static function () { + 'c' => static function () : string { return 'Cookie'; }, - 'd' => static function () { + 'd' => static function () : string { return 'Donut'; }, - 'e' => static function () { + 'e' => static function () : string { return 'Egg'; }, 'f' => 'Fish', - 'pic' => static function ($size = 50) { + 'pic' => static function ($size = 50) : string { return 'Pic of size: ' . $size; }, - 'promise' => static function () use ($promiseData) { + 'promise' => static function () use ($promiseData) : Deferred { return $promiseData(); }, 'deep' => static function () use (&$deepData) { @@ -81,16 +81,16 @@ public function testExecutesArbitraryCode() : void // Required for that & reference above $deepData = [ - 'a' => static function () { + 'a' => static function () : string { return 'Already Been Done'; }, - 'b' => static function () { + 'b' => static function () : string { return 'Boring'; }, - 'c' => static function () { + 'c' => static function () : array { return ['Contrived', null, 'Confusing']; }, - 'deeper' => static function () use (&$data) { + 'deeper' => static function () use (&$data) : array { return [$data, null, $data]; }, ]; @@ -216,25 +216,25 @@ public function testMergesParallelFragments() : void return [ 'a' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return 'Apple'; }, ], 'b' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return 'Banana'; }, ], 'c' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return 'Cherry'; }, ], 'deep' => [ 'type' => $Type, - 'resolve' => static function () { + 'resolve' => static function () : array { return []; }, ], @@ -277,7 +277,7 @@ public function testProvidesInfoAboutCurrentExecutionState() : void 'fields' => [ 'test' => [ 'type' => Type::string(), - 'resolve' => static function ($test, $args, $ctx, $_info) use (&$info) { + 'resolve' => static function ($test, $args, $ctx, $_info) use (&$info) : void { $info = $_info; }, ], @@ -324,7 +324,7 @@ public function testThreadsContextCorrectly() : void 'fields' => [ 'a' => [ 'type' => Type::string(), - 'resolve' => static function ($context) use (&$gotHere) { + 'resolve' => static function ($context) use (&$gotHere) : void { self::assertEquals('thing', $context['contextThing']); $gotHere = true; }, @@ -361,7 +361,7 @@ public function testCorrectlyThreadsArguments() : void 'stringArg' => ['type' => Type::string()], ], 'type' => Type::string(), - 'resolve' => static function ($_, $args) use (&$gotHere) { + 'resolve' => static function ($_, $args) use (&$gotHere) : void { self::assertEquals(123, $args['numArg']); self::assertEquals('foo', $args['stringArg']); $gotHere = true; @@ -396,21 +396,21 @@ public function testNullsOutErrorSubtrees() : void }'; $data = [ - 'sync' => static function () { + 'sync' => static function () : string { return 'sync'; }, - 'syncError' => static function () { + 'syncError' => static function () : void { throw new UserError('Error getting syncError'); }, - 'syncRawError' => static function () { + 'syncRawError' => static function () : void { throw new UserError('Error getting syncRawError'); }, // inherited from JS reference implementation, but make no sense in this PHP impl // leaving it just to simplify migrations from newer js versions - 'syncReturnError' => static function () { + 'syncReturnError' => static function () : UserError { return new UserError('Error getting syncReturnError'); }, - 'syncReturnErrorList' => static function () { + 'syncReturnErrorList' => static function () : array { return [ 'sync0', new UserError('Error getting syncReturnErrorList1'), @@ -418,45 +418,45 @@ public function testNullsOutErrorSubtrees() : void new UserError('Error getting syncReturnErrorList3'), ]; }, - 'async' => static function () { - return new Deferred(static function () { + 'async' => static function () : Deferred { + return new Deferred(static function () : string { return 'async'; }); }, - 'asyncReject' => static function () { - return new Deferred(static function () { + 'asyncReject' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('Error getting asyncReject'); }); }, - 'asyncRawReject' => static function () { - return new Deferred(static function () { + 'asyncRawReject' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('Error getting asyncRawReject'); }); }, - 'asyncEmptyReject' => static function () { - return new Deferred(static function () { + 'asyncEmptyReject' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError(); }); }, - 'asyncError' => static function () { - return new Deferred(static function () { + 'asyncError' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('Error getting asyncError'); }); }, // inherited from JS reference implementation, but make no sense in this PHP impl // leaving it just to simplify migrations from newer js versions - 'asyncRawError' => static function () { - return new Deferred(static function () { + 'asyncRawError' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('Error getting asyncRawError'); }); }, - 'asyncReturnError' => static function () { - return new Deferred(static function () { + 'asyncReturnError' => static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('Error getting asyncReturnError'); }); }, - 'asyncReturnErrorWithExtensions' => static function () { - return new Deferred(static function () { + 'asyncReturnErrorWithExtensions' => static function () : Deferred { + return new Deferred(static function () : void { $error = new Error( 'Error getting asyncReturnErrorWithExtensions', null, @@ -824,23 +824,23 @@ public function testCorrectFieldOrderingDespiteExecutionOrder() : void e }'; $data = [ - 'a' => static function () { + 'a' => static function () : string { return 'a'; }, 'b' => static function () { - return new Deferred(static function () { + return new Deferred(static function () : string { return 'b'; }); }, - 'c' => static function () { + 'c' => static function () : string { return 'c'; }, - 'd' => static function () { - return new Deferred(static function () { + 'd' => static function () : Deferred { + return new Deferred(static function () : string { return 'd'; }); }, - 'e' => static function () { + 'e' => static function () : string { return 'e'; }, ]; @@ -973,7 +973,7 @@ public function testFailsWhenAnIsTypeOfCheckIsNotMet() : void { $SpecialType = new ObjectType([ 'name' => 'SpecialType', - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Special; }, 'fields' => [ @@ -1068,7 +1068,7 @@ public function testUsesACustomFieldResolver() : void ]); // For the purposes of test, just return the name of the field! - $customResolver = static function ($source, $args, $context, ResolveInfo $info) { + $customResolver = static function ($source, $args, $context, ResolveInfo $info) : string { return $info->fieldName; }; @@ -1155,7 +1155,7 @@ public function testSerializesToEmptyObjectVsEmptyArray() : void 'fields' => [ 'id' => Type::id(), ], - 'interfaces' => static function () use (&$iface) { + 'interfaces' => static function () use (&$iface) : array { return [$iface]; }, ]); @@ -1165,7 +1165,7 @@ public function testSerializesToEmptyObjectVsEmptyArray() : void 'fields' => [ 'id' => Type::id(), ], - 'interfaces' => static function () use (&$iface) { + 'interfaces' => static function () use (&$iface) : array { return [$iface]; }, ]); @@ -1175,7 +1175,7 @@ public function testSerializesToEmptyObjectVsEmptyArray() : void 'fields' => [ 'id' => Type::id(), ], - 'resolveType' => static function ($v) use ($a, $b) { + 'resolveType' => static function ($v) use ($a, $b) : ObjectType { return $v['type'] === 'A' ? $a : $b; }, ]); diff --git a/tests/Executor/LazyInterfaceTest.php b/tests/Executor/LazyInterfaceTest.php index b1602ecec..7917b483d 100644 --- a/tests/Executor/LazyInterfaceTest.php +++ b/tests/Executor/LazyInterfaceTest.php @@ -58,7 +58,7 @@ protected function setUp() : void return [ 'lazyInterface' => [ 'type' => $this->getLazyInterfaceType(), - 'resolve' => static function () { + 'resolve' => static function () : array { return []; }, ], @@ -82,7 +82,7 @@ protected function getLazyInterfaceType() 'fields' => [ 'a' => Type::string(), ], - 'resolveType' => function () { + 'resolveType' => function () : ObjectType { return $this->getTestObjectType(); }, ]); @@ -104,7 +104,7 @@ protected function getTestObjectType() 'fields' => [ 'name' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return 'testname'; }, ], diff --git a/tests/Executor/ListsTest.php b/tests/Executor/ListsTest.php index 036a908f2..103841ab8 100644 --- a/tests/Executor/ListsTest.php +++ b/tests/Executor/ListsTest.php @@ -62,7 +62,7 @@ private function check($testType, $testData, $expected, $debug = false) 'test' => ['type' => $testType], 'nest' => [ 'type' => $dataType, - 'resolve' => static function () use ($data) { + 'resolve' => static function () use ($data) : array { return $data; }, ], @@ -85,7 +85,7 @@ public function testHandlesNullableListsWithPromiseArray() : void { // Contains values $this->checkHandlesNullableLists( - new Deferred(static function () { + new Deferred(static function () : array { return [1, 2]; }), ['data' => ['nest' => ['test' => [1, 2]]]] @@ -93,7 +93,7 @@ public function testHandlesNullableListsWithPromiseArray() : void // Contains null $this->checkHandlesNullableLists( - new Deferred(static function () { + new Deferred(static function () : array { return [1, null, 2]; }), ['data' => ['nest' => ['test' => [1, null, 2]]]] @@ -109,8 +109,8 @@ public function testHandlesNullableListsWithPromiseArray() : void // Rejected $this->checkHandlesNullableLists( - static function () { - return new Deferred(static function () { + static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('bad'); }); }, @@ -135,10 +135,10 @@ public function testHandlesNullableListsWithArrayPromise() : void // Contains values $this->checkHandlesNullableLists( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -148,13 +148,13 @@ public function testHandlesNullableListsWithArrayPromise() : void // Contains null $this->checkHandlesNullableLists( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), new Deferred(static function () { return null; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -173,13 +173,13 @@ public function testHandlesNullableListsWithArrayPromise() : void $this->checkHandlesNullableLists( static function () { return [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : void { throw new UserError('bad'); }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ]; @@ -243,7 +243,7 @@ public function testHandlesNonNullableListsWithPromiseArray() : void { // Contains values $this->checkHandlesNonNullableLists( - new Deferred(static function () { + new Deferred(static function () : array { return [1, 2]; }), ['data' => ['nest' => ['test' => [1, 2]]]] @@ -251,7 +251,7 @@ public function testHandlesNonNullableListsWithPromiseArray() : void // Contains null $this->checkHandlesNonNullableLists( - new Deferred(static function () { + new Deferred(static function () : array { return [1, null, 2]; }), ['data' => ['nest' => ['test' => [1, null, 2]]]] @@ -274,8 +274,8 @@ public function testHandlesNonNullableListsWithPromiseArray() : void // Rejected $this->checkHandlesNonNullableLists( - static function () { - return new Deferred(static function () { + static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('bad'); }); }, @@ -300,10 +300,10 @@ public function testHandlesNonNullableListsWithArrayPromise() : void // Contains values $this->checkHandlesNonNullableLists( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -313,13 +313,13 @@ public function testHandlesNonNullableListsWithArrayPromise() : void // Contains null $this->checkHandlesNonNullableLists( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), new Deferred(static function () { return null; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -330,13 +330,13 @@ public function testHandlesNonNullableListsWithArrayPromise() : void $this->checkHandlesNonNullableLists( static function () { return [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : void { throw new UserError('bad'); }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ]; @@ -400,7 +400,7 @@ public function testHandlesListOfNonNullsWithPromiseArray() : void { // Contains values $this->checkHandlesListOfNonNulls( - new Deferred(static function () { + new Deferred(static function () : array { return [1, 2]; }), ['data' => ['nest' => ['test' => [1, 2]]]] @@ -408,7 +408,7 @@ public function testHandlesListOfNonNullsWithPromiseArray() : void // Contains null $this->checkHandlesListOfNonNulls( - new Deferred(static function () { + new Deferred(static function () : array { return [1, null, 2]; }), [ @@ -433,8 +433,8 @@ public function testHandlesListOfNonNullsWithPromiseArray() : void // Rejected $this->checkHandlesListOfNonNulls( - static function () { - return new Deferred(static function () { + static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('bad'); }); }, @@ -459,10 +459,10 @@ public function testHandlesListOfNonNullsWithArrayPromise() : void // Contains values $this->checkHandlesListOfNonNulls( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -472,13 +472,13 @@ public function testHandlesListOfNonNullsWithArrayPromise() : void // Contains null $this->checkHandlesListOfNonNulls( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), new Deferred(static function () { return null; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -489,13 +489,13 @@ public function testHandlesListOfNonNullsWithArrayPromise() : void $this->checkHandlesListOfNonNulls( static function () { return [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : void { throw new UserError('bad'); }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ]; @@ -568,7 +568,7 @@ public function testHandlesNonNullListOfNonNullsWithPromiseArray() : void { // Contains values $this->checkHandlesNonNullListOfNonNulls( - new Deferred(static function () { + new Deferred(static function () : array { return [1, 2]; }), ['data' => ['nest' => ['test' => [1, 2]]]] @@ -576,7 +576,7 @@ public function testHandlesNonNullListOfNonNullsWithPromiseArray() : void // Contains null $this->checkHandlesNonNullListOfNonNulls( - new Deferred(static function () { + new Deferred(static function () : array { return [1, null, 2]; }), [ @@ -610,8 +610,8 @@ public function testHandlesNonNullListOfNonNullsWithPromiseArray() : void // Rejected $this->checkHandlesNonNullListOfNonNulls( - static function () { - return new Deferred(static function () { + static function () : Deferred { + return new Deferred(static function () : void { throw new UserError('bad'); }); }, @@ -636,10 +636,10 @@ public function testHandlesNonNullListOfNonNullsWithArrayPromise() : void // Contains values $this->checkHandlesNonNullListOfNonNulls( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), @@ -650,13 +650,13 @@ public function testHandlesNonNullListOfNonNullsWithArrayPromise() : void // Contains null $this->checkHandlesNonNullListOfNonNulls( [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), new Deferred(static function () { return null; }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ], @@ -676,13 +676,13 @@ public function testHandlesNonNullListOfNonNullsWithArrayPromise() : void $this->checkHandlesNonNullListOfNonNulls( static function () { return [ - new Deferred(static function () { + new Deferred(static function () : int { return 1; }), - new Deferred(static function () { + new Deferred(static function () : void { throw new UserError('bad'); }), - new Deferred(static function () { + new Deferred(static function () : int { return 2; }), ]; diff --git a/tests/Executor/MutationsTest.php b/tests/Executor/MutationsTest.php index 2f45a186a..7b61ae472 100644 --- a/tests/Executor/MutationsTest.php +++ b/tests/Executor/MutationsTest.php @@ -4,8 +4,10 @@ namespace GraphQL\Tests\Executor; +use GraphQL\Deferred; use GraphQL\Executor\Executor; use GraphQL\Language\Parser; +use GraphQL\Tests\Executor\TestClasses\NumberHolder; use GraphQL\Tests\Executor\TestClasses\Root; use GraphQL\Tests\PHPUnit\ArraySubsetAsserts; use GraphQL\Type\Definition\ObjectType; @@ -76,28 +78,28 @@ private function schema() : Schema 'immediatelyChangeTheNumber' => [ 'type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], - 'resolve' => static function (Root $obj, $args) { + 'resolve' => static function (Root $obj, $args) : NumberHolder { return $obj->immediatelyChangeTheNumber($args['newNumber']); }, ], 'promiseToChangeTheNumber' => [ 'type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], - 'resolve' => static function (Root $obj, $args) { + 'resolve' => static function (Root $obj, $args) : Deferred { return $obj->promiseToChangeTheNumber($args['newNumber']); }, ], 'failToChangeTheNumber' => [ 'type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], - 'resolve' => static function (Root $obj, $args) { + 'resolve' => static function (Root $obj, $args) : void { $obj->failToChangeTheNumber(); }, ], 'promiseAndFailToChangeTheNumber' => [ 'type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], - 'resolve' => static function (Root $obj, $args) { + 'resolve' => static function (Root $obj, $args) : Deferred { return $obj->promiseAndFailToChangeTheNumber(); }, ], diff --git a/tests/Executor/NonNullTest.php b/tests/Executor/NonNullTest.php index a0f36ea25..a057bd665 100644 --- a/tests/Executor/NonNullTest.php +++ b/tests/Executor/NonNullTest.php @@ -57,35 +57,35 @@ public function setUp() : void $this->promiseNonNullError = new UserError('promiseNonNull'); $this->throwingData = [ - 'sync' => function () { + 'sync' => function () : void { throw $this->syncError; }, - 'syncNonNull' => function () { + 'syncNonNull' => function () : void { throw $this->syncNonNullError; }, - 'promise' => function () { - return new Deferred(function () { + 'promise' => function () : Deferred { + return new Deferred(function () : void { throw $this->promiseError; }); }, - 'promiseNonNull' => function () { - return new Deferred(function () { + 'promiseNonNull' => function () : Deferred { + return new Deferred(function () : void { throw $this->promiseNonNullError; }); }, - 'syncNest' => function () { + 'syncNest' => function () : array { return $this->throwingData; }, - 'syncNonNullNest' => function () { + 'syncNonNullNest' => function () : array { return $this->throwingData; }, - 'promiseNest' => function () { - return new Deferred(function () { + 'promiseNest' => function () : Deferred { + return new Deferred(function () : array { return $this->throwingData; }); }, - 'promiseNonNullNest' => function () { - return new Deferred(function () { + 'promiseNonNullNest' => function () : Deferred { + return new Deferred(function () : array { return $this->throwingData; }); }, @@ -98,29 +98,29 @@ public function setUp() : void 'syncNonNull' => static function () { return null; }, - 'promise' => static function () { + 'promise' => static function () : Deferred { return new Deferred(static function () { return null; }); }, - 'promiseNonNull' => static function () { + 'promiseNonNull' => static function () : Deferred { return new Deferred(static function () { return null; }); }, - 'syncNest' => function () { + 'syncNest' => function () : array { return $this->nullingData; }, - 'syncNonNullNest' => function () { + 'syncNonNullNest' => function () : array { return $this->nullingData; }, - 'promiseNest' => function () { - return new Deferred(function () { + 'promiseNest' => function () : Deferred { + return new Deferred(function () : array { return $this->nullingData; }); }, - 'promiseNonNullNest' => function () { - return new Deferred(function () { + 'promiseNonNullNest' => function () : Deferred { + return new Deferred(function () : array { return $this->nullingData; }); }, @@ -128,7 +128,7 @@ public function setUp() : void $dataType = new ObjectType([ 'name' => 'DataType', - 'fields' => static function () use (&$dataType) { + 'fields' => static function () use (&$dataType) : array { return [ 'sync' => ['type' => Type::string()], 'syncNonNull' => ['type' => Type::nonNull(Type::string())], @@ -155,10 +155,12 @@ public function setUp() : void 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($value, $args) { + 'resolve' => static function ($value, $args) : ?string { if (is_string($args['cannotBeNull'])) { return 'Passed: ' . $args['cannotBeNull']; } + + return null; }, ], ], diff --git a/tests/Executor/Promise/ReactPromiseAdapterTest.php b/tests/Executor/Promise/ReactPromiseAdapterTest.php index 58e821ffe..4c3fbb80e 100644 --- a/tests/Executor/Promise/ReactPromiseAdapterTest.php +++ b/tests/Executor/Promise/ReactPromiseAdapterTest.php @@ -34,13 +34,13 @@ public function testIsThenableReturnsTrueWhenAReactPromiseIsGiven() : void $reactAdapter = new ReactPromiseAdapter(); self::assertTrue( - $reactAdapter->isThenable(new ReactPromise(static function () { + $reactAdapter->isThenable(new ReactPromise(static function () : void { })) ); self::assertTrue($reactAdapter->isThenable(new FulfilledPromise())); self::assertTrue($reactAdapter->isThenable(new RejectedPromise())); self::assertTrue( - $reactAdapter->isThenable(new LazyPromise(static function () { + $reactAdapter->isThenable(new LazyPromise(static function () : void { })) ); self::assertFalse($reactAdapter->isThenable(false)); @@ -74,7 +74,7 @@ public function testThen() : void $resultPromise = $reactAdapter->then( $promise, - static function ($value) use (&$result) { + static function ($value) use (&$result) : void { $result = $value; } ); @@ -87,7 +87,7 @@ static function ($value) use (&$result) { public function testCreate() : void { $reactAdapter = new ReactPromiseAdapter(); - $resolvedPromise = $reactAdapter->create(static function ($resolve) { + $resolvedPromise = $reactAdapter->create(static function ($resolve) : void { $resolve(1); }); @@ -96,7 +96,7 @@ public function testCreate() : void $result = null; - $resolvedPromise->then(static function ($value) use (&$result) { + $resolvedPromise->then(static function ($value) use (&$result) : void { $result = $value; }); @@ -113,7 +113,7 @@ public function testCreateFulfilled() : void $result = null; - $fulfilledPromise->then(static function ($value) use (&$result) { + $fulfilledPromise->then(static function ($value) use (&$result) : void { $result = $value; }); @@ -132,7 +132,7 @@ public function testCreateRejected() : void $rejectedPromise->then( null, - static function ($error) use (&$exception) { + static function ($error) use (&$exception) : void { $exception = $error; } ); @@ -153,7 +153,7 @@ public function testAll() : void $result = null; - $allPromise->then(static function ($values) use (&$result) { + $allPromise->then(static function ($values) use (&$result) : void { $result = $values; }); @@ -167,7 +167,7 @@ public function testAllShouldPreserveTheOrderOfTheArrayWhenResolvingAsyncPromise $promises = [new FulfilledPromise(1), $deferred->promise(), new FulfilledPromise(3)]; $result = null; - $reactAdapter->all($promises)->then(static function ($values) use (&$result) { + $reactAdapter->all($promises)->then(static function ($values) use (&$result) : void { $result = $values; }); diff --git a/tests/Executor/Promise/SyncPromiseAdapterTest.php b/tests/Executor/Promise/SyncPromiseAdapterTest.php index a7c7fa219..47ec89c68 100644 --- a/tests/Executor/Promise/SyncPromiseAdapterTest.php +++ b/tests/Executor/Promise/SyncPromiseAdapterTest.php @@ -28,7 +28,7 @@ public function testIsThenable() : void { self::assertEquals( true, - $this->promises->isThenable(new Deferred(static function () { + $this->promises->isThenable(new Deferred(static function () : void { })) ); self::assertEquals(false, $this->promises->isThenable(false)); @@ -43,7 +43,7 @@ public function testIsThenable() : void public function testConvert() : void { - $dfd = new Deferred(static function () { + $dfd = new Deferred(static function () : void { }); $result = $this->promises->convertThenable($dfd); @@ -57,7 +57,7 @@ public function testConvert() : void public function testThen() : void { - $dfd = new Deferred(static function () { + $dfd = new Deferred(static function () : void { }); $promise = $this->promises->convertThenable($dfd); @@ -69,13 +69,13 @@ public function testThen() : void public function testCreatePromise() : void { - $promise = $this->promises->create(static function ($resolve, $reject) { + $promise = $this->promises->create(static function ($resolve, $reject) : void { }); self::assertInstanceOf('GraphQL\Executor\Promise\Promise', $promise); self::assertInstanceOf('GraphQL\Executor\Promise\Adapter\SyncPromise', $promise->adoptedPromise); - $promise = $this->promises->create(static function ($resolve, $reject) { + $promise = $this->promises->create(static function ($resolve, $reject) : void { $resolve('A'); }); @@ -93,11 +93,11 @@ private static function assertValidPromise($promise, $expectedNextReason, $expec $onRejectedCalled = false; $promise->then( - static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) { + static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) : void { $onFulfilledCalled = true; $actualNextValue = $nextValue; }, - static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) { + static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) : void { $onRejectedCalled = true; $actualNextReason = $reason->getMessage(); } @@ -141,7 +141,7 @@ public function testCreatePromiseAll() : void $promise1 = new SyncPromise(); $promise2 = new SyncPromise(); $promise3 = $promise2->then( - static function ($value) { + static function ($value) : string { return $value . '-value3'; } ); @@ -173,12 +173,12 @@ public function testWait() : void { $called = []; - $deferred1 = new Deferred(static function () use (&$called) { + $deferred1 = new Deferred(static function () use (&$called) : int { $called[] = 1; return 1; }); - $deferred2 = new Deferred(static function () use (&$called) { + $deferred2 = new Deferred(static function () use (&$called) : int { $called[] = 2; return 2; @@ -187,8 +187,8 @@ public function testWait() : void $p1 = $this->promises->convertThenable($deferred1); $p2 = $this->promises->convertThenable($deferred2); - $p3 = $p2->then(function () use (&$called) { - $dfd = new Deferred(static function () use (&$called) { + $p3 = $p2->then(function () use (&$called) : Promise { + $dfd = new Deferred(static function () use (&$called) : int { $called[] = 3; return 3; @@ -198,7 +198,7 @@ public function testWait() : void }); $p4 = $p3->then(static function () use (&$called) { - return new Deferred(static function () use (&$called) { + return new Deferred(static function () use (&$called) : int { $called[] = 4; return 4; diff --git a/tests/Executor/Promise/SyncPromiseTest.php b/tests/Executor/Promise/SyncPromiseTest.php index 732f95e8b..b7e117000 100644 --- a/tests/Executor/Promise/SyncPromiseTest.php +++ b/tests/Executor/Promise/SyncPromiseTest.php @@ -23,11 +23,11 @@ public function getFulfilledPromiseResolveData() return $value; }; - $onFulfilledReturnsOtherValue = static function ($value) { + $onFulfilledReturnsOtherValue = static function ($value) : string { return 'other-' . $value; }; - $onFulfilledThrows = static function ($value) { + $onFulfilledThrows = static function ($value) : void { throw new Exception('onFulfilled throws this!'); }; @@ -101,7 +101,7 @@ public function testFulfilledPromise( $nextPromise = $promise->then( null, - static function () { + static function () : void { } ); self::assertSame($promise, $nextPromise); @@ -109,7 +109,7 @@ static function () { $onRejectedCalled = false; $nextPromise = $promise->then( $onFulfilled, - static function () use (&$onRejectedCalled) { + static function () use (&$onRejectedCalled) : void { $onRejectedCalled = true; } ); @@ -149,11 +149,11 @@ private static function assertValidPromise( $onRejectedCalled = false; $promise->then( - static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) { + static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) : void { $onFulfilledCalled = true; $actualNextValue = $nextValue; }, - static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) { + static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) : void { $onRejectedCalled = true; $actualNextReason = $reason->getMessage(); } @@ -178,15 +178,15 @@ public function getRejectedPromiseData() return null; }; - $onRejectedReturnsSomeValue = static function ($reason) { + $onRejectedReturnsSomeValue = static function ($reason) : string { return 'some-value'; }; - $onRejectedThrowsSameReason = static function ($reason) { + $onRejectedThrowsSameReason = static function ($reason) : void { throw $reason; }; - $onRejectedThrowsOtherReason = static function ($value) { + $onRejectedThrowsOtherReason = static function ($value) : void { throw new Exception('onRejected throws other!'); }; @@ -273,7 +273,7 @@ public function testRejectedPromise( } $nextPromise = $promise->then( - static function () { + static function () : void { }, null ); @@ -281,7 +281,7 @@ static function () { $onFulfilledCalled = false; $nextPromise = $promise->then( - static function () use (&$onFulfilledCalled) { + static function () use (&$onFulfilledCalled) : void { $onFulfilledCalled = true; }, $onRejected @@ -358,7 +358,7 @@ public function testPendingPromise() : void $promise = new SyncPromise(); $promise2 = $promise->then( null, - static function () { + static function () : string { return 'value'; } ); @@ -384,13 +384,13 @@ public function testPendingPromiseThen() : void // Make sure that it queues derivative promises until resolution: $onFulfilledCount = 0; $onRejectedCount = 0; - $onFulfilled = static function ($value) use (&$onFulfilledCount) { + $onFulfilled = static function ($value) use (&$onFulfilledCount) : int { $onFulfilledCount++; return $onFulfilledCount; }; - $onRejected = static function ($reason) use (&$onRejectedCount) { + $onRejected = static function ($reason) use (&$onRejectedCount) : void { $onRejectedCount++; throw $reason; }; diff --git a/tests/Executor/ResolveTest.php b/tests/Executor/ResolveTest.php index 8fe4ab7ca..c4ca4e62d 100644 --- a/tests/Executor/ResolveTest.php +++ b/tests/Executor/ResolveTest.php @@ -51,7 +51,7 @@ public function testDefaultFunctionCallsClosures() : void $_secret = 'secretValue' . uniqid(); $source = [ - 'test' => static function () use ($_secret) { + 'test' => static function () use ($_secret) : string { return $_secret; }, ]; diff --git a/tests/Executor/SyncTest.php b/tests/Executor/SyncTest.php index 6128dfd64..f05df29e8 100644 --- a/tests/Executor/SyncTest.php +++ b/tests/Executor/SyncTest.php @@ -202,7 +202,7 @@ public function testDoesNotReturnAPromiseForValidationErrors() : void $expected = [ 'errors' => Utils::map( $validationErrors, - static function ($e) { + static function ($e) : array { return FormattedError::createFromException($e); } ), diff --git a/tests/Executor/TestClasses/Adder.php b/tests/Executor/TestClasses/Adder.php index 562aba6e0..e28814cda 100644 --- a/tests/Executor/TestClasses/Adder.php +++ b/tests/Executor/TestClasses/Adder.php @@ -16,7 +16,7 @@ public function __construct(float $num) { $this->num = $num; - $this->test = function ($objectValue, $args, $context) { + $this->test = function ($objectValue, $args, $context) : float { return $this->num + $args['addend1'] + $context['addend2']; }; } diff --git a/tests/Executor/TestClasses/Root.php b/tests/Executor/TestClasses/Root.php index 6263bd9e6..d77d9459c 100644 --- a/tests/Executor/TestClasses/Root.php +++ b/tests/Executor/TestClasses/Root.php @@ -19,7 +19,7 @@ public function __construct(float $originalNumber) public function promiseToChangeTheNumber($newNumber) : Deferred { - return new Deferred(function () use ($newNumber) { + return new Deferred(function () use ($newNumber) : NumberHolder { return $this->immediatelyChangeTheNumber($newNumber); }); } @@ -38,7 +38,7 @@ public function failToChangeTheNumber() : void public function promiseAndFailToChangeTheNumber() : Deferred { - return new Deferred(function () { + return new Deferred(function () : void { $this->failToChangeTheNumber(); }); } diff --git a/tests/Executor/UnionInterfaceTest.php b/tests/Executor/UnionInterfaceTest.php index 766a966ee..56982ae97 100644 --- a/tests/Executor/UnionInterfaceTest.php +++ b/tests/Executor/UnionInterfaceTest.php @@ -4,6 +4,7 @@ namespace GraphQL\Tests\Executor; +use GraphQL\Error\InvariantViolation; use GraphQL\Executor\Executor; use GraphQL\GraphQL; use GraphQL\Language\Parser; @@ -51,7 +52,7 @@ public function setUp() : void 'name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()], ], - 'isTypeOf' => static function ($value) { + 'isTypeOf' => static function ($value) : bool { return $value instanceof Dog; }, ]); @@ -63,7 +64,7 @@ public function setUp() : void 'name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()], ], - 'isTypeOf' => static function ($value) { + 'isTypeOf' => static function ($value) : bool { return $value instanceof Cat; }, ]); @@ -71,13 +72,15 @@ public function setUp() : void $PetType = new UnionType([ 'name' => 'Pet', 'types' => [$DogType, $CatType], - 'resolveType' => static function ($value) use ($DogType, $CatType) { + 'resolveType' => static function ($value) use ($DogType, $CatType) : ObjectType { if ($value instanceof Dog) { return $DogType; } if ($value instanceof Cat) { return $CatType; } + + throw new InvariantViolation('Unknown type'); }, ]); @@ -89,7 +92,7 @@ public function setUp() : void 'pets' => ['type' => Type::listOf($PetType)], 'friends' => ['type' => Type::listOf($NamedType)], ], - 'isTypeOf' => static function ($value) { + 'isTypeOf' => static function ($value) : bool { return $value instanceof Person; }, ]); diff --git a/tests/Executor/VariablesTest.php b/tests/Executor/VariablesTest.php index 7676985d3..e7a97de70 100644 --- a/tests/Executor/VariablesTest.php +++ b/tests/Executor/VariablesTest.php @@ -187,7 +187,7 @@ private function fieldWithInputArg($inputArg) return [ 'type' => Type::string(), 'args' => ['input' => $inputArg], - 'resolve' => static function ($_, $args) { + 'resolve' => static function ($_, $args) : ?string { if (isset($args['input'])) { return Utils::printSafeJson($args['input']); } diff --git a/tests/Experimental/Executor/CollectorTest.php b/tests/Experimental/Executor/CollectorTest.php index b081e9cc6..3a5852fa0 100644 --- a/tests/Experimental/Executor/CollectorTest.php +++ b/tests/Experimental/Executor/CollectorTest.php @@ -71,7 +71,7 @@ public function addError($error) foreach ($collector->collectFields($collector->rootType, $collector->operation->selectionSet) as $shared) { $execution = new stdClass(); if (! empty($shared->fieldNodes)) { - $execution->fieldNodes = array_map(static function (Node $node) { + $execution->fieldNodes = array_map(static function (Node $node) : array { return $node->toArray(true); }, $shared->fieldNodes); } diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php index 6d28e0970..32396856c 100644 --- a/tests/GraphQLTest.php +++ b/tests/GraphQLTest.php @@ -5,6 +5,7 @@ namespace GraphQL\Tests; use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter; +use GraphQL\Executor\Promise\Promise; use GraphQL\GraphQL; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; @@ -30,7 +31,7 @@ public function testPromiseToExecute() : void 'type' => Type::nonNull(Type::string()), ], ], - 'resolve' => static function ($rootValue, $args) use ($promiseAdapter) { + 'resolve' => static function ($rootValue, $args) use ($promiseAdapter) : Promise { return $promiseAdapter->createFulfilled(sprintf('Hi %s!', $args['name'])); }, ], diff --git a/tests/Language/ParserTest.php b/tests/Language/ParserTest.php index c61a5870d..229bcc473 100644 --- a/tests/Language/ParserTest.php +++ b/tests/Language/ParserTest.php @@ -457,7 +457,7 @@ public function testParseCreatesAstFromNamelessQueryWithoutVariables() : void '); $result = Parser::parse($source); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return [ 'start' => $start, 'end' => $end, diff --git a/tests/Language/SchemaParserTest.php b/tests/Language/SchemaParserTest.php index ca2677a97..267db2246 100644 --- a/tests/Language/SchemaParserTest.php +++ b/tests/Language/SchemaParserTest.php @@ -27,7 +27,7 @@ public function testSimpleType() : void world: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -102,7 +102,7 @@ public function testParsesTypeWithDescriptionString() : void world: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -149,7 +149,7 @@ public function testParsesTypeWithDescriptionMultiLineString() : void world: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -193,7 +193,7 @@ public function testSimpleExtension() : void } '; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -227,7 +227,7 @@ public function testExtensionWithoutFields() : void { $body = 'extend type Hello implements Greeting'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -360,7 +360,7 @@ public function testSimpleNonNullType() : void }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -400,7 +400,7 @@ public function testSimpleTypeInheritingInterface() : void { $body = 'type Hello implements World { field: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -438,7 +438,7 @@ public function testSimpleTypeInheritingMultipleInterfaces() : void { $body = 'type Hello implements Wo & rld { field: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -477,7 +477,7 @@ public function testSimpleTypeInheritingMultipleInterfacesWithLeadingAmpersand() { $body = 'type Hello implements & Wo & rld { field: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -515,7 +515,7 @@ public function testSingleValueEnum() : void { $body = 'enum Hello { WORLD }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -555,7 +555,7 @@ public function testDoubleValueEnum() : void { $body = 'enum Hello { WO, RLD }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -590,7 +590,7 @@ interface Hello { world: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -627,7 +627,7 @@ public function testSimpleFieldWithArg() : void world(flag: Boolean): String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -687,7 +687,7 @@ public function testSimpleFieldWithArgWithDefaultValue() : void world(flag: Boolean = true): String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -733,7 +733,7 @@ public function testSimpleFieldWithListArg() : void world(things: [String]): String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -786,7 +786,7 @@ public function testSimpleFieldWithTwoArgs() : void world(argOne: Boolean, argTwo: Int): String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -836,7 +836,7 @@ public function testSimpleUnion() : void { $body = 'union Hello = World'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -865,7 +865,7 @@ public function testUnionWithTwoTypes() : void { $body = 'union Hello = Wo | Rld'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -971,7 +971,7 @@ public function testScalar() : void { $body = 'scalar Hello'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; @@ -1001,7 +1001,7 @@ public function testSimpleInputObject() : void world: String }'; $doc = Parser::parse($body); - $loc = static function ($start, $end) { + $loc = static function ($start, $end) : array { return TestUtils::locArray($start, $end); }; diff --git a/tests/Language/VisitorTest.php b/tests/Language/VisitorTest.php index 0e0787832..04cd7476c 100644 --- a/tests/Language/VisitorTest.php +++ b/tests/Language/VisitorTest.php @@ -16,6 +16,7 @@ use GraphQL\Language\Parser; use GraphQL\Language\Printer; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Tests\Validator\ValidatorTestCase; use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; @@ -49,11 +50,11 @@ public function testValidatesPathArgument() : void Visitor::visit( $ast, [ - 'enter' => function ($node, $key, $parent, $path) use ($ast, &$visited) { + 'enter' => function ($node, $key, $parent, $path) use ($ast, &$visited) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $path]; }, - 'leave' => function ($node, $key, $parent, $path) use ($ast, &$visited) { + 'leave' => function ($node, $key, $parent, $path) use ($ast, &$visited) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $path]; }, @@ -85,7 +86,7 @@ public function testValidatesAncestorsArgument() $visitedNodes = []; Visitor::visit($ast, [ - 'enter' => static function ($node, $key, $parent, $path, $ancestors) use (&$visitedNodes) { + 'enter' => static function ($node, $key, $parent, $path, $ancestors) use (&$visitedNodes) : void { $inArray = is_numeric($key); if ($inArray) { $visitedNodes[] = $parent; @@ -95,7 +96,7 @@ public function testValidatesAncestorsArgument() $expectedAncestors = array_slice($visitedNodes, 0, -2); self::assertEquals($expectedAncestors, $ancestors); }, - 'leave' => static function ($node, $key, $parent, $path, $ancestors) use (&$visitedNodes) { + 'leave' => static function ($node, $key, $parent, $path, $ancestors) use (&$visitedNodes) : void { $expectedAncestors = array_slice($visitedNodes, 0, -2); self::assertEquals($expectedAncestors, $ancestors); @@ -181,7 +182,7 @@ public function testAllowsEditingNodeOnEnterAndOnLeave() : void $ast, [ NodeKind::OPERATION_DEFINITION => [ - 'enter' => function (OperationDefinitionNode $node) use (&$selectionSet, $ast) { + 'enter' => function (OperationDefinitionNode $node) use (&$selectionSet, $ast) : OperationDefinitionNode { $this->checkVisitorFnArgs($ast, func_get_args()); $selectionSet = $node->selectionSet; @@ -193,7 +194,7 @@ public function testAllowsEditingNodeOnEnterAndOnLeave() : void return $newNode; }, - 'leave' => function (OperationDefinitionNode $node) use (&$selectionSet, $ast) { + 'leave' => function (OperationDefinitionNode $node) use (&$selectionSet, $ast) : OperationDefinitionNode { $this->checkVisitorFnArgs($ast, func_get_args(), true); $newNode = clone $node; $newNode->selectionSet = $selectionSet; @@ -224,7 +225,7 @@ public function testAllowsEditingRootNodeOnEnterAndLeave() : void $ast, [ NodeKind::DOCUMENT => [ - 'enter' => function (DocumentNode $node) use ($ast) { + 'enter' => function (DocumentNode $node) use ($ast) : DocumentNode { $this->checkVisitorFnArgs($ast, func_get_args()); /** @var NodeList $definitionNodeList */ $definitionNodeList = new NodeList([]); @@ -234,7 +235,7 @@ public function testAllowsEditingRootNodeOnEnterAndLeave() : void return $tmp; }, - 'leave' => function (DocumentNode $node) use ($definitions, $ast) { + 'leave' => function (DocumentNode $node) use ($definitions, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args(), true); $node->definitions = $definitions; $node->didLeave = true; @@ -258,11 +259,13 @@ public function testAllowsForEditingOnEnter() : void $editedAst = Visitor::visit( $ast, [ - 'enter' => function ($node) use ($ast) { + 'enter' => function ($node) use ($ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); if ($node instanceof FieldNode && $node->name->value === 'b') { return Visitor::removeNode(); } + + return null; }, ] ); @@ -283,11 +286,13 @@ public function testAllowsForEditingOnLeave() : void $editedAst = Visitor::visit( $ast, [ - 'leave' => function ($node) use ($ast) { + 'leave' => function ($node) use ($ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args(), true); if ($node instanceof FieldNode && $node->name->value === 'b') { return Visitor::removeNode(); } + + return null; }, ] ); @@ -316,7 +321,7 @@ public function testVisitsEditedNode() : void Visitor::visit( $ast, [ - 'enter' => function ($node) use ($addedField, &$didVisitAddedField, $ast) { + 'enter' => function ($node) use ($addedField, &$didVisitAddedField, $ast) : ?FieldNode { $this->checkVisitorFnArgs($ast, func_get_args(), true); if ($node instanceof FieldNode && $node->name->value === 'a') { return new FieldNode([ @@ -330,6 +335,8 @@ public function testVisitsEditedNode() : void } $didVisitAddedField = true; + + return null; }, ] ); @@ -345,14 +352,16 @@ public function testAllowsSkippingASubTree() : void Visitor::visit( $ast, [ - 'enter' => function (Node $node) use (&$visited, $ast) { + 'enter' => function (Node $node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; if ($node instanceof FieldNode && $node->name->value === 'b') { return Visitor::skipNode(); } + + return null; }, - 'leave' => function (Node $node) use (&$visited, $ast) { + 'leave' => function (Node $node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -388,14 +397,16 @@ public function testAllowsEarlyExitWhileVisiting() : void Visitor::visit( $ast, [ - 'enter' => function (Node $node) use (&$visited, $ast) { + 'enter' => function (Node $node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; if ($node instanceof NameNode && $node->value === 'x') { return Visitor::stop(); } + + return null; }, - 'leave' => function (Node $node) use (&$visited, $ast) { + 'leave' => function (Node $node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -429,17 +440,19 @@ public function testAllowsEarlyExitWhileLeaving() : void Visitor::visit( $ast, [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; if ($node instanceof NameNode && $node->value === 'x') { return Visitor::stop(); } + + return null; }, ] ); @@ -473,16 +486,16 @@ public function testAllowsANamedFunctionsVisitorAPI() : void Visitor::visit( $ast, [ - NodeKind::NAME => function (NameNode $node) use (&$visited, $ast) { + NodeKind::NAME => function (NameNode $node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value]; }, NodeKind::SELECTION_SET => [ - 'enter' => function (SelectionSetNode $node) use (&$visited, $ast) { + 'enter' => function (SelectionSetNode $node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, null]; }, - 'leave' => function (SelectionSetNode $node) use (&$visited, $ast) { + 'leave' => function (SelectionSetNode $node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, null]; }, @@ -518,11 +531,11 @@ public function testExperimentalVisitsVariablesDefinedInFragments() : void Visitor::visit( $ast, [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -572,12 +585,12 @@ public function testVisitsKitchenSink() : void Visitor::visit( $ast, [ - 'enter' => function (Node $node, $key, $parent) use (&$visited, $ast) { + 'enter' => function (Node $node, $key, $parent) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $r = ['enter', $node->kind, $key, $parent instanceof Node ? $parent->kind : null]; $visited[] = $r; }, - 'leave' => function (Node $node, $key, $parent) use (&$visited, $ast) { + 'leave' => function (Node $node, $key, $parent) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $r = ['leave', $node->kind, $key, $parent instanceof Node ? $parent->kind : null]; $visited[] = $r; @@ -914,16 +927,18 @@ public function testAllowsSkippingSubTree() : void $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::skipNode(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -962,27 +977,31 @@ public function testAllowsSkippingDifferentSubTrees() : void $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['no-a', 'enter', $node->kind, $node->value ?? null]; if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'a') { return Visitor::skipNode(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['no-a', 'leave', $node->kind, $node->value ?? null]; }, ], [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['no-b', 'enter', $node->kind, $node->value ?? null]; if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::skipNode(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['no-b', 'leave', $node->kind, $node->value ?? null]; }, @@ -1039,15 +1058,17 @@ public function testAllowsEarlyExitWhileVisiting2() : void Visitor::visit( $ast, Visitor::visitInParallel([[ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $value = $node->value ?? null; $visited[] = ['enter', $node->kind, $value]; if ($node->kind === 'Name' && $value === 'x') { return Visitor::stop(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -1084,29 +1105,33 @@ public function testAllowsEarlyExitFromDifferentPoints() : void $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $value = $node->value ?? null; $visited[] = ['break-a', 'enter', $node->kind, $value]; if ($node->kind === 'Name' && $value === 'a') { return Visitor::stop(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-a', 'leave', $node->kind, $node->value ?? null]; }, ], [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $value = $node->value ?? null; $visited[] = ['break-b', 'enter', $node->kind, $value]; if ($node->kind === 'Name' && $value === 'b') { return Visitor::stop(); } + + return null; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-b', 'leave', $node->kind, $node->value ?? null]; }, @@ -1149,17 +1174,19 @@ public function testAllowsEarlyExitWhileLeaving2() : void Visitor::visit( $ast, Visitor::visitInParallel([[ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $value = $node->value ?? null; $visited[] = ['leave', $node->kind, $value]; if ($node->kind === 'Name' && $value === 'x') { return Visitor::stop(); } + + return null; }, ], ]) @@ -1195,29 +1222,33 @@ public function testAllowsEarlyExitFromLeavingDifferentPoints() : void $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-a', 'enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-a', 'leave', $node->kind, $node->value ?? null]; if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'a') { return Visitor::stop(); } + + return null; }, ], [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-b', 'enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['break-b', 'leave', $node->kind, $node->value ?? null]; if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::stop(); } + + return null; }, ], ]) @@ -1275,19 +1306,21 @@ public function testAllowsForEditingOnEnter2() : void $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use ($ast) { + 'enter' => function ($node) use ($ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args()); if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::removeNode(); } + + return null; }, ], [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args(), true); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -1345,19 +1378,21 @@ public function testAllowsForEditingOnLeave2() : void $ast, Visitor::visitInParallel([ [ - 'leave' => function ($node) use ($ast) { + 'leave' => function ($node) use ($ast) : ?VisitorOperation { $this->checkVisitorFnArgs($ast, func_get_args(), true); if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::removeNode(); } + + return null; }, ], [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $visited[] = ['enter', $node->kind, $node->value ?? null]; }, - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use (&$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args(), true); $visited[] = ['leave', $node->kind, $node->value ?? null]; }, @@ -1427,7 +1462,7 @@ public function testMaintainsTypeInfoDuringVisit() : void Visitor::visitWithTypeInfo( $typeInfo, [ - 'enter' => function ($node) use ($typeInfo, &$visited, $ast) { + 'enter' => function ($node) use ($typeInfo, &$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $parentType = $typeInfo->getParentType(); $type = $typeInfo->getType(); @@ -1442,7 +1477,7 @@ public function testMaintainsTypeInfoDuringVisit() : void $inputType ? (string) $inputType : null, ]; }, - 'leave' => function ($node) use ($typeInfo, &$visited, $ast) { + 'leave' => function ($node) use ($typeInfo, &$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args()); $parentType = $typeInfo->getParentType(); $type = $typeInfo->getType(); @@ -1521,7 +1556,7 @@ public function testMaintainsTypeInfoDuringEdit() : void Visitor::visitWithTypeInfo( $typeInfo, [ - 'enter' => function ($node) use ($typeInfo, &$visited, $ast) { + 'enter' => function ($node) use ($typeInfo, &$visited, $ast) : ?FieldNode { $this->checkVisitorFnArgs($ast, func_get_args(), true); $parentType = $typeInfo->getParentType(); $type = $typeInfo->getType(); @@ -1555,8 +1590,10 @@ public function testMaintainsTypeInfoDuringEdit() : void ]), ]); } + + return null; }, - 'leave' => function ($node) use ($typeInfo, &$visited, $ast) { + 'leave' => function ($node) use ($typeInfo, &$visited, $ast) : void { $this->checkVisitorFnArgs($ast, func_get_args(), true); $parentType = $typeInfo->getParentType(); $type = $typeInfo->getType(); diff --git a/tests/Regression/Issue396Test.php b/tests/Regression/Issue396Test.php index 06cf5e819..33e494b07 100644 --- a/tests/Regression/Issue396Test.php +++ b/tests/Regression/Issue396Test.php @@ -30,7 +30,7 @@ public function testUnionResolveType() $unionResult = new UnionType([ 'name' => 'UnionResult', 'types' => [$a, $b, $c], - 'resolveType' => static function ($result, $value, ResolveInfo $info) use ($a, $b, $c, &$log) : Type { + 'resolveType' => static function ($result, $value, ResolveInfo $info) use ($a, $b, $c, &$log) : ?Type { $log[] = [$result, $info->path]; if (stristr($result['name'], 'A')) { return $a; @@ -41,6 +41,8 @@ public function testUnionResolveType() if (stristr($result['name'], 'C')) { return $c; } + + return null; }, ]); @@ -108,6 +110,8 @@ public function testInterfaceResolveType() if (stristr($result['name'], 'C')) { return $c; } + + return null; }, ]); diff --git a/tests/Server/QueryExecutionTest.php b/tests/Server/QueryExecutionTest.php index b1fc4db24..fcfca7c5f 100644 --- a/tests/Server/QueryExecutionTest.php +++ b/tests/Server/QueryExecutionTest.php @@ -174,7 +174,7 @@ public function testPassesCustomValidationRules() : void $called = false; $rules = [ - new CustomValidationRule('SomeRule', static function () use (&$called) { + new CustomValidationRule('SomeRule', static function () use (&$called) : array { $called = true; return []; @@ -194,7 +194,7 @@ public function testAllowsValidationRulesAsClosure() : void $called = false; $params = $doc = $operationType = null; - $this->config->setValidationRules(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) { + $this->config->setValidationRules(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) : array { $called = true; $params = $p; $doc = $d; @@ -218,7 +218,7 @@ public function testAllowsDifferentValidationRulesDependingOnOperation() : void $called1 = false; $called2 = false; - $this->config->setValidationRules(static function (OperationParams $params) use ($q1, &$called1, &$called2) { + $this->config->setValidationRules(static function (OperationParams $params) use ($q1, &$called1, &$called2) : array { if ($params->query === $q1) { $called1 = true; @@ -228,7 +228,7 @@ public function testAllowsDifferentValidationRulesDependingOnOperation() : void $called2 = true; return [ - new CustomValidationRule('MyRule', static function (ValidationContext $context) { + new CustomValidationRule('MyRule', static function (ValidationContext $context) : void { $context->reportError(new Error('This is the error we are looking for!')); }), ]; @@ -357,7 +357,7 @@ public function testMutationsAreNotAllowedInReadonlyMode() : void public function testAllowsPersistentQueries() : void { $called = false; - $this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) { + $this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) : string { $called = true; self::assertEquals('some-id', $queryId); @@ -374,7 +374,7 @@ public function testAllowsPersistentQueries() : void // Make sure it allows returning document node: $called = false; - $this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) { + $this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) : DocumentNode { $called = true; self::assertEquals('some-id', $queryId); @@ -392,7 +392,7 @@ public function testProhibitsInvalidPersistedQueryLoader() : void 'Persistent query loader must return query string or instance of GraphQL\Language\AST\DocumentNode ' . 'but got: {"err":"err"}' ); - $this->config->setPersistentQueryLoader(static function () { + $this->config->setPersistentQueryLoader(static function () : array { return ['err' => 'err']; }); $this->executePersistedQuery('some-id'); @@ -400,7 +400,7 @@ public function testProhibitsInvalidPersistedQueryLoader() : void public function testPersistedQueriesAreStillValidatedByDefault() : void { - $this->config->setPersistentQueryLoader(static function () { + $this->config->setPersistentQueryLoader(static function () : string { return '{invalid}'; }); $result = $this->executePersistedQuery('some-id'); @@ -426,7 +426,7 @@ public function testAllowSkippingValidationForPersistedQueries() : void return '{invalid2}'; }) - ->setValidationRules(static function (OperationParams $params) { + ->setValidationRules(static function (OperationParams $params) : array { if ($params->queryId === 'some-id') { return []; } @@ -457,7 +457,7 @@ public function testProhibitsUnexpectedValidationRules() : void { $this->expectException(InvariantViolation::class); $this->expectExceptionMessage('Expecting validation rules to be array or callable returning array, but got: instance of stdClass'); - $this->config->setValidationRules(static function (OperationParams $params) { + $this->config->setValidationRules(static function (OperationParams $params) : stdClass { return new stdClass(); }); $this->executeQuery('{f1}'); @@ -523,10 +523,10 @@ public function testDeferredsAreSharedAmongAllBatchedQueries() : void ->setQueryBatching(true) ->setRootValue('1') ->setContext([ - 'buffer' => static function ($num) use (&$calls) { + 'buffer' => static function ($num) use (&$calls) : void { $calls[] = sprintf('buffer: %d', $num); }, - 'load' => static function ($num) use (&$calls) { + 'load' => static function ($num) use (&$calls) : string { $calls[] = sprintf('load: %d', $num); return sprintf('loaded: %d', $num); @@ -588,7 +588,7 @@ public function testAllowsContextAsClosure() : void $called = false; $params = $doc = $operationType = null; - $this->config->setContext(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) { + $this->config->setContext(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) : void { $called = true; $params = $p; $doc = $d; @@ -608,7 +608,7 @@ public function testAllowsRootValueAsClosure() : void $called = false; $params = $doc = $operationType = null; - $this->config->setRootValue(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) { + $this->config->setRootValue(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) : void { $called = true; $params = $p; $doc = $d; @@ -627,7 +627,7 @@ public function testAppliesErrorFormatter() : void { $called = false; $error = null; - $this->config->setErrorFormatter(static function ($e) use (&$called, &$error) { + $this->config->setErrorFormatter(static function ($e) use (&$called, &$error) : array { $called = true; $error = $e; @@ -664,7 +664,7 @@ public function testAppliesErrorsHandler() : void $called = false; $errors = null; $formatter = null; - $this->config->setErrorsHandler(static function ($e, $f) use (&$called, &$errors, &$formatter) { + $this->config->setErrorsHandler(static function ($e, $f) use (&$called, &$errors, &$formatter) : array { $called = true; $errors = $e; $formatter = $f; diff --git a/tests/Server/RequestParsingTest.php b/tests/Server/RequestParsingTest.php index 8db287daa..a926b1263 100644 --- a/tests/Server/RequestParsingTest.php +++ b/tests/Server/RequestParsingTest.php @@ -43,7 +43,7 @@ private function parseRawRequest($contentType, $content, string $method = 'POST' $helper = new Helper(); - return $helper->parseHttpRequest(static function () use ($content) { + return $helper->parseHttpRequest(static function () use ($content) : string { return $content; }); } @@ -138,7 +138,7 @@ private function parseRawFormUrlencodedRequest($postValue) $helper = new Helper(); - return $helper->parseHttpRequest(static function () { + return $helper->parseHttpRequest(static function () : void { throw new InvariantViolation("Shouldn't read from php://input for urlencoded request"); }); } @@ -194,7 +194,7 @@ private function parseRawGetRequest($getValue) $helper = new Helper(); - return $helper->parseHttpRequest(static function () { + return $helper->parseHttpRequest(static function () : void { throw new InvariantViolation("Shouldn't read from php://input for urlencoded request"); }); } @@ -250,7 +250,7 @@ private function parseRawMultipartFormDataRequest($postValue) $helper = new Helper(); - return $helper->parseHttpRequest(static function () { + return $helper->parseHttpRequest(static function () : void { throw new InvariantViolation("Shouldn't read from php://input for multipart/form-data request"); }); } diff --git a/tests/Server/ServerConfigTest.php b/tests/Server/ServerConfigTest.php index a596ab300..6311fab92 100644 --- a/tests/Server/ServerConfigTest.php +++ b/tests/Server/ServerConfigTest.php @@ -74,7 +74,7 @@ public function testAllowsSettingErrorFormatter() : void { $config = ServerConfig::create(); - $formatter = static function () { + $formatter = static function () : void { }; $config->setErrorFormatter($formatter); self::assertSame($formatter, $config->getErrorFormatter()); @@ -88,7 +88,7 @@ public function testAllowsSettingErrorsHandler() : void { $config = ServerConfig::create(); - $handler = static function () { + $handler = static function () : void { }; $config->setErrorsHandler($handler); self::assertSame($handler, $config->getErrorsHandler()); @@ -119,14 +119,14 @@ public function testAllowsSettingValidationRules() : void $config->setValidationRules($rules); self::assertSame($rules, $config->getValidationRules()); - $rules = [static function () { + $rules = [static function () : void { }, ]; $config->setValidationRules($rules); self::assertSame($rules, $config->getValidationRules()); - $rules = static function () { - return [static function () { + $rules = static function () : array { + return [static function () : void { }, ]; }; @@ -138,7 +138,7 @@ public function testAllowsSettingDefaultFieldResolver() : void { $config = ServerConfig::create(); - $resolver = static function () { + $resolver = static function () : void { }; $config->setFieldResolver($resolver); self::assertSame($resolver, $config->getFieldResolver()); @@ -152,7 +152,7 @@ public function testAllowsSettingPersistedQueryLoader() : void { $config = ServerConfig::create(); - $loader = static function () { + $loader = static function () : void { }; $config->setPersistentQueryLoader($loader); self::assertSame($loader, $config->getPersistentQueryLoader()); @@ -181,15 +181,15 @@ public function testAcceptsArray() : void ]), 'context' => new stdClass(), 'rootValue' => new stdClass(), - 'errorFormatter' => static function () { + 'errorFormatter' => static function () : void { }, 'promiseAdapter' => new SyncPromiseAdapter(), - 'validationRules' => [static function () { + 'validationRules' => [static function () : void { }, ], - 'fieldResolver' => static function () { + 'fieldResolver' => static function () : void { }, - 'persistentQueryLoader' => static function () { + 'persistentQueryLoader' => static function () : void { }, 'debug' => true, 'queryBatching' => true, diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 62001988d..45db91fde 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -47,13 +47,13 @@ protected function buildSchema() ], 'fieldWithSafeException' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : void { throw new UserError('This is the exception we want'); }, ], 'fieldWithUnsafeException' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : void { throw new Unsafe('This exception should not be shown to the user'); }, ], diff --git a/tests/StarWarsSchema.php b/tests/StarWarsSchema.php index 86221e698..4304914c8 100644 --- a/tests/StarWarsSchema.php +++ b/tests/StarWarsSchema.php @@ -109,7 +109,7 @@ public static function build() : Schema $characterInterface = new InterfaceType([ 'name' => 'Character', 'description' => 'A character in the Star Wars Trilogy', - 'fields' => static function () use (&$characterInterface, $episodeEnum) { + 'fields' => static function () use (&$characterInterface, $episodeEnum) : array { return [ 'id' => [ 'type' => Type::nonNull(Type::string()), @@ -165,12 +165,12 @@ public static function build() : Schema 'friends' => [ 'type' => Type::listOf($characterInterface), 'description' => 'The friends of the human, or an empty list if they have none.', - 'resolve' => static function ($human, $args, $context, ResolveInfo $info) { + 'resolve' => static function ($human, $args, $context, ResolveInfo $info) : array { $fieldSelection = $info->getFieldSelection(); $fieldSelection['id'] = true; return array_map( - static function ($friend) use ($fieldSelection) { + static function ($friend) use ($fieldSelection) : array { return array_intersect_key($friend, $fieldSelection); }, StarWarsData::getFriends($human) @@ -188,7 +188,7 @@ static function ($friend) use ($fieldSelection) { 'secretBackstory' => [ 'type' => Type::string(), 'description' => 'Where are they from and how they came to be who they are.', - 'resolve' => static function () { + 'resolve' => static function () : void { // This is to demonstrate error reporting throw new Exception('secretBackstory is secret.'); }, @@ -236,7 +236,7 @@ static function ($friend) use ($fieldSelection) { 'secretBackstory' => [ 'type' => Type::string(), 'description' => 'Construction date and the name of the designer.', - 'resolve' => static function () { + 'resolve' => static function () : void { // This is to demonstrate error reporting throw new Exception('secretBackstory is secret.'); }, @@ -273,7 +273,7 @@ static function ($friend) use ($fieldSelection) { 'type' => $episodeEnum, ], ], - 'resolve' => static function ($rootValue, $args) { + 'resolve' => static function ($rootValue, $args) : array { return StarWarsData::getHero($args['episode'] ?? null); }, ], diff --git a/tests/Type/DefinitionTest.php b/tests/Type/DefinitionTest.php index 7a6ec9c05..3a750be6a 100644 --- a/tests/Type/DefinitionTest.php +++ b/tests/Type/DefinitionTest.php @@ -82,11 +82,11 @@ public function setUp() : void $this->scalarType = new CustomScalarType([ 'name' => 'Scalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]); @@ -101,7 +101,7 @@ public function setUp() : void $this->blogAuthor = new ObjectType([ 'name' => 'Author', - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], @@ -405,7 +405,7 @@ public function testIncludesInterfacesThunkSubtypesInTheTypeMap() : void 'fields' => [ 'f' => ['type' => Type::int()], ], - 'interfaces' => static function () use (&$someInterface) { + 'interfaces' => static function () use (&$someInterface) : array { return [$someInterface]; }, ]); @@ -542,7 +542,7 @@ public function testAllowsThunkForUnionTypes() : void { $union = new UnionType([ 'name' => 'ThunkUnion', - 'types' => function () { + 'types' => function () : array { return [$this->objectType]; }, ]); @@ -567,7 +567,7 @@ public function testAllowsRecursiveDefinitions() : void $user = new ObjectType([ 'name' => 'User', - 'fields' => static function () use (&$blog, &$called) { + 'fields' => static function () use (&$blog, &$called) : array { self::assertNotNull($blog, 'Blog type is expected to be defined at this point, but it is null'); $called = true; @@ -576,20 +576,20 @@ public function testAllowsRecursiveDefinitions() : void 'blogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull($blog)))], ]; }, - 'interfaces' => static function () use ($node) { + 'interfaces' => static function () use ($node) : array { return [$node]; }, ]); $blog = new ObjectType([ 'name' => 'Blog', - 'fields' => static function () use ($user) { + 'fields' => static function () use ($user) : array { return [ 'id' => ['type' => Type::nonNull(Type::id())], 'owner' => ['type' => Type::nonNull($user)], ]; }, - 'interfaces' => static function () use ($node) { + 'interfaces' => static function () use ($node) : array { return [$node]; }, ]); @@ -626,7 +626,7 @@ public function testInputObjectTypeAllowsRecursiveDefinitions() : void $called = false; $inputObject = new InputObjectType([ 'name' => 'InputObject', - 'fields' => static function () use (&$inputObject, &$called) { + 'fields' => static function () use (&$inputObject, &$called) : array { $called = true; return [ @@ -663,7 +663,7 @@ public function testInterfaceTypeAllowsRecursiveDefinitions() : void $called = false; $interface = new InterfaceType([ 'name' => 'SomeInterface', - 'fields' => static function () use (&$interface, &$called) { + 'fields' => static function () use (&$interface, &$called) : array { $called = true; return [ @@ -693,7 +693,7 @@ public function testAllowsShorthandFieldDefinition() : void { $interface = new InterfaceType([ 'name' => 'SomeInterface', - 'fields' => static function () use (&$interface) { + 'fields' => static function () use (&$interface) : array { return [ 'value' => Type::string(), 'nested' => $interface, @@ -749,11 +749,11 @@ public function testAllowsOverridingInternalTypes() : void { $idType = new CustomScalarType([ 'name' => 'ID', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]); @@ -774,7 +774,7 @@ public function testAcceptsAnObjectTypeWithAFieldFunction() : void { $objType = new ObjectType([ 'name' => 'SomeObject', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'f' => ['type' => Type::string()], ]; @@ -824,7 +824,7 @@ public function testRejectsAnObjectTypeWithAFieldFunctionThatReturnsIncorrectTyp { $objType = new ObjectType([ 'name' => 'SomeObject', - 'fields' => static function () { + 'fields' => static function () : array { return [['field' => Type::string()]]; }, ]); @@ -905,7 +905,7 @@ public function testAcceptsAnObjectTypeWithInterfacesAsAFunctionReturningAnArray { $objType = new ObjectType([ 'name' => 'SomeObject', - 'interfaces' => function () { + 'interfaces' => function () : array { return [$this->interfaceType]; }, 'fields' => ['f' => ['type' => Type::string()]], @@ -937,7 +937,7 @@ public function testRejectsAnObjectTypeWithInterfacesAsAFunctionReturningAnIncor { $objType = new ObjectType([ 'name' => 'SomeObject', - 'interfaces' => static function () { + 'interfaces' => static function () : stdClass { return new stdClass(); }, 'fields' => ['f' => ['type' => Type::string()]], @@ -958,7 +958,7 @@ public function testAcceptsALambdaAsAnObjectFieldResolver() : void { $this->expectNotToPerformAssertions(); // should not throw: - $this->schemaWithObjectWithFieldResolver(static function () { + $this->schemaWithObjectWithFieldResolver(static function () : void { }); } @@ -1237,11 +1237,11 @@ public function testAcceptsAScalarTypeDefiningParseValueAndParseLiteral() : void $this->schemaWithFieldType( new CustomScalarType([ 'name' => 'SomeScalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]) ); @@ -1259,9 +1259,9 @@ public function testRejectsAScalarTypeDefiningParseValueButNotParseLiteral() : v $this->schemaWithFieldType( new CustomScalarType([ 'name' => 'SomeScalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, ]) ); @@ -1279,9 +1279,9 @@ public function testRejectsAScalarTypeDefiningParseLiteralButNotParseValue() : v $this->schemaWithFieldType( new CustomScalarType([ 'name' => 'SomeScalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]) ); @@ -1299,7 +1299,7 @@ public function testRejectsAScalarTypeDefiningParseValueAndParseLiteralWithAnInc $this->schemaWithFieldType( new CustomScalarType([ 'name' => 'SomeScalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, 'parseValue' => new stdClass(), 'parseLiteral' => new stdClass(), @@ -1368,7 +1368,7 @@ public function testAcceptsAUnionTypeWithFunctionReturningAnArrayOfTypes() : voi $this->schemaWithFieldType( new UnionType([ 'name' => 'SomeUnion', - 'types' => function () { + 'types' => function () : array { return [$this->objectType]; }, ]) @@ -1430,7 +1430,7 @@ public function testAcceptsAnInputObjectTypeWithAFieldFunction() : void { $inputObjType = new InputObjectType([ 'name' => 'SomeInputObject', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'f' => ['type' => Type::string()], ]; @@ -1464,7 +1464,7 @@ public function testRejectsAnInputObjectTypeWithFieldsFunctionThatReturnsIncorre { $inputObjType = new InputObjectType([ 'name' => 'SomeInputObject', - 'fields' => static function () { + 'fields' => static function () : array { return []; }, ]); @@ -1486,7 +1486,7 @@ public function testRejectsAnInputObjectTypeWithResolvers() : void 'fields' => [ 'f' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : int { return 0; }, ], @@ -1600,7 +1600,7 @@ public function testRejectsASchemaWhichRedefinesABuiltInType() : void { $FakeString = new CustomScalarType([ 'name' => 'String', - 'serialize' => static function () { + 'serialize' => static function () : void { }, ]); diff --git a/tests/Type/EnumTypeTest.php b/tests/Type/EnumTypeTest.php index 3573613b2..18abe98bf 100644 --- a/tests/Type/EnumTypeTest.php +++ b/tests/Type/EnumTypeTest.php @@ -54,7 +54,7 @@ public function setUp() : void ]); $Complex1 = [ - 'someRandomFunction' => static function () { + 'someRandomFunction' => static function () : void { }, ]; $Complex2 = new ArrayObject(['someRandomValue' => 123]); diff --git a/tests/Type/QueryPlanTest.php b/tests/Type/QueryPlanTest.php index 20c6f555b..25fabc010 100644 --- a/tests/Type/QueryPlanTest.php +++ b/tests/Type/QueryPlanTest.php @@ -424,7 +424,7 @@ public function testMergedFragmentsQueryPlan() : void $author = new ObjectType([ 'name' => 'Author', - 'fields' => static function () use ($image, &$article) { + 'fields' => static function () use ($image, &$article) : array { return [ 'id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], @@ -868,7 +868,7 @@ public function testQueryPlanOnUnionGroupingImplementorFields() : void $item = new UnionType([ 'name' => 'Item', 'types' => [$car, $building], - 'resolveType' => static function () use ($car) { + 'resolveType' => static function () use ($car) : ObjectType { return $car; }, ]);