Fix CS in tests

This commit is contained in:
Simon Podlipsky 2018-09-26 11:07:23 +02:00
parent af31ca7ad8
commit 07c070d795
No known key found for this signature in database
GPG Key ID: 725C2BD962B42663
56 changed files with 844 additions and 801 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Error;
use Exception;
use GraphQL\Error\Error;
use GraphQL\Language\Parser;
use GraphQL\Language\Source;
@ -17,7 +18,7 @@ class ErrorTest extends TestCase
*/
public function testUsesTheStackOfAnOriginalError() : void
{
$prev = new \Exception('Original');
$prev = new Exception('Original');
$err = new Error('msg', null, null, null, null, $prev);
self::assertSame($err->getPrevious(), $prev);

View File

@ -37,8 +37,8 @@ class AbstractPromiseTest extends TestCase
$DogType = new ObjectType([
'name' => 'Dog',
'interfaces' => [$PetType],
'isTypeOf' => function ($obj) {
return new Deferred(function () use ($obj) {
'isTypeOf' => static function ($obj) {
return new Deferred(static function () use ($obj) {
return $obj instanceof Dog;
});
},
@ -51,8 +51,8 @@ class AbstractPromiseTest extends TestCase
$CatType = new ObjectType([
'name' => 'Cat',
'interfaces' => [$PetType],
'isTypeOf' => function ($obj) {
return new Deferred(function () use ($obj) {
'isTypeOf' => static function ($obj) {
return new Deferred(static function () use ($obj) {
return $obj instanceof Cat;
});
},
@ -68,7 +68,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -121,8 +121,8 @@ class AbstractPromiseTest extends TestCase
$DogType = new ObjectType([
'name' => 'Dog',
'interfaces' => [$PetType],
'isTypeOf' => function () {
return new Deferred(function () {
'isTypeOf' => static function () {
return new Deferred(static function () {
throw new UserError('We are testing this error');
});
},
@ -135,8 +135,8 @@ class AbstractPromiseTest extends TestCase
$CatType = new ObjectType([
'name' => 'Cat',
'interfaces' => [$PetType],
'isTypeOf' => function ($obj) {
return new Deferred(function () use ($obj) {
'isTypeOf' => static function ($obj) {
return new Deferred(static function () use ($obj) {
return $obj instanceof Cat;
});
},
@ -152,7 +152,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -206,8 +206,8 @@ class AbstractPromiseTest extends TestCase
{
$DogType = new ObjectType([
'name' => 'Dog',
'isTypeOf' => function ($obj) {
return new Deferred(function () use ($obj) {
'isTypeOf' => static function ($obj) {
return new Deferred(static function () use ($obj) {
return $obj instanceof Dog;
});
},
@ -219,8 +219,8 @@ class AbstractPromiseTest extends TestCase
$CatType = new ObjectType([
'name' => 'Cat',
'isTypeOf' => function ($obj) {
return new Deferred(function () use ($obj) {
'isTypeOf' => static function ($obj) {
return new Deferred(static function () use ($obj) {
return $obj instanceof Cat;
});
},
@ -241,7 +241,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [new Dog('Odie', true), new Cat('Garfield', false)];
},
],
@ -283,8 +283,8 @@ class AbstractPromiseTest extends TestCase
{
$PetType = new InterfaceType([
'name' => 'Pet',
'resolveType' => function ($obj) use (&$DogType, &$CatType, &$HumanType) {
return new Deferred(function () use ($obj, $DogType, $CatType, $HumanType) {
'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) {
return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) {
if ($obj instanceof Dog) {
return $DogType;
}
@ -334,8 +334,8 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
return new Deferred(function () {
'resolve' => static function () {
return new Deferred(static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -413,8 +413,8 @@ class AbstractPromiseTest extends TestCase
$PetType = new UnionType([
'name' => 'Pet',
'resolveType' => function ($obj) use ($DogType, $CatType, $HumanType) {
return new Deferred(function () use ($obj, $DogType, $CatType, $HumanType) {
'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) {
return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) {
if ($obj instanceof Dog) {
return $DogType;
}
@ -437,7 +437,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -491,8 +491,8 @@ class AbstractPromiseTest extends TestCase
{
$PetType = new InterfaceType([
'name' => 'Pet',
'resolveType' => function ($obj) {
return new Deferred(function () use ($obj) {
'resolveType' => static function ($obj) {
return new Deferred(static function () use ($obj) {
if ($obj instanceof Dog) {
return 'Dog';
}
@ -532,7 +532,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -576,8 +576,8 @@ class AbstractPromiseTest extends TestCase
{
$PetType = new InterfaceType([
'name' => 'Pet',
'resolveType' => function () {
return new Deferred(function () {
'resolveType' => static function () {
return new Deferred(static function () {
throw new UserError('We are testing this error');
});
},
@ -610,7 +610,7 @@ class AbstractPromiseTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),

View File

@ -40,7 +40,7 @@ class AbstractTest extends TestCase
$dogType = new ObjectType([
'name' => 'Dog',
'interfaces' => [$petType],
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Dog;
},
'fields' => [
@ -52,7 +52,7 @@ class AbstractTest extends TestCase
$catType = new ObjectType([
'name' => 'Cat',
'interfaces' => [$petType],
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Cat;
},
'fields' => [
@ -67,7 +67,7 @@ class AbstractTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($petType),
'resolve' => function () {
'resolve' => static function () {
return [new Dog('Odie', true), new Cat('Garfield', false)];
},
],
@ -106,7 +106,7 @@ class AbstractTest extends TestCase
{
$dogType = new ObjectType([
'name' => 'Dog',
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Dog;
},
'fields' => [
@ -117,7 +117,7 @@ class AbstractTest extends TestCase
$catType = new ObjectType([
'name' => 'Cat',
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Cat;
},
'fields' => [
@ -137,7 +137,7 @@ class AbstractTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($petType),
'resolve' => function () {
'resolve' => static function () {
return [new Dog('Odie', true), new Cat('Garfield', false)];
},
],
@ -178,7 +178,7 @@ class AbstractTest extends TestCase
$PetType = new InterfaceType([
'name' => 'Pet',
'resolveType' => function ($obj) use (&$DogType, &$CatType, &$HumanType) {
'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) {
if ($obj instanceof Dog) {
return $DogType;
}
@ -227,7 +227,7 @@ class AbstractTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -302,7 +302,7 @@ class AbstractTest extends TestCase
$PetType = new UnionType([
'name' => 'Pet',
'resolveType' => function ($obj) use ($DogType, $CatType, $HumanType) {
'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) {
if ($obj instanceof Dog) {
return $DogType;
}
@ -322,7 +322,7 @@ class AbstractTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -380,7 +380,7 @@ class AbstractTest extends TestCase
$fooInterface = new InterfaceType([
'name' => 'FooInterface',
'fields' => ['bar' => ['type' => Type::string()]],
'resolveType' => function () {
'resolveType' => static function () {
return [];
},
]);
@ -397,7 +397,7 @@ class AbstractTest extends TestCase
'fields' => [
'foo' => [
'type' => $fooInterface,
'resolve' => function () {
'resolve' => static function () {
return 'dummy';
},
],
@ -434,7 +434,7 @@ class AbstractTest extends TestCase
{
$PetType = new InterfaceType([
'name' => 'Pet',
'resolveType' => function ($obj) {
'resolveType' => static function ($obj) {
if ($obj instanceof Dog) {
return 'Dog';
}
@ -473,7 +473,7 @@ class AbstractTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($PetType),
'resolve' => function () {
'resolve' => static function () {
return [
new Dog('Odie', true),
new Cat('Garfield', false),
@ -514,13 +514,13 @@ class AbstractTest extends TestCase
public function testHintsOnConflictingTypeInstancesInResolveType() : void
{
$createTest = function () use (&$iface) {
$createTest = static function () use (&$iface) {
return new ObjectType([
'name' => 'Test',
'fields' => [
'a' => Type::string(),
],
'interfaces' => function () use ($iface) {
'interfaces' => static function () use ($iface) {
return [$iface];
},
]);
@ -531,7 +531,7 @@ class AbstractTest extends TestCase
'fields' => [
'a' => Type::string(),
],
'resolveType' => function () use (&$createTest) {
'resolveType' => static function () use (&$createTest) {
return $createTest();
},
]);

View File

@ -91,7 +91,7 @@ class DeferredFieldsTest extends TestCase
return Utils::find(
$this->userDataSource,
function ($entry) use ($user) {
static function ($entry) use ($user) {
return $entry['id'] === $user['bestFriendId'];
}
);
@ -123,7 +123,7 @@ class DeferredFieldsTest extends TestCase
return Utils::find(
$this->userDataSource,
function ($entry) use ($story) {
static function ($entry) use ($story) {
return $entry['id'] === $story['authorId'];
}
);
@ -152,7 +152,7 @@ class DeferredFieldsTest extends TestCase
return Utils::filter(
$this->storyDataSource,
function ($story) use ($category) {
static function ($story) use ($category) {
return in_array($category['id'], $story['categoryIds']);
}
);
@ -168,7 +168,7 @@ class DeferredFieldsTest extends TestCase
return Utils::find(
$this->storyDataSource,
function ($story) use ($category) {
static function ($story) use ($category) {
return $story['id'] === $category['topStoryId'];
}
);
@ -188,7 +188,7 @@ class DeferredFieldsTest extends TestCase
return Utils::filter(
$this->storyDataSource,
function ($story) {
static function ($story) {
return $story['id'] % 2 === 1;
}
);

View File

@ -33,6 +33,7 @@ class DirectivesTest extends TestCase
/**
* @param Source|string $doc
*
* @return mixed[]
*/
private function executeTestQuery($doc) : array

View File

@ -64,7 +64,7 @@ class ExecutorLazySchemaTest extends TestCase
// isTypeOf used to resolve runtime type for Interface
$petType = new InterfaceType([
'name' => 'Pet',
'fields' => function () {
'fields' => static function () {
return [
'name' => ['type' => Type::string()],
];
@ -75,10 +75,10 @@ class ExecutorLazySchemaTest extends TestCase
$dogType = new ObjectType([
'name' => 'Dog',
'interfaces' => [$petType],
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Dog;
},
'fields' => function () {
'fields' => static function () {
return [
'name' => ['type' => Type::string()],
'woofs' => ['type' => Type::boolean()],
@ -89,10 +89,10 @@ class ExecutorLazySchemaTest extends TestCase
$catType = new ObjectType([
'name' => 'Cat',
'interfaces' => [$petType],
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Cat;
},
'fields' => function () {
'fields' => static function () {
return [
'name' => ['type' => Type::string()],
'meows' => ['type' => Type::boolean()],
@ -106,14 +106,14 @@ class ExecutorLazySchemaTest extends TestCase
'fields' => [
'pets' => [
'type' => Type::listOf($petType),
'resolve' => function () {
'resolve' => static function () {
return [new Dog('Odie', true), new Cat('Garfield', false)];
},
],
],
]),
'types' => [$catType, $dogType],
'typeLoader' => function ($name) use ($dogType, $petType, $catType) {
'typeLoader' => static function ($name) use ($dogType, $petType, $catType) {
switch ($name) {
case 'Dog':
return $dogType;
@ -165,13 +165,13 @@ class ExecutorLazySchemaTest extends TestCase
public function testHintsOnConflictingTypeInstancesInDefinitions() : void
{
$calls = [];
$typeLoader = function ($name) use (&$calls) {
$typeLoader = static function ($name) use (&$calls) {
$calls[] = $name;
switch ($name) {
case 'Test':
return new ObjectType([
'name' => 'Test',
'fields' => function () {
'fields' => static function () {
return [
'test' => Type::string(),
];
@ -184,7 +184,7 @@ class ExecutorLazySchemaTest extends TestCase
$query = new ObjectType([
'name' => 'Query',
'fields' => function () use ($typeLoader) {
'fields' => static function () use ($typeLoader) {
return [
'test' => $typeLoader('Test'),
];
@ -311,13 +311,13 @@ class ExecutorLazySchemaTest extends TestCase
case 'SomeScalar':
return $this->someScalarType ?: $this->someScalarType = new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function ($value) {
'serialize' => static function ($value) {
return $value;
},
'parseValue' => function ($value) {
'parseValue' => static function ($value) {
return $value;
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
]);
case 'SomeUnion':

View File

@ -32,14 +32,14 @@ class ExecutorSchemaTest extends TestCase
$BlogAuthor = new ObjectType([
'name' => 'Author',
'fields' => function () use (&$BlogArticle, &$BlogImage) {
'fields' => static function () use (&$BlogArticle, &$BlogImage) {
return [
'id' => ['type' => Type::string()],
'name' => ['type' => Type::string()],
'pic' => [
'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]],
'type' => $BlogImage,
'resolve' => function ($obj, $args) {
'resolve' => static function ($obj, $args) {
return $obj['pic']($args['width'], $args['height']);
},
],
@ -201,7 +201,7 @@ class ExecutorSchemaTest extends TestCase
private function article($id)
{
$johnSmith = null;
$article = function ($id) use (&$johnSmith) {
$article = static function ($id) use (&$johnSmith) {
return [
'id' => $id,
'isPublished' => 'true',
@ -213,7 +213,7 @@ class ExecutorSchemaTest extends TestCase
];
};
$getPic = function ($uid, $width, $height) {
$getPic = static function ($uid, $width, $height) {
return [
'url' => sprintf('cdn://%s', $uid),
'width' => $width,
@ -224,7 +224,7 @@ class ExecutorSchemaTest extends TestCase
$johnSmith = [
'id' => 123,
'name' => 'John Smith',
'pic' => function ($width, $height) use ($getPic) {
'pic' => static function ($width, $height) use ($getPic) {
return $getPic(123, $width, $height);
},
'recentArticle' => $article(1),

View File

@ -17,6 +17,7 @@ use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;
use stdClass;
use function array_keys;
use function count;
use function json_encode;
@ -38,52 +39,52 @@ class ExecutorTest extends TestCase
$deepData = null;
$data = null;
$promiseData = function () use (&$data) {
return new Deferred(function () use (&$data) {
$promiseData = static function () use (&$data) {
return new Deferred(static function () use (&$data) {
return $data;
});
};
$data = [
'a' => function () {
'a' => static function () {
return 'Apple';
},
'b' => function () {
'b' => static function () {
return 'Banana';
},
'c' => function () {
'c' => static function () {
return 'Cookie';
},
'd' => function () {
'd' => static function () {
return 'Donut';
},
'e' => function () {
'e' => static function () {
return 'Egg';
},
'f' => 'Fish',
'pic' => function ($size = 50) {
'pic' => static function ($size = 50) {
return 'Pic of size: ' . $size;
},
'promise' => function () use ($promiseData) {
'promise' => static function () use ($promiseData) {
return $promiseData();
},
'deep' => function () use (&$deepData) {
'deep' => static function () use (&$deepData) {
return $deepData;
},
];
// Required for that & reference above
$deepData = [
'a' => function () {
'a' => static function () {
return 'Already Been Done';
},
'b' => function () {
'b' => static function () {
return 'Boring';
},
'c' => function () {
'c' => static function () {
return ['Contrived', null, 'Confusing'];
},
'deeper' => function () use (&$data) {
'deeper' => static function () use (&$data) {
return [$data, null, $data];
},
];
@ -145,7 +146,7 @@ class ExecutorTest extends TestCase
$deepDataType = null;
$dataType = new ObjectType([
'name' => 'DataType',
'fields' => function () use (&$dataType, &$deepDataType) {
'fields' => static function () use (&$dataType, &$deepDataType) {
return [
'a' => ['type' => Type::string()],
'b' => ['type' => Type::string()],
@ -156,7 +157,7 @@ class ExecutorTest extends TestCase
'pic' => [
'args' => ['size' => ['type' => Type::int()]],
'type' => Type::string(),
'resolve' => function ($obj, $args) {
'resolve' => static function ($obj, $args) {
return $obj['pic']($args['size']);
},
],
@ -205,29 +206,29 @@ class ExecutorTest extends TestCase
$Type = new ObjectType([
'name' => 'Type',
'fields' => function () use (&$Type) {
'fields' => static function () use (&$Type) {
return [
'a' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return 'Apple';
},
],
'b' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return 'Banana';
},
],
'c' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return 'Cherry';
},
],
'deep' => [
'type' => $Type,
'resolve' => function () {
'resolve' => static function () {
return [];
},
],
@ -270,7 +271,7 @@ class ExecutorTest extends TestCase
'fields' => [
'test' => [
'type' => Type::string(),
'resolve' => function ($val, $args, $ctx, $_info) use (&$info) {
'resolve' => static function ($val, $args, $ctx, $_info) use (&$info) {
$info = $_info;
},
],
@ -329,7 +330,7 @@ class ExecutorTest extends TestCase
'fields' => [
'a' => [
'type' => Type::string(),
'resolve' => function ($context) use (&$gotHere) {
'resolve' => static function ($context) use (&$gotHere) {
self::assertEquals('thing', $context['contextThing']);
$gotHere = true;
},
@ -366,7 +367,7 @@ class ExecutorTest extends TestCase
'stringArg' => ['type' => Type::string()],
],
'type' => Type::string(),
'resolve' => function ($_, $args) use (&$gotHere) {
'resolve' => static function ($_, $args) use (&$gotHere) {
self::assertEquals(123, $args['numArg']);
self::assertEquals('foo', $args['stringArg']);
$gotHere = true;
@ -400,21 +401,21 @@ class ExecutorTest extends TestCase
}';
$data = [
'sync' => function () {
'sync' => static function () {
return 'sync';
},
'syncError' => function () {
'syncError' => static function () {
throw new UserError('Error getting syncError');
},
'syncRawError' => function () {
'syncRawError' => static function () {
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' => function () {
'syncReturnError' => static function () {
return new UserError('Error getting syncReturnError');
},
'syncReturnErrorList' => function () {
'syncReturnErrorList' => static function () {
return [
'sync0',
new UserError('Error getting syncReturnErrorList1'),
@ -422,40 +423,40 @@ class ExecutorTest extends TestCase
new UserError('Error getting syncReturnErrorList3'),
];
},
'async' => function () {
return new Deferred(function () {
'async' => static function () {
return new Deferred(static function () {
return 'async';
});
},
'asyncReject' => function () {
return new Deferred(function () {
'asyncReject' => static function () {
return new Deferred(static function () {
throw new UserError('Error getting asyncReject');
});
},
'asyncRawReject' => function () {
return new Deferred(function () {
'asyncRawReject' => static function () {
return new Deferred(static function () {
throw new UserError('Error getting asyncRawReject');
});
},
'asyncEmptyReject' => function () {
return new Deferred(function () {
'asyncEmptyReject' => static function () {
return new Deferred(static function () {
throw new UserError();
});
},
'asyncError' => function () {
return new Deferred(function () {
'asyncError' => static function () {
return new Deferred(static function () {
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' => function () {
return new Deferred(function () {
'asyncRawError' => static function () {
return new Deferred(static function () {
throw new UserError('Error getting asyncRawError');
});
},
'asyncReturnError' => function () {
return new Deferred(function () {
'asyncReturnError' => static function () {
return new Deferred(static function () {
throw new UserError('Error getting asyncReturnError');
});
},
@ -805,23 +806,23 @@ class ExecutorTest extends TestCase
e
}';
$data = [
'a' => function () {
'a' => static function () {
return 'a';
},
'b' => function () {
return new Deferred(function () {
'b' => static function () {
return new Deferred(static function () {
return 'b';
});
},
'c' => function () {
'c' => static function () {
return 'c';
},
'd' => function () {
return new Deferred(function () {
'd' => static function () {
return new Deferred(static function () {
return 'd';
});
},
'e' => function () {
'e' => static function () {
return 'e';
},
];
@ -923,7 +924,7 @@ class ExecutorTest extends TestCase
'fields' => [
'field' => [
'type' => Type::string(),
'resolve' => function ($data, $args) {
'resolve' => static function ($data, $args) {
return $args ? json_encode($args) : '';
},
'args' => [
@ -954,7 +955,7 @@ class ExecutorTest extends TestCase
{
$SpecialType = new ObjectType([
'name' => 'SpecialType',
'isTypeOf' => function ($obj) {
'isTypeOf' => static function ($obj) {
return $obj instanceof Special;
},
'fields' => [
@ -968,7 +969,7 @@ class ExecutorTest extends TestCase
'fields' => [
'specials' => [
'type' => Type::listOf($SpecialType),
'resolve' => function ($rootValue) {
'resolve' => static function ($rootValue) {
return $rootValue['specials'];
},
],
@ -1049,7 +1050,7 @@ class ExecutorTest extends TestCase
]);
// For the purposes of test, just return the name of the field!
$customResolver = function ($source, $args, $context, ResolveInfo $info) {
$customResolver = static function ($source, $args, $context, ResolveInfo $info) {
return $info->fieldName;
};
@ -1078,7 +1079,7 @@ class ExecutorTest extends TestCase
'fields' => [
'field' => [
'type' => Type::string(),
'resolve' => function ($data, $args) {
'resolve' => static function ($data, $args) {
return $args ? json_encode($args) : '';
},
'args' => [
@ -1125,7 +1126,7 @@ class ExecutorTest extends TestCase
'fields' => [
'id' => Type::id(),
],
'interfaces' => function () use (&$iface) {
'interfaces' => static function () use (&$iface) {
return [$iface];
},
]);
@ -1135,7 +1136,7 @@ class ExecutorTest extends TestCase
'fields' => [
'id' => Type::id(),
],
'interfaces' => function () use (&$iface) {
'interfaces' => static function () use (&$iface) {
return [$iface];
},
]);
@ -1145,7 +1146,7 @@ class ExecutorTest extends TestCase
'fields' => [
'id' => Type::id(),
],
'resolveType' => function ($v) use ($a, $b) {
'resolveType' => static function ($v) use ($a, $b) {
return $v['type'] === 'A' ? $a : $b;
},
]);
@ -1187,8 +1188,8 @@ class ExecutorTest extends TestCase
'ab' => [
['id' => '1'],
['id' => '2'],
new \stdClass(),
new \stdClass(),
new stdClass(),
new stdClass(),
],
],
],

View File

@ -64,7 +64,7 @@ class LazyInterfaceTest extends TestCase
return [
'lazyInterface' => [
'type' => $this->getLazyInterfaceType(),
'resolve' => function () {
'resolve' => static function () {
return [];
},
],
@ -99,6 +99,7 @@ class LazyInterfaceTest extends TestCase
/**
* Returns the test ObjectType
*
* @return ObjectType
*/
protected function getTestObjectType()
@ -109,7 +110,7 @@ class LazyInterfaceTest extends TestCase
'fields' => [
'name' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return 'testname';
},
],

View File

@ -53,12 +53,12 @@ class ListsTest extends TestCase
$dataType = new ObjectType([
'name' => 'DataType',
'fields' => function () use (&$testType, &$dataType, $data) {
'fields' => static function () use (&$testType, &$dataType, $data) {
return [
'test' => ['type' => $testType],
'nest' => [
'type' => $dataType,
'resolve' => function () use ($data) {
'resolve' => static function () use ($data) {
return $data;
},
],
@ -81,7 +81,7 @@ class ListsTest extends TestCase
{
// Contains values
$this->checkHandlesNullableLists(
new Deferred(function () {
new Deferred(static function () {
return [1, 2];
}),
['data' => ['nest' => ['test' => [1, 2]]]]
@ -89,7 +89,7 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNullableLists(
new Deferred(function () {
new Deferred(static function () {
return [1, null, 2];
}),
['data' => ['nest' => ['test' => [1, null, 2]]]]
@ -97,7 +97,7 @@ class ListsTest extends TestCase
// Returns null
$this->checkHandlesNullableLists(
new Deferred(function () {
new Deferred(static function () {
return null;
}),
['data' => ['nest' => ['test' => null]]]
@ -105,8 +105,8 @@ class ListsTest extends TestCase
// Rejected
$this->checkHandlesNullableLists(
function () {
return new Deferred(function () {
static function () {
return new Deferred(static function () {
throw new UserError('bad');
});
},
@ -131,10 +131,10 @@ class ListsTest extends TestCase
// Contains values
$this->checkHandlesNullableLists(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -144,13 +144,13 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNullableLists(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return null;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -159,7 +159,7 @@ class ListsTest extends TestCase
// Returns null
$this->checkHandlesNullableLists(
new Deferred(function () {
new Deferred(static function () {
return null;
}),
['data' => ['nest' => ['test' => null]]]
@ -167,15 +167,15 @@ class ListsTest extends TestCase
// Contains reject
$this->checkHandlesNullableLists(
function () {
static function () {
return [
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
throw new UserError('bad');
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
];
@ -239,7 +239,7 @@ class ListsTest extends TestCase
{
// Contains values
$this->checkHandlesNonNullableLists(
new Deferred(function () {
new Deferred(static function () {
return [1, 2];
}),
['data' => ['nest' => ['test' => [1, 2]]]]
@ -247,7 +247,7 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNonNullableLists(
new Deferred(function () {
new Deferred(static function () {
return [1, null, 2];
}),
['data' => ['nest' => ['test' => [1, null, 2]]]]
@ -270,8 +270,8 @@ class ListsTest extends TestCase
// Rejected
$this->checkHandlesNonNullableLists(
function () {
return new Deferred(function () {
static function () {
return new Deferred(static function () {
throw new UserError('bad');
});
},
@ -296,10 +296,10 @@ class ListsTest extends TestCase
// Contains values
$this->checkHandlesNonNullableLists(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -309,13 +309,13 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNonNullableLists(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return null;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -324,15 +324,15 @@ class ListsTest extends TestCase
// Contains reject
$this->checkHandlesNonNullableLists(
function () {
static function () {
return [
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
throw new UserError('bad');
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
];
@ -396,7 +396,7 @@ class ListsTest extends TestCase
{
// Contains values
$this->checkHandlesListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return [1, 2];
}),
['data' => ['nest' => ['test' => [1, 2]]]]
@ -404,7 +404,7 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return [1, null, 2];
}),
[
@ -421,7 +421,7 @@ class ListsTest extends TestCase
// Returns null
$this->checkHandlesListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return null;
}),
['data' => ['nest' => ['test' => null]]]
@ -429,8 +429,8 @@ class ListsTest extends TestCase
// Rejected
$this->checkHandlesListOfNonNulls(
function () {
return new Deferred(function () {
static function () {
return new Deferred(static function () {
throw new UserError('bad');
});
},
@ -455,10 +455,10 @@ class ListsTest extends TestCase
// Contains values
$this->checkHandlesListOfNonNulls(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -468,13 +468,13 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesListOfNonNulls(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return null;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -483,15 +483,15 @@ class ListsTest extends TestCase
// Contains reject
$this->checkHandlesListOfNonNulls(
function () {
static function () {
return [
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
throw new UserError('bad');
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
];
@ -564,7 +564,7 @@ class ListsTest extends TestCase
{
// Contains values
$this->checkHandlesNonNullListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return [1, 2];
}),
['data' => ['nest' => ['test' => [1, 2]]]]
@ -572,7 +572,7 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNonNullListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return [1, null, 2];
}),
[
@ -589,7 +589,7 @@ class ListsTest extends TestCase
// Returns null
$this->checkHandlesNonNullListOfNonNulls(
new Deferred(function () {
new Deferred(static function () {
return null;
}),
[
@ -606,8 +606,8 @@ class ListsTest extends TestCase
// Rejected
$this->checkHandlesNonNullListOfNonNulls(
function () {
return new Deferred(function () {
static function () {
return new Deferred(static function () {
throw new UserError('bad');
});
},
@ -632,10 +632,10 @@ class ListsTest extends TestCase
// Contains values
$this->checkHandlesNonNullListOfNonNulls(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
@ -646,13 +646,13 @@ class ListsTest extends TestCase
// Contains null
$this->checkHandlesNonNullListOfNonNulls(
[
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
return null;
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
],
@ -670,15 +670,15 @@ class ListsTest extends TestCase
// Contains reject
$this->checkHandlesNonNullListOfNonNulls(
function () {
static function () {
return [
new Deferred(function () {
new Deferred(static function () {
return 1;
}),
new Deferred(function () {
new Deferred(static function () {
throw new UserError('bad');
}),
new Deferred(function () {
new Deferred(static function () {
return 2;
}),
];

View File

@ -59,7 +59,7 @@ class MutationsTest extends TestCase
],
'name' => 'NumberHolder',
]);
$schema = new Schema([
return new Schema([
'query' => new ObjectType([
'fields' => [
'numberHolder' => ['type' => $numberHolderType],
@ -71,28 +71,28 @@ class MutationsTest extends TestCase
'immediatelyChangeTheNumber' => [
'type' => $numberHolderType,
'args' => ['newNumber' => ['type' => Type::int()]],
'resolve' => function (Root $obj, $args) {
'resolve' => static function (Root $obj, $args) {
return $obj->immediatelyChangeTheNumber($args['newNumber']);
},
],
'promiseToChangeTheNumber' => [
'type' => $numberHolderType,
'args' => ['newNumber' => ['type' => Type::int()]],
'resolve' => function (Root $obj, $args) {
'resolve' => static function (Root $obj, $args) {
return $obj->promiseToChangeTheNumber($args['newNumber']);
},
],
'failToChangeTheNumber' => [
'type' => $numberHolderType,
'args' => ['newNumber' => ['type' => Type::int()]],
'resolve' => function (Root $obj, $args) {
'resolve' => static function (Root $obj, $args) {
$obj->failToChangeTheNumber();
},
],
'promiseAndFailToChangeTheNumber' => [
'type' => $numberHolderType,
'args' => ['newNumber' => ['type' => Type::int()]],
'resolve' => function (Root $obj, $args) {
'resolve' => static function (Root $obj, $args) {
return $obj->promiseAndFailToChangeTheNumber();
},
],
@ -100,8 +100,6 @@ class MutationsTest extends TestCase
'name' => 'Mutation',
]),
]);
return $schema;
}
/**

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Executor;
use Exception;
use GraphQL\Deferred;
use GraphQL\Error\FormattedError;
use GraphQL\Error\UserError;
@ -17,16 +18,16 @@ use PHPUnit\Framework\TestCase;
class NonNullTest extends TestCase
{
/** @var \Exception */
/** @var Exception */
public $syncError;
/** @var \Exception */
/** @var Exception */
public $syncNonNullError;
/** @var \Exception */
/** @var Exception */
public $promiseError;
/** @var \Exception */
/** @var Exception */
public $promiseNonNullError;
/** @var callable[] */
@ -81,19 +82,19 @@ class NonNullTest extends TestCase
];
$this->nullingData = [
'sync' => function () {
'sync' => static function () {
return null;
},
'syncNonNull' => function () {
'syncNonNull' => static function () {
return null;
},
'promise' => function () {
return new Deferred(function () {
'promise' => static function () {
return new Deferred(static function () {
return null;
});
},
'promiseNonNull' => function () {
return new Deferred(function () {
'promiseNonNull' => static function () {
return new Deferred(static function () {
return null;
});
},
@ -117,7 +118,7 @@ class NonNullTest extends TestCase
$dataType = new ObjectType([
'name' => 'DataType',
'fields' => function () use (&$dataType) {
'fields' => static function () use (&$dataType) {
return [
'sync' => ['type' => Type::string()],
'syncNonNull' => ['type' => Type::nonNull(Type::string())],

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Executor\Promise;
use Exception;
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
use PHPUnit\Framework\TestCase;
use React\Promise\Deferred;
@ -11,6 +12,7 @@ use React\Promise\FulfilledPromise;
use React\Promise\LazyPromise;
use React\Promise\Promise as ReactPromise;
use React\Promise\RejectedPromise;
use stdClass;
use function class_exists;
/**
@ -32,13 +34,13 @@ class ReactPromiseAdapterTest extends TestCase
$reactAdapter = new ReactPromiseAdapter();
self::assertTrue(
$reactAdapter->isThenable(new ReactPromise(function () {
$reactAdapter->isThenable(new ReactPromise(static function () {
}))
);
self::assertTrue($reactAdapter->isThenable(new FulfilledPromise()));
self::assertTrue($reactAdapter->isThenable(new RejectedPromise()));
self::assertTrue(
$reactAdapter->isThenable(new LazyPromise(function () {
$reactAdapter->isThenable(new LazyPromise(static function () {
}))
);
self::assertFalse($reactAdapter->isThenable(false));
@ -48,7 +50,7 @@ class ReactPromiseAdapterTest extends TestCase
self::assertFalse($reactAdapter->isThenable('test'));
self::assertFalse($reactAdapter->isThenable(''));
self::assertFalse($reactAdapter->isThenable([]));
self::assertFalse($reactAdapter->isThenable(new \stdClass()));
self::assertFalse($reactAdapter->isThenable(new stdClass()));
}
public function testConvertsReactPromisesToGraphQlOnes() : void
@ -72,7 +74,7 @@ class ReactPromiseAdapterTest extends TestCase
$resultPromise = $reactAdapter->then(
$promise,
function ($value) use (&$result) {
static function ($value) use (&$result) {
$result = $value;
}
);
@ -85,7 +87,7 @@ class ReactPromiseAdapterTest extends TestCase
public function testCreate() : void
{
$reactAdapter = new ReactPromiseAdapter();
$resolvedPromise = $reactAdapter->create(function ($resolve) {
$resolvedPromise = $reactAdapter->create(static function ($resolve) {
$resolve(1);
});
@ -94,7 +96,7 @@ class ReactPromiseAdapterTest extends TestCase
$result = null;
$resolvedPromise->then(function ($value) use (&$result) {
$resolvedPromise->then(static function ($value) use (&$result) {
$result = $value;
});
@ -111,7 +113,7 @@ class ReactPromiseAdapterTest extends TestCase
$result = null;
$fulfilledPromise->then(function ($value) use (&$result) {
$fulfilledPromise->then(static function ($value) use (&$result) {
$result = $value;
});
@ -121,7 +123,7 @@ class ReactPromiseAdapterTest extends TestCase
public function testCreateRejected() : void
{
$reactAdapter = new ReactPromiseAdapter();
$rejectedPromise = $reactAdapter->createRejected(new \Exception('I am a bad promise'));
$rejectedPromise = $reactAdapter->createRejected(new Exception('I am a bad promise'));
self::assertInstanceOf('GraphQL\Executor\Promise\Promise', $rejectedPromise);
self::assertInstanceOf('React\Promise\RejectedPromise', $rejectedPromise->adoptedPromise);
@ -130,7 +132,7 @@ class ReactPromiseAdapterTest extends TestCase
$rejectedPromise->then(
null,
function ($error) use (&$exception) {
static function ($error) use (&$exception) {
$exception = $error;
}
);
@ -151,7 +153,7 @@ class ReactPromiseAdapterTest extends TestCase
$result = null;
$allPromise->then(function ($values) use (&$result) {
$allPromise->then(static function ($values) use (&$result) {
$result = $values;
});
@ -165,7 +167,7 @@ class ReactPromiseAdapterTest extends TestCase
$promises = [new FulfilledPromise(1), $deferred->promise(), new FulfilledPromise(3)];
$result = null;
$reactAdapter->all($promises)->then(function ($values) use (&$result) {
$reactAdapter->all($promises)->then(static function ($values) use (&$result) {
$result = $values;
});

View File

@ -4,12 +4,15 @@ declare(strict_types=1);
namespace GraphQL\Tests\Executor\Promise;
use Exception;
use GraphQL\Deferred;
use GraphQL\Error\InvariantViolation;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
use GraphQL\Executor\Promise\Promise;
use PHPUnit\Framework\TestCase;
use stdClass;
use Throwable;
class SyncPromiseAdapterTest extends TestCase
{
@ -25,7 +28,7 @@ class SyncPromiseAdapterTest extends TestCase
{
self::assertEquals(
true,
$this->promises->isThenable(new Deferred(function () {
$this->promises->isThenable(new Deferred(static function () {
}))
);
self::assertEquals(false, $this->promises->isThenable(false));
@ -35,12 +38,12 @@ class SyncPromiseAdapterTest extends TestCase
self::assertEquals(false, $this->promises->isThenable('test'));
self::assertEquals(false, $this->promises->isThenable(''));
self::assertEquals(false, $this->promises->isThenable([]));
self::assertEquals(false, $this->promises->isThenable(new \stdClass()));
self::assertEquals(false, $this->promises->isThenable(new stdClass()));
}
public function testConvert() : void
{
$dfd = new Deferred(function () {
$dfd = new Deferred(static function () {
});
$result = $this->promises->convertThenable($dfd);
@ -54,7 +57,7 @@ class SyncPromiseAdapterTest extends TestCase
public function testThen() : void
{
$dfd = new Deferred(function () {
$dfd = new Deferred(static function () {
});
$promise = $this->promises->convertThenable($dfd);
@ -66,13 +69,13 @@ class SyncPromiseAdapterTest extends TestCase
public function testCreatePromise() : void
{
$promise = $this->promises->create(function ($resolve, $reject) {
$promise = $this->promises->create(static function ($resolve, $reject) {
});
self::assertInstanceOf('GraphQL\Executor\Promise\Promise', $promise);
self::assertInstanceOf('GraphQL\Executor\Promise\Adapter\SyncPromise', $promise->adoptedPromise);
$promise = $this->promises->create(function ($resolve, $reject) {
$promise = $this->promises->create(static function ($resolve, $reject) {
$resolve('A');
});
@ -90,11 +93,11 @@ class SyncPromiseAdapterTest extends TestCase
$onRejectedCalled = false;
$promise->then(
function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) {
static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) {
$onFulfilledCalled = true;
$actualNextValue = $nextValue;
},
function (\Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
$onRejectedCalled = true;
$actualNextReason = $reason->getMessage();
}
@ -123,7 +126,7 @@ class SyncPromiseAdapterTest extends TestCase
public function testCreateRejectedPromise() : void
{
$promise = $this->promises->createRejected(new \Exception('test reason'));
$promise = $this->promises->createRejected(new Exception('test reason'));
self::assertValidPromise($promise, 'test reason', null, SyncPromise::REJECTED);
}
@ -138,7 +141,7 @@ class SyncPromiseAdapterTest extends TestCase
$promise1 = new SyncPromise();
$promise2 = new SyncPromise();
$promise3 = $promise2->then(
function ($value) {
static function ($value) {
return $value . '-value3';
}
);
@ -170,12 +173,12 @@ class SyncPromiseAdapterTest extends TestCase
{
$called = [];
$deferred1 = new Deferred(function () use (&$called) {
$deferred1 = new Deferred(static function () use (&$called) {
$called[] = 1;
return 1;
});
$deferred2 = new Deferred(function () use (&$called) {
$deferred2 = new Deferred(static function () use (&$called) {
$called[] = 2;
return 2;
@ -185,7 +188,7 @@ class SyncPromiseAdapterTest extends TestCase
$p2 = $this->promises->convertThenable($deferred2);
$p3 = $p2->then(function () use (&$called) {
$dfd = new Deferred(function () use (&$called) {
$dfd = new Deferred(static function () use (&$called) {
$called[] = 3;
return 3;
@ -194,8 +197,8 @@ class SyncPromiseAdapterTest extends TestCase
return $this->promises->convertThenable($dfd);
});
$p4 = $p3->then(function () use (&$called) {
return new Deferred(function () use (&$called) {
$p4 = $p3->then(static function () use (&$called) {
return new Deferred(static function () use (&$called) {
$called[] = 4;
return 4;

View File

@ -4,29 +4,31 @@ declare(strict_types=1);
namespace GraphQL\Tests\Executor\Promise;
use Exception;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\TestCase;
use Throwable;
use function uniqid;
class SyncPromiseTest extends TestCase
{
public function getFulfilledPromiseResolveData()
{
$onFulfilledReturnsNull = function () {
$onFulfilledReturnsNull = static function () {
return null;
};
$onFulfilledReturnsSameValue = function ($value) {
$onFulfilledReturnsSameValue = static function ($value) {
return $value;
};
$onFulfilledReturnsOtherValue = function ($value) {
$onFulfilledReturnsOtherValue = static function ($value) {
return 'other-' . $value;
};
$onFulfilledThrows = function ($value) {
throw new \Exception('onFulfilled throws this!');
$onFulfilledThrows = static function ($value) {
throw new Exception('onFulfilled throws this!');
};
return [
@ -55,7 +57,7 @@ class SyncPromiseTest extends TestCase
$promise->resolve($resolvedValue);
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Cannot change value of fulfilled promise');
$promise->resolve($resolvedValue . '-other-value');
}
@ -76,9 +78,9 @@ class SyncPromiseTest extends TestCase
$promise->resolve($resolvedValue);
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Cannot reject fulfilled promise');
$promise->reject(new \Exception('anything'));
$promise->reject(new Exception('anything'));
}
/**
@ -99,7 +101,7 @@ class SyncPromiseTest extends TestCase
$nextPromise = $promise->then(
null,
function () {
static function () {
}
);
self::assertSame($promise, $nextPromise);
@ -107,7 +109,7 @@ class SyncPromiseTest extends TestCase
$onRejectedCalled = false;
$nextPromise = $promise->then(
$onFulfilled,
function () use (&$onRejectedCalled) {
static function () use (&$onRejectedCalled) {
$onRejectedCalled = true;
}
);
@ -151,7 +153,7 @@ class SyncPromiseTest extends TestCase
$onFulfilledCalled = true;
$actualNextValue = $nextValue;
},
static function (\Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
$onRejectedCalled = true;
$actualNextReason = $reason->getMessage();
}
@ -172,29 +174,29 @@ class SyncPromiseTest extends TestCase
public function getRejectedPromiseData()
{
$onRejectedReturnsNull = function () {
$onRejectedReturnsNull = static function () {
return null;
};
$onRejectedReturnsSomeValue = function ($reason) {
$onRejectedReturnsSomeValue = static function ($reason) {
return 'some-value';
};
$onRejectedThrowsSameReason = function ($reason) {
$onRejectedThrowsSameReason = static function ($reason) {
throw $reason;
};
$onRejectedThrowsOtherReason = function ($value) {
throw new \Exception('onRejected throws other!');
$onRejectedThrowsOtherReason = static function ($value) {
throw new Exception('onRejected throws other!');
};
return [
// $rejectedReason, $onRejected, $expectedNextValue, $expectedNextReason, $expectedNextState
[new \Exception('test-reason'), null, null, 'test-reason', SyncPromise::REJECTED],
[new \Exception('test-reason-2'), $onRejectedReturnsNull, null, null, SyncPromise::FULFILLED],
[new \Exception('test-reason-3'), $onRejectedReturnsSomeValue, 'some-value', null, SyncPromise::FULFILLED],
[new \Exception('test-reason-4'), $onRejectedThrowsSameReason, null, 'test-reason-4', SyncPromise::REJECTED],
[new \Exception('test-reason-5'), $onRejectedThrowsOtherReason, null, 'onRejected throws other!', SyncPromise::REJECTED],
[new Exception('test-reason'), null, null, 'test-reason', SyncPromise::REJECTED],
[new Exception('test-reason-2'), $onRejectedReturnsNull, null, null, SyncPromise::FULFILLED],
[new Exception('test-reason-3'), $onRejectedReturnsSomeValue, 'some-value', null, SyncPromise::FULFILLED],
[new Exception('test-reason-4'), $onRejectedThrowsSameReason, null, 'test-reason-4', SyncPromise::REJECTED],
[new Exception('test-reason-5'), $onRejectedThrowsOtherReason, null, 'onRejected throws other!', SyncPromise::REJECTED],
];
}
@ -214,9 +216,9 @@ class SyncPromiseTest extends TestCase
$promise->reject($rejectedReason);
self::assertEquals(SyncPromise::REJECTED, $promise->state);
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Cannot change rejection reason');
$promise->reject(new \Exception('other-reason'));
$promise->reject(new Exception('other-reason'));
}
/**
@ -235,7 +237,7 @@ class SyncPromiseTest extends TestCase
$promise->reject($rejectedReason);
self::assertEquals(SyncPromise::REJECTED, $promise->state);
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Cannot resolve rejected promise');
$promise->resolve('anything');
}
@ -257,21 +259,21 @@ class SyncPromiseTest extends TestCase
self::assertEquals(SyncPromise::REJECTED, $promise->state);
try {
$promise->reject(new \Exception('other-reason'));
$promise->reject(new Exception('other-reason'));
$this->fail('Expected exception not thrown');
} catch (\Throwable $e) {
} catch (Throwable $e) {
self::assertEquals('Cannot change rejection reason', $e->getMessage());
}
try {
$promise->resolve('anything');
$this->fail('Expected exception not thrown');
} catch (\Throwable $e) {
} catch (Throwable $e) {
self::assertEquals('Cannot resolve rejected promise', $e->getMessage());
}
$nextPromise = $promise->then(
function () {
static function () {
},
null
);
@ -279,7 +281,7 @@ class SyncPromiseTest extends TestCase
$onFulfilledCalled = false;
$nextPromise = $promise->then(
function () use (&$onFulfilledCalled) {
static function () use (&$onFulfilledCalled) {
$onFulfilledCalled = true;
},
$onRejected
@ -315,7 +317,7 @@ class SyncPromiseTest extends TestCase
try {
$promise->resolve($promise);
$this->fail('Expected exception not thrown');
} catch (\Throwable $e) {
} catch (Throwable $e) {
self::assertEquals('Cannot resolve promise with self', $e->getMessage());
self::assertEquals(SyncPromise::PENDING, $promise->state);
}
@ -346,26 +348,26 @@ class SyncPromiseTest extends TestCase
$this->fail('Expected exception not thrown');
} catch (Error $e) {
throw $e;
} catch (\Throwable $e) {
} catch (Throwable $e) {
self::assertEquals(SyncPromise::PENDING, $promise->state);
}
$promise->reject(new \Exception('Rejected Reason'));
$promise->reject(new Exception('Rejected Reason'));
self::assertValidPromise($promise, 'Rejected Reason', null, SyncPromise::REJECTED);
$promise = new SyncPromise();
$promise2 = $promise->then(
null,
function () {
static function () {
return 'value';
}
);
$promise->reject(new \Exception('Rejected Again'));
$promise->reject(new Exception('Rejected Again'));
self::assertValidPromise($promise2, null, 'value', SyncPromise::FULFILLED);
$promise = new SyncPromise();
$promise2 = $promise->then();
$promise->reject(new \Exception('Rejected Once Again'));
$promise->reject(new Exception('Rejected Once Again'));
self::assertValidPromise($promise2, 'Rejected Once Again', null, SyncPromise::REJECTED);
}
@ -382,13 +384,13 @@ class SyncPromiseTest extends TestCase
// Make sure that it queues derivative promises until resolution:
$onFulfilledCount = 0;
$onRejectedCount = 0;
$onFulfilled = function ($value) use (&$onFulfilledCount) {
$onFulfilled = static function ($value) use (&$onFulfilledCount) {
$onFulfilledCount++;
return $onFulfilledCount;
};
$onRejected = function ($reason) use (&$onRejectedCount) {
$onRejected = static function ($reason) use (&$onRejectedCount) {
$onRejectedCount++;
throw $reason;
};

View File

@ -51,7 +51,7 @@ class ResolveTest extends TestCase
$_secret = 'secretValue' . uniqid();
$source = [
'test' => function () use ($_secret) {
'test' => static function () use ($_secret) {
return $_secret;
},
];
@ -90,7 +90,7 @@ class ResolveTest extends TestCase
'aStr' => ['type' => Type::string()],
'aInt' => ['type' => Type::int()],
],
'resolve' => function ($source, $args) {
'resolve' => static function ($source, $args) {
return json_encode([$source, $args]);
},
]);

View File

@ -36,14 +36,14 @@ class SyncTest extends TestCase
'fields' => [
'syncField' => [
'type' => Type::string(),
'resolve' => function ($rootValue) {
'resolve' => static function ($rootValue) {
return $rootValue;
},
],
'asyncField' => [
'type' => Type::string(),
'resolve' => function ($rootValue) {
return new Deferred(function () use ($rootValue) {
'resolve' => static function ($rootValue) {
return new Deferred(static function () use ($rootValue) {
return $rootValue;
});
},
@ -55,7 +55,7 @@ class SyncTest extends TestCase
'fields' => [
'syncMutationField' => [
'type' => Type::string(),
'resolve' => function ($rootValue) {
'resolve' => static function ($rootValue) {
return $rootValue;
},
],
@ -199,7 +199,7 @@ class SyncTest extends TestCase
$expected = [
'errors' => Utils::map(
$validationErrors,
function ($e) {
static function ($e) {
return FormattedError::createFromException($e);
}
),

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Executor\TestClasses;
use Exception;
use GraphQL\Deferred;
class Root
@ -32,7 +33,7 @@ class Root
public function failToChangeTheNumber() : void
{
throw new \Exception('Cannot change the number');
throw new Exception('Cannot change the number');
}
public function promiseAndFailToChangeTheNumber() : Deferred

View File

@ -51,7 +51,7 @@ class UnionInterfaceTest extends TestCase
'name' => ['type' => Type::string()],
'woofs' => ['type' => Type::boolean()],
],
'isTypeOf' => function ($value) {
'isTypeOf' => static function ($value) {
return $value instanceof Dog;
},
]);
@ -63,7 +63,7 @@ class UnionInterfaceTest extends TestCase
'name' => ['type' => Type::string()],
'meows' => ['type' => Type::boolean()],
],
'isTypeOf' => function ($value) {
'isTypeOf' => static function ($value) {
return $value instanceof Cat;
},
]);
@ -71,7 +71,7 @@ class UnionInterfaceTest extends TestCase
$PetType = new UnionType([
'name' => 'Pet',
'types' => [$DogType, $CatType],
'resolveType' => function ($value) use ($DogType, $CatType) {
'resolveType' => static function ($value) use ($DogType, $CatType) {
if ($value instanceof Dog) {
return $DogType;
}
@ -89,7 +89,7 @@ class UnionInterfaceTest extends TestCase
'pets' => ['type' => Type::listOf($PetType)],
'friends' => ['type' => Type::listOf($NamedType)],
],
'isTypeOf' => function ($value) {
'isTypeOf' => static function ($value) {
return $value instanceof Person;
},
]);
@ -376,7 +376,7 @@ class UnionInterfaceTest extends TestCase
'fields' => [
'name' => ['type' => Type::string()],
],
'resolveType' => function (
'resolveType' => static function (
$obj,
$context,
ResolveInfo $info

View File

@ -43,6 +43,7 @@ class ValuesTest extends TestCase
/**
* @param mixed[] $variables
*
* @return mixed[]
*/
private function runTestCase($variables) : array

View File

@ -156,7 +156,7 @@ class VariablesTest extends TestCase
return [
'type' => Type::string(),
'args' => ['input' => $inputArg],
'resolve' => function ($_, $args) {
'resolve' => static function ($_, $args) {
if (isset($args['input'])) {
return json_encode($args['input']);
}

View File

@ -42,6 +42,7 @@ class LexerTest extends TestCase
/**
* @param string $body
*
* @return Token
*/
private function lexOne($body)
@ -433,8 +434,9 @@ class LexerTest extends TestCase
}
/**
* @dataProvider reportsUsefulStringErrors
* @see it('lex reports useful string errors')
*
* @dataProvider reportsUsefulStringErrors
*/
public function testLexReportsUsefulStringErrors($str, $expectedMessage, $location) : void
{
@ -466,8 +468,9 @@ class LexerTest extends TestCase
}
/**
* @dataProvider reportsUsefulBlockStringErrors
* @see it('lex reports useful block string errors')
*
* @dataProvider reportsUsefulBlockStringErrors
*/
public function testReportsUsefulBlockStringErrors($str, $expectedMessage, $location) : void
{
@ -561,8 +564,9 @@ class LexerTest extends TestCase
}
/**
* @dataProvider reportsUsefulNumberErrors
* @see it('lex reports useful number errors')
*
* @dataProvider reportsUsefulNumberErrors
*/
public function testReportsUsefulNumberErrors($str, $expectedMessage, $location) : void
{
@ -642,8 +646,9 @@ class LexerTest extends TestCase
}
/**
* @dataProvider reportsUsefulUnknownCharErrors
* @see it('lex reports useful unknown character error')
*
* @dataProvider reportsUsefulUnknownCharErrors
*/
public function testReportsUsefulUnknownCharErrors($str, $expectedMessage, $location) : void
{
@ -714,7 +719,7 @@ class LexerTest extends TestCase
],
Utils::map(
$tokens,
function ($tok) {
static function ($tok) {
return $tok->kind;
}
)

View File

@ -19,6 +19,7 @@ use GraphQL\Language\Source;
use GraphQL\Language\SourceLocation;
use GraphQL\Utils\Utils;
use PHPUnit\Framework\TestCase;
use stdClass;
use function file_get_contents;
use function sprintf;
@ -42,7 +43,7 @@ class ParserTest extends TestCase
{
$this->expectException(InvariantViolation::class);
$this->expectExceptionMessage('GraphQL query body is expected to be string, but got stdClass');
Parser::parse(new \stdClass());
Parser::parse(new stdClass());
}
public function parseProvidesUsefulErrors()
@ -72,8 +73,9 @@ fragment MissingOn Type
}
/**
* @dataProvider parseProvidesUsefulErrors
* @see it('parse provides useful errors')
*
* @dataProvider parseProvidesUsefulErrors
*/
public function testParseProvidesUsefulErrors(
$str,
@ -331,7 +333,7 @@ GRAPHQL
');
$result = Parser::parse($source);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return [
'start' => $start,
'end' => $end,
@ -442,7 +444,7 @@ GRAPHQL
');
$result = Parser::parse($source);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return [
'start' => $start,
'end' => $end,

View File

@ -4,11 +4,13 @@ declare(strict_types=1);
namespace GraphQL\Tests\Language;
use ArrayObject;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\Parser;
use GraphQL\Language\Printer;
use PHPUnit\Framework\TestCase;
use Throwable;
use function file_get_contents;
class PrinterTest extends TestCase
@ -42,8 +44,8 @@ class PrinterTest extends TestCase
*/
public function testProducesHelpfulErrorMessages() : void
{
$badAst1 = new \ArrayObject(['random' => 'Data']);
$this->expectException(\Throwable::class);
$badAst1 = new ArrayObject(['random' => 'Data']);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Invalid AST Node: {"random":"Data"}');
Printer::doPrint($badAst1);
}

View File

@ -23,7 +23,7 @@ type Hello {
world: String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -98,7 +98,7 @@ type Hello {
world: String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -145,7 +145,7 @@ type Hello {
world: String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -189,7 +189,7 @@ extend type Hello {
}
';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -223,7 +223,7 @@ extend type Hello {
{
$body = 'extend type Hello implements Greeting';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -356,7 +356,7 @@ type Hello {
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -396,7 +396,7 @@ type Hello {
{
$body = 'type Hello implements World { field: String }';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -434,7 +434,7 @@ type Hello {
{
$body = 'type Hello implements Wo & rld { field: String }';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -473,7 +473,7 @@ type Hello {
{
$body = 'type Hello implements & Wo & rld { field: String }';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -511,7 +511,7 @@ type Hello {
{
$body = 'enum Hello { WORLD }';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -551,7 +551,7 @@ type Hello {
{
$body = 'enum Hello { WO, RLD }';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -586,7 +586,7 @@ interface Hello {
world: String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -623,7 +623,7 @@ type Hello {
world(flag: Boolean): String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -683,7 +683,7 @@ type Hello {
world(flag: Boolean = true): String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -729,7 +729,7 @@ type Hello {
world(things: [String]): String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -782,7 +782,7 @@ type Hello {
world(argOne: Boolean, argTwo: Int): String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -832,7 +832,7 @@ type Hello {
{
$body = 'union Hello = World';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -861,7 +861,7 @@ type Hello {
{
$body = 'union Hello = Wo | Rld';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -967,7 +967,7 @@ type Hello {
{
$body = 'scalar Hello';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};
@ -997,7 +997,7 @@ input Hello {
world: String
}';
$doc = Parser::parse($body);
$loc = function ($start, $end) {
$loc = static function ($start, $end) {
return TestUtils::locArray($start, $end);
};

View File

@ -68,7 +68,7 @@ class VisitorTest extends ValidatorTestCase
private function checkVisitorFnArgs($ast, $args, $isEdited = false)
{
/** @var Node $node */
list($node, $key, $parent, $path, $ancestors) = $args;
[$node, $key, $parent, $path, $ancestors] = $args;
$parentArray = $parent && ! is_array($parent) ? ($parent instanceof NodeList ? iterator_to_array($parent) : $parent->toArray()) : $parent;
@ -880,21 +880,21 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
],
$visited
);
@ -939,40 +939,40 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['no-a', 'enter', 'Document', null],
['no-b', 'enter', 'Document', null],
['no-a', 'enter', 'OperationDefinition', null],
['no-b', 'enter', 'OperationDefinition', null],
['no-a', 'enter', 'SelectionSet', null],
['no-b', 'enter', 'SelectionSet', null],
['no-a', 'enter', 'Field', null],
['no-b', 'enter', 'Field', null],
['no-b', 'enter', 'Name', 'a'],
['no-b', 'leave', 'Name', 'a'],
['no-b', 'enter', 'SelectionSet', null],
['no-b', 'enter', 'Field', null],
['no-b', 'enter', 'Name', 'x'],
['no-b', 'leave', 'Name', 'x'],
['no-b', 'leave', 'Field', null],
['no-b', 'leave', 'SelectionSet', null],
['no-b', 'leave', 'Field', null],
['no-a', 'enter', 'Field', null],
['no-b', 'enter', 'Field', null],
['no-a', 'enter', 'Name', 'b'],
['no-a', 'leave', 'Name', 'b'],
['no-a', 'enter', 'SelectionSet', null],
['no-a', 'enter', 'Field', null],
['no-a', 'enter', 'Name', 'y'],
['no-a', 'leave', 'Name', 'y'],
['no-a', 'leave', 'Field', null],
['no-a', 'leave', 'SelectionSet', null],
['no-a', 'leave', 'Field', null],
['no-a', 'leave', 'SelectionSet', null],
['no-b', 'leave', 'SelectionSet', null],
['no-a', 'leave', 'OperationDefinition', null],
['no-b', 'leave', 'OperationDefinition', null],
['no-a', 'leave', 'Document', null],
['no-b', 'leave', 'Document', null],
['no-a', 'enter', 'Document', null],
['no-b', 'enter', 'Document', null],
['no-a', 'enter', 'OperationDefinition', null],
['no-b', 'enter', 'OperationDefinition', null],
['no-a', 'enter', 'SelectionSet', null],
['no-b', 'enter', 'SelectionSet', null],
['no-a', 'enter', 'Field', null],
['no-b', 'enter', 'Field', null],
['no-b', 'enter', 'Name', 'a'],
['no-b', 'leave', 'Name', 'a'],
['no-b', 'enter', 'SelectionSet', null],
['no-b', 'enter', 'Field', null],
['no-b', 'enter', 'Name', 'x'],
['no-b', 'leave', 'Name', 'x'],
['no-b', 'leave', 'Field', null],
['no-b', 'leave', 'SelectionSet', null],
['no-b', 'leave', 'Field', null],
['no-a', 'enter', 'Field', null],
['no-b', 'enter', 'Field', null],
['no-a', 'enter', 'Name', 'b'],
['no-a', 'leave', 'Name', 'b'],
['no-a', 'enter', 'SelectionSet', null],
['no-a', 'enter', 'Field', null],
['no-a', 'enter', 'Name', 'y'],
['no-a', 'leave', 'Name', 'y'],
['no-a', 'leave', 'Field', null],
['no-a', 'leave', 'SelectionSet', null],
['no-a', 'leave', 'Field', null],
['no-a', 'leave', 'SelectionSet', null],
['no-b', 'leave', 'SelectionSet', null],
['no-a', 'leave', 'OperationDefinition', null],
['no-b', 'leave', 'OperationDefinition', null],
['no-a', 'leave', 'Document', null],
['no-b', 'leave', 'Document', null],
],
$visited
);
@ -1004,19 +1004,19 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'x'],
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'x'],
],
$visited
);
@ -1063,26 +1063,26 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['break-a', 'enter', 'Document', null],
['break-b', 'enter', 'Document', null],
['break-a', 'enter', 'OperationDefinition', null],
['break-b', 'enter', 'OperationDefinition', null],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'a'],
['break-b', 'enter', 'Name', 'a'],
['break-b', 'leave', 'Name', 'a'],
['break-b', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'y'],
['break-b', 'leave', 'Name', 'y'],
['break-b', 'leave', 'Field', null],
['break-b', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'b'],
['break-a', 'enter', 'Document', null],
['break-b', 'enter', 'Document', null],
['break-a', 'enter', 'OperationDefinition', null],
['break-b', 'enter', 'OperationDefinition', null],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'a'],
['break-b', 'enter', 'Name', 'a'],
['break-b', 'leave', 'Name', 'a'],
['break-b', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'y'],
['break-b', 'leave', 'Name', 'y'],
['break-b', 'leave', 'Field', null],
['break-b', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'b'],
],
$visited
);
@ -1114,20 +1114,20 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'x'],
['leave', 'Name', 'x'],
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'x'],
['leave', 'Name', 'x'],
],
$visited
);
@ -1172,42 +1172,42 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['break-a', 'enter', 'Document', null],
['break-b', 'enter', 'Document', null],
['break-a', 'enter', 'OperationDefinition', null],
['break-b', 'enter', 'OperationDefinition', null],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'a'],
['break-b', 'enter', 'Name', 'a'],
['break-a', 'leave', 'Name', 'a'],
['break-b', 'leave', 'Name', 'a'],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'y'],
['break-b', 'enter', 'Name', 'y'],
['break-a', 'leave', 'Name', 'y'],
['break-b', 'leave', 'Name', 'y'],
['break-a', 'leave', 'Field', null],
['break-b', 'leave', 'Field', null],
['break-a', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'SelectionSet', null],
['break-a', 'leave', 'Field', null],
['break-b', 'leave', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'b'],
['break-b', 'leave', 'Name', 'b'],
['break-b', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'x'],
['break-b', 'leave', 'Name', 'x'],
['break-b', 'leave', 'Field', null],
['break-b', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'Field', null],
['break-a', 'enter', 'Document', null],
['break-b', 'enter', 'Document', null],
['break-a', 'enter', 'OperationDefinition', null],
['break-b', 'enter', 'OperationDefinition', null],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'a'],
['break-b', 'enter', 'Name', 'a'],
['break-a', 'leave', 'Name', 'a'],
['break-b', 'leave', 'Name', 'a'],
['break-a', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'SelectionSet', null],
['break-a', 'enter', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-a', 'enter', 'Name', 'y'],
['break-b', 'enter', 'Name', 'y'],
['break-a', 'leave', 'Name', 'y'],
['break-b', 'leave', 'Name', 'y'],
['break-a', 'leave', 'Field', null],
['break-b', 'leave', 'Field', null],
['break-a', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'SelectionSet', null],
['break-a', 'leave', 'Field', null],
['break-b', 'leave', 'Field', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'b'],
['break-b', 'leave', 'Name', 'b'],
['break-b', 'enter', 'SelectionSet', null],
['break-b', 'enter', 'Field', null],
['break-b', 'enter', 'Name', 'x'],
['break-b', 'leave', 'Name', 'x'],
['break-b', 'leave', 'Field', null],
['break-b', 'leave', 'SelectionSet', null],
['break-b', 'leave', 'Field', null],
],
$visited
);
@ -1254,30 +1254,30 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
],
$visited
);
@ -1324,36 +1324,36 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
['enter', 'Document', null],
['enter', 'OperationDefinition', null],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['enter', 'SelectionSet', null],
['enter', 'Field', null],
['enter', 'Name', 'a'],
['leave', 'Name', 'a'],
['leave', 'Field', null],
['enter', 'Field', null],
['enter', 'Name', 'b'],
['leave', 'Name', 'b'],
['enter', 'Field', null],
['enter', 'Name', 'c'],
['leave', 'Name', 'c'],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'Field', null],
['leave', 'SelectionSet', null],
['leave', 'OperationDefinition', null],
['leave', 'Document', null],
],
$visited
);
@ -1408,46 +1408,46 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null, null, null, null],
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['enter', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'SelectionSet', null, 'Human', 'Human', null],
['enter', 'Field', null, 'Human', 'String', null],
['enter', 'Name', 'name', 'Human', 'String', null],
['leave', 'Name', 'name', 'Human', 'String', null],
['leave', 'Field', null, 'Human', 'String', null],
['enter', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
['enter', 'InlineFragment', null, 'Pet', 'Pet', null],
['enter', 'SelectionSet', null, 'Pet', 'Pet', null],
['enter', 'Field', null, 'Pet', 'String', null],
['enter', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Field', null, 'Pet', 'String', null],
['leave', 'SelectionSet', null, 'Pet', 'Pet', null],
['leave', 'InlineFragment', null, 'Pet', 'Pet', null],
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
['leave', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Field', null, 'Human', null, null],
['enter', 'Name', 'unknown', 'Human', null, null],
['leave', 'Name', 'unknown', 'Human', null, null],
['leave', 'Field', null, 'Human', null, null],
['leave', 'SelectionSet', null, 'Human', 'Human', null],
['leave', 'Field', null, 'QueryRoot', 'Human', null],
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
['leave', 'Document', null, null, null, null],
['enter', 'Document', null, null, null, null],
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['enter', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'SelectionSet', null, 'Human', 'Human', null],
['enter', 'Field', null, 'Human', 'String', null],
['enter', 'Name', 'name', 'Human', 'String', null],
['leave', 'Name', 'name', 'Human', 'String', null],
['leave', 'Field', null, 'Human', 'String', null],
['enter', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
['enter', 'InlineFragment', null, 'Pet', 'Pet', null],
['enter', 'SelectionSet', null, 'Pet', 'Pet', null],
['enter', 'Field', null, 'Pet', 'String', null],
['enter', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Name', 'name', 'Pet', 'String', null],
['leave', 'Field', null, 'Pet', 'String', null],
['leave', 'SelectionSet', null, 'Pet', 'Pet', null],
['leave', 'InlineFragment', null, 'Pet', 'Pet', null],
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
['leave', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Field', null, 'Human', null, null],
['enter', 'Name', 'unknown', 'Human', null, null],
['leave', 'Name', 'unknown', 'Human', null, null],
['leave', 'Field', null, 'Human', null, null],
['leave', 'SelectionSet', null, 'Human', 'Human', null],
['leave', 'Field', null, 'QueryRoot', 'Human', null],
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
['leave', 'Document', null, null, null, null],
],
$visited
);
@ -1534,48 +1534,48 @@ class VisitorTest extends ValidatorTestCase
self::assertEquals(
[
['enter', 'Document', null, null, null, null],
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['enter', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'SelectionSet', null, 'Human', 'Human', null],
['enter', 'Field', null, 'Human', 'String', null],
['enter', 'Name', 'name', 'Human', 'String', null],
['leave', 'Name', 'name', 'Human', 'String', null],
['leave', 'Field', null, 'Human', 'String', null],
['enter', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
['enter', 'Field', null, 'Pet', 'String!', null],
['enter', 'Name', '__typename', 'Pet', 'String!', null],
['leave', 'Name', '__typename', 'Pet', 'String!', null],
['leave', 'Field', null, 'Pet', 'String!', null],
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
['leave', 'Field', null, 'Human', '[Pet]', null],
['leave', 'SelectionSet', null, 'Human', 'Human', null],
['leave', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Field', null, 'QueryRoot', 'Alien', null],
['enter', 'Name', 'alien', 'QueryRoot', 'Alien', null],
['leave', 'Name', 'alien', 'QueryRoot', 'Alien', null],
['enter', 'SelectionSet', null, 'Alien', 'Alien', null],
['enter', 'Field', null, 'Alien', 'String!', null],
['enter', 'Name', '__typename', 'Alien', 'String!', null],
['leave', 'Name', '__typename', 'Alien', 'String!', null],
['leave', 'Field', null, 'Alien', 'String!', null],
['leave', 'SelectionSet', null, 'Alien', 'Alien', null],
['leave', 'Field', null, 'QueryRoot', 'Alien', null],
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
['leave', 'Document', null, null, null, null],
['enter', 'Document', null, null, null, null],
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['enter', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
['enter', 'SelectionSet', null, 'Human', 'Human', null],
['enter', 'Field', null, 'Human', 'String', null],
['enter', 'Name', 'name', 'Human', 'String', null],
['leave', 'Name', 'name', 'Human', 'String', null],
['leave', 'Field', null, 'Human', 'String', null],
['enter', 'Field', null, 'Human', '[Pet]', null],
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
['enter', 'Field', null, 'Pet', 'String!', null],
['enter', 'Name', '__typename', 'Pet', 'String!', null],
['leave', 'Name', '__typename', 'Pet', 'String!', null],
['leave', 'Field', null, 'Pet', 'String!', null],
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
['leave', 'Field', null, 'Human', '[Pet]', null],
['leave', 'SelectionSet', null, 'Human', 'Human', null],
['leave', 'Field', null, 'QueryRoot', 'Human', null],
['enter', 'Field', null, 'QueryRoot', 'Alien', null],
['enter', 'Name', 'alien', 'QueryRoot', 'Alien', null],
['leave', 'Name', 'alien', 'QueryRoot', 'Alien', null],
['enter', 'SelectionSet', null, 'Alien', 'Alien', null],
['enter', 'Field', null, 'Alien', 'String!', null],
['enter', 'Name', '__typename', 'Alien', 'String!', null],
['leave', 'Name', '__typename', 'Alien', 'String!', null],
['leave', 'Field', null, 'Alien', 'String!', null],
['leave', 'SelectionSet', null, 'Alien', 'Alien', null],
['leave', 'Field', null, 'QueryRoot', 'Alien', null],
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
['leave', 'Document', null, null, null, null],
],
$visited
);

View File

@ -17,6 +17,7 @@ use GraphQL\Server\ServerConfig;
use GraphQL\Validator\DocumentValidator;
use GraphQL\Validator\Rules\CustomValidationRule;
use GraphQL\Validator\ValidationContext;
use stdClass;
use function count;
use function sprintf;
@ -119,7 +120,7 @@ class QueryExecutionTest extends ServerTestCase
public function testPassesRootValueAndContext() : void
{
$rootValue = 'myRootValue';
$context = new \stdClass();
$context = new stdClass();
$this->config
->setContext($context)
@ -170,7 +171,7 @@ class QueryExecutionTest extends ServerTestCase
$called = false;
$rules = [
new CustomValidationRule('SomeRule', function () use (&$called) {
new CustomValidationRule('SomeRule', static function () use (&$called) {
$called = true;
return [];
@ -190,7 +191,7 @@ class QueryExecutionTest extends ServerTestCase
$called = false;
$params = $doc = $operationType = null;
$this->config->setValidationRules(function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$this->config->setValidationRules(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$called = true;
$params = $p;
$doc = $d;
@ -214,7 +215,7 @@ class QueryExecutionTest extends ServerTestCase
$called1 = false;
$called2 = false;
$this->config->setValidationRules(function (OperationParams $params) use ($q1, &$called1, &$called2) {
$this->config->setValidationRules(static function (OperationParams $params) use ($q1, &$called1, &$called2) {
if ($params->query === $q1) {
$called1 = true;
@ -224,7 +225,7 @@ class QueryExecutionTest extends ServerTestCase
$called2 = true;
return [
new CustomValidationRule('MyRule', function (ValidationContext $context) {
new CustomValidationRule('MyRule', static function (ValidationContext $context) {
$context->reportError(new Error('This is the error we are looking for!'));
}),
];
@ -353,7 +354,7 @@ class QueryExecutionTest extends ServerTestCase
public function testAllowsPersistentQueries() : void
{
$called = false;
$this->config->setPersistentQueryLoader(function ($queryId, OperationParams $params) use (&$called) {
$this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) {
$called = true;
self::assertEquals('some-id', $queryId);
@ -370,7 +371,7 @@ class QueryExecutionTest extends ServerTestCase
// Make sure it allows returning document node:
$called = false;
$this->config->setPersistentQueryLoader(function ($queryId, OperationParams $params) use (&$called) {
$this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) {
$called = true;
self::assertEquals('some-id', $queryId);
@ -388,7 +389,7 @@ class QueryExecutionTest extends ServerTestCase
'Persistent query loader must return query string or instance of GraphQL\Language\AST\DocumentNode ' .
'but got: {"err":"err"}'
);
$this->config->setPersistentQueryLoader(function () {
$this->config->setPersistentQueryLoader(static function () {
return ['err' => 'err'];
});
$this->executePersistedQuery('some-id');
@ -396,7 +397,7 @@ class QueryExecutionTest extends ServerTestCase
public function testPersistedQueriesAreStillValidatedByDefault() : void
{
$this->config->setPersistentQueryLoader(function () {
$this->config->setPersistentQueryLoader(static function () {
return '{invalid}';
});
$result = $this->executePersistedQuery('some-id');
@ -415,14 +416,14 @@ class QueryExecutionTest extends ServerTestCase
public function testAllowSkippingValidationForPersistedQueries() : void
{
$this->config
->setPersistentQueryLoader(function ($queryId) {
->setPersistentQueryLoader(static function ($queryId) {
if ($queryId === 'some-id') {
return '{invalid}';
}
return '{invalid2}';
})
->setValidationRules(function (OperationParams $params) {
->setValidationRules(static function (OperationParams $params) {
if ($params->queryId === 'some-id') {
return [];
}
@ -453,8 +454,8 @@ class QueryExecutionTest extends ServerTestCase
{
$this->expectException(InvariantViolation::class);
$this->expectExceptionMessage('Expecting validation rules to be array or callable returning array, but got: instance of stdClass');
$this->config->setValidationRules(function (OperationParams $params) {
return new \stdClass();
$this->config->setValidationRules(static function (OperationParams $params) {
return new stdClass();
});
$this->executeQuery('{f1}');
}
@ -519,10 +520,10 @@ class QueryExecutionTest extends ServerTestCase
->setQueryBatching(true)
->setRootValue('1')
->setContext([
'buffer' => function ($num) use (&$calls) {
'buffer' => static function ($num) use (&$calls) {
$calls[] = sprintf('buffer: %d', $num);
},
'load' => function ($num) use (&$calls) {
'load' => static function ($num) use (&$calls) {
$calls[] = sprintf('load: %d', $num);
return sprintf('loaded: %d', $num);
@ -584,7 +585,7 @@ class QueryExecutionTest extends ServerTestCase
$called = false;
$params = $doc = $operationType = null;
$this->config->setContext(function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$this->config->setContext(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$called = true;
$params = $p;
$doc = $d;
@ -604,7 +605,7 @@ class QueryExecutionTest extends ServerTestCase
$called = false;
$params = $doc = $operationType = null;
$this->config->setRootValue(function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$this->config->setRootValue(static function ($p, $d, $o) use (&$called, &$params, &$doc, &$operationType) {
$called = true;
$params = $p;
$doc = $d;
@ -623,7 +624,7 @@ class QueryExecutionTest extends ServerTestCase
{
$called = false;
$error = null;
$this->config->setErrorFormatter(function ($e) use (&$called, &$error) {
$this->config->setErrorFormatter(static function ($e) use (&$called, &$error) {
$called = true;
$error = $e;
@ -660,7 +661,7 @@ class QueryExecutionTest extends ServerTestCase
$called = false;
$errors = null;
$formatter = null;
$this->config->setErrorsHandler(function ($e, $f) use (&$called, &$errors, &$formatter) {
$this->config->setErrorsHandler(static function ($e, $f) use (&$called, &$errors, &$formatter) {
$called = true;
$errors = $e;
$formatter = $f;

View File

@ -43,7 +43,7 @@ class RequestParsingTest extends TestCase
$helper = new Helper();
return $helper->parseHttpRequest(function () use ($content) {
return $helper->parseHttpRequest(static function () use ($content) {
return $content;
});
}
@ -125,6 +125,7 @@ class RequestParsingTest extends TestCase
/**
* @param mixed[] $postValue
*
* @return OperationParams|OperationParams[]
*/
private function parseRawFormUrlencodedRequest($postValue)
@ -135,13 +136,14 @@ class RequestParsingTest extends TestCase
$helper = new Helper();
return $helper->parseHttpRequest(function () {
return $helper->parseHttpRequest(static function () {
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
});
}
/**
* @param mixed[] $postValue
*
* @return OperationParams[]|OperationParams
*/
private function parsePsrFormUrlEncodedRequest($postValue)
@ -180,6 +182,7 @@ class RequestParsingTest extends TestCase
/**
* @param mixed[] $getValue
*
* @return OperationParams
*/
private function parseRawGetRequest($getValue)
@ -189,13 +192,14 @@ class RequestParsingTest extends TestCase
$helper = new Helper();
return $helper->parseHttpRequest(function () {
return $helper->parseHttpRequest(static function () {
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
});
}
/**
* @param mixed[] $getValue
*
* @return OperationParams[]|OperationParams
*/
private function parsePsrGetRequest($getValue)
@ -233,6 +237,7 @@ class RequestParsingTest extends TestCase
/**
* @param mixed[] $postValue
*
* @return OperationParams|OperationParams[]
*/
private function parseRawMultipartFormDataRequest($postValue)
@ -243,13 +248,14 @@ class RequestParsingTest extends TestCase
$helper = new Helper();
return $helper->parseHttpRequest(function () {
return $helper->parseHttpRequest(static function () {
throw new InvariantViolation("Shouldn't read from php://input for multipart/form-data request");
});
}
/**
* @param mixed[] $postValue
*
* @return OperationParams|OperationParams[]
*/
private function parsePsrMultipartFormDataRequest($postValue)

View File

@ -11,6 +11,7 @@ use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;
use stdClass;
class ServerConfigTest extends TestCase
{
@ -51,7 +52,7 @@ class ServerConfigTest extends TestCase
$config->setContext($context);
self::assertSame($context, $config->getContext());
$context2 = new \stdClass();
$context2 = new stdClass();
$config->setContext($context2);
self::assertSame($context2, $config->getContext());
}
@ -64,7 +65,7 @@ class ServerConfigTest extends TestCase
$config->setRootValue($rootValue);
self::assertSame($rootValue, $config->getRootValue());
$context2 = new \stdClass();
$context2 = new stdClass();
$config->setRootValue($context2);
self::assertSame($context2, $config->getRootValue());
}
@ -73,7 +74,7 @@ class ServerConfigTest extends TestCase
{
$config = ServerConfig::create();
$formatter = function () {
$formatter = static function () {
};
$config->setErrorFormatter($formatter);
self::assertSame($formatter, $config->getErrorFormatter());
@ -87,7 +88,7 @@ class ServerConfigTest extends TestCase
{
$config = ServerConfig::create();
$handler = function () {
$handler = static function () {
};
$config->setErrorsHandler($handler);
self::assertSame($handler, $config->getErrorsHandler());
@ -118,14 +119,14 @@ class ServerConfigTest extends TestCase
$config->setValidationRules($rules);
self::assertSame($rules, $config->getValidationRules());
$rules = [function () {
$rules = [static function () {
},
];
$config->setValidationRules($rules);
self::assertSame($rules, $config->getValidationRules());
$rules = function () {
return [function () {
$rules = static function () {
return [static function () {
},
];
};
@ -137,7 +138,7 @@ class ServerConfigTest extends TestCase
{
$config = ServerConfig::create();
$resolver = function () {
$resolver = static function () {
};
$config->setFieldResolver($resolver);
self::assertSame($resolver, $config->getFieldResolver());
@ -151,7 +152,7 @@ class ServerConfigTest extends TestCase
{
$config = ServerConfig::create();
$loader = function () {
$loader = static function () {
};
$config->setPersistentQueryLoader($loader);
self::assertSame($loader, $config->getPersistentQueryLoader());
@ -178,17 +179,17 @@ class ServerConfigTest extends TestCase
'schema' => new Schema([
'query' => new ObjectType(['name' => 't', 'fields' => ['a' => Type::string()]]),
]),
'context' => new \stdClass(),
'rootValue' => new \stdClass(),
'errorFormatter' => function () {
'context' => new stdClass(),
'rootValue' => new stdClass(),
'errorFormatter' => static function () {
},
'promiseAdapter' => new SyncPromiseAdapter(),
'validationRules' => [function () {
'validationRules' => [static function () {
},
],
'fieldResolver' => function () {
'fieldResolver' => static function () {
},
'persistentQueryLoader' => function () {
'persistentQueryLoader' => static function () {
},
'debug' => true,
'queryBatching' => true,
@ -220,7 +221,7 @@ class ServerConfigTest extends TestCase
public function testInvalidValidationRules() : void
{
$rules = new \stdClass();
$rules = new stdClass();
$config = ServerConfig::create();
$this->expectException(InvariantViolation::class);

View File

@ -19,19 +19,19 @@ abstract class ServerTestCase extends TestCase
{
protected function buildSchema()
{
$schema = new Schema([
return new Schema([
'query' => new ObjectType([
'name' => 'Query',
'fields' => [
'f1' => [
'type' => Type::string(),
'resolve' => function ($root, $args, $context, $info) {
'resolve' => static function ($root, $args, $context, $info) {
return $info->fieldName;
},
],
'fieldWithPhpError' => [
'type' => Type::string(),
'resolve' => function ($root, $args, $context, $info) {
'resolve' => static function ($root, $args, $context, $info) {
trigger_error('deprecated', E_USER_DEPRECATED);
trigger_error('notice', E_USER_NOTICE);
trigger_error('warning', E_USER_WARNING);
@ -43,19 +43,19 @@ abstract class ServerTestCase extends TestCase
],
'fieldWithSafeException' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
throw new UserError('This is the exception we want');
},
],
'fieldWithUnsafeException' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
throw new Unsafe('This exception should not be shown to the user');
},
],
'testContextAndRootValue' => [
'type' => Type::string(),
'resolve' => function ($root, $args, $context, $info) {
'resolve' => static function ($root, $args, $context, $info) {
$context->testedRootValue = $root;
return $info->fieldName;
@ -68,7 +68,7 @@ abstract class ServerTestCase extends TestCase
'type' => Type::nonNull(Type::string()),
],
],
'resolve' => function ($root, $args) {
'resolve' => static function ($root, $args) {
return $args['arg'];
},
],
@ -79,10 +79,10 @@ abstract class ServerTestCase extends TestCase
'type' => Type::nonNull(Type::int()),
],
],
'resolve' => function ($root, $args, $context) {
'resolve' => static function ($root, $args, $context) {
$context['buffer']($args['num']);
return new Deferred(function () use ($args, $context) {
return new Deferred(static function () use ($args, $context) {
return $context['load']($args['num']);
});
},
@ -103,7 +103,5 @@ abstract class ServerTestCase extends TestCase
],
]),
]);
return $schema;
}
}

View File

@ -45,7 +45,7 @@ class StandardServerTest extends ServerTestCase
$helper = new Helper();
return $helper->parseHttpRequest(function () use ($content) {
return $helper->parseHttpRequest(static function () use ($content) {
return $content;
});
}

View File

@ -4,15 +4,17 @@ declare(strict_types=1);
namespace GraphQL\Tests\Server;
use Exception;
use GraphQL\Error\ClientAware;
class Unsafe extends \Exception implements ClientAware
class Unsafe extends Exception implements ClientAware
{
/**
* Returns true when exception message is safe to be displayed to a client.
*
* @api
* @return bool
*
* @api
*/
public function isClientSafe()
{
@ -24,8 +26,9 @@ class Unsafe extends \Exception implements ClientAware
*
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
*
* @api
* @return string
*
* @api
*/
public function getCategory()
{

View File

@ -129,11 +129,12 @@ class StarWarsData
*/
public static function getFriends($character)
{
return array_map([__CLASS__, 'getCharacter'], $character['friends']);
return array_map([self::class, 'getCharacter'], $character['friends']);
}
/**
* @param int $episode
*
* @return mixed[]
*/
public static function getHero($episode)
@ -149,6 +150,7 @@ class StarWarsData
/**
* @param string $id
*
* @return mixed|null
*/
public static function getHuman($id)
@ -160,6 +162,7 @@ class StarWarsData
/**
* @param string $id
*
* @return mixed|null
*/
public static function getDroid($id)

View File

@ -15,6 +15,7 @@ namespace GraphQL\Tests;
* Wars trilogy.
*/
use Exception;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\NonNull;
@ -108,7 +109,7 @@ class StarWarsSchema
$characterInterface = new InterfaceType([
'name' => 'Character',
'description' => 'A character in the Star Wars Trilogy',
'fields' => function () use (&$characterInterface, $episodeEnum) {
'fields' => static function () use (&$characterInterface, $episodeEnum) {
return [
'id' => [
'type' => Type::nonNull(Type::string()),
@ -132,7 +133,7 @@ class StarWarsSchema
],
];
},
'resolveType' => function ($obj) use (&$humanType, &$droidType) {
'resolveType' => static function ($obj) use (&$humanType, &$droidType) {
return StarWarsData::getHuman($obj['id']) ? $humanType : $droidType;
},
]);
@ -164,18 +165,16 @@ class StarWarsSchema
'friends' => [
'type' => Type::listOf($characterInterface),
'description' => 'The friends of the human, or an empty list if they have none.',
'resolve' => function ($human, $args, $context, ResolveInfo $info) {
'resolve' => static function ($human, $args, $context, ResolveInfo $info) {
$fieldSelection = $info->getFieldSelection();
$fieldSelection['id'] = true;
$friends = array_map(
function ($friend) use ($fieldSelection) {
return array_map(
static function ($friend) use ($fieldSelection) {
return array_intersect_key($friend, $fieldSelection);
},
StarWarsData::getFriends($human)
);
return $friends;
},
],
'appearsIn' => [
@ -189,9 +188,9 @@ class StarWarsSchema
'secretBackstory' => [
'type' => Type::string(),
'description' => 'Where are they from and how they came to be who they are.',
'resolve' => function () {
'resolve' => static function () {
// This is to demonstrate error reporting
throw new \Exception('secretBackstory is secret.');
throw new Exception('secretBackstory is secret.');
},
],
],
@ -226,7 +225,7 @@ class StarWarsSchema
'friends' => [
'type' => Type::listOf($characterInterface),
'description' => 'The friends of the droid, or an empty list if they have none.',
'resolve' => function ($droid) {
'resolve' => static function ($droid) {
return StarWarsData::getFriends($droid);
},
],
@ -237,9 +236,9 @@ class StarWarsSchema
'secretBackstory' => [
'type' => Type::string(),
'description' => 'Construction date and the name of the designer.',
'resolve' => function () {
'resolve' => static function () {
// This is to demonstrate error reporting
throw new \Exception('secretBackstory is secret.');
throw new Exception('secretBackstory is secret.');
},
],
'primaryFunction' => [
@ -262,7 +261,6 @@ class StarWarsSchema
* human(id: String!): Human
* droid(id: String!): Droid
* }
*
*/
$queryType = new ObjectType([
'name' => 'Query',
@ -275,7 +273,7 @@ class StarWarsSchema
'type' => $episodeEnum,
],
],
'resolve' => function ($root, $args) {
'resolve' => static function ($root, $args) {
return StarWarsData::getHero($args['episode'] ?? null);
},
],
@ -288,7 +286,7 @@ class StarWarsSchema
'type' => Type::nonNull(Type::string()),
],
],
'resolve' => function ($root, $args) {
'resolve' => static function ($root, $args) {
$humans = StarWarsData::humans();
return $humans[$args['id']] ?? null;
@ -303,7 +301,7 @@ class StarWarsSchema
'type' => Type::nonNull(Type::string()),
],
],
'resolve' => function ($root, $args) {
'resolve' => static function ($root, $args) {
$droids = StarWarsData::droids();
return $droids[$args['id']] ?? null;

View File

@ -19,6 +19,8 @@ use GraphQL\Type\Definition\UnionType;
use GraphQL\Type\Schema;
use GraphQL\Utils\Utils;
use PHPUnit\Framework\TestCase;
use stdClass;
use Throwable;
use function count;
use function get_class;
use function json_encode;
@ -80,11 +82,11 @@ class DefinitionTest extends TestCase
$this->scalarType = new CustomScalarType([
'name' => 'Scalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => function () {
'parseValue' => static function () {
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
]);
@ -403,7 +405,7 @@ class DefinitionTest extends TestCase
'fields' => [
'f' => ['type' => Type::int()],
],
'interfaces' => function () use (&$someInterface) {
'interfaces' => static function () use (&$someInterface) {
return [$someInterface];
},
]);
@ -557,7 +559,7 @@ class DefinitionTest extends TestCase
$user = new ObjectType([
'name' => 'User',
'fields' => function () use (&$blog, &$called) {
'fields' => static function () use (&$blog, &$called) {
self::assertNotNull($blog, 'Blog type is expected to be defined at this point, but it is null');
$called = true;
@ -566,20 +568,20 @@ class DefinitionTest extends TestCase
'blogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull($blog)))],
];
},
'interfaces' => function () use ($node) {
'interfaces' => static function () use ($node) {
return [$node];
},
]);
$blog = new ObjectType([
'name' => 'Blog',
'fields' => function () use ($user) {
'fields' => static function () use ($user) {
return [
'id' => ['type' => Type::nonNull(Type::id())],
'owner' => ['type' => Type::nonNull($user)],
];
},
'interfaces' => function () use ($node) {
'interfaces' => static function () use ($node) {
return [$node];
},
]);
@ -612,7 +614,7 @@ class DefinitionTest extends TestCase
$called = false;
$inputObject = new InputObjectType([
'name' => 'InputObject',
'fields' => function () use (&$inputObject, &$called) {
'fields' => static function () use (&$inputObject, &$called) {
$called = true;
return [
@ -649,7 +651,7 @@ class DefinitionTest extends TestCase
$called = false;
$interface = new InterfaceType([
'name' => 'SomeInterface',
'fields' => function () use (&$interface, &$called) {
'fields' => static function () use (&$interface, &$called) {
$called = true;
return [
@ -679,7 +681,7 @@ class DefinitionTest extends TestCase
{
$interface = new InterfaceType([
'name' => 'SomeInterface',
'fields' => function () use (&$interface) {
'fields' => static function () use (&$interface) {
return [
'value' => Type::string(),
'nested' => $interface,
@ -730,11 +732,11 @@ class DefinitionTest extends TestCase
{
$idType = new CustomScalarType([
'name' => 'ID',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => function () {
'parseValue' => static function () {
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
]);
@ -755,7 +757,7 @@ class DefinitionTest extends TestCase
{
$objType = new ObjectType([
'name' => 'SomeObject',
'fields' => function () {
'fields' => static function () {
return [
'f' => ['type' => Type::string()],
];
@ -805,7 +807,7 @@ class DefinitionTest extends TestCase
{
$objType = new ObjectType([
'name' => 'SomeObject',
'fields' => function () {
'fields' => static function () {
return [['field' => Type::string()]];
},
]);
@ -901,7 +903,7 @@ class DefinitionTest extends TestCase
{
$objType = new ObjectType([
'name' => 'SomeObject',
'interfaces' => new \stdClass(),
'interfaces' => new stdClass(),
'fields' => ['f' => ['type' => Type::string()]],
]);
$this->expectException(InvariantViolation::class);
@ -918,8 +920,8 @@ class DefinitionTest extends TestCase
{
$objType = new ObjectType([
'name' => 'SomeObject',
'interfaces' => function () {
return new \stdClass();
'interfaces' => static function () {
return new stdClass();
},
'fields' => ['f' => ['type' => Type::string()]],
]);
@ -939,7 +941,7 @@ class DefinitionTest extends TestCase
{
$this->expectNotToPerformAssertions();
// should not throw:
$this->schemaWithObjectWithFieldResolver(function () {
$this->schemaWithObjectWithFieldResolver(static function () {
});
}
@ -1083,7 +1085,7 @@ class DefinitionTest extends TestCase
$type = new InterfaceType([
'name' => 'AnotherInterface',
'resolveType' => new \stdClass(),
'resolveType' => new stdClass(),
'fields' => ['f' => ['type' => Type::string()]],
]);
$type->assertValid();
@ -1148,7 +1150,7 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new UnionType([
'name' => 'SomeUnion',
'resolveType' => new \stdClass(),
'resolveType' => new stdClass(),
'types' => [$this->objectWithIsTypeOf],
])
);
@ -1164,7 +1166,7 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
return null;
},
])
@ -1203,7 +1205,7 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => new \stdClass(),
'serialize' => new stdClass(),
])
);
}
@ -1218,11 +1220,11 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => function () {
'parseValue' => static function () {
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
])
);
@ -1240,9 +1242,9 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => function () {
'parseValue' => static function () {
},
])
);
@ -1260,9 +1262,9 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
])
);
@ -1280,10 +1282,10 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => new \stdClass(),
'parseLiteral' => new \stdClass(),
'parseValue' => new stdClass(),
'parseLiteral' => new stdClass(),
])
);
}
@ -1317,7 +1319,7 @@ class DefinitionTest extends TestCase
$this->schemaWithFieldType(
new ObjectType([
'name' => 'AnotherObject',
'isTypeOf' => new \stdClass(),
'isTypeOf' => new stdClass(),
'fields' => ['f' => ['type' => Type::string()]],
])
);
@ -1411,7 +1413,7 @@ class DefinitionTest extends TestCase
{
$inputObjType = new InputObjectType([
'name' => 'SomeInputObject',
'fields' => function () {
'fields' => static function () {
return [
'f' => ['type' => Type::string()],
];
@ -1445,7 +1447,7 @@ class DefinitionTest extends TestCase
{
$inputObjType = new InputObjectType([
'name' => 'SomeInputObject',
'fields' => function () {
'fields' => static function () {
return [];
},
]);
@ -1467,7 +1469,7 @@ class DefinitionTest extends TestCase
'fields' => [
'f' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return 0;
},
],
@ -1493,7 +1495,7 @@ class DefinitionTest extends TestCase
'fields' => [
'f' => [
'type' => Type::string(),
'resolve' => new \stdClass(),
'resolve' => new stdClass(),
],
],
]);
@ -1591,12 +1593,12 @@ class DefinitionTest extends TestCase
Type::nonNull(Type::string()),
];
$badTypes = [[], new \stdClass(), '', null];
$badTypes = [[], new stdClass(), '', null];
foreach ($types as $type) {
try {
Type::listOf($type);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->fail('List is expected to accept type: ' . get_class($type) . ', but got error: ' . $e->getMessage());
}
}
@ -1630,14 +1632,14 @@ class DefinitionTest extends TestCase
$notNullableTypes = [
Type::nonNull(Type::string()),
[],
new \stdClass(),
new stdClass(),
'',
null,
];
foreach ($nullableTypes as $type) {
try {
Type::nonNull($type);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->fail('NonNull is expected to accept type: ' . get_class($type) . ', but got error: ' . $e->getMessage());
}
}
@ -1659,7 +1661,7 @@ class DefinitionTest extends TestCase
{
$FakeString = new CustomScalarType([
'name' => 'String',
'serialize' => function () {
'serialize' => static function () {
},
]);

View File

@ -51,10 +51,10 @@ class EnumTypeTest extends TestCase
]);
$Complex1 = [
'someRandomFunction' => function () {
'someRandomFunction' => static function () {
},
];
$Complex2 = new \ArrayObject(['someRandomValue' => 123]);
$Complex2 = new ArrayObject(['someRandomValue' => 123]);
$ComplexEnum = new EnumType([
'name' => 'Complex',
@ -74,7 +74,7 @@ class EnumTypeTest extends TestCase
'fromInt' => ['type' => Type::int()],
'fromString' => ['type' => Type::string()],
],
'resolve' => function ($value, $args) {
'resolve' => static function ($value, $args) {
if (isset($args['fromInt'])) {
return $args['fromInt'];
}
@ -92,7 +92,7 @@ class EnumTypeTest extends TestCase
'fromName' => ['type' => Type::string()],
'fromValue' => ['type' => Type::string()],
],
'resolve' => function ($value, $args) {
'resolve' => static function ($value, $args) {
if (isset($args['fromName'])) {
return $args['fromName'];
}
@ -107,7 +107,7 @@ class EnumTypeTest extends TestCase
'fromEnum' => ['type' => $ColorType],
'fromInt' => ['type' => Type::int()],
],
'resolve' => function ($value, $args) {
'resolve' => static function ($value, $args) {
if (isset($args['fromInt'])) {
return $args['fromInt'];
}
@ -132,7 +132,7 @@ class EnumTypeTest extends TestCase
'type' => Type::boolean(),
],
],
'resolve' => function ($value, $args) use ($Complex2) {
'resolve' => static function ($value, $args) use ($Complex2) {
if (! empty($args['provideGoodValue'])) {
// Note: this is one of the references of the internal values which
// ComplexEnum allows.
@ -141,7 +141,7 @@ class EnumTypeTest extends TestCase
if (! empty($args['provideBadValue'])) {
// Note: similar shape, but not the same *reference*
// as Complex2 above. Enum internal values require === equality.
return new \ArrayObject(['someRandomValue' => 123]);
return new ArrayObject(['someRandomValue' => 123]);
}
return $args['fromEnum'];
@ -156,7 +156,7 @@ class EnumTypeTest extends TestCase
'favoriteEnum' => [
'type' => $ColorType,
'args' => ['color' => ['type' => $ColorType]],
'resolve' => function ($value, $args) {
'resolve' => static function ($value, $args) {
return $args['color'] ?? null;
},
],
@ -169,7 +169,7 @@ class EnumTypeTest extends TestCase
'subscribeToEnum' => [
'type' => $ColorType,
'args' => ['color' => ['type' => $ColorType]],
'resolve' => function ($value, $args) {
'resolve' => static function ($value, $args) {
return $args['color'] ?? null;
},
],
@ -365,6 +365,7 @@ class EnumTypeTest extends TestCase
/**
* @see it('accepts enum literals as input arguments to subscriptions')
*
* @todo
*/
public function testAcceptsEnumLiteralsAsInputArgumentsToSubscriptions() : void

View File

@ -1049,7 +1049,7 @@ class IntrospectionTest extends TestCase
'field' => [
'type' => Type::string(),
'args' => ['complex' => ['type' => $TestInputObject]],
'resolve' => function ($_, $args) {
'resolve' => static function ($_, $args) {
return json_encode($args['complex']);
},
],

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Type;
use Exception;
use GraphQL\Error\InvariantViolation;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\InterfaceType;
@ -460,8 +461,8 @@ class ResolutionTest extends TestCase
$eager = new EagerResolution([]);
$emptyDescriptor = $eager->getDescriptor();
$typeLoader = function ($name) {
throw new \Exception('This should be never called for empty descriptor');
$typeLoader = static function () {
throw new Exception('This should be never called for empty descriptor');
};
$lazy = new LazyResolution($emptyDescriptor, $typeLoader);
@ -547,7 +548,7 @@ class ResolutionTest extends TestCase
],
];
$invalidTypeLoader = function ($name) {
$invalidTypeLoader = static function ($name) {
switch ($name) {
case 'null':
return null;

View File

@ -28,7 +28,7 @@ class ResolveInfoTest extends TestCase
$author = new ObjectType([
'name' => 'Author',
'fields' => function () use ($image, &$article) {
'fields' => static function () use ($image, &$article) {
return [
'id' => ['type' => Type::string()],
'name' => ['type' => Type::string()],
@ -151,7 +151,7 @@ class ResolveInfoTest extends TestCase
'fields' => [
'article' => [
'type' => $article,
'resolve' => function (
'resolve' => static function (
$value,
$args,
$context,
@ -196,7 +196,7 @@ class ResolveInfoTest extends TestCase
$author = new ObjectType([
'name' => 'Author',
'fields' => function () use ($image, &$article) {
'fields' => static function () use ($image, &$article) {
return [
'id' => ['type' => Type::string()],
'name' => ['type' => Type::string()],
@ -324,7 +324,7 @@ class ResolveInfoTest extends TestCase
'fields' => [
'article' => [
'type' => $article,
'resolve' => function (
'resolve' => static function (
$value,
$args,
$context,

View File

@ -7,6 +7,7 @@ namespace GraphQL\Tests\Type;
use GraphQL\Error\Error;
use GraphQL\Type\Definition\Type;
use PHPUnit\Framework\TestCase;
use stdClass;
class ScalarSerializationTest extends TestCase
{
@ -176,7 +177,7 @@ class ScalarSerializationTest extends TestCase
$stringType = Type::string();
$this->expectException(Error::class);
$this->expectExceptionMessage('String cannot represent non scalar value: instance of stdClass');
$stringType->serialize(new \stdClass());
$stringType->serialize(new stdClass());
}
/**
@ -215,6 +216,6 @@ class ScalarSerializationTest extends TestCase
$idType = Type::id();
$this->expectException(Error::class);
$this->expectExceptionMessage('ID type cannot represent non scalar value: instance of stdClass');
$idType->serialize(new \stdClass());
$idType->serialize(new stdClass());
}
}

View File

@ -46,7 +46,7 @@ class SchemaTest extends TestCase
'fields' => [
'fieldName' => [
'type' => Type::string(),
'resolve' => function () {
'resolve' => static function () {
return '';
},
],
@ -90,7 +90,7 @@ class SchemaTest extends TestCase
'fields' => [
'getObject' => [
'type' => $this->interfaceType,
'resolve' => function () {
'resolve' => static function () {
return [];
},
],

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Type;
use Exception;
use GraphQL\Error\InvariantViolation;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\InterfaceType;
@ -11,6 +12,8 @@ use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;
use stdClass;
use Throwable;
use function lcfirst;
class TypeLoaderTest extends TestCase
@ -55,7 +58,7 @@ class TypeLoaderTest extends TestCase
'id' => Type::string(),
];
},
'resolveType' => function () {
'resolveType' => static function () {
},
]);
@ -69,7 +72,7 @@ class TypeLoaderTest extends TestCase
'body' => Type::string(),
];
},
'resolveType' => function () {
'resolveType' => static function () {
},
]);
@ -152,7 +155,7 @@ class TypeLoaderTest extends TestCase
'name' => 'Query',
'fields' => ['a' => Type::string()],
]),
'typeLoader' => function () {
'typeLoader' => static function () {
},
]);
}
@ -253,7 +256,7 @@ class TypeLoaderTest extends TestCase
{
$schema = new Schema([
'query' => $this->query,
'typeLoader' => function () {
'typeLoader' => static function () {
},
]);
@ -267,8 +270,8 @@ class TypeLoaderTest extends TestCase
{
$schema = new Schema([
'query' => $this->query,
'typeLoader' => function () {
return new \stdClass();
'typeLoader' => static function () {
return new stdClass();
},
]);
@ -297,12 +300,12 @@ class TypeLoaderTest extends TestCase
{
$schema = new Schema([
'query' => $this->query,
'typeLoader' => function () {
throw new \Exception('This is the exception we are looking for');
'typeLoader' => static function () {
throw new Exception('This is the exception we are looking for');
},
]);
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('This is the exception we are looking for');
$schema->getType('Node');

View File

@ -66,11 +66,11 @@ class ValidationTest extends TestCase
$this->SomeScalarType = new CustomScalarType([
'name' => 'SomeScalar',
'serialize' => function () {
'serialize' => static function () {
},
'parseValue' => function () {
'parseValue' => static function () {
},
'parseLiteral' => function () {
'parseLiteral' => static function () {
},
]);
@ -144,19 +144,19 @@ class ValidationTest extends TestCase
$types,
Utils::map(
$types,
function ($type) {
static function ($type) {
return Type::listOf($type);
}
),
Utils::map(
$types,
function ($type) {
static function ($type) {
return Type::nonNull($type);
}
),
Utils::map(
$types,
function ($type) {
static function ($type) {
return Type::nonNull(Type::listOf($type));
}
)
@ -173,19 +173,19 @@ class ValidationTest extends TestCase
{
$this->assertEachCallableThrows(
[
function () {
static function () {
return new ObjectType([]);
},
function () {
static function () {
return new EnumType([]);
},
function () {
static function () {
return new InputObjectType([]);
},
function () {
static function () {
return new UnionType([]);
},
function () {
static function () {
return new InterfaceType([]);
},
],
@ -347,7 +347,7 @@ class ValidationTest extends TestCase
implode(
"\n",
array_map(
function ($error) {
static function ($error) {
return $error->getMessage();
},
$array
@ -581,7 +581,7 @@ class ValidationTest extends TestCase
$manualSchema2 = $this->schemaWithFieldType(
new ObjectType([
'name' => 'IncompleteObject',
'fields' => function () {
'fields' => static function () {
return [];
},
])
@ -989,6 +989,7 @@ class ValidationTest extends TestCase
/**
* @see it('rejects an Enum type with incorrectly named values')
*
* @dataProvider invalidEnumValueName
*/
public function testRejectsAnEnumTypeWithIncorrectlyNamedValues($name, $expectedMessage) : void
@ -1974,7 +1975,7 @@ class ValidationTest extends TestCase
public function testRejectsDifferentInstancesOfTheSameType() : void
{
// Invalid: always creates new instance vs returning one from registry
$typeLoader = function ($name) {
$typeLoader = static function ($name) {
switch ($name) {
case 'Query':
return new ObjectType([

View File

@ -20,6 +20,7 @@ use GraphQL\Type\Definition\Type;
use GraphQL\Utils\AST;
use PHPUnit\Framework\TestCase;
use stdClass;
use Throwable;
class AstFromValueTest extends TestCase
{
@ -61,14 +62,14 @@ class AstFromValueTest extends TestCase
{
// GraphQL spec does not allow coercing non-integer values to Int to avoid
// accidental data loss.
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Int cannot represent non-integer value: 123.5');
AST::astFromValue(123.5, Type::int());
}
public function testConvertsIntValuesToASTsCannotRepresentNon32bitsInteger() : void
{
$this->expectException(\Throwable::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Int cannot represent non 32-bit signed integer value: 1.0E+40');
AST::astFromValue(
1e40,
@ -165,7 +166,7 @@ class AstFromValueTest extends TestCase
private function complexValue()
{
if (! $this->complexValue) {
$this->complexValue = new \stdClass();
$this->complexValue = new stdClass();
$this->complexValue->someArbitrary = 'complexValue';
}
@ -232,6 +233,7 @@ class AstFromValueTest extends TestCase
/**
* @param mixed $value
*
* @return ObjectFieldNode
*/
private function objectField(string $name, $value)
@ -257,9 +259,9 @@ class AstFromValueTest extends TestCase
self::assertEquals(
new ObjectValueNode([
'fields' => [
$this->objectField('foo', new NullValueNode([])),
],
'fields' => [
$this->objectField('foo', new NullValueNode([])),
],
]),
AST::astFromValue(['foo' => null], $inputObj)
);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Utils;
use Closure;
use GraphQL\Error\Error;
use GraphQL\GraphQL;
use GraphQL\Language\AST\EnumTypeDefinitionNode;
@ -51,7 +52,7 @@ class BuildSchemaTest extends TestCase
');
$root = [
'add' => function ($root, $args) {
'add' => static function ($root, $args) {
return $args['x'] + $args['y'];
},
];
@ -1196,7 +1197,7 @@ interface Hello {
$decorated = [];
$calls = [];
$typeConfigDecorator = function ($defaultConfig, $node, $allNodesMap) use (&$decorated, &$calls) {
$typeConfigDecorator = static function ($defaultConfig, $node, $allNodesMap) use (&$decorated, &$calls) {
$decorated[] = $defaultConfig['name'];
$calls[] = [$defaultConfig, $node, $allNodesMap];
@ -1207,17 +1208,17 @@ interface Hello {
$schema->getTypeMap();
self::assertEquals(['Query', 'Color', 'Hello'], $decorated);
list($defaultConfig, $node, $allNodesMap) = $calls[0];
[$defaultConfig, $node, $allNodesMap] = $calls[0];
self::assertInstanceOf(ObjectTypeDefinitionNode::class, $node);
self::assertEquals('Query', $defaultConfig['name']);
self::assertInstanceOf(\Closure::class, $defaultConfig['fields']);
self::assertInstanceOf(\Closure::class, $defaultConfig['interfaces']);
self::assertInstanceOf(Closure::class, $defaultConfig['fields']);
self::assertInstanceOf(Closure::class, $defaultConfig['interfaces']);
self::assertArrayHasKey('description', $defaultConfig);
self::assertCount(5, $defaultConfig);
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
self::assertEquals('My description of Query', $schema->getType('Query')->description);
list($defaultConfig, $node, $allNodesMap) = $calls[1];
[$defaultConfig, $node, $allNodesMap] = $calls[1];
self::assertInstanceOf(EnumTypeDefinitionNode::class, $node);
self::assertEquals('Color', $defaultConfig['name']);
$enumValue = [
@ -1236,10 +1237,10 @@ interface Hello {
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
self::assertEquals('My description of Color', $schema->getType('Color')->description);
list($defaultConfig, $node, $allNodesMap) = $calls[2];
[$defaultConfig, $node, $allNodesMap] = $calls[2];
self::assertInstanceOf(InterfaceTypeDefinitionNode::class, $node);
self::assertEquals('Hello', $defaultConfig['name']);
self::assertInstanceOf(\Closure::class, $defaultConfig['fields']);
self::assertInstanceOf(Closure::class, $defaultConfig['fields']);
self::assertArrayHasKey('description', $defaultConfig);
self::assertCount(4, $defaultConfig);
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
@ -1276,7 +1277,7 @@ type World implements Hello {
$doc = Parser::parse($body);
$created = [];
$typeConfigDecorator = function ($config, $node) use (&$created) {
$typeConfigDecorator = static function ($config, $node) use (&$created) {
$created[] = $node->name->value;
return $config;

View File

@ -7,6 +7,7 @@ namespace GraphQL\Tests\Utils;
use GraphQL\Utils\MixedStore;
use GraphQL\Utils\Utils;
use PHPUnit\Framework\TestCase;
use stdClass;
class MixedStoreTest extends TestCase
{
@ -36,8 +37,8 @@ class MixedStoreTest extends TestCase
'1',
'a',
[],
new \stdClass(),
function () {
new stdClass(),
static function () {
},
new MixedStore(),
];
@ -111,7 +112,7 @@ class MixedStoreTest extends TestCase
$this->assertAcceptsKeyValue([], $value);
$this->assertAcceptsKeyValue([null], $value);
$this->assertAcceptsKeyValue([[]], $value);
$this->assertAcceptsKeyValue([new \stdClass()], $value);
$this->assertAcceptsKeyValue([new stdClass()], $value);
$this->assertAcceptsKeyValue(['a', 'b'], $value);
$this->assertAcceptsKeyValue(['a' => 'b'], $value);
}
@ -120,10 +121,10 @@ class MixedStoreTest extends TestCase
public function testAcceptsObjectKeys() : void
{
foreach ($this->getPossibleValues() as $value) {
$this->assertAcceptsKeyValue(new \stdClass(), $value);
$this->assertAcceptsKeyValue(new stdClass(), $value);
$this->assertAcceptsKeyValue(new MixedStore(), $value);
$this->assertAcceptsKeyValue(
function () {
static function () {
},
$value
);

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Utils;
use GraphQL\Utils\Utils;
use LogicException;
use PHPUnit\Framework\TestCase;
class QuotedOrListTest extends TestCase
@ -15,7 +16,7 @@ class QuotedOrListTest extends TestCase
*/
public function testResturnsResultsWhenInputIsEmpty() : void
{
$this->expectException(\LogicException::class);
$this->expectException(LogicException::class);
Utils::quotedOrList([]);
}

View File

@ -591,7 +591,7 @@ type Query {
{
$oddType = new CustomScalarType([
'name' => 'Odd',
'serialize' => function ($value) {
'serialize' => static function ($value) {
return $value % 2 === 1 ? $value : null;
},
]);

View File

@ -5,16 +5,18 @@ declare(strict_types=1);
namespace GraphQL\Tests;
use GraphQL\Utils\Utils;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use stdClass;
class UtilsTest extends TestCase
{
public function testAssignThrowsExceptionOnMissingRequiredKey() : void
{
$object = new \stdClass();
$object = new stdClass();
$object->requiredKey = 'value';
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Key requiredKey is expected to be set and not to be null');
Utils::assign($object, [], ['requiredKey']);
}

View File

@ -703,7 +703,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
$SomeBox = new InterfaceType([
'name' => 'SomeBox',
'fields' => function () use (&$SomeBox) {
'fields' => static function () use (&$SomeBox) {
return [
'deepBox' => ['type' => $SomeBox],
'unrelatedField' => ['type' => Type::string()],
@ -714,7 +714,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
$StringBox = new ObjectType([
'name' => 'StringBox',
'interfaces' => [$SomeBox],
'fields' => function () use (&$StringBox, &$IntBox) {
'fields' => static function () use (&$StringBox, &$IntBox) {
return [
'scalar' => ['type' => Type::string()],
'deepBox' => ['type' => $StringBox],
@ -729,7 +729,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
$IntBox = new ObjectType([
'name' => 'IntBox',
'interfaces' => [$SomeBox],
'fields' => function () use (&$StringBox, &$IntBox) {
'fields' => static function () use (&$StringBox, &$IntBox) {
return [
'scalar' => ['type' => Type::int()],
'deepBox' => ['type' => $IntBox],
@ -797,7 +797,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
],
]);
$schema = new Schema([
return new Schema([
'query' => new ObjectType([
'name' => 'QueryRoot',
'fields' => [
@ -807,8 +807,6 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
]),
'types' => [$IntBox, $StringBox, $NonNullStringBox1Impl, $NonNullStringBox2Impl],
]);
return $schema;
}
/**

View File

@ -168,10 +168,10 @@ class QueryComplexityTest extends QuerySecurityTestCase
$reportedError = new Error('OtherValidatorError');
$otherRule = new CustomValidationRule(
'otherRule',
function (ValidationContext $context) use ($reportedError) {
static function (ValidationContext $context) use ($reportedError) {
return [
NodeKind::OPERATION_DEFINITION => [
'leave' => function () use ($context, $reportedError) {
'leave' => static function () use ($context, $reportedError) {
$context->reportError($reportedError);
},
],

View File

@ -14,6 +14,7 @@ class QueryDepthTest extends QuerySecurityTestCase
* @param int $queryDepth
* @param int $maxQueryDepth
* @param string[][] $expectedErrors
*
* @dataProvider queryDataProvider
*/
public function testSimpleQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
@ -23,9 +24,7 @@ class QueryDepthTest extends QuerySecurityTestCase
private function buildRecursiveQuery($depth)
{
$query = sprintf('query MyQuery { human%s }', $this->buildRecursiveQueryPart($depth));
return $query;
return sprintf('query MyQuery { human%s }', $this->buildRecursiveQueryPart($depth));
}
private function buildRecursiveQueryPart($depth)
@ -38,7 +37,7 @@ class QueryDepthTest extends QuerySecurityTestCase
$part = $templates['human'];
for ($i = 1; $i <= $depth; ++$i) {
$key = ($i % 2 === 1) ? 'human' : 'dog';
$key = $i % 2 === 1 ? 'human' : 'dog';
$template = $templates[$key];
$part = sprintf($part, ($key === 'human' ? ' owner ' : '') . $template);
@ -52,6 +51,7 @@ class QueryDepthTest extends QuerySecurityTestCase
* @param int $queryDepth
* @param int $maxQueryDepth
* @param string[][] $expectedErrors
*
* @dataProvider queryDataProvider
*/
public function testFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
@ -65,18 +65,17 @@ class QueryDepthTest extends QuerySecurityTestCase
private function buildRecursiveUsingFragmentQuery($depth)
{
$query = sprintf(
return sprintf(
'query MyQuery { human { ...F1 } } fragment F1 on Human %s',
$this->buildRecursiveQueryPart($depth)
);
return $query;
}
/**
* @param int $queryDepth
* @param int $maxQueryDepth
* @param string[][] $expectedErrors
*
* @dataProvider queryDataProvider
*/
public function testInlineFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
@ -90,12 +89,10 @@ class QueryDepthTest extends QuerySecurityTestCase
private function buildRecursiveUsingInlineFragmentQuery($depth)
{
$query = sprintf(
return sprintf(
'query MyQuery { human { ...on Human %s } }',
$this->buildRecursiveQueryPart($depth)
);
return $query;
}
public function testComplexityIntrospectionQuery() : void

View File

@ -66,7 +66,7 @@ class QuerySecuritySchema
self::$humanType = new ObjectType(
[
'name' => 'Human',
'fields' => function () {
'fields' => static function () {
return [
'firstName' => ['type' => Type::nonNull(Type::string())],
'dogs' => [
@ -75,7 +75,7 @@ class QuerySecuritySchema
Type::nonNull(self::buildDogType())
)
),
'complexity' => function ($childrenComplexity, $args) {
'complexity' => static function ($childrenComplexity, $args) {
$complexity = isset($args['name']) ? 1 : 10;
return $childrenComplexity + $complexity;

View File

@ -52,6 +52,7 @@ abstract class QuerySecurityTestCase extends TestCase
* @param string $queryString
* @param int $max
* @param string[][] $expectedErrors
*
* @return Error[]
*/
protected function assertDocumentValidator($queryString, $max, array $expectedErrors = []) : array

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace GraphQL\Tests\Validator;
use Exception;
use GraphQL\Language\Parser;
use GraphQL\Type\Definition\CustomScalarType;
use GraphQL\Type\Definition\Directive;
@ -63,7 +64,7 @@ abstract class ValidatorTestCase extends TestCase
$Canine = new InterfaceType([
'name' => 'Canine',
'fields' => function () {
'fields' => static function () {
return [
'name' => [
'type' => Type::string(),
@ -110,7 +111,7 @@ abstract class ValidatorTestCase extends TestCase
$Cat = new ObjectType([
'name' => 'Cat',
'fields' => function () use (&$FurColor) {
'fields' => static function () use (&$FurColor) {
return [
'name' => [
'type' => Type::string(),
@ -141,7 +142,7 @@ abstract class ValidatorTestCase extends TestCase
$Human = new ObjectType([
'name' => 'Human',
'interfaces' => [$Being, $Intelligent],
'fields' => function () use (&$Human, $Pet) {
'fields' => static function () use (&$Human, $Pet) {
return [
'name' => [
'type' => Type::string(),
@ -289,26 +290,26 @@ abstract class ValidatorTestCase extends TestCase
$invalidScalar = new CustomScalarType([
'name' => 'Invalid',
'serialize' => function ($value) {
'serialize' => static function ($value) {
return $value;
},
'parseLiteral' => function ($node) {
throw new \Exception('Invalid scalar is always invalid: ' . $node->value);
'parseLiteral' => static function ($node) {
throw new Exception('Invalid scalar is always invalid: ' . $node->value);
},
'parseValue' => function ($node) {
throw new \Exception('Invalid scalar is always invalid: ' . $node);
'parseValue' => static function ($node) {
throw new Exception('Invalid scalar is always invalid: ' . $node);
},
]);
$anyScalar = new CustomScalarType([
'name' => 'Any',
'serialize' => function ($value) {
'serialize' => static function ($value) {
return $value;
},
'parseLiteral' => function ($node) {
'parseLiteral' => static function ($node) {
return $node;
}, // Allows any value
'parseValue' => function ($value) {
'parseValue' => static function ($value) {
return $value;
}, // Allows any value
]);
@ -341,7 +342,7 @@ abstract class ValidatorTestCase extends TestCase
],
]);
$testSchema = new Schema([
return new Schema([
'query' => $queryRoot,
'directives' => [
Directive::includeDirective(),
@ -420,8 +421,6 @@ abstract class ValidatorTestCase extends TestCase
]),
],
]);
return $testSchema;
}
protected function expectFailsRule($rule, $queryString, $errors)

View File

@ -1286,6 +1286,7 @@ class ValuesOfCorrectTypeTest extends ValidatorTestCase
* @see it('Partial object, unknown field arg')
*
* The sorting of equal elements has changed so that the test fails on php < 7
*
* @requires PHP 7.0
*/
public function testPartialObjectUnknownFieldArg() : void