mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Fix CS in tests
This commit is contained in:
parent
af31ca7ad8
commit
07c070d795
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Error;
|
namespace GraphQL\Tests\Error;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Language\Source;
|
use GraphQL\Language\Source;
|
||||||
@ -17,7 +18,7 @@ class ErrorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUsesTheStackOfAnOriginalError() : void
|
public function testUsesTheStackOfAnOriginalError() : void
|
||||||
{
|
{
|
||||||
$prev = new \Exception('Original');
|
$prev = new Exception('Original');
|
||||||
$err = new Error('msg', null, null, null, null, $prev);
|
$err = new Error('msg', null, null, null, null, $prev);
|
||||||
|
|
||||||
self::assertSame($err->getPrevious(), $prev);
|
self::assertSame($err->getPrevious(), $prev);
|
||||||
|
@ -37,8 +37,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
$DogType = new ObjectType([
|
$DogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'interfaces' => [$PetType],
|
'interfaces' => [$PetType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
return $obj instanceof Dog;
|
return $obj instanceof Dog;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -51,8 +51,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
$CatType = new ObjectType([
|
$CatType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'interfaces' => [$PetType],
|
'interfaces' => [$PetType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -68,7 +68,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -121,8 +121,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
$DogType = new ObjectType([
|
$DogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'interfaces' => [$PetType],
|
'interfaces' => [$PetType],
|
||||||
'isTypeOf' => function () {
|
'isTypeOf' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('We are testing this error');
|
throw new UserError('We are testing this error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -135,8 +135,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
$CatType = new ObjectType([
|
$CatType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'interfaces' => [$PetType],
|
'interfaces' => [$PetType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -152,7 +152,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -206,8 +206,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
{
|
{
|
||||||
$DogType = new ObjectType([
|
$DogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
return $obj instanceof Dog;
|
return $obj instanceof Dog;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -219,8 +219,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
|
|
||||||
$CatType = new ObjectType([
|
$CatType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -241,7 +241,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -283,8 +283,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
{
|
{
|
||||||
$PetType = new InterfaceType([
|
$PetType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) use (&$DogType, &$CatType, &$HumanType) {
|
'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) {
|
||||||
return new Deferred(function () use ($obj, $DogType, $CatType, $HumanType) {
|
return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return $DogType;
|
return $DogType;
|
||||||
}
|
}
|
||||||
@ -334,8 +334,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -413,8 +413,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
|
|
||||||
$PetType = new UnionType([
|
$PetType = new UnionType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) use ($DogType, $CatType, $HumanType) {
|
'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) {
|
||||||
return new Deferred(function () use ($obj, $DogType, $CatType, $HumanType) {
|
return new Deferred(static function () use ($obj, $DogType, $CatType, $HumanType) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return $DogType;
|
return $DogType;
|
||||||
}
|
}
|
||||||
@ -437,7 +437,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -491,8 +491,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
{
|
{
|
||||||
$PetType = new InterfaceType([
|
$PetType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) {
|
'resolveType' => static function ($obj) {
|
||||||
return new Deferred(function () use ($obj) {
|
return new Deferred(static function () use ($obj) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return 'Dog';
|
return 'Dog';
|
||||||
}
|
}
|
||||||
@ -532,7 +532,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -576,8 +576,8 @@ class AbstractPromiseTest extends TestCase
|
|||||||
{
|
{
|
||||||
$PetType = new InterfaceType([
|
$PetType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function () {
|
'resolveType' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('We are testing this error');
|
throw new UserError('We are testing this error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -610,7 +610,7 @@ class AbstractPromiseTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
|
@ -40,7 +40,7 @@ class AbstractTest extends TestCase
|
|||||||
$dogType = new ObjectType([
|
$dogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'interfaces' => [$petType],
|
'interfaces' => [$petType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Dog;
|
return $obj instanceof Dog;
|
||||||
},
|
},
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -52,7 +52,7 @@ class AbstractTest extends TestCase
|
|||||||
$catType = new ObjectType([
|
$catType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'interfaces' => [$petType],
|
'interfaces' => [$petType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
},
|
},
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -67,7 +67,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($petType),
|
'type' => Type::listOf($petType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -106,7 +106,7 @@ class AbstractTest extends TestCase
|
|||||||
{
|
{
|
||||||
$dogType = new ObjectType([
|
$dogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Dog;
|
return $obj instanceof Dog;
|
||||||
},
|
},
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -117,7 +117,7 @@ class AbstractTest extends TestCase
|
|||||||
|
|
||||||
$catType = new ObjectType([
|
$catType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
},
|
},
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -137,7 +137,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($petType),
|
'type' => Type::listOf($petType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -178,7 +178,7 @@ class AbstractTest extends TestCase
|
|||||||
|
|
||||||
$PetType = new InterfaceType([
|
$PetType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) use (&$DogType, &$CatType, &$HumanType) {
|
'resolveType' => static function ($obj) use (&$DogType, &$CatType, &$HumanType) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return $DogType;
|
return $DogType;
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -302,7 +302,7 @@ class AbstractTest extends TestCase
|
|||||||
|
|
||||||
$PetType = new UnionType([
|
$PetType = new UnionType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) use ($DogType, $CatType, $HumanType) {
|
'resolveType' => static function ($obj) use ($DogType, $CatType, $HumanType) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return $DogType;
|
return $DogType;
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -380,7 +380,7 @@ class AbstractTest extends TestCase
|
|||||||
$fooInterface = new InterfaceType([
|
$fooInterface = new InterfaceType([
|
||||||
'name' => 'FooInterface',
|
'name' => 'FooInterface',
|
||||||
'fields' => ['bar' => ['type' => Type::string()]],
|
'fields' => ['bar' => ['type' => Type::string()]],
|
||||||
'resolveType' => function () {
|
'resolveType' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -397,7 +397,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'foo' => [
|
'foo' => [
|
||||||
'type' => $fooInterface,
|
'type' => $fooInterface,
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 'dummy';
|
return 'dummy';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -434,7 +434,7 @@ class AbstractTest extends TestCase
|
|||||||
{
|
{
|
||||||
$PetType = new InterfaceType([
|
$PetType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'resolveType' => function ($obj) {
|
'resolveType' => static function ($obj) {
|
||||||
if ($obj instanceof Dog) {
|
if ($obj instanceof Dog) {
|
||||||
return 'Dog';
|
return 'Dog';
|
||||||
}
|
}
|
||||||
@ -473,7 +473,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($PetType),
|
'type' => Type::listOf($PetType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [
|
return [
|
||||||
new Dog('Odie', true),
|
new Dog('Odie', true),
|
||||||
new Cat('Garfield', false),
|
new Cat('Garfield', false),
|
||||||
@ -514,13 +514,13 @@ class AbstractTest extends TestCase
|
|||||||
|
|
||||||
public function testHintsOnConflictingTypeInstancesInResolveType() : void
|
public function testHintsOnConflictingTypeInstancesInResolveType() : void
|
||||||
{
|
{
|
||||||
$createTest = function () use (&$iface) {
|
$createTest = static function () use (&$iface) {
|
||||||
return new ObjectType([
|
return new ObjectType([
|
||||||
'name' => 'Test',
|
'name' => 'Test',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'a' => Type::string(),
|
'a' => Type::string(),
|
||||||
],
|
],
|
||||||
'interfaces' => function () use ($iface) {
|
'interfaces' => static function () use ($iface) {
|
||||||
return [$iface];
|
return [$iface];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -531,7 +531,7 @@ class AbstractTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'a' => Type::string(),
|
'a' => Type::string(),
|
||||||
],
|
],
|
||||||
'resolveType' => function () use (&$createTest) {
|
'resolveType' => static function () use (&$createTest) {
|
||||||
return $createTest();
|
return $createTest();
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -91,7 +91,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
|
|
||||||
return Utils::find(
|
return Utils::find(
|
||||||
$this->userDataSource,
|
$this->userDataSource,
|
||||||
function ($entry) use ($user) {
|
static function ($entry) use ($user) {
|
||||||
return $entry['id'] === $user['bestFriendId'];
|
return $entry['id'] === $user['bestFriendId'];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -123,7 +123,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
|
|
||||||
return Utils::find(
|
return Utils::find(
|
||||||
$this->userDataSource,
|
$this->userDataSource,
|
||||||
function ($entry) use ($story) {
|
static function ($entry) use ($story) {
|
||||||
return $entry['id'] === $story['authorId'];
|
return $entry['id'] === $story['authorId'];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -152,7 +152,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
|
|
||||||
return Utils::filter(
|
return Utils::filter(
|
||||||
$this->storyDataSource,
|
$this->storyDataSource,
|
||||||
function ($story) use ($category) {
|
static function ($story) use ($category) {
|
||||||
return in_array($category['id'], $story['categoryIds']);
|
return in_array($category['id'], $story['categoryIds']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -168,7 +168,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
|
|
||||||
return Utils::find(
|
return Utils::find(
|
||||||
$this->storyDataSource,
|
$this->storyDataSource,
|
||||||
function ($story) use ($category) {
|
static function ($story) use ($category) {
|
||||||
return $story['id'] === $category['topStoryId'];
|
return $story['id'] === $category['topStoryId'];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -188,7 +188,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
|
|
||||||
return Utils::filter(
|
return Utils::filter(
|
||||||
$this->storyDataSource,
|
$this->storyDataSource,
|
||||||
function ($story) {
|
static function ($story) {
|
||||||
return $story['id'] % 2 === 1;
|
return $story['id'] % 2 === 1;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -33,6 +33,7 @@ class DirectivesTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Source|string $doc
|
* @param Source|string $doc
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
private function executeTestQuery($doc) : array
|
private function executeTestQuery($doc) : array
|
||||||
|
@ -64,7 +64,7 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
// isTypeOf used to resolve runtime type for Interface
|
// isTypeOf used to resolve runtime type for Interface
|
||||||
$petType = new InterfaceType([
|
$petType = new InterfaceType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
];
|
];
|
||||||
@ -75,10 +75,10 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
$dogType = new ObjectType([
|
$dogType = new ObjectType([
|
||||||
'name' => 'Dog',
|
'name' => 'Dog',
|
||||||
'interfaces' => [$petType],
|
'interfaces' => [$petType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Dog;
|
return $obj instanceof Dog;
|
||||||
},
|
},
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
'woofs' => ['type' => Type::boolean()],
|
'woofs' => ['type' => Type::boolean()],
|
||||||
@ -89,10 +89,10 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
$catType = new ObjectType([
|
$catType = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'interfaces' => [$petType],
|
'interfaces' => [$petType],
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Cat;
|
return $obj instanceof Cat;
|
||||||
},
|
},
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
'meows' => ['type' => Type::boolean()],
|
'meows' => ['type' => Type::boolean()],
|
||||||
@ -106,14 +106,14 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'pets' => [
|
'pets' => [
|
||||||
'type' => Type::listOf($petType),
|
'type' => Type::listOf($petType),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
return [new Dog('Odie', true), new Cat('Garfield', false)];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]),
|
]),
|
||||||
'types' => [$catType, $dogType],
|
'types' => [$catType, $dogType],
|
||||||
'typeLoader' => function ($name) use ($dogType, $petType, $catType) {
|
'typeLoader' => static function ($name) use ($dogType, $petType, $catType) {
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'Dog':
|
case 'Dog':
|
||||||
return $dogType;
|
return $dogType;
|
||||||
@ -165,13 +165,13 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
public function testHintsOnConflictingTypeInstancesInDefinitions() : void
|
public function testHintsOnConflictingTypeInstancesInDefinitions() : void
|
||||||
{
|
{
|
||||||
$calls = [];
|
$calls = [];
|
||||||
$typeLoader = function ($name) use (&$calls) {
|
$typeLoader = static function ($name) use (&$calls) {
|
||||||
$calls[] = $name;
|
$calls[] = $name;
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'Test':
|
case 'Test':
|
||||||
return new ObjectType([
|
return new ObjectType([
|
||||||
'name' => 'Test',
|
'name' => 'Test',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'test' => Type::string(),
|
'test' => Type::string(),
|
||||||
];
|
];
|
||||||
@ -184,7 +184,7 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
|
|
||||||
$query = new ObjectType([
|
$query = new ObjectType([
|
||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
'fields' => function () use ($typeLoader) {
|
'fields' => static function () use ($typeLoader) {
|
||||||
return [
|
return [
|
||||||
'test' => $typeLoader('Test'),
|
'test' => $typeLoader('Test'),
|
||||||
];
|
];
|
||||||
@ -311,13 +311,13 @@ class ExecutorLazySchemaTest extends TestCase
|
|||||||
case 'SomeScalar':
|
case 'SomeScalar':
|
||||||
return $this->someScalarType ?: $this->someScalarType = new CustomScalarType([
|
return $this->someScalarType ?: $this->someScalarType = new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => function ($value) {
|
'serialize' => static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
},
|
},
|
||||||
'parseValue' => function ($value) {
|
'parseValue' => static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
},
|
},
|
||||||
'parseLiteral' => function () {
|
'parseLiteral' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
case 'SomeUnion':
|
case 'SomeUnion':
|
||||||
|
@ -32,14 +32,14 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
|
|
||||||
$BlogAuthor = new ObjectType([
|
$BlogAuthor = new ObjectType([
|
||||||
'name' => 'Author',
|
'name' => 'Author',
|
||||||
'fields' => function () use (&$BlogArticle, &$BlogImage) {
|
'fields' => static function () use (&$BlogArticle, &$BlogImage) {
|
||||||
return [
|
return [
|
||||||
'id' => ['type' => Type::string()],
|
'id' => ['type' => Type::string()],
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
'pic' => [
|
'pic' => [
|
||||||
'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]],
|
'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]],
|
||||||
'type' => $BlogImage,
|
'type' => $BlogImage,
|
||||||
'resolve' => function ($obj, $args) {
|
'resolve' => static function ($obj, $args) {
|
||||||
return $obj['pic']($args['width'], $args['height']);
|
return $obj['pic']($args['width'], $args['height']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -201,7 +201,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
private function article($id)
|
private function article($id)
|
||||||
{
|
{
|
||||||
$johnSmith = null;
|
$johnSmith = null;
|
||||||
$article = function ($id) use (&$johnSmith) {
|
$article = static function ($id) use (&$johnSmith) {
|
||||||
return [
|
return [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'isPublished' => 'true',
|
'isPublished' => 'true',
|
||||||
@ -213,7 +213,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
$getPic = function ($uid, $width, $height) {
|
$getPic = static function ($uid, $width, $height) {
|
||||||
return [
|
return [
|
||||||
'url' => sprintf('cdn://%s', $uid),
|
'url' => sprintf('cdn://%s', $uid),
|
||||||
'width' => $width,
|
'width' => $width,
|
||||||
@ -224,7 +224,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
$johnSmith = [
|
$johnSmith = [
|
||||||
'id' => 123,
|
'id' => 123,
|
||||||
'name' => 'John Smith',
|
'name' => 'John Smith',
|
||||||
'pic' => function ($width, $height) use ($getPic) {
|
'pic' => static function ($width, $height) use ($getPic) {
|
||||||
return $getPic(123, $width, $height);
|
return $getPic(123, $width, $height);
|
||||||
},
|
},
|
||||||
'recentArticle' => $article(1),
|
'recentArticle' => $article(1),
|
||||||
|
@ -17,6 +17,7 @@ use GraphQL\Type\Definition\ResolveInfo;
|
|||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
use function array_keys;
|
use function array_keys;
|
||||||
use function count;
|
use function count;
|
||||||
use function json_encode;
|
use function json_encode;
|
||||||
@ -38,52 +39,52 @@ class ExecutorTest extends TestCase
|
|||||||
$deepData = null;
|
$deepData = null;
|
||||||
$data = null;
|
$data = null;
|
||||||
|
|
||||||
$promiseData = function () use (&$data) {
|
$promiseData = static function () use (&$data) {
|
||||||
return new Deferred(function () use (&$data) {
|
return new Deferred(static function () use (&$data) {
|
||||||
return $data;
|
return $data;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'a' => function () {
|
'a' => static function () {
|
||||||
return 'Apple';
|
return 'Apple';
|
||||||
},
|
},
|
||||||
'b' => function () {
|
'b' => static function () {
|
||||||
return 'Banana';
|
return 'Banana';
|
||||||
},
|
},
|
||||||
'c' => function () {
|
'c' => static function () {
|
||||||
return 'Cookie';
|
return 'Cookie';
|
||||||
},
|
},
|
||||||
'd' => function () {
|
'd' => static function () {
|
||||||
return 'Donut';
|
return 'Donut';
|
||||||
},
|
},
|
||||||
'e' => function () {
|
'e' => static function () {
|
||||||
return 'Egg';
|
return 'Egg';
|
||||||
},
|
},
|
||||||
'f' => 'Fish',
|
'f' => 'Fish',
|
||||||
'pic' => function ($size = 50) {
|
'pic' => static function ($size = 50) {
|
||||||
return 'Pic of size: ' . $size;
|
return 'Pic of size: ' . $size;
|
||||||
},
|
},
|
||||||
'promise' => function () use ($promiseData) {
|
'promise' => static function () use ($promiseData) {
|
||||||
return $promiseData();
|
return $promiseData();
|
||||||
},
|
},
|
||||||
'deep' => function () use (&$deepData) {
|
'deep' => static function () use (&$deepData) {
|
||||||
return $deepData;
|
return $deepData;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// Required for that & reference above
|
// Required for that & reference above
|
||||||
$deepData = [
|
$deepData = [
|
||||||
'a' => function () {
|
'a' => static function () {
|
||||||
return 'Already Been Done';
|
return 'Already Been Done';
|
||||||
},
|
},
|
||||||
'b' => function () {
|
'b' => static function () {
|
||||||
return 'Boring';
|
return 'Boring';
|
||||||
},
|
},
|
||||||
'c' => function () {
|
'c' => static function () {
|
||||||
return ['Contrived', null, 'Confusing'];
|
return ['Contrived', null, 'Confusing'];
|
||||||
},
|
},
|
||||||
'deeper' => function () use (&$data) {
|
'deeper' => static function () use (&$data) {
|
||||||
return [$data, null, $data];
|
return [$data, null, $data];
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -145,7 +146,7 @@ class ExecutorTest extends TestCase
|
|||||||
$deepDataType = null;
|
$deepDataType = null;
|
||||||
$dataType = new ObjectType([
|
$dataType = new ObjectType([
|
||||||
'name' => 'DataType',
|
'name' => 'DataType',
|
||||||
'fields' => function () use (&$dataType, &$deepDataType) {
|
'fields' => static function () use (&$dataType, &$deepDataType) {
|
||||||
return [
|
return [
|
||||||
'a' => ['type' => Type::string()],
|
'a' => ['type' => Type::string()],
|
||||||
'b' => ['type' => Type::string()],
|
'b' => ['type' => Type::string()],
|
||||||
@ -156,7 +157,7 @@ class ExecutorTest extends TestCase
|
|||||||
'pic' => [
|
'pic' => [
|
||||||
'args' => ['size' => ['type' => Type::int()]],
|
'args' => ['size' => ['type' => Type::int()]],
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($obj, $args) {
|
'resolve' => static function ($obj, $args) {
|
||||||
return $obj['pic']($args['size']);
|
return $obj['pic']($args['size']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -205,29 +206,29 @@ class ExecutorTest extends TestCase
|
|||||||
|
|
||||||
$Type = new ObjectType([
|
$Type = new ObjectType([
|
||||||
'name' => 'Type',
|
'name' => 'Type',
|
||||||
'fields' => function () use (&$Type) {
|
'fields' => static function () use (&$Type) {
|
||||||
return [
|
return [
|
||||||
'a' => [
|
'a' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 'Apple';
|
return 'Apple';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'b' => [
|
'b' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 'Banana';
|
return 'Banana';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'c' => [
|
'c' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 'Cherry';
|
return 'Cherry';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'deep' => [
|
'deep' => [
|
||||||
'type' => $Type,
|
'type' => $Type,
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -270,7 +271,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'test' => [
|
'test' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($val, $args, $ctx, $_info) use (&$info) {
|
'resolve' => static function ($val, $args, $ctx, $_info) use (&$info) {
|
||||||
$info = $_info;
|
$info = $_info;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -329,7 +330,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'a' => [
|
'a' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($context) use (&$gotHere) {
|
'resolve' => static function ($context) use (&$gotHere) {
|
||||||
self::assertEquals('thing', $context['contextThing']);
|
self::assertEquals('thing', $context['contextThing']);
|
||||||
$gotHere = true;
|
$gotHere = true;
|
||||||
},
|
},
|
||||||
@ -366,7 +367,7 @@ class ExecutorTest extends TestCase
|
|||||||
'stringArg' => ['type' => Type::string()],
|
'stringArg' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($_, $args) use (&$gotHere) {
|
'resolve' => static function ($_, $args) use (&$gotHere) {
|
||||||
self::assertEquals(123, $args['numArg']);
|
self::assertEquals(123, $args['numArg']);
|
||||||
self::assertEquals('foo', $args['stringArg']);
|
self::assertEquals('foo', $args['stringArg']);
|
||||||
$gotHere = true;
|
$gotHere = true;
|
||||||
@ -400,21 +401,21 @@ class ExecutorTest extends TestCase
|
|||||||
}';
|
}';
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'sync' => function () {
|
'sync' => static function () {
|
||||||
return 'sync';
|
return 'sync';
|
||||||
},
|
},
|
||||||
'syncError' => function () {
|
'syncError' => static function () {
|
||||||
throw new UserError('Error getting syncError');
|
throw new UserError('Error getting syncError');
|
||||||
},
|
},
|
||||||
'syncRawError' => function () {
|
'syncRawError' => static function () {
|
||||||
throw new UserError('Error getting syncRawError');
|
throw new UserError('Error getting syncRawError');
|
||||||
},
|
},
|
||||||
// inherited from JS reference implementation, but make no sense in this PHP impl
|
// inherited from JS reference implementation, but make no sense in this PHP impl
|
||||||
// leaving it just to simplify migrations from newer js versions
|
// leaving it just to simplify migrations from newer js versions
|
||||||
'syncReturnError' => function () {
|
'syncReturnError' => static function () {
|
||||||
return new UserError('Error getting syncReturnError');
|
return new UserError('Error getting syncReturnError');
|
||||||
},
|
},
|
||||||
'syncReturnErrorList' => function () {
|
'syncReturnErrorList' => static function () {
|
||||||
return [
|
return [
|
||||||
'sync0',
|
'sync0',
|
||||||
new UserError('Error getting syncReturnErrorList1'),
|
new UserError('Error getting syncReturnErrorList1'),
|
||||||
@ -422,40 +423,40 @@ class ExecutorTest extends TestCase
|
|||||||
new UserError('Error getting syncReturnErrorList3'),
|
new UserError('Error getting syncReturnErrorList3'),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'async' => function () {
|
'async' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return 'async';
|
return 'async';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'asyncReject' => function () {
|
'asyncReject' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('Error getting asyncReject');
|
throw new UserError('Error getting asyncReject');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'asyncRawReject' => function () {
|
'asyncRawReject' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('Error getting asyncRawReject');
|
throw new UserError('Error getting asyncRawReject');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'asyncEmptyReject' => function () {
|
'asyncEmptyReject' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError();
|
throw new UserError();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'asyncError' => function () {
|
'asyncError' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('Error getting asyncError');
|
throw new UserError('Error getting asyncError');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// inherited from JS reference implementation, but make no sense in this PHP impl
|
// inherited from JS reference implementation, but make no sense in this PHP impl
|
||||||
// leaving it just to simplify migrations from newer js versions
|
// leaving it just to simplify migrations from newer js versions
|
||||||
'asyncRawError' => function () {
|
'asyncRawError' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('Error getting asyncRawError');
|
throw new UserError('Error getting asyncRawError');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'asyncReturnError' => function () {
|
'asyncReturnError' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('Error getting asyncReturnError');
|
throw new UserError('Error getting asyncReturnError');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -805,23 +806,23 @@ class ExecutorTest extends TestCase
|
|||||||
e
|
e
|
||||||
}';
|
}';
|
||||||
$data = [
|
$data = [
|
||||||
'a' => function () {
|
'a' => static function () {
|
||||||
return 'a';
|
return 'a';
|
||||||
},
|
},
|
||||||
'b' => function () {
|
'b' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return 'b';
|
return 'b';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'c' => function () {
|
'c' => static function () {
|
||||||
return 'c';
|
return 'c';
|
||||||
},
|
},
|
||||||
'd' => function () {
|
'd' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return 'd';
|
return 'd';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'e' => function () {
|
'e' => static function () {
|
||||||
return 'e';
|
return 'e';
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -923,7 +924,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'field' => [
|
'field' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($data, $args) {
|
'resolve' => static function ($data, $args) {
|
||||||
return $args ? json_encode($args) : '';
|
return $args ? json_encode($args) : '';
|
||||||
},
|
},
|
||||||
'args' => [
|
'args' => [
|
||||||
@ -954,7 +955,7 @@ class ExecutorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$SpecialType = new ObjectType([
|
$SpecialType = new ObjectType([
|
||||||
'name' => 'SpecialType',
|
'name' => 'SpecialType',
|
||||||
'isTypeOf' => function ($obj) {
|
'isTypeOf' => static function ($obj) {
|
||||||
return $obj instanceof Special;
|
return $obj instanceof Special;
|
||||||
},
|
},
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -968,7 +969,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'specials' => [
|
'specials' => [
|
||||||
'type' => Type::listOf($SpecialType),
|
'type' => Type::listOf($SpecialType),
|
||||||
'resolve' => function ($rootValue) {
|
'resolve' => static function ($rootValue) {
|
||||||
return $rootValue['specials'];
|
return $rootValue['specials'];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -1049,7 +1050,7 @@ class ExecutorTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// For the purposes of test, just return the name of the field!
|
// 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;
|
return $info->fieldName;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1078,7 +1079,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'field' => [
|
'field' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($data, $args) {
|
'resolve' => static function ($data, $args) {
|
||||||
return $args ? json_encode($args) : '';
|
return $args ? json_encode($args) : '';
|
||||||
},
|
},
|
||||||
'args' => [
|
'args' => [
|
||||||
@ -1125,7 +1126,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'id' => Type::id(),
|
'id' => Type::id(),
|
||||||
],
|
],
|
||||||
'interfaces' => function () use (&$iface) {
|
'interfaces' => static function () use (&$iface) {
|
||||||
return [$iface];
|
return [$iface];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -1135,7 +1136,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'id' => Type::id(),
|
'id' => Type::id(),
|
||||||
],
|
],
|
||||||
'interfaces' => function () use (&$iface) {
|
'interfaces' => static function () use (&$iface) {
|
||||||
return [$iface];
|
return [$iface];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -1145,7 +1146,7 @@ class ExecutorTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'id' => Type::id(),
|
'id' => Type::id(),
|
||||||
],
|
],
|
||||||
'resolveType' => function ($v) use ($a, $b) {
|
'resolveType' => static function ($v) use ($a, $b) {
|
||||||
return $v['type'] === 'A' ? $a : $b;
|
return $v['type'] === 'A' ? $a : $b;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -1187,8 +1188,8 @@ class ExecutorTest extends TestCase
|
|||||||
'ab' => [
|
'ab' => [
|
||||||
['id' => '1'],
|
['id' => '1'],
|
||||||
['id' => '2'],
|
['id' => '2'],
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -64,7 +64,7 @@ class LazyInterfaceTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
'lazyInterface' => [
|
'lazyInterface' => [
|
||||||
'type' => $this->getLazyInterfaceType(),
|
'type' => $this->getLazyInterfaceType(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -99,6 +99,7 @@ class LazyInterfaceTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the test ObjectType
|
* Returns the test ObjectType
|
||||||
|
*
|
||||||
* @return ObjectType
|
* @return ObjectType
|
||||||
*/
|
*/
|
||||||
protected function getTestObjectType()
|
protected function getTestObjectType()
|
||||||
@ -109,7 +110,7 @@ class LazyInterfaceTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => [
|
'name' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 'testname';
|
return 'testname';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -53,12 +53,12 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
$dataType = new ObjectType([
|
$dataType = new ObjectType([
|
||||||
'name' => 'DataType',
|
'name' => 'DataType',
|
||||||
'fields' => function () use (&$testType, &$dataType, $data) {
|
'fields' => static function () use (&$testType, &$dataType, $data) {
|
||||||
return [
|
return [
|
||||||
'test' => ['type' => $testType],
|
'test' => ['type' => $testType],
|
||||||
'nest' => [
|
'nest' => [
|
||||||
'type' => $dataType,
|
'type' => $dataType,
|
||||||
'resolve' => function () use ($data) {
|
'resolve' => static function () use ($data) {
|
||||||
return $data;
|
return $data;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -81,7 +81,7 @@ class ListsTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, 2];
|
return [1, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, 2]]]]
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
||||||
@ -89,7 +89,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, null, 2];
|
return [1, null, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
||||||
@ -97,7 +97,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Returns null
|
// Returns null
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => null]]]
|
['data' => ['nest' => ['test' => null]]]
|
||||||
@ -105,8 +105,8 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Rejected
|
// Rejected
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
function () {
|
static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -131,10 +131,10 @@ class ListsTest extends TestCase
|
|||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -144,13 +144,13 @@ class ListsTest extends TestCase
|
|||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -159,7 +159,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Returns null
|
// Returns null
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => null]]]
|
['data' => ['nest' => ['test' => null]]]
|
||||||
@ -167,15 +167,15 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains reject
|
// Contains reject
|
||||||
$this->checkHandlesNullableLists(
|
$this->checkHandlesNullableLists(
|
||||||
function () {
|
static function () {
|
||||||
return [
|
return [
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
@ -239,7 +239,7 @@ class ListsTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, 2];
|
return [1, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, 2]]]]
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
||||||
@ -247,7 +247,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, null, 2];
|
return [1, null, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
||||||
@ -270,8 +270,8 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Rejected
|
// Rejected
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
function () {
|
static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -296,10 +296,10 @@ class ListsTest extends TestCase
|
|||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -309,13 +309,13 @@ class ListsTest extends TestCase
|
|||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -324,15 +324,15 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains reject
|
// Contains reject
|
||||||
$this->checkHandlesNonNullableLists(
|
$this->checkHandlesNonNullableLists(
|
||||||
function () {
|
static function () {
|
||||||
return [
|
return [
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
@ -396,7 +396,7 @@ class ListsTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, 2];
|
return [1, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, 2]]]]
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
||||||
@ -404,7 +404,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, null, 2];
|
return [1, null, 2];
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@ -421,7 +421,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Returns null
|
// Returns null
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => null]]]
|
['data' => ['nest' => ['test' => null]]]
|
||||||
@ -429,8 +429,8 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Rejected
|
// Rejected
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
function () {
|
static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -455,10 +455,10 @@ class ListsTest extends TestCase
|
|||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -468,13 +468,13 @@ class ListsTest extends TestCase
|
|||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -483,15 +483,15 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains reject
|
// Contains reject
|
||||||
$this->checkHandlesListOfNonNulls(
|
$this->checkHandlesListOfNonNulls(
|
||||||
function () {
|
static function () {
|
||||||
return [
|
return [
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
@ -564,7 +564,7 @@ class ListsTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, 2];
|
return [1, 2];
|
||||||
}),
|
}),
|
||||||
['data' => ['nest' => ['test' => [1, 2]]]]
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
||||||
@ -572,7 +572,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return [1, null, 2];
|
return [1, null, 2];
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@ -589,7 +589,7 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Returns null
|
// Returns null
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@ -606,8 +606,8 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Rejected
|
// Rejected
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
function () {
|
static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -632,10 +632,10 @@ class ListsTest extends TestCase
|
|||||||
// Contains values
|
// Contains values
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -646,13 +646,13 @@ class ListsTest extends TestCase
|
|||||||
// Contains null
|
// Contains null
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
[
|
[
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -670,15 +670,15 @@ class ListsTest extends TestCase
|
|||||||
|
|
||||||
// Contains reject
|
// Contains reject
|
||||||
$this->checkHandlesNonNullListOfNonNulls(
|
$this->checkHandlesNonNullListOfNonNulls(
|
||||||
function () {
|
static function () {
|
||||||
return [
|
return [
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 1;
|
return 1;
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
throw new UserError('bad');
|
throw new UserError('bad');
|
||||||
}),
|
}),
|
||||||
new Deferred(function () {
|
new Deferred(static function () {
|
||||||
return 2;
|
return 2;
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
@ -59,7 +59,7 @@ class MutationsTest extends TestCase
|
|||||||
],
|
],
|
||||||
'name' => 'NumberHolder',
|
'name' => 'NumberHolder',
|
||||||
]);
|
]);
|
||||||
$schema = new Schema([
|
return new Schema([
|
||||||
'query' => new ObjectType([
|
'query' => new ObjectType([
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'numberHolder' => ['type' => $numberHolderType],
|
'numberHolder' => ['type' => $numberHolderType],
|
||||||
@ -71,28 +71,28 @@ class MutationsTest extends TestCase
|
|||||||
'immediatelyChangeTheNumber' => [
|
'immediatelyChangeTheNumber' => [
|
||||||
'type' => $numberHolderType,
|
'type' => $numberHolderType,
|
||||||
'args' => ['newNumber' => ['type' => Type::int()]],
|
'args' => ['newNumber' => ['type' => Type::int()]],
|
||||||
'resolve' => function (Root $obj, $args) {
|
'resolve' => static function (Root $obj, $args) {
|
||||||
return $obj->immediatelyChangeTheNumber($args['newNumber']);
|
return $obj->immediatelyChangeTheNumber($args['newNumber']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'promiseToChangeTheNumber' => [
|
'promiseToChangeTheNumber' => [
|
||||||
'type' => $numberHolderType,
|
'type' => $numberHolderType,
|
||||||
'args' => ['newNumber' => ['type' => Type::int()]],
|
'args' => ['newNumber' => ['type' => Type::int()]],
|
||||||
'resolve' => function (Root $obj, $args) {
|
'resolve' => static function (Root $obj, $args) {
|
||||||
return $obj->promiseToChangeTheNumber($args['newNumber']);
|
return $obj->promiseToChangeTheNumber($args['newNumber']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'failToChangeTheNumber' => [
|
'failToChangeTheNumber' => [
|
||||||
'type' => $numberHolderType,
|
'type' => $numberHolderType,
|
||||||
'args' => ['newNumber' => ['type' => Type::int()]],
|
'args' => ['newNumber' => ['type' => Type::int()]],
|
||||||
'resolve' => function (Root $obj, $args) {
|
'resolve' => static function (Root $obj, $args) {
|
||||||
$obj->failToChangeTheNumber();
|
$obj->failToChangeTheNumber();
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'promiseAndFailToChangeTheNumber' => [
|
'promiseAndFailToChangeTheNumber' => [
|
||||||
'type' => $numberHolderType,
|
'type' => $numberHolderType,
|
||||||
'args' => ['newNumber' => ['type' => Type::int()]],
|
'args' => ['newNumber' => ['type' => Type::int()]],
|
||||||
'resolve' => function (Root $obj, $args) {
|
'resolve' => static function (Root $obj, $args) {
|
||||||
return $obj->promiseAndFailToChangeTheNumber();
|
return $obj->promiseAndFailToChangeTheNumber();
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -100,8 +100,6 @@ class MutationsTest extends TestCase
|
|||||||
'name' => 'Mutation',
|
'name' => 'Mutation',
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Executor;
|
namespace GraphQL\Tests\Executor;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Deferred;
|
use GraphQL\Deferred;
|
||||||
use GraphQL\Error\FormattedError;
|
use GraphQL\Error\FormattedError;
|
||||||
use GraphQL\Error\UserError;
|
use GraphQL\Error\UserError;
|
||||||
@ -17,16 +18,16 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class NonNullTest extends TestCase
|
class NonNullTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var \Exception */
|
/** @var Exception */
|
||||||
public $syncError;
|
public $syncError;
|
||||||
|
|
||||||
/** @var \Exception */
|
/** @var Exception */
|
||||||
public $syncNonNullError;
|
public $syncNonNullError;
|
||||||
|
|
||||||
/** @var \Exception */
|
/** @var Exception */
|
||||||
public $promiseError;
|
public $promiseError;
|
||||||
|
|
||||||
/** @var \Exception */
|
/** @var Exception */
|
||||||
public $promiseNonNullError;
|
public $promiseNonNullError;
|
||||||
|
|
||||||
/** @var callable[] */
|
/** @var callable[] */
|
||||||
@ -81,19 +82,19 @@ class NonNullTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$this->nullingData = [
|
$this->nullingData = [
|
||||||
'sync' => function () {
|
'sync' => static function () {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
'syncNonNull' => function () {
|
'syncNonNull' => static function () {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
'promise' => function () {
|
'promise' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'promiseNonNull' => function () {
|
'promiseNonNull' => static function () {
|
||||||
return new Deferred(function () {
|
return new Deferred(static function () {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -117,7 +118,7 @@ class NonNullTest extends TestCase
|
|||||||
|
|
||||||
$dataType = new ObjectType([
|
$dataType = new ObjectType([
|
||||||
'name' => 'DataType',
|
'name' => 'DataType',
|
||||||
'fields' => function () use (&$dataType) {
|
'fields' => static function () use (&$dataType) {
|
||||||
return [
|
return [
|
||||||
'sync' => ['type' => Type::string()],
|
'sync' => ['type' => Type::string()],
|
||||||
'syncNonNull' => ['type' => Type::nonNull(Type::string())],
|
'syncNonNull' => ['type' => Type::nonNull(Type::string())],
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Executor\Promise;
|
namespace GraphQL\Tests\Executor\Promise;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
|
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use React\Promise\Deferred;
|
use React\Promise\Deferred;
|
||||||
@ -11,6 +12,7 @@ use React\Promise\FulfilledPromise;
|
|||||||
use React\Promise\LazyPromise;
|
use React\Promise\LazyPromise;
|
||||||
use React\Promise\Promise as ReactPromise;
|
use React\Promise\Promise as ReactPromise;
|
||||||
use React\Promise\RejectedPromise;
|
use React\Promise\RejectedPromise;
|
||||||
|
use stdClass;
|
||||||
use function class_exists;
|
use function class_exists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,13 +34,13 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
$reactAdapter = new ReactPromiseAdapter();
|
$reactAdapter = new ReactPromiseAdapter();
|
||||||
|
|
||||||
self::assertTrue(
|
self::assertTrue(
|
||||||
$reactAdapter->isThenable(new ReactPromise(function () {
|
$reactAdapter->isThenable(new ReactPromise(static function () {
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
self::assertTrue($reactAdapter->isThenable(new FulfilledPromise()));
|
self::assertTrue($reactAdapter->isThenable(new FulfilledPromise()));
|
||||||
self::assertTrue($reactAdapter->isThenable(new RejectedPromise()));
|
self::assertTrue($reactAdapter->isThenable(new RejectedPromise()));
|
||||||
self::assertTrue(
|
self::assertTrue(
|
||||||
$reactAdapter->isThenable(new LazyPromise(function () {
|
$reactAdapter->isThenable(new LazyPromise(static function () {
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
self::assertFalse($reactAdapter->isThenable(false));
|
self::assertFalse($reactAdapter->isThenable(false));
|
||||||
@ -48,7 +50,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
self::assertFalse($reactAdapter->isThenable('test'));
|
self::assertFalse($reactAdapter->isThenable('test'));
|
||||||
self::assertFalse($reactAdapter->isThenable(''));
|
self::assertFalse($reactAdapter->isThenable(''));
|
||||||
self::assertFalse($reactAdapter->isThenable([]));
|
self::assertFalse($reactAdapter->isThenable([]));
|
||||||
self::assertFalse($reactAdapter->isThenable(new \stdClass()));
|
self::assertFalse($reactAdapter->isThenable(new stdClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConvertsReactPromisesToGraphQlOnes() : void
|
public function testConvertsReactPromisesToGraphQlOnes() : void
|
||||||
@ -72,7 +74,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
$resultPromise = $reactAdapter->then(
|
$resultPromise = $reactAdapter->then(
|
||||||
$promise,
|
$promise,
|
||||||
function ($value) use (&$result) {
|
static function ($value) use (&$result) {
|
||||||
$result = $value;
|
$result = $value;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -85,7 +87,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
public function testCreate() : void
|
public function testCreate() : void
|
||||||
{
|
{
|
||||||
$reactAdapter = new ReactPromiseAdapter();
|
$reactAdapter = new ReactPromiseAdapter();
|
||||||
$resolvedPromise = $reactAdapter->create(function ($resolve) {
|
$resolvedPromise = $reactAdapter->create(static function ($resolve) {
|
||||||
$resolve(1);
|
$resolve(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,7 +96,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
$resolvedPromise->then(function ($value) use (&$result) {
|
$resolvedPromise->then(static function ($value) use (&$result) {
|
||||||
$result = $value;
|
$result = $value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -111,7 +113,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
$fulfilledPromise->then(function ($value) use (&$result) {
|
$fulfilledPromise->then(static function ($value) use (&$result) {
|
||||||
$result = $value;
|
$result = $value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
public function testCreateRejected() : void
|
public function testCreateRejected() : void
|
||||||
{
|
{
|
||||||
$reactAdapter = new ReactPromiseAdapter();
|
$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('GraphQL\Executor\Promise\Promise', $rejectedPromise);
|
||||||
self::assertInstanceOf('React\Promise\RejectedPromise', $rejectedPromise->adoptedPromise);
|
self::assertInstanceOf('React\Promise\RejectedPromise', $rejectedPromise->adoptedPromise);
|
||||||
@ -130,7 +132,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
$rejectedPromise->then(
|
$rejectedPromise->then(
|
||||||
null,
|
null,
|
||||||
function ($error) use (&$exception) {
|
static function ($error) use (&$exception) {
|
||||||
$exception = $error;
|
$exception = $error;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -151,7 +153,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
$allPromise->then(function ($values) use (&$result) {
|
$allPromise->then(static function ($values) use (&$result) {
|
||||||
$result = $values;
|
$result = $values;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
$promises = [new FulfilledPromise(1), $deferred->promise(), new FulfilledPromise(3)];
|
$promises = [new FulfilledPromise(1), $deferred->promise(), new FulfilledPromise(3)];
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
$reactAdapter->all($promises)->then(function ($values) use (&$result) {
|
$reactAdapter->all($promises)->then(static function ($values) use (&$result) {
|
||||||
$result = $values;
|
$result = $values;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,12 +4,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Executor\Promise;
|
namespace GraphQL\Tests\Executor\Promise;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Deferred;
|
use GraphQL\Deferred;
|
||||||
use GraphQL\Error\InvariantViolation;
|
use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Executor\Promise\Adapter\SyncPromise;
|
use GraphQL\Executor\Promise\Adapter\SyncPromise;
|
||||||
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
|
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
|
||||||
use GraphQL\Executor\Promise\Promise;
|
use GraphQL\Executor\Promise\Promise;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class SyncPromiseAdapterTest extends TestCase
|
class SyncPromiseAdapterTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -25,7 +28,7 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
{
|
{
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
true,
|
true,
|
||||||
$this->promises->isThenable(new Deferred(function () {
|
$this->promises->isThenable(new Deferred(static function () {
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
self::assertEquals(false, $this->promises->isThenable(false));
|
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('test'));
|
||||||
self::assertEquals(false, $this->promises->isThenable(''));
|
self::assertEquals(false, $this->promises->isThenable(''));
|
||||||
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
|
public function testConvert() : void
|
||||||
{
|
{
|
||||||
$dfd = new Deferred(function () {
|
$dfd = new Deferred(static function () {
|
||||||
});
|
});
|
||||||
$result = $this->promises->convertThenable($dfd);
|
$result = $this->promises->convertThenable($dfd);
|
||||||
|
|
||||||
@ -54,7 +57,7 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
public function testThen() : void
|
public function testThen() : void
|
||||||
{
|
{
|
||||||
$dfd = new Deferred(function () {
|
$dfd = new Deferred(static function () {
|
||||||
});
|
});
|
||||||
$promise = $this->promises->convertThenable($dfd);
|
$promise = $this->promises->convertThenable($dfd);
|
||||||
|
|
||||||
@ -66,13 +69,13 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
public function testCreatePromise() : void
|
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\Promise', $promise);
|
||||||
self::assertInstanceOf('GraphQL\Executor\Promise\Adapter\SyncPromise', $promise->adoptedPromise);
|
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');
|
$resolve('A');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -90,11 +93,11 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
$onRejectedCalled = false;
|
$onRejectedCalled = false;
|
||||||
|
|
||||||
$promise->then(
|
$promise->then(
|
||||||
function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) {
|
static function ($nextValue) use (&$actualNextValue, &$onFulfilledCalled) {
|
||||||
$onFulfilledCalled = true;
|
$onFulfilledCalled = true;
|
||||||
$actualNextValue = $nextValue;
|
$actualNextValue = $nextValue;
|
||||||
},
|
},
|
||||||
function (\Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
|
static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
|
||||||
$onRejectedCalled = true;
|
$onRejectedCalled = true;
|
||||||
$actualNextReason = $reason->getMessage();
|
$actualNextReason = $reason->getMessage();
|
||||||
}
|
}
|
||||||
@ -123,7 +126,7 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
|
|
||||||
public function testCreateRejectedPromise() : void
|
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);
|
self::assertValidPromise($promise, 'test reason', null, SyncPromise::REJECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +141,7 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
$promise1 = new SyncPromise();
|
$promise1 = new SyncPromise();
|
||||||
$promise2 = new SyncPromise();
|
$promise2 = new SyncPromise();
|
||||||
$promise3 = $promise2->then(
|
$promise3 = $promise2->then(
|
||||||
function ($value) {
|
static function ($value) {
|
||||||
return $value . '-value3';
|
return $value . '-value3';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -170,12 +173,12 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
{
|
{
|
||||||
$called = [];
|
$called = [];
|
||||||
|
|
||||||
$deferred1 = new Deferred(function () use (&$called) {
|
$deferred1 = new Deferred(static function () use (&$called) {
|
||||||
$called[] = 1;
|
$called[] = 1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
$deferred2 = new Deferred(function () use (&$called) {
|
$deferred2 = new Deferred(static function () use (&$called) {
|
||||||
$called[] = 2;
|
$called[] = 2;
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
@ -185,7 +188,7 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
$p2 = $this->promises->convertThenable($deferred2);
|
$p2 = $this->promises->convertThenable($deferred2);
|
||||||
|
|
||||||
$p3 = $p2->then(function () use (&$called) {
|
$p3 = $p2->then(function () use (&$called) {
|
||||||
$dfd = new Deferred(function () use (&$called) {
|
$dfd = new Deferred(static function () use (&$called) {
|
||||||
$called[] = 3;
|
$called[] = 3;
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
@ -194,8 +197,8 @@ class SyncPromiseAdapterTest extends TestCase
|
|||||||
return $this->promises->convertThenable($dfd);
|
return $this->promises->convertThenable($dfd);
|
||||||
});
|
});
|
||||||
|
|
||||||
$p4 = $p3->then(function () use (&$called) {
|
$p4 = $p3->then(static function () use (&$called) {
|
||||||
return new Deferred(function () use (&$called) {
|
return new Deferred(static function () use (&$called) {
|
||||||
$called[] = 4;
|
$called[] = 4;
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
|
@ -4,29 +4,31 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Executor\Promise;
|
namespace GraphQL\Tests\Executor\Promise;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Executor\Promise\Adapter\SyncPromise;
|
use GraphQL\Executor\Promise\Adapter\SyncPromise;
|
||||||
use PHPUnit\Framework\Error\Error;
|
use PHPUnit\Framework\Error\Error;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Throwable;
|
||||||
use function uniqid;
|
use function uniqid;
|
||||||
|
|
||||||
class SyncPromiseTest extends TestCase
|
class SyncPromiseTest extends TestCase
|
||||||
{
|
{
|
||||||
public function getFulfilledPromiseResolveData()
|
public function getFulfilledPromiseResolveData()
|
||||||
{
|
{
|
||||||
$onFulfilledReturnsNull = function () {
|
$onFulfilledReturnsNull = static function () {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onFulfilledReturnsSameValue = function ($value) {
|
$onFulfilledReturnsSameValue = static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onFulfilledReturnsOtherValue = function ($value) {
|
$onFulfilledReturnsOtherValue = static function ($value) {
|
||||||
return 'other-' . $value;
|
return 'other-' . $value;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onFulfilledThrows = function ($value) {
|
$onFulfilledThrows = static function ($value) {
|
||||||
throw new \Exception('onFulfilled throws this!');
|
throw new Exception('onFulfilled throws this!');
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -55,7 +57,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
$promise->resolve($resolvedValue);
|
$promise->resolve($resolvedValue);
|
||||||
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
|
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
|
||||||
|
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Cannot change value of fulfilled promise');
|
$this->expectExceptionMessage('Cannot change value of fulfilled promise');
|
||||||
$promise->resolve($resolvedValue . '-other-value');
|
$promise->resolve($resolvedValue . '-other-value');
|
||||||
}
|
}
|
||||||
@ -76,9 +78,9 @@ class SyncPromiseTest extends TestCase
|
|||||||
$promise->resolve($resolvedValue);
|
$promise->resolve($resolvedValue);
|
||||||
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
|
self::assertEquals(SyncPromise::FULFILLED, $promise->state);
|
||||||
|
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Cannot reject fulfilled promise');
|
$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(
|
$nextPromise = $promise->then(
|
||||||
null,
|
null,
|
||||||
function () {
|
static function () {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
self::assertSame($promise, $nextPromise);
|
self::assertSame($promise, $nextPromise);
|
||||||
@ -107,7 +109,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
$onRejectedCalled = false;
|
$onRejectedCalled = false;
|
||||||
$nextPromise = $promise->then(
|
$nextPromise = $promise->then(
|
||||||
$onFulfilled,
|
$onFulfilled,
|
||||||
function () use (&$onRejectedCalled) {
|
static function () use (&$onRejectedCalled) {
|
||||||
$onRejectedCalled = true;
|
$onRejectedCalled = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -151,7 +153,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
$onFulfilledCalled = true;
|
$onFulfilledCalled = true;
|
||||||
$actualNextValue = $nextValue;
|
$actualNextValue = $nextValue;
|
||||||
},
|
},
|
||||||
static function (\Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
|
static function (Throwable $reason) use (&$actualNextReason, &$onRejectedCalled) {
|
||||||
$onRejectedCalled = true;
|
$onRejectedCalled = true;
|
||||||
$actualNextReason = $reason->getMessage();
|
$actualNextReason = $reason->getMessage();
|
||||||
}
|
}
|
||||||
@ -172,29 +174,29 @@ class SyncPromiseTest extends TestCase
|
|||||||
|
|
||||||
public function getRejectedPromiseData()
|
public function getRejectedPromiseData()
|
||||||
{
|
{
|
||||||
$onRejectedReturnsNull = function () {
|
$onRejectedReturnsNull = static function () {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onRejectedReturnsSomeValue = function ($reason) {
|
$onRejectedReturnsSomeValue = static function ($reason) {
|
||||||
return 'some-value';
|
return 'some-value';
|
||||||
};
|
};
|
||||||
|
|
||||||
$onRejectedThrowsSameReason = function ($reason) {
|
$onRejectedThrowsSameReason = static function ($reason) {
|
||||||
throw $reason;
|
throw $reason;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onRejectedThrowsOtherReason = function ($value) {
|
$onRejectedThrowsOtherReason = static function ($value) {
|
||||||
throw new \Exception('onRejected throws other!');
|
throw new Exception('onRejected throws other!');
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
// $rejectedReason, $onRejected, $expectedNextValue, $expectedNextReason, $expectedNextState
|
// $rejectedReason, $onRejected, $expectedNextValue, $expectedNextReason, $expectedNextState
|
||||||
[new \Exception('test-reason'), null, null, 'test-reason', 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-2'), $onRejectedReturnsNull, null, null, SyncPromise::FULFILLED],
|
||||||
[new \Exception('test-reason-3'), $onRejectedReturnsSomeValue, 'some-value', 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-4'), $onRejectedThrowsSameReason, null, 'test-reason-4', SyncPromise::REJECTED],
|
||||||
[new \Exception('test-reason-5'), $onRejectedThrowsOtherReason, null, 'onRejected throws other!', 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);
|
$promise->reject($rejectedReason);
|
||||||
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
||||||
|
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Cannot change rejection reason');
|
$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);
|
$promise->reject($rejectedReason);
|
||||||
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
||||||
|
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Cannot resolve rejected promise');
|
$this->expectExceptionMessage('Cannot resolve rejected promise');
|
||||||
$promise->resolve('anything');
|
$promise->resolve('anything');
|
||||||
}
|
}
|
||||||
@ -257,21 +259,21 @@ class SyncPromiseTest extends TestCase
|
|||||||
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
self::assertEquals(SyncPromise::REJECTED, $promise->state);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$promise->reject(new \Exception('other-reason'));
|
$promise->reject(new Exception('other-reason'));
|
||||||
$this->fail('Expected exception not thrown');
|
$this->fail('Expected exception not thrown');
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
self::assertEquals('Cannot change rejection reason', $e->getMessage());
|
self::assertEquals('Cannot change rejection reason', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$promise->resolve('anything');
|
$promise->resolve('anything');
|
||||||
$this->fail('Expected exception not thrown');
|
$this->fail('Expected exception not thrown');
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
self::assertEquals('Cannot resolve rejected promise', $e->getMessage());
|
self::assertEquals('Cannot resolve rejected promise', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$nextPromise = $promise->then(
|
$nextPromise = $promise->then(
|
||||||
function () {
|
static function () {
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@ -279,7 +281,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
|
|
||||||
$onFulfilledCalled = false;
|
$onFulfilledCalled = false;
|
||||||
$nextPromise = $promise->then(
|
$nextPromise = $promise->then(
|
||||||
function () use (&$onFulfilledCalled) {
|
static function () use (&$onFulfilledCalled) {
|
||||||
$onFulfilledCalled = true;
|
$onFulfilledCalled = true;
|
||||||
},
|
},
|
||||||
$onRejected
|
$onRejected
|
||||||
@ -315,7 +317,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$promise->resolve($promise);
|
$promise->resolve($promise);
|
||||||
$this->fail('Expected exception not thrown');
|
$this->fail('Expected exception not thrown');
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
self::assertEquals('Cannot resolve promise with self', $e->getMessage());
|
self::assertEquals('Cannot resolve promise with self', $e->getMessage());
|
||||||
self::assertEquals(SyncPromise::PENDING, $promise->state);
|
self::assertEquals(SyncPromise::PENDING, $promise->state);
|
||||||
}
|
}
|
||||||
@ -346,26 +348,26 @@ class SyncPromiseTest extends TestCase
|
|||||||
$this->fail('Expected exception not thrown');
|
$this->fail('Expected exception not thrown');
|
||||||
} catch (Error $e) {
|
} catch (Error $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
self::assertEquals(SyncPromise::PENDING, $promise->state);
|
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);
|
self::assertValidPromise($promise, 'Rejected Reason', null, SyncPromise::REJECTED);
|
||||||
|
|
||||||
$promise = new SyncPromise();
|
$promise = new SyncPromise();
|
||||||
$promise2 = $promise->then(
|
$promise2 = $promise->then(
|
||||||
null,
|
null,
|
||||||
function () {
|
static function () {
|
||||||
return 'value';
|
return 'value';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$promise->reject(new \Exception('Rejected Again'));
|
$promise->reject(new Exception('Rejected Again'));
|
||||||
self::assertValidPromise($promise2, null, 'value', SyncPromise::FULFILLED);
|
self::assertValidPromise($promise2, null, 'value', SyncPromise::FULFILLED);
|
||||||
|
|
||||||
$promise = new SyncPromise();
|
$promise = new SyncPromise();
|
||||||
$promise2 = $promise->then();
|
$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);
|
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:
|
// Make sure that it queues derivative promises until resolution:
|
||||||
$onFulfilledCount = 0;
|
$onFulfilledCount = 0;
|
||||||
$onRejectedCount = 0;
|
$onRejectedCount = 0;
|
||||||
$onFulfilled = function ($value) use (&$onFulfilledCount) {
|
$onFulfilled = static function ($value) use (&$onFulfilledCount) {
|
||||||
$onFulfilledCount++;
|
$onFulfilledCount++;
|
||||||
|
|
||||||
return $onFulfilledCount;
|
return $onFulfilledCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
$onRejected = function ($reason) use (&$onRejectedCount) {
|
$onRejected = static function ($reason) use (&$onRejectedCount) {
|
||||||
$onRejectedCount++;
|
$onRejectedCount++;
|
||||||
throw $reason;
|
throw $reason;
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ class ResolveTest extends TestCase
|
|||||||
$_secret = 'secretValue' . uniqid();
|
$_secret = 'secretValue' . uniqid();
|
||||||
|
|
||||||
$source = [
|
$source = [
|
||||||
'test' => function () use ($_secret) {
|
'test' => static function () use ($_secret) {
|
||||||
return $_secret;
|
return $_secret;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -90,7 +90,7 @@ class ResolveTest extends TestCase
|
|||||||
'aStr' => ['type' => Type::string()],
|
'aStr' => ['type' => Type::string()],
|
||||||
'aInt' => ['type' => Type::int()],
|
'aInt' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($source, $args) {
|
'resolve' => static function ($source, $args) {
|
||||||
return json_encode([$source, $args]);
|
return json_encode([$source, $args]);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -36,14 +36,14 @@ class SyncTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'syncField' => [
|
'syncField' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($rootValue) {
|
'resolve' => static function ($rootValue) {
|
||||||
return $rootValue;
|
return $rootValue;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'asyncField' => [
|
'asyncField' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($rootValue) {
|
'resolve' => static function ($rootValue) {
|
||||||
return new Deferred(function () use ($rootValue) {
|
return new Deferred(static function () use ($rootValue) {
|
||||||
return $rootValue;
|
return $rootValue;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -55,7 +55,7 @@ class SyncTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'syncMutationField' => [
|
'syncMutationField' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($rootValue) {
|
'resolve' => static function ($rootValue) {
|
||||||
return $rootValue;
|
return $rootValue;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -199,7 +199,7 @@ class SyncTest extends TestCase
|
|||||||
$expected = [
|
$expected = [
|
||||||
'errors' => Utils::map(
|
'errors' => Utils::map(
|
||||||
$validationErrors,
|
$validationErrors,
|
||||||
function ($e) {
|
static function ($e) {
|
||||||
return FormattedError::createFromException($e);
|
return FormattedError::createFromException($e);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Executor\TestClasses;
|
namespace GraphQL\Tests\Executor\TestClasses;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Deferred;
|
use GraphQL\Deferred;
|
||||||
|
|
||||||
class Root
|
class Root
|
||||||
@ -32,7 +33,7 @@ class Root
|
|||||||
|
|
||||||
public function failToChangeTheNumber() : void
|
public function failToChangeTheNumber() : void
|
||||||
{
|
{
|
||||||
throw new \Exception('Cannot change the number');
|
throw new Exception('Cannot change the number');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function promiseAndFailToChangeTheNumber() : Deferred
|
public function promiseAndFailToChangeTheNumber() : Deferred
|
||||||
|
@ -51,7 +51,7 @@ class UnionInterfaceTest extends TestCase
|
|||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
'woofs' => ['type' => Type::boolean()],
|
'woofs' => ['type' => Type::boolean()],
|
||||||
],
|
],
|
||||||
'isTypeOf' => function ($value) {
|
'isTypeOf' => static function ($value) {
|
||||||
return $value instanceof Dog;
|
return $value instanceof Dog;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -63,7 +63,7 @@ class UnionInterfaceTest extends TestCase
|
|||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
'meows' => ['type' => Type::boolean()],
|
'meows' => ['type' => Type::boolean()],
|
||||||
],
|
],
|
||||||
'isTypeOf' => function ($value) {
|
'isTypeOf' => static function ($value) {
|
||||||
return $value instanceof Cat;
|
return $value instanceof Cat;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -71,7 +71,7 @@ class UnionInterfaceTest extends TestCase
|
|||||||
$PetType = new UnionType([
|
$PetType = new UnionType([
|
||||||
'name' => 'Pet',
|
'name' => 'Pet',
|
||||||
'types' => [$DogType, $CatType],
|
'types' => [$DogType, $CatType],
|
||||||
'resolveType' => function ($value) use ($DogType, $CatType) {
|
'resolveType' => static function ($value) use ($DogType, $CatType) {
|
||||||
if ($value instanceof Dog) {
|
if ($value instanceof Dog) {
|
||||||
return $DogType;
|
return $DogType;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ class UnionInterfaceTest extends TestCase
|
|||||||
'pets' => ['type' => Type::listOf($PetType)],
|
'pets' => ['type' => Type::listOf($PetType)],
|
||||||
'friends' => ['type' => Type::listOf($NamedType)],
|
'friends' => ['type' => Type::listOf($NamedType)],
|
||||||
],
|
],
|
||||||
'isTypeOf' => function ($value) {
|
'isTypeOf' => static function ($value) {
|
||||||
return $value instanceof Person;
|
return $value instanceof Person;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -376,7 +376,7 @@ class UnionInterfaceTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolveType' => function (
|
'resolveType' => static function (
|
||||||
$obj,
|
$obj,
|
||||||
$context,
|
$context,
|
||||||
ResolveInfo $info
|
ResolveInfo $info
|
||||||
|
@ -43,6 +43,7 @@ class ValuesTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $variables
|
* @param mixed[] $variables
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
private function runTestCase($variables) : array
|
private function runTestCase($variables) : array
|
||||||
|
@ -156,7 +156,7 @@ class VariablesTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'args' => ['input' => $inputArg],
|
'args' => ['input' => $inputArg],
|
||||||
'resolve' => function ($_, $args) {
|
'resolve' => static function ($_, $args) {
|
||||||
if (isset($args['input'])) {
|
if (isset($args['input'])) {
|
||||||
return json_encode($args['input']);
|
return json_encode($args['input']);
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ class LexerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $body
|
* @param string $body
|
||||||
|
*
|
||||||
* @return Token
|
* @return Token
|
||||||
*/
|
*/
|
||||||
private function lexOne($body)
|
private function lexOne($body)
|
||||||
@ -433,8 +434,9 @@ class LexerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider reportsUsefulStringErrors
|
|
||||||
* @see it('lex reports useful string errors')
|
* @see it('lex reports useful string errors')
|
||||||
|
*
|
||||||
|
* @dataProvider reportsUsefulStringErrors
|
||||||
*/
|
*/
|
||||||
public function testLexReportsUsefulStringErrors($str, $expectedMessage, $location) : void
|
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')
|
* @see it('lex reports useful block string errors')
|
||||||
|
*
|
||||||
|
* @dataProvider reportsUsefulBlockStringErrors
|
||||||
*/
|
*/
|
||||||
public function testReportsUsefulBlockStringErrors($str, $expectedMessage, $location) : void
|
public function testReportsUsefulBlockStringErrors($str, $expectedMessage, $location) : void
|
||||||
{
|
{
|
||||||
@ -561,8 +564,9 @@ class LexerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider reportsUsefulNumberErrors
|
|
||||||
* @see it('lex reports useful number errors')
|
* @see it('lex reports useful number errors')
|
||||||
|
*
|
||||||
|
* @dataProvider reportsUsefulNumberErrors
|
||||||
*/
|
*/
|
||||||
public function testReportsUsefulNumberErrors($str, $expectedMessage, $location) : void
|
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')
|
* @see it('lex reports useful unknown character error')
|
||||||
|
*
|
||||||
|
* @dataProvider reportsUsefulUnknownCharErrors
|
||||||
*/
|
*/
|
||||||
public function testReportsUsefulUnknownCharErrors($str, $expectedMessage, $location) : void
|
public function testReportsUsefulUnknownCharErrors($str, $expectedMessage, $location) : void
|
||||||
{
|
{
|
||||||
@ -714,7 +719,7 @@ class LexerTest extends TestCase
|
|||||||
],
|
],
|
||||||
Utils::map(
|
Utils::map(
|
||||||
$tokens,
|
$tokens,
|
||||||
function ($tok) {
|
static function ($tok) {
|
||||||
return $tok->kind;
|
return $tok->kind;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,7 @@ use GraphQL\Language\Source;
|
|||||||
use GraphQL\Language\SourceLocation;
|
use GraphQL\Language\SourceLocation;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ class ParserTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(InvariantViolation::class);
|
$this->expectException(InvariantViolation::class);
|
||||||
$this->expectExceptionMessage('GraphQL query body is expected to be string, but got stdClass');
|
$this->expectExceptionMessage('GraphQL query body is expected to be string, but got stdClass');
|
||||||
Parser::parse(new \stdClass());
|
Parser::parse(new stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseProvidesUsefulErrors()
|
public function parseProvidesUsefulErrors()
|
||||||
@ -72,8 +73,9 @@ fragment MissingOn Type
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider parseProvidesUsefulErrors
|
|
||||||
* @see it('parse provides useful errors')
|
* @see it('parse provides useful errors')
|
||||||
|
*
|
||||||
|
* @dataProvider parseProvidesUsefulErrors
|
||||||
*/
|
*/
|
||||||
public function testParseProvidesUsefulErrors(
|
public function testParseProvidesUsefulErrors(
|
||||||
$str,
|
$str,
|
||||||
@ -331,7 +333,7 @@ GRAPHQL
|
|||||||
');
|
');
|
||||||
$result = Parser::parse($source);
|
$result = Parser::parse($source);
|
||||||
|
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return [
|
return [
|
||||||
'start' => $start,
|
'start' => $start,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
@ -442,7 +444,7 @@ GRAPHQL
|
|||||||
');
|
');
|
||||||
$result = Parser::parse($source);
|
$result = Parser::parse($source);
|
||||||
|
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return [
|
return [
|
||||||
'start' => $start,
|
'start' => $start,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
|
@ -4,11 +4,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Language;
|
namespace GraphQL\Tests\Language;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
use GraphQL\Language\AST\FieldNode;
|
use GraphQL\Language\AST\FieldNode;
|
||||||
use GraphQL\Language\AST\NameNode;
|
use GraphQL\Language\AST\NameNode;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Throwable;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
|
|
||||||
class PrinterTest extends TestCase
|
class PrinterTest extends TestCase
|
||||||
@ -42,8 +44,8 @@ class PrinterTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testProducesHelpfulErrorMessages() : void
|
public function testProducesHelpfulErrorMessages() : void
|
||||||
{
|
{
|
||||||
$badAst1 = new \ArrayObject(['random' => 'Data']);
|
$badAst1 = new ArrayObject(['random' => 'Data']);
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Invalid AST Node: {"random":"Data"}');
|
$this->expectExceptionMessage('Invalid AST Node: {"random":"Data"}');
|
||||||
Printer::doPrint($badAst1);
|
Printer::doPrint($badAst1);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ type Hello {
|
|||||||
world: String
|
world: String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ type Hello {
|
|||||||
world: String
|
world: String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ type Hello {
|
|||||||
world: String
|
world: String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ extend type Hello {
|
|||||||
}
|
}
|
||||||
';
|
';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ extend type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'extend type Hello implements Greeting';
|
$body = 'extend type Hello implements Greeting';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ type Hello {
|
|||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
|
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -396,7 +396,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'type Hello implements World { field: String }';
|
$body = 'type Hello implements World { field: String }';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'type Hello implements Wo & rld { field: String }';
|
$body = 'type Hello implements Wo & rld { field: String }';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'type Hello implements & Wo & rld { field: String }';
|
$body = 'type Hello implements & Wo & rld { field: String }';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -511,7 +511,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'enum Hello { WORLD }';
|
$body = 'enum Hello { WORLD }';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -551,7 +551,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'enum Hello { WO, RLD }';
|
$body = 'enum Hello { WO, RLD }';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -586,7 +586,7 @@ interface Hello {
|
|||||||
world: String
|
world: String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -623,7 +623,7 @@ type Hello {
|
|||||||
world(flag: Boolean): String
|
world(flag: Boolean): String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -683,7 +683,7 @@ type Hello {
|
|||||||
world(flag: Boolean = true): String
|
world(flag: Boolean = true): String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -729,7 +729,7 @@ type Hello {
|
|||||||
world(things: [String]): String
|
world(things: [String]): String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -782,7 +782,7 @@ type Hello {
|
|||||||
world(argOne: Boolean, argTwo: Int): String
|
world(argOne: Boolean, argTwo: Int): String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -832,7 +832,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'union Hello = World';
|
$body = 'union Hello = World';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -861,7 +861,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'union Hello = Wo | Rld';
|
$body = 'union Hello = Wo | Rld';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -967,7 +967,7 @@ type Hello {
|
|||||||
{
|
{
|
||||||
$body = 'scalar Hello';
|
$body = 'scalar Hello';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -997,7 +997,7 @@ input Hello {
|
|||||||
world: String
|
world: String
|
||||||
}';
|
}';
|
||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$loc = function ($start, $end) {
|
$loc = static function ($start, $end) {
|
||||||
return TestUtils::locArray($start, $end);
|
return TestUtils::locArray($start, $end);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
private function checkVisitorFnArgs($ast, $args, $isEdited = false)
|
private function checkVisitorFnArgs($ast, $args, $isEdited = false)
|
||||||
{
|
{
|
||||||
/** @var Node $node */
|
/** @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;
|
$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(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null],
|
['enter', 'Document', null],
|
||||||
['enter', 'OperationDefinition', null],
|
['enter', 'OperationDefinition', null],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'c'],
|
['enter', 'Name', 'c'],
|
||||||
['leave', 'Name', 'c'],
|
['leave', 'Name', 'c'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['leave', 'SelectionSet', null],
|
['leave', 'SelectionSet', null],
|
||||||
['leave', 'OperationDefinition', null],
|
['leave', 'OperationDefinition', null],
|
||||||
['leave', 'Document', null],
|
['leave', 'Document', null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -939,40 +939,40 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['no-a', 'enter', 'Document', null],
|
['no-a', 'enter', 'Document', null],
|
||||||
['no-b', 'enter', 'Document', null],
|
['no-b', 'enter', 'Document', null],
|
||||||
['no-a', 'enter', 'OperationDefinition', null],
|
['no-a', 'enter', 'OperationDefinition', null],
|
||||||
['no-b', 'enter', 'OperationDefinition', null],
|
['no-b', 'enter', 'OperationDefinition', null],
|
||||||
['no-a', 'enter', 'SelectionSet', null],
|
['no-a', 'enter', 'SelectionSet', null],
|
||||||
['no-b', 'enter', 'SelectionSet', null],
|
['no-b', 'enter', 'SelectionSet', null],
|
||||||
['no-a', 'enter', 'Field', null],
|
['no-a', 'enter', 'Field', null],
|
||||||
['no-b', 'enter', 'Field', null],
|
['no-b', 'enter', 'Field', null],
|
||||||
['no-b', 'enter', 'Name', 'a'],
|
['no-b', 'enter', 'Name', 'a'],
|
||||||
['no-b', 'leave', 'Name', 'a'],
|
['no-b', 'leave', 'Name', 'a'],
|
||||||
['no-b', 'enter', 'SelectionSet', null],
|
['no-b', 'enter', 'SelectionSet', null],
|
||||||
['no-b', 'enter', 'Field', null],
|
['no-b', 'enter', 'Field', null],
|
||||||
['no-b', 'enter', 'Name', 'x'],
|
['no-b', 'enter', 'Name', 'x'],
|
||||||
['no-b', 'leave', 'Name', 'x'],
|
['no-b', 'leave', 'Name', 'x'],
|
||||||
['no-b', 'leave', 'Field', null],
|
['no-b', 'leave', 'Field', null],
|
||||||
['no-b', 'leave', 'SelectionSet', null],
|
['no-b', 'leave', 'SelectionSet', null],
|
||||||
['no-b', 'leave', 'Field', null],
|
['no-b', 'leave', 'Field', null],
|
||||||
['no-a', 'enter', 'Field', null],
|
['no-a', 'enter', 'Field', null],
|
||||||
['no-b', 'enter', 'Field', null],
|
['no-b', 'enter', 'Field', null],
|
||||||
['no-a', 'enter', 'Name', 'b'],
|
['no-a', 'enter', 'Name', 'b'],
|
||||||
['no-a', 'leave', 'Name', 'b'],
|
['no-a', 'leave', 'Name', 'b'],
|
||||||
['no-a', 'enter', 'SelectionSet', null],
|
['no-a', 'enter', 'SelectionSet', null],
|
||||||
['no-a', 'enter', 'Field', null],
|
['no-a', 'enter', 'Field', null],
|
||||||
['no-a', 'enter', 'Name', 'y'],
|
['no-a', 'enter', 'Name', 'y'],
|
||||||
['no-a', 'leave', 'Name', 'y'],
|
['no-a', 'leave', 'Name', 'y'],
|
||||||
['no-a', 'leave', 'Field', null],
|
['no-a', 'leave', 'Field', null],
|
||||||
['no-a', 'leave', 'SelectionSet', null],
|
['no-a', 'leave', 'SelectionSet', null],
|
||||||
['no-a', 'leave', 'Field', null],
|
['no-a', 'leave', 'Field', null],
|
||||||
['no-a', 'leave', 'SelectionSet', null],
|
['no-a', 'leave', 'SelectionSet', null],
|
||||||
['no-b', 'leave', 'SelectionSet', null],
|
['no-b', 'leave', 'SelectionSet', null],
|
||||||
['no-a', 'leave', 'OperationDefinition', null],
|
['no-a', 'leave', 'OperationDefinition', null],
|
||||||
['no-b', 'leave', 'OperationDefinition', null],
|
['no-b', 'leave', 'OperationDefinition', null],
|
||||||
['no-a', 'leave', 'Document', null],
|
['no-a', 'leave', 'Document', null],
|
||||||
['no-b', 'leave', 'Document', null],
|
['no-b', 'leave', 'Document', null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1004,19 +1004,19 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null],
|
['enter', 'Document', null],
|
||||||
['enter', 'OperationDefinition', null],
|
['enter', 'OperationDefinition', null],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'b'],
|
['enter', 'Name', 'b'],
|
||||||
['leave', 'Name', 'b'],
|
['leave', 'Name', 'b'],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'x'],
|
['enter', 'Name', 'x'],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1063,26 +1063,26 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['break-a', 'enter', 'Document', null],
|
['break-a', 'enter', 'Document', null],
|
||||||
['break-b', 'enter', 'Document', null],
|
['break-b', 'enter', 'Document', null],
|
||||||
['break-a', 'enter', 'OperationDefinition', null],
|
['break-a', 'enter', 'OperationDefinition', null],
|
||||||
['break-b', 'enter', 'OperationDefinition', null],
|
['break-b', 'enter', 'OperationDefinition', null],
|
||||||
['break-a', 'enter', 'SelectionSet', null],
|
['break-a', 'enter', 'SelectionSet', null],
|
||||||
['break-b', 'enter', 'SelectionSet', null],
|
['break-b', 'enter', 'SelectionSet', null],
|
||||||
['break-a', 'enter', 'Field', null],
|
['break-a', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-a', 'enter', 'Name', 'a'],
|
['break-a', 'enter', 'Name', 'a'],
|
||||||
['break-b', 'enter', 'Name', 'a'],
|
['break-b', 'enter', 'Name', 'a'],
|
||||||
['break-b', 'leave', 'Name', 'a'],
|
['break-b', 'leave', 'Name', 'a'],
|
||||||
['break-b', 'enter', 'SelectionSet', null],
|
['break-b', 'enter', 'SelectionSet', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Name', 'y'],
|
['break-b', 'enter', 'Name', 'y'],
|
||||||
['break-b', 'leave', 'Name', 'y'],
|
['break-b', 'leave', 'Name', 'y'],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
['break-b', 'leave', 'SelectionSet', null],
|
['break-b', 'leave', 'SelectionSet', null],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Name', 'b'],
|
['break-b', 'enter', 'Name', 'b'],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1114,20 +1114,20 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null],
|
['enter', 'Document', null],
|
||||||
['enter', 'OperationDefinition', null],
|
['enter', 'OperationDefinition', null],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'b'],
|
['enter', 'Name', 'b'],
|
||||||
['leave', 'Name', 'b'],
|
['leave', 'Name', 'b'],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'x'],
|
['enter', 'Name', 'x'],
|
||||||
['leave', 'Name', 'x'],
|
['leave', 'Name', 'x'],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1172,42 +1172,42 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['break-a', 'enter', 'Document', null],
|
['break-a', 'enter', 'Document', null],
|
||||||
['break-b', 'enter', 'Document', null],
|
['break-b', 'enter', 'Document', null],
|
||||||
['break-a', 'enter', 'OperationDefinition', null],
|
['break-a', 'enter', 'OperationDefinition', null],
|
||||||
['break-b', 'enter', 'OperationDefinition', null],
|
['break-b', 'enter', 'OperationDefinition', null],
|
||||||
['break-a', 'enter', 'SelectionSet', null],
|
['break-a', 'enter', 'SelectionSet', null],
|
||||||
['break-b', 'enter', 'SelectionSet', null],
|
['break-b', 'enter', 'SelectionSet', null],
|
||||||
['break-a', 'enter', 'Field', null],
|
['break-a', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-a', 'enter', 'Name', 'a'],
|
['break-a', 'enter', 'Name', 'a'],
|
||||||
['break-b', 'enter', 'Name', 'a'],
|
['break-b', 'enter', 'Name', 'a'],
|
||||||
['break-a', 'leave', 'Name', 'a'],
|
['break-a', 'leave', 'Name', 'a'],
|
||||||
['break-b', 'leave', 'Name', 'a'],
|
['break-b', 'leave', 'Name', 'a'],
|
||||||
['break-a', 'enter', 'SelectionSet', null],
|
['break-a', 'enter', 'SelectionSet', null],
|
||||||
['break-b', 'enter', 'SelectionSet', null],
|
['break-b', 'enter', 'SelectionSet', null],
|
||||||
['break-a', 'enter', 'Field', null],
|
['break-a', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-a', 'enter', 'Name', 'y'],
|
['break-a', 'enter', 'Name', 'y'],
|
||||||
['break-b', 'enter', 'Name', 'y'],
|
['break-b', 'enter', 'Name', 'y'],
|
||||||
['break-a', 'leave', 'Name', 'y'],
|
['break-a', 'leave', 'Name', 'y'],
|
||||||
['break-b', 'leave', 'Name', 'y'],
|
['break-b', 'leave', 'Name', 'y'],
|
||||||
['break-a', 'leave', 'Field', null],
|
['break-a', 'leave', 'Field', null],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
['break-a', 'leave', 'SelectionSet', null],
|
['break-a', 'leave', 'SelectionSet', null],
|
||||||
['break-b', 'leave', 'SelectionSet', null],
|
['break-b', 'leave', 'SelectionSet', null],
|
||||||
['break-a', 'leave', 'Field', null],
|
['break-a', 'leave', 'Field', null],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Name', 'b'],
|
['break-b', 'enter', 'Name', 'b'],
|
||||||
['break-b', 'leave', 'Name', 'b'],
|
['break-b', 'leave', 'Name', 'b'],
|
||||||
['break-b', 'enter', 'SelectionSet', null],
|
['break-b', 'enter', 'SelectionSet', null],
|
||||||
['break-b', 'enter', 'Field', null],
|
['break-b', 'enter', 'Field', null],
|
||||||
['break-b', 'enter', 'Name', 'x'],
|
['break-b', 'enter', 'Name', 'x'],
|
||||||
['break-b', 'leave', 'Name', 'x'],
|
['break-b', 'leave', 'Name', 'x'],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
['break-b', 'leave', 'SelectionSet', null],
|
['break-b', 'leave', 'SelectionSet', null],
|
||||||
['break-b', 'leave', 'Field', null],
|
['break-b', 'leave', 'Field', null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1254,30 +1254,30 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null],
|
['enter', 'Document', null],
|
||||||
['enter', 'OperationDefinition', null],
|
['enter', 'OperationDefinition', null],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'c'],
|
['enter', 'Name', 'c'],
|
||||||
['leave', 'Name', 'c'],
|
['leave', 'Name', 'c'],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'c'],
|
['enter', 'Name', 'c'],
|
||||||
['leave', 'Name', 'c'],
|
['leave', 'Name', 'c'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['leave', 'SelectionSet', null],
|
['leave', 'SelectionSet', null],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['leave', 'SelectionSet', null],
|
['leave', 'SelectionSet', null],
|
||||||
['leave', 'OperationDefinition', null],
|
['leave', 'OperationDefinition', null],
|
||||||
['leave', 'Document', null],
|
['leave', 'Document', null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1324,36 +1324,36 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null],
|
['enter', 'Document', null],
|
||||||
['enter', 'OperationDefinition', null],
|
['enter', 'OperationDefinition', null],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'b'],
|
['enter', 'Name', 'b'],
|
||||||
['leave', 'Name', 'b'],
|
['leave', 'Name', 'b'],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'c'],
|
['enter', 'Name', 'c'],
|
||||||
['leave', 'Name', 'c'],
|
['leave', 'Name', 'c'],
|
||||||
['enter', 'SelectionSet', null],
|
['enter', 'SelectionSet', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'a'],
|
['enter', 'Name', 'a'],
|
||||||
['leave', 'Name', 'a'],
|
['leave', 'Name', 'a'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'b'],
|
['enter', 'Name', 'b'],
|
||||||
['leave', 'Name', 'b'],
|
['leave', 'Name', 'b'],
|
||||||
['enter', 'Field', null],
|
['enter', 'Field', null],
|
||||||
['enter', 'Name', 'c'],
|
['enter', 'Name', 'c'],
|
||||||
['leave', 'Name', 'c'],
|
['leave', 'Name', 'c'],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['leave', 'SelectionSet', null],
|
['leave', 'SelectionSet', null],
|
||||||
['leave', 'Field', null],
|
['leave', 'Field', null],
|
||||||
['leave', 'SelectionSet', null],
|
['leave', 'SelectionSet', null],
|
||||||
['leave', 'OperationDefinition', null],
|
['leave', 'OperationDefinition', null],
|
||||||
['leave', 'Document', null],
|
['leave', 'Document', null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1408,46 +1408,46 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null, null, null, null],
|
['enter', 'Document', null, null, null, null],
|
||||||
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
|
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
|
||||||
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
||||||
['enter', 'Field', null, 'QueryRoot', 'Human', null],
|
['enter', 'Field', null, 'QueryRoot', 'Human', null],
|
||||||
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
|
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
|
||||||
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
|
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
|
||||||
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'SelectionSet', null, 'Human', 'Human', null],
|
['enter', 'SelectionSet', null, 'Human', 'Human', null],
|
||||||
['enter', 'Field', null, 'Human', 'String', null],
|
['enter', 'Field', null, 'Human', 'String', null],
|
||||||
['enter', 'Name', 'name', 'Human', 'String', null],
|
['enter', 'Name', 'name', 'Human', 'String', null],
|
||||||
['leave', 'Name', 'name', 'Human', 'String', null],
|
['leave', 'Name', 'name', 'Human', 'String', null],
|
||||||
['leave', 'Field', null, 'Human', 'String', null],
|
['leave', 'Field', null, 'Human', 'String', null],
|
||||||
['enter', 'Field', null, 'Human', '[Pet]', null],
|
['enter', 'Field', null, 'Human', '[Pet]', null],
|
||||||
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
|
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
|
||||||
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
|
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
|
||||||
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
||||||
['enter', 'InlineFragment', null, 'Pet', 'Pet', null],
|
['enter', 'InlineFragment', null, 'Pet', 'Pet', null],
|
||||||
['enter', 'SelectionSet', null, 'Pet', 'Pet', null],
|
['enter', 'SelectionSet', null, 'Pet', 'Pet', null],
|
||||||
['enter', 'Field', null, 'Pet', 'String', null],
|
['enter', 'Field', null, 'Pet', 'String', null],
|
||||||
['enter', 'Name', 'name', 'Pet', 'String', null],
|
['enter', 'Name', 'name', 'Pet', 'String', null],
|
||||||
['leave', 'Name', 'name', 'Pet', 'String', null],
|
['leave', 'Name', 'name', 'Pet', 'String', null],
|
||||||
['leave', 'Field', null, 'Pet', 'String', null],
|
['leave', 'Field', null, 'Pet', 'String', null],
|
||||||
['leave', 'SelectionSet', null, 'Pet', 'Pet', null],
|
['leave', 'SelectionSet', null, 'Pet', 'Pet', null],
|
||||||
['leave', 'InlineFragment', null, 'Pet', 'Pet', null],
|
['leave', 'InlineFragment', null, 'Pet', 'Pet', null],
|
||||||
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
||||||
['leave', 'Field', null, 'Human', '[Pet]', null],
|
['leave', 'Field', null, 'Human', '[Pet]', null],
|
||||||
['enter', 'Field', null, 'Human', null, null],
|
['enter', 'Field', null, 'Human', null, null],
|
||||||
['enter', 'Name', 'unknown', 'Human', null, null],
|
['enter', 'Name', 'unknown', 'Human', null, null],
|
||||||
['leave', 'Name', 'unknown', 'Human', null, null],
|
['leave', 'Name', 'unknown', 'Human', null, null],
|
||||||
['leave', 'Field', null, 'Human', null, null],
|
['leave', 'Field', null, 'Human', null, null],
|
||||||
['leave', 'SelectionSet', null, 'Human', 'Human', null],
|
['leave', 'SelectionSet', null, 'Human', 'Human', null],
|
||||||
['leave', 'Field', null, 'QueryRoot', 'Human', null],
|
['leave', 'Field', null, 'QueryRoot', 'Human', null],
|
||||||
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
||||||
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
|
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
|
||||||
['leave', 'Document', null, null, null, null],
|
['leave', 'Document', null, null, null, null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
@ -1534,48 +1534,48 @@ class VisitorTest extends ValidatorTestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[
|
[
|
||||||
['enter', 'Document', null, null, null, null],
|
['enter', 'Document', null, null, null, null],
|
||||||
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
|
['enter', 'OperationDefinition', null, null, 'QueryRoot', null],
|
||||||
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
||||||
['enter', 'Field', null, 'QueryRoot', 'Human', null],
|
['enter', 'Field', null, 'QueryRoot', 'Human', null],
|
||||||
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
|
['enter', 'Name', 'human', 'QueryRoot', 'Human', null],
|
||||||
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
|
['leave', 'Name', 'human', 'QueryRoot', 'Human', null],
|
||||||
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'],
|
||||||
['enter', 'SelectionSet', null, 'Human', 'Human', null],
|
['enter', 'SelectionSet', null, 'Human', 'Human', null],
|
||||||
['enter', 'Field', null, 'Human', 'String', null],
|
['enter', 'Field', null, 'Human', 'String', null],
|
||||||
['enter', 'Name', 'name', 'Human', 'String', null],
|
['enter', 'Name', 'name', 'Human', 'String', null],
|
||||||
['leave', 'Name', 'name', 'Human', 'String', null],
|
['leave', 'Name', 'name', 'Human', 'String', null],
|
||||||
['leave', 'Field', null, 'Human', 'String', null],
|
['leave', 'Field', null, 'Human', 'String', null],
|
||||||
['enter', 'Field', null, 'Human', '[Pet]', null],
|
['enter', 'Field', null, 'Human', '[Pet]', null],
|
||||||
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
|
['enter', 'Name', 'pets', 'Human', '[Pet]', null],
|
||||||
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
|
['leave', 'Name', 'pets', 'Human', '[Pet]', null],
|
||||||
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
['enter', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
||||||
['enter', 'Field', null, 'Pet', 'String!', null],
|
['enter', 'Field', null, 'Pet', 'String!', null],
|
||||||
['enter', 'Name', '__typename', 'Pet', 'String!', null],
|
['enter', 'Name', '__typename', 'Pet', 'String!', null],
|
||||||
['leave', 'Name', '__typename', 'Pet', 'String!', null],
|
['leave', 'Name', '__typename', 'Pet', 'String!', null],
|
||||||
['leave', 'Field', null, 'Pet', 'String!', null],
|
['leave', 'Field', null, 'Pet', 'String!', null],
|
||||||
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
['leave', 'SelectionSet', null, 'Pet', '[Pet]', null],
|
||||||
['leave', 'Field', null, 'Human', '[Pet]', null],
|
['leave', 'Field', null, 'Human', '[Pet]', null],
|
||||||
['leave', 'SelectionSet', null, 'Human', 'Human', null],
|
['leave', 'SelectionSet', null, 'Human', 'Human', null],
|
||||||
['leave', 'Field', null, 'QueryRoot', 'Human', null],
|
['leave', 'Field', null, 'QueryRoot', 'Human', null],
|
||||||
['enter', 'Field', null, 'QueryRoot', 'Alien', null],
|
['enter', 'Field', null, 'QueryRoot', 'Alien', null],
|
||||||
['enter', 'Name', 'alien', 'QueryRoot', 'Alien', null],
|
['enter', 'Name', 'alien', 'QueryRoot', 'Alien', null],
|
||||||
['leave', 'Name', 'alien', 'QueryRoot', 'Alien', null],
|
['leave', 'Name', 'alien', 'QueryRoot', 'Alien', null],
|
||||||
['enter', 'SelectionSet', null, 'Alien', 'Alien', null],
|
['enter', 'SelectionSet', null, 'Alien', 'Alien', null],
|
||||||
['enter', 'Field', null, 'Alien', 'String!', null],
|
['enter', 'Field', null, 'Alien', 'String!', null],
|
||||||
['enter', 'Name', '__typename', 'Alien', 'String!', null],
|
['enter', 'Name', '__typename', 'Alien', 'String!', null],
|
||||||
['leave', 'Name', '__typename', 'Alien', 'String!', null],
|
['leave', 'Name', '__typename', 'Alien', 'String!', null],
|
||||||
['leave', 'Field', null, 'Alien', 'String!', null],
|
['leave', 'Field', null, 'Alien', 'String!', null],
|
||||||
['leave', 'SelectionSet', null, 'Alien', 'Alien', null],
|
['leave', 'SelectionSet', null, 'Alien', 'Alien', null],
|
||||||
['leave', 'Field', null, 'QueryRoot', 'Alien', null],
|
['leave', 'Field', null, 'QueryRoot', 'Alien', null],
|
||||||
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null],
|
||||||
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
|
['leave', 'OperationDefinition', null, null, 'QueryRoot', null],
|
||||||
['leave', 'Document', null, null, null, null],
|
['leave', 'Document', null, null, null, null],
|
||||||
],
|
],
|
||||||
$visited
|
$visited
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,7 @@ use GraphQL\Server\ServerConfig;
|
|||||||
use GraphQL\Validator\DocumentValidator;
|
use GraphQL\Validator\DocumentValidator;
|
||||||
use GraphQL\Validator\Rules\CustomValidationRule;
|
use GraphQL\Validator\Rules\CustomValidationRule;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
use stdClass;
|
||||||
use function count;
|
use function count;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
public function testPassesRootValueAndContext() : void
|
public function testPassesRootValueAndContext() : void
|
||||||
{
|
{
|
||||||
$rootValue = 'myRootValue';
|
$rootValue = 'myRootValue';
|
||||||
$context = new \stdClass();
|
$context = new stdClass();
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->setContext($context)
|
->setContext($context)
|
||||||
@ -170,7 +171,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
new CustomValidationRule('SomeRule', function () use (&$called) {
|
new CustomValidationRule('SomeRule', static function () use (&$called) {
|
||||||
$called = true;
|
$called = true;
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
@ -190,7 +191,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$params = $doc = $operationType = null;
|
$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;
|
$called = true;
|
||||||
$params = $p;
|
$params = $p;
|
||||||
$doc = $d;
|
$doc = $d;
|
||||||
@ -214,7 +215,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called1 = false;
|
$called1 = false;
|
||||||
$called2 = 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) {
|
if ($params->query === $q1) {
|
||||||
$called1 = true;
|
$called1 = true;
|
||||||
|
|
||||||
@ -224,7 +225,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called2 = true;
|
$called2 = true;
|
||||||
|
|
||||||
return [
|
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!'));
|
$context->reportError(new Error('This is the error we are looking for!'));
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
@ -353,7 +354,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
public function testAllowsPersistentQueries() : void
|
public function testAllowsPersistentQueries() : void
|
||||||
{
|
{
|
||||||
$called = false;
|
$called = false;
|
||||||
$this->config->setPersistentQueryLoader(function ($queryId, OperationParams $params) use (&$called) {
|
$this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) {
|
||||||
$called = true;
|
$called = true;
|
||||||
self::assertEquals('some-id', $queryId);
|
self::assertEquals('some-id', $queryId);
|
||||||
|
|
||||||
@ -370,7 +371,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
|
|
||||||
// Make sure it allows returning document node:
|
// Make sure it allows returning document node:
|
||||||
$called = false;
|
$called = false;
|
||||||
$this->config->setPersistentQueryLoader(function ($queryId, OperationParams $params) use (&$called) {
|
$this->config->setPersistentQueryLoader(static function ($queryId, OperationParams $params) use (&$called) {
|
||||||
$called = true;
|
$called = true;
|
||||||
self::assertEquals('some-id', $queryId);
|
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 ' .
|
'Persistent query loader must return query string or instance of GraphQL\Language\AST\DocumentNode ' .
|
||||||
'but got: {"err":"err"}'
|
'but got: {"err":"err"}'
|
||||||
);
|
);
|
||||||
$this->config->setPersistentQueryLoader(function () {
|
$this->config->setPersistentQueryLoader(static function () {
|
||||||
return ['err' => 'err'];
|
return ['err' => 'err'];
|
||||||
});
|
});
|
||||||
$this->executePersistedQuery('some-id');
|
$this->executePersistedQuery('some-id');
|
||||||
@ -396,7 +397,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
|
|
||||||
public function testPersistedQueriesAreStillValidatedByDefault() : void
|
public function testPersistedQueriesAreStillValidatedByDefault() : void
|
||||||
{
|
{
|
||||||
$this->config->setPersistentQueryLoader(function () {
|
$this->config->setPersistentQueryLoader(static function () {
|
||||||
return '{invalid}';
|
return '{invalid}';
|
||||||
});
|
});
|
||||||
$result = $this->executePersistedQuery('some-id');
|
$result = $this->executePersistedQuery('some-id');
|
||||||
@ -415,14 +416,14 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
public function testAllowSkippingValidationForPersistedQueries() : void
|
public function testAllowSkippingValidationForPersistedQueries() : void
|
||||||
{
|
{
|
||||||
$this->config
|
$this->config
|
||||||
->setPersistentQueryLoader(function ($queryId) {
|
->setPersistentQueryLoader(static function ($queryId) {
|
||||||
if ($queryId === 'some-id') {
|
if ($queryId === 'some-id') {
|
||||||
return '{invalid}';
|
return '{invalid}';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '{invalid2}';
|
return '{invalid2}';
|
||||||
})
|
})
|
||||||
->setValidationRules(function (OperationParams $params) {
|
->setValidationRules(static function (OperationParams $params) {
|
||||||
if ($params->queryId === 'some-id') {
|
if ($params->queryId === 'some-id') {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -453,8 +454,8 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(InvariantViolation::class);
|
$this->expectException(InvariantViolation::class);
|
||||||
$this->expectExceptionMessage('Expecting validation rules to be array or callable returning array, but got: instance of stdClass');
|
$this->expectExceptionMessage('Expecting validation rules to be array or callable returning array, but got: instance of stdClass');
|
||||||
$this->config->setValidationRules(function (OperationParams $params) {
|
$this->config->setValidationRules(static function (OperationParams $params) {
|
||||||
return new \stdClass();
|
return new stdClass();
|
||||||
});
|
});
|
||||||
$this->executeQuery('{f1}');
|
$this->executeQuery('{f1}');
|
||||||
}
|
}
|
||||||
@ -519,10 +520,10 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
->setQueryBatching(true)
|
->setQueryBatching(true)
|
||||||
->setRootValue('1')
|
->setRootValue('1')
|
||||||
->setContext([
|
->setContext([
|
||||||
'buffer' => function ($num) use (&$calls) {
|
'buffer' => static function ($num) use (&$calls) {
|
||||||
$calls[] = sprintf('buffer: %d', $num);
|
$calls[] = sprintf('buffer: %d', $num);
|
||||||
},
|
},
|
||||||
'load' => function ($num) use (&$calls) {
|
'load' => static function ($num) use (&$calls) {
|
||||||
$calls[] = sprintf('load: %d', $num);
|
$calls[] = sprintf('load: %d', $num);
|
||||||
|
|
||||||
return sprintf('loaded: %d', $num);
|
return sprintf('loaded: %d', $num);
|
||||||
@ -584,7 +585,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$params = $doc = $operationType = null;
|
$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;
|
$called = true;
|
||||||
$params = $p;
|
$params = $p;
|
||||||
$doc = $d;
|
$doc = $d;
|
||||||
@ -604,7 +605,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$params = $doc = $operationType = null;
|
$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;
|
$called = true;
|
||||||
$params = $p;
|
$params = $p;
|
||||||
$doc = $d;
|
$doc = $d;
|
||||||
@ -623,7 +624,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
{
|
{
|
||||||
$called = false;
|
$called = false;
|
||||||
$error = null;
|
$error = null;
|
||||||
$this->config->setErrorFormatter(function ($e) use (&$called, &$error) {
|
$this->config->setErrorFormatter(static function ($e) use (&$called, &$error) {
|
||||||
$called = true;
|
$called = true;
|
||||||
$error = $e;
|
$error = $e;
|
||||||
|
|
||||||
@ -660,7 +661,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$errors = null;
|
$errors = null;
|
||||||
$formatter = 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;
|
$called = true;
|
||||||
$errors = $e;
|
$errors = $e;
|
||||||
$formatter = $f;
|
$formatter = $f;
|
||||||
|
@ -43,7 +43,7 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
$helper = new Helper();
|
$helper = new Helper();
|
||||||
|
|
||||||
return $helper->parseHttpRequest(function () use ($content) {
|
return $helper->parseHttpRequest(static function () use ($content) {
|
||||||
return $content;
|
return $content;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -125,6 +125,7 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $postValue
|
* @param mixed[] $postValue
|
||||||
|
*
|
||||||
* @return OperationParams|OperationParams[]
|
* @return OperationParams|OperationParams[]
|
||||||
*/
|
*/
|
||||||
private function parseRawFormUrlencodedRequest($postValue)
|
private function parseRawFormUrlencodedRequest($postValue)
|
||||||
@ -135,13 +136,14 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
$helper = new Helper();
|
$helper = new Helper();
|
||||||
|
|
||||||
return $helper->parseHttpRequest(function () {
|
return $helper->parseHttpRequest(static function () {
|
||||||
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
|
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $postValue
|
* @param mixed[] $postValue
|
||||||
|
*
|
||||||
* @return OperationParams[]|OperationParams
|
* @return OperationParams[]|OperationParams
|
||||||
*/
|
*/
|
||||||
private function parsePsrFormUrlEncodedRequest($postValue)
|
private function parsePsrFormUrlEncodedRequest($postValue)
|
||||||
@ -180,6 +182,7 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $getValue
|
* @param mixed[] $getValue
|
||||||
|
*
|
||||||
* @return OperationParams
|
* @return OperationParams
|
||||||
*/
|
*/
|
||||||
private function parseRawGetRequest($getValue)
|
private function parseRawGetRequest($getValue)
|
||||||
@ -189,13 +192,14 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
$helper = new Helper();
|
$helper = new Helper();
|
||||||
|
|
||||||
return $helper->parseHttpRequest(function () {
|
return $helper->parseHttpRequest(static function () {
|
||||||
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
|
throw new InvariantViolation("Shouldn't read from php://input for urlencoded request");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $getValue
|
* @param mixed[] $getValue
|
||||||
|
*
|
||||||
* @return OperationParams[]|OperationParams
|
* @return OperationParams[]|OperationParams
|
||||||
*/
|
*/
|
||||||
private function parsePsrGetRequest($getValue)
|
private function parsePsrGetRequest($getValue)
|
||||||
@ -233,6 +237,7 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $postValue
|
* @param mixed[] $postValue
|
||||||
|
*
|
||||||
* @return OperationParams|OperationParams[]
|
* @return OperationParams|OperationParams[]
|
||||||
*/
|
*/
|
||||||
private function parseRawMultipartFormDataRequest($postValue)
|
private function parseRawMultipartFormDataRequest($postValue)
|
||||||
@ -243,13 +248,14 @@ class RequestParsingTest extends TestCase
|
|||||||
|
|
||||||
$helper = new Helper();
|
$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");
|
throw new InvariantViolation("Shouldn't read from php://input for multipart/form-data request");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $postValue
|
* @param mixed[] $postValue
|
||||||
|
*
|
||||||
* @return OperationParams|OperationParams[]
|
* @return OperationParams|OperationParams[]
|
||||||
*/
|
*/
|
||||||
private function parsePsrMultipartFormDataRequest($postValue)
|
private function parsePsrMultipartFormDataRequest($postValue)
|
||||||
|
@ -11,6 +11,7 @@ use GraphQL\Type\Definition\ObjectType;
|
|||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class ServerConfigTest extends TestCase
|
class ServerConfigTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -51,7 +52,7 @@ class ServerConfigTest extends TestCase
|
|||||||
$config->setContext($context);
|
$config->setContext($context);
|
||||||
self::assertSame($context, $config->getContext());
|
self::assertSame($context, $config->getContext());
|
||||||
|
|
||||||
$context2 = new \stdClass();
|
$context2 = new stdClass();
|
||||||
$config->setContext($context2);
|
$config->setContext($context2);
|
||||||
self::assertSame($context2, $config->getContext());
|
self::assertSame($context2, $config->getContext());
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ class ServerConfigTest extends TestCase
|
|||||||
$config->setRootValue($rootValue);
|
$config->setRootValue($rootValue);
|
||||||
self::assertSame($rootValue, $config->getRootValue());
|
self::assertSame($rootValue, $config->getRootValue());
|
||||||
|
|
||||||
$context2 = new \stdClass();
|
$context2 = new stdClass();
|
||||||
$config->setRootValue($context2);
|
$config->setRootValue($context2);
|
||||||
self::assertSame($context2, $config->getRootValue());
|
self::assertSame($context2, $config->getRootValue());
|
||||||
}
|
}
|
||||||
@ -73,7 +74,7 @@ class ServerConfigTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = ServerConfig::create();
|
$config = ServerConfig::create();
|
||||||
|
|
||||||
$formatter = function () {
|
$formatter = static function () {
|
||||||
};
|
};
|
||||||
$config->setErrorFormatter($formatter);
|
$config->setErrorFormatter($formatter);
|
||||||
self::assertSame($formatter, $config->getErrorFormatter());
|
self::assertSame($formatter, $config->getErrorFormatter());
|
||||||
@ -87,7 +88,7 @@ class ServerConfigTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = ServerConfig::create();
|
$config = ServerConfig::create();
|
||||||
|
|
||||||
$handler = function () {
|
$handler = static function () {
|
||||||
};
|
};
|
||||||
$config->setErrorsHandler($handler);
|
$config->setErrorsHandler($handler);
|
||||||
self::assertSame($handler, $config->getErrorsHandler());
|
self::assertSame($handler, $config->getErrorsHandler());
|
||||||
@ -118,14 +119,14 @@ class ServerConfigTest extends TestCase
|
|||||||
$config->setValidationRules($rules);
|
$config->setValidationRules($rules);
|
||||||
self::assertSame($rules, $config->getValidationRules());
|
self::assertSame($rules, $config->getValidationRules());
|
||||||
|
|
||||||
$rules = [function () {
|
$rules = [static function () {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
$config->setValidationRules($rules);
|
$config->setValidationRules($rules);
|
||||||
self::assertSame($rules, $config->getValidationRules());
|
self::assertSame($rules, $config->getValidationRules());
|
||||||
|
|
||||||
$rules = function () {
|
$rules = static function () {
|
||||||
return [function () {
|
return [static function () {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@ -137,7 +138,7 @@ class ServerConfigTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = ServerConfig::create();
|
$config = ServerConfig::create();
|
||||||
|
|
||||||
$resolver = function () {
|
$resolver = static function () {
|
||||||
};
|
};
|
||||||
$config->setFieldResolver($resolver);
|
$config->setFieldResolver($resolver);
|
||||||
self::assertSame($resolver, $config->getFieldResolver());
|
self::assertSame($resolver, $config->getFieldResolver());
|
||||||
@ -151,7 +152,7 @@ class ServerConfigTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = ServerConfig::create();
|
$config = ServerConfig::create();
|
||||||
|
|
||||||
$loader = function () {
|
$loader = static function () {
|
||||||
};
|
};
|
||||||
$config->setPersistentQueryLoader($loader);
|
$config->setPersistentQueryLoader($loader);
|
||||||
self::assertSame($loader, $config->getPersistentQueryLoader());
|
self::assertSame($loader, $config->getPersistentQueryLoader());
|
||||||
@ -178,17 +179,17 @@ class ServerConfigTest extends TestCase
|
|||||||
'schema' => new Schema([
|
'schema' => new Schema([
|
||||||
'query' => new ObjectType(['name' => 't', 'fields' => ['a' => Type::string()]]),
|
'query' => new ObjectType(['name' => 't', 'fields' => ['a' => Type::string()]]),
|
||||||
]),
|
]),
|
||||||
'context' => new \stdClass(),
|
'context' => new stdClass(),
|
||||||
'rootValue' => new \stdClass(),
|
'rootValue' => new stdClass(),
|
||||||
'errorFormatter' => function () {
|
'errorFormatter' => static function () {
|
||||||
},
|
},
|
||||||
'promiseAdapter' => new SyncPromiseAdapter(),
|
'promiseAdapter' => new SyncPromiseAdapter(),
|
||||||
'validationRules' => [function () {
|
'validationRules' => [static function () {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'fieldResolver' => function () {
|
'fieldResolver' => static function () {
|
||||||
},
|
},
|
||||||
'persistentQueryLoader' => function () {
|
'persistentQueryLoader' => static function () {
|
||||||
},
|
},
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'queryBatching' => true,
|
'queryBatching' => true,
|
||||||
@ -220,7 +221,7 @@ class ServerConfigTest extends TestCase
|
|||||||
|
|
||||||
public function testInvalidValidationRules() : void
|
public function testInvalidValidationRules() : void
|
||||||
{
|
{
|
||||||
$rules = new \stdClass();
|
$rules = new stdClass();
|
||||||
$config = ServerConfig::create();
|
$config = ServerConfig::create();
|
||||||
|
|
||||||
$this->expectException(InvariantViolation::class);
|
$this->expectException(InvariantViolation::class);
|
||||||
|
@ -19,19 +19,19 @@ abstract class ServerTestCase extends TestCase
|
|||||||
{
|
{
|
||||||
protected function buildSchema()
|
protected function buildSchema()
|
||||||
{
|
{
|
||||||
$schema = new Schema([
|
return new Schema([
|
||||||
'query' => new ObjectType([
|
'query' => new ObjectType([
|
||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'f1' => [
|
'f1' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($root, $args, $context, $info) {
|
'resolve' => static function ($root, $args, $context, $info) {
|
||||||
return $info->fieldName;
|
return $info->fieldName;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'fieldWithPhpError' => [
|
'fieldWithPhpError' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($root, $args, $context, $info) {
|
'resolve' => static function ($root, $args, $context, $info) {
|
||||||
trigger_error('deprecated', E_USER_DEPRECATED);
|
trigger_error('deprecated', E_USER_DEPRECATED);
|
||||||
trigger_error('notice', E_USER_NOTICE);
|
trigger_error('notice', E_USER_NOTICE);
|
||||||
trigger_error('warning', E_USER_WARNING);
|
trigger_error('warning', E_USER_WARNING);
|
||||||
@ -43,19 +43,19 @@ abstract class ServerTestCase extends TestCase
|
|||||||
],
|
],
|
||||||
'fieldWithSafeException' => [
|
'fieldWithSafeException' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
throw new UserError('This is the exception we want');
|
throw new UserError('This is the exception we want');
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'fieldWithUnsafeException' => [
|
'fieldWithUnsafeException' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
throw new Unsafe('This exception should not be shown to the user');
|
throw new Unsafe('This exception should not be shown to the user');
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'testContextAndRootValue' => [
|
'testContextAndRootValue' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function ($root, $args, $context, $info) {
|
'resolve' => static function ($root, $args, $context, $info) {
|
||||||
$context->testedRootValue = $root;
|
$context->testedRootValue = $root;
|
||||||
|
|
||||||
return $info->fieldName;
|
return $info->fieldName;
|
||||||
@ -68,7 +68,7 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => static function ($root, $args) {
|
||||||
return $args['arg'];
|
return $args['arg'];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -79,10 +79,10 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'type' => Type::nonNull(Type::int()),
|
'type' => Type::nonNull(Type::int()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args, $context) {
|
'resolve' => static function ($root, $args, $context) {
|
||||||
$context['buffer']($args['num']);
|
$context['buffer']($args['num']);
|
||||||
|
|
||||||
return new Deferred(function () use ($args, $context) {
|
return new Deferred(static function () use ($args, $context) {
|
||||||
return $context['load']($args['num']);
|
return $context['load']($args['num']);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -103,7 +103,5 @@ abstract class ServerTestCase extends TestCase
|
|||||||
],
|
],
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class StandardServerTest extends ServerTestCase
|
|||||||
|
|
||||||
$helper = new Helper();
|
$helper = new Helper();
|
||||||
|
|
||||||
return $helper->parseHttpRequest(function () use ($content) {
|
return $helper->parseHttpRequest(static function () use ($content) {
|
||||||
return $content;
|
return $content;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Server;
|
namespace GraphQL\Tests\Server;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Error\ClientAware;
|
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.
|
* Returns true when exception message is safe to be displayed to a client.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function isClientSafe()
|
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.
|
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function getCategory()
|
public function getCategory()
|
||||||
{
|
{
|
||||||
|
@ -129,11 +129,12 @@ class StarWarsData
|
|||||||
*/
|
*/
|
||||||
public static function getFriends($character)
|
public static function getFriends($character)
|
||||||
{
|
{
|
||||||
return array_map([__CLASS__, 'getCharacter'], $character['friends']);
|
return array_map([self::class, 'getCharacter'], $character['friends']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $episode
|
* @param int $episode
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public static function getHero($episode)
|
public static function getHero($episode)
|
||||||
@ -149,6 +150,7 @@ class StarWarsData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
*
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public static function getHuman($id)
|
public static function getHuman($id)
|
||||||
@ -160,6 +162,7 @@ class StarWarsData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
*
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public static function getDroid($id)
|
public static function getDroid($id)
|
||||||
|
@ -15,6 +15,7 @@ namespace GraphQL\Tests;
|
|||||||
* Wars trilogy.
|
* Wars trilogy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Type\Definition\EnumType;
|
use GraphQL\Type\Definition\EnumType;
|
||||||
use GraphQL\Type\Definition\InterfaceType;
|
use GraphQL\Type\Definition\InterfaceType;
|
||||||
use GraphQL\Type\Definition\NonNull;
|
use GraphQL\Type\Definition\NonNull;
|
||||||
@ -108,7 +109,7 @@ class StarWarsSchema
|
|||||||
$characterInterface = new InterfaceType([
|
$characterInterface = new InterfaceType([
|
||||||
'name' => 'Character',
|
'name' => 'Character',
|
||||||
'description' => 'A character in the Star Wars Trilogy',
|
'description' => 'A character in the Star Wars Trilogy',
|
||||||
'fields' => function () use (&$characterInterface, $episodeEnum) {
|
'fields' => static function () use (&$characterInterface, $episodeEnum) {
|
||||||
return [
|
return [
|
||||||
'id' => [
|
'id' => [
|
||||||
'type' => Type::nonNull(Type::string()),
|
'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;
|
return StarWarsData::getHuman($obj['id']) ? $humanType : $droidType;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -164,18 +165,16 @@ class StarWarsSchema
|
|||||||
'friends' => [
|
'friends' => [
|
||||||
'type' => Type::listOf($characterInterface),
|
'type' => Type::listOf($characterInterface),
|
||||||
'description' => 'The friends of the human, or an empty list if they have none.',
|
'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 = $info->getFieldSelection();
|
||||||
$fieldSelection['id'] = true;
|
$fieldSelection['id'] = true;
|
||||||
|
|
||||||
$friends = array_map(
|
return array_map(
|
||||||
function ($friend) use ($fieldSelection) {
|
static function ($friend) use ($fieldSelection) {
|
||||||
return array_intersect_key($friend, $fieldSelection);
|
return array_intersect_key($friend, $fieldSelection);
|
||||||
},
|
},
|
||||||
StarWarsData::getFriends($human)
|
StarWarsData::getFriends($human)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $friends;
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'appearsIn' => [
|
'appearsIn' => [
|
||||||
@ -189,9 +188,9 @@ class StarWarsSchema
|
|||||||
'secretBackstory' => [
|
'secretBackstory' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'description' => 'Where are they from and how they came to be who they are.',
|
'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
|
// 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' => [
|
'friends' => [
|
||||||
'type' => Type::listOf($characterInterface),
|
'type' => Type::listOf($characterInterface),
|
||||||
'description' => 'The friends of the droid, or an empty list if they have none.',
|
'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);
|
return StarWarsData::getFriends($droid);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -237,9 +236,9 @@ class StarWarsSchema
|
|||||||
'secretBackstory' => [
|
'secretBackstory' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'description' => 'Construction date and the name of the designer.',
|
'description' => 'Construction date and the name of the designer.',
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
// This is to demonstrate error reporting
|
// This is to demonstrate error reporting
|
||||||
throw new \Exception('secretBackstory is secret.');
|
throw new Exception('secretBackstory is secret.');
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'primaryFunction' => [
|
'primaryFunction' => [
|
||||||
@ -262,7 +261,6 @@ class StarWarsSchema
|
|||||||
* human(id: String!): Human
|
* human(id: String!): Human
|
||||||
* droid(id: String!): Droid
|
* droid(id: String!): Droid
|
||||||
* }
|
* }
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
$queryType = new ObjectType([
|
$queryType = new ObjectType([
|
||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
@ -275,7 +273,7 @@ class StarWarsSchema
|
|||||||
'type' => $episodeEnum,
|
'type' => $episodeEnum,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => static function ($root, $args) {
|
||||||
return StarWarsData::getHero($args['episode'] ?? null);
|
return StarWarsData::getHero($args['episode'] ?? null);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -288,7 +286,7 @@ class StarWarsSchema
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => static function ($root, $args) {
|
||||||
$humans = StarWarsData::humans();
|
$humans = StarWarsData::humans();
|
||||||
|
|
||||||
return $humans[$args['id']] ?? null;
|
return $humans[$args['id']] ?? null;
|
||||||
@ -303,7 +301,7 @@ class StarWarsSchema
|
|||||||
'type' => Type::nonNull(Type::string()),
|
'type' => Type::nonNull(Type::string()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($root, $args) {
|
'resolve' => static function ($root, $args) {
|
||||||
$droids = StarWarsData::droids();
|
$droids = StarWarsData::droids();
|
||||||
|
|
||||||
return $droids[$args['id']] ?? null;
|
return $droids[$args['id']] ?? null;
|
||||||
|
@ -19,6 +19,8 @@ use GraphQL\Type\Definition\UnionType;
|
|||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
use Throwable;
|
||||||
use function count;
|
use function count;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function json_encode;
|
use function json_encode;
|
||||||
@ -80,11 +82,11 @@ class DefinitionTest extends TestCase
|
|||||||
|
|
||||||
$this->scalarType = new CustomScalarType([
|
$this->scalarType = new CustomScalarType([
|
||||||
'name' => 'Scalar',
|
'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' => [
|
'fields' => [
|
||||||
'f' => ['type' => Type::int()],
|
'f' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'interfaces' => function () use (&$someInterface) {
|
'interfaces' => static function () use (&$someInterface) {
|
||||||
return [$someInterface];
|
return [$someInterface];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -557,7 +559,7 @@ class DefinitionTest extends TestCase
|
|||||||
|
|
||||||
$user = new ObjectType([
|
$user = new ObjectType([
|
||||||
'name' => 'User',
|
'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');
|
self::assertNotNull($blog, 'Blog type is expected to be defined at this point, but it is null');
|
||||||
$called = true;
|
$called = true;
|
||||||
|
|
||||||
@ -566,20 +568,20 @@ class DefinitionTest extends TestCase
|
|||||||
'blogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull($blog)))],
|
'blogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull($blog)))],
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'interfaces' => function () use ($node) {
|
'interfaces' => static function () use ($node) {
|
||||||
return [$node];
|
return [$node];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$blog = new ObjectType([
|
$blog = new ObjectType([
|
||||||
'name' => 'Blog',
|
'name' => 'Blog',
|
||||||
'fields' => function () use ($user) {
|
'fields' => static function () use ($user) {
|
||||||
return [
|
return [
|
||||||
'id' => ['type' => Type::nonNull(Type::id())],
|
'id' => ['type' => Type::nonNull(Type::id())],
|
||||||
'owner' => ['type' => Type::nonNull($user)],
|
'owner' => ['type' => Type::nonNull($user)],
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'interfaces' => function () use ($node) {
|
'interfaces' => static function () use ($node) {
|
||||||
return [$node];
|
return [$node];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -612,7 +614,7 @@ class DefinitionTest extends TestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$inputObject = new InputObjectType([
|
$inputObject = new InputObjectType([
|
||||||
'name' => 'InputObject',
|
'name' => 'InputObject',
|
||||||
'fields' => function () use (&$inputObject, &$called) {
|
'fields' => static function () use (&$inputObject, &$called) {
|
||||||
$called = true;
|
$called = true;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -649,7 +651,7 @@ class DefinitionTest extends TestCase
|
|||||||
$called = false;
|
$called = false;
|
||||||
$interface = new InterfaceType([
|
$interface = new InterfaceType([
|
||||||
'name' => 'SomeInterface',
|
'name' => 'SomeInterface',
|
||||||
'fields' => function () use (&$interface, &$called) {
|
'fields' => static function () use (&$interface, &$called) {
|
||||||
$called = true;
|
$called = true;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -679,7 +681,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$interface = new InterfaceType([
|
$interface = new InterfaceType([
|
||||||
'name' => 'SomeInterface',
|
'name' => 'SomeInterface',
|
||||||
'fields' => function () use (&$interface) {
|
'fields' => static function () use (&$interface) {
|
||||||
return [
|
return [
|
||||||
'value' => Type::string(),
|
'value' => Type::string(),
|
||||||
'nested' => $interface,
|
'nested' => $interface,
|
||||||
@ -730,11 +732,11 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$idType = new CustomScalarType([
|
$idType = new CustomScalarType([
|
||||||
'name' => 'ID',
|
'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([
|
$objType = new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'f' => ['type' => Type::string()],
|
'f' => ['type' => Type::string()],
|
||||||
];
|
];
|
||||||
@ -805,7 +807,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$objType = new ObjectType([
|
$objType = new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [['field' => Type::string()]];
|
return [['field' => Type::string()]];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -901,7 +903,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$objType = new ObjectType([
|
$objType = new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'interfaces' => new \stdClass(),
|
'interfaces' => new stdClass(),
|
||||||
'fields' => ['f' => ['type' => Type::string()]],
|
'fields' => ['f' => ['type' => Type::string()]],
|
||||||
]);
|
]);
|
||||||
$this->expectException(InvariantViolation::class);
|
$this->expectException(InvariantViolation::class);
|
||||||
@ -918,8 +920,8 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$objType = new ObjectType([
|
$objType = new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'interfaces' => function () {
|
'interfaces' => static function () {
|
||||||
return new \stdClass();
|
return new stdClass();
|
||||||
},
|
},
|
||||||
'fields' => ['f' => ['type' => Type::string()]],
|
'fields' => ['f' => ['type' => Type::string()]],
|
||||||
]);
|
]);
|
||||||
@ -939,7 +941,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectNotToPerformAssertions();
|
$this->expectNotToPerformAssertions();
|
||||||
// should not throw:
|
// should not throw:
|
||||||
$this->schemaWithObjectWithFieldResolver(function () {
|
$this->schemaWithObjectWithFieldResolver(static function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1083,7 +1085,7 @@ class DefinitionTest extends TestCase
|
|||||||
|
|
||||||
$type = new InterfaceType([
|
$type = new InterfaceType([
|
||||||
'name' => 'AnotherInterface',
|
'name' => 'AnotherInterface',
|
||||||
'resolveType' => new \stdClass(),
|
'resolveType' => new stdClass(),
|
||||||
'fields' => ['f' => ['type' => Type::string()]],
|
'fields' => ['f' => ['type' => Type::string()]],
|
||||||
]);
|
]);
|
||||||
$type->assertValid();
|
$type->assertValid();
|
||||||
@ -1148,7 +1150,7 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new UnionType([
|
new UnionType([
|
||||||
'name' => 'SomeUnion',
|
'name' => 'SomeUnion',
|
||||||
'resolveType' => new \stdClass(),
|
'resolveType' => new stdClass(),
|
||||||
'types' => [$this->objectWithIsTypeOf],
|
'types' => [$this->objectWithIsTypeOf],
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -1164,7 +1166,7 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => function () {
|
'serialize' => static function () {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
@ -1203,7 +1205,7 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => new \stdClass(),
|
'serialize' => new stdClass(),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1218,11 +1220,11 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'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(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => function () {
|
'serialize' => static function () {
|
||||||
},
|
},
|
||||||
'parseValue' => function () {
|
'parseValue' => static function () {
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -1260,9 +1262,9 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => function () {
|
'serialize' => static function () {
|
||||||
},
|
},
|
||||||
'parseLiteral' => function () {
|
'parseLiteral' => static function () {
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -1280,10 +1282,10 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new CustomScalarType([
|
new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'name' => 'SomeScalar',
|
||||||
'serialize' => function () {
|
'serialize' => static function () {
|
||||||
},
|
},
|
||||||
'parseValue' => new \stdClass(),
|
'parseValue' => new stdClass(),
|
||||||
'parseLiteral' => new \stdClass(),
|
'parseLiteral' => new stdClass(),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1317,7 +1319,7 @@ class DefinitionTest extends TestCase
|
|||||||
$this->schemaWithFieldType(
|
$this->schemaWithFieldType(
|
||||||
new ObjectType([
|
new ObjectType([
|
||||||
'name' => 'AnotherObject',
|
'name' => 'AnotherObject',
|
||||||
'isTypeOf' => new \stdClass(),
|
'isTypeOf' => new stdClass(),
|
||||||
'fields' => ['f' => ['type' => Type::string()]],
|
'fields' => ['f' => ['type' => Type::string()]],
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -1411,7 +1413,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$inputObjType = new InputObjectType([
|
$inputObjType = new InputObjectType([
|
||||||
'name' => 'SomeInputObject',
|
'name' => 'SomeInputObject',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'f' => ['type' => Type::string()],
|
'f' => ['type' => Type::string()],
|
||||||
];
|
];
|
||||||
@ -1445,7 +1447,7 @@ class DefinitionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$inputObjType = new InputObjectType([
|
$inputObjType = new InputObjectType([
|
||||||
'name' => 'SomeInputObject',
|
'name' => 'SomeInputObject',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -1467,7 +1469,7 @@ class DefinitionTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'f' => [
|
'f' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -1493,7 +1495,7 @@ class DefinitionTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'f' => [
|
'f' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => new \stdClass(),
|
'resolve' => new stdClass(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
@ -1591,12 +1593,12 @@ class DefinitionTest extends TestCase
|
|||||||
Type::nonNull(Type::string()),
|
Type::nonNull(Type::string()),
|
||||||
];
|
];
|
||||||
|
|
||||||
$badTypes = [[], new \stdClass(), '', null];
|
$badTypes = [[], new stdClass(), '', null];
|
||||||
|
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
try {
|
try {
|
||||||
Type::listOf($type);
|
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());
|
$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 = [
|
$notNullableTypes = [
|
||||||
Type::nonNull(Type::string()),
|
Type::nonNull(Type::string()),
|
||||||
[],
|
[],
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
'',
|
'',
|
||||||
null,
|
null,
|
||||||
];
|
];
|
||||||
foreach ($nullableTypes as $type) {
|
foreach ($nullableTypes as $type) {
|
||||||
try {
|
try {
|
||||||
Type::nonNull($type);
|
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());
|
$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([
|
$FakeString = new CustomScalarType([
|
||||||
'name' => 'String',
|
'name' => 'String',
|
||||||
'serialize' => function () {
|
'serialize' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ class EnumTypeTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$Complex1 = [
|
$Complex1 = [
|
||||||
'someRandomFunction' => function () {
|
'someRandomFunction' => static function () {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
$Complex2 = new \ArrayObject(['someRandomValue' => 123]);
|
$Complex2 = new ArrayObject(['someRandomValue' => 123]);
|
||||||
|
|
||||||
$ComplexEnum = new EnumType([
|
$ComplexEnum = new EnumType([
|
||||||
'name' => 'Complex',
|
'name' => 'Complex',
|
||||||
@ -74,7 +74,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromInt' => ['type' => Type::int()],
|
'fromInt' => ['type' => Type::int()],
|
||||||
'fromString' => ['type' => Type::string()],
|
'fromString' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($value, $args) {
|
'resolve' => static function ($value, $args) {
|
||||||
if (isset($args['fromInt'])) {
|
if (isset($args['fromInt'])) {
|
||||||
return $args['fromInt'];
|
return $args['fromInt'];
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromName' => ['type' => Type::string()],
|
'fromName' => ['type' => Type::string()],
|
||||||
'fromValue' => ['type' => Type::string()],
|
'fromValue' => ['type' => Type::string()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($value, $args) {
|
'resolve' => static function ($value, $args) {
|
||||||
if (isset($args['fromName'])) {
|
if (isset($args['fromName'])) {
|
||||||
return $args['fromName'];
|
return $args['fromName'];
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'fromEnum' => ['type' => $ColorType],
|
'fromEnum' => ['type' => $ColorType],
|
||||||
'fromInt' => ['type' => Type::int()],
|
'fromInt' => ['type' => Type::int()],
|
||||||
],
|
],
|
||||||
'resolve' => function ($value, $args) {
|
'resolve' => static function ($value, $args) {
|
||||||
if (isset($args['fromInt'])) {
|
if (isset($args['fromInt'])) {
|
||||||
return $args['fromInt'];
|
return $args['fromInt'];
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'type' => Type::boolean(),
|
'type' => Type::boolean(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'resolve' => function ($value, $args) use ($Complex2) {
|
'resolve' => static function ($value, $args) use ($Complex2) {
|
||||||
if (! empty($args['provideGoodValue'])) {
|
if (! empty($args['provideGoodValue'])) {
|
||||||
// Note: this is one of the references of the internal values which
|
// Note: this is one of the references of the internal values which
|
||||||
// ComplexEnum allows.
|
// ComplexEnum allows.
|
||||||
@ -141,7 +141,7 @@ class EnumTypeTest extends TestCase
|
|||||||
if (! empty($args['provideBadValue'])) {
|
if (! empty($args['provideBadValue'])) {
|
||||||
// Note: similar shape, but not the same *reference*
|
// Note: similar shape, but not the same *reference*
|
||||||
// as Complex2 above. Enum internal values require === equality.
|
// as Complex2 above. Enum internal values require === equality.
|
||||||
return new \ArrayObject(['someRandomValue' => 123]);
|
return new ArrayObject(['someRandomValue' => 123]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args['fromEnum'];
|
return $args['fromEnum'];
|
||||||
@ -156,7 +156,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'favoriteEnum' => [
|
'favoriteEnum' => [
|
||||||
'type' => $ColorType,
|
'type' => $ColorType,
|
||||||
'args' => ['color' => ['type' => $ColorType]],
|
'args' => ['color' => ['type' => $ColorType]],
|
||||||
'resolve' => function ($value, $args) {
|
'resolve' => static function ($value, $args) {
|
||||||
return $args['color'] ?? null;
|
return $args['color'] ?? null;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -169,7 +169,7 @@ class EnumTypeTest extends TestCase
|
|||||||
'subscribeToEnum' => [
|
'subscribeToEnum' => [
|
||||||
'type' => $ColorType,
|
'type' => $ColorType,
|
||||||
'args' => ['color' => ['type' => $ColorType]],
|
'args' => ['color' => ['type' => $ColorType]],
|
||||||
'resolve' => function ($value, $args) {
|
'resolve' => static function ($value, $args) {
|
||||||
return $args['color'] ?? null;
|
return $args['color'] ?? null;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -365,6 +365,7 @@ class EnumTypeTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see it('accepts enum literals as input arguments to subscriptions')
|
* @see it('accepts enum literals as input arguments to subscriptions')
|
||||||
|
*
|
||||||
* @todo
|
* @todo
|
||||||
*/
|
*/
|
||||||
public function testAcceptsEnumLiteralsAsInputArgumentsToSubscriptions() : void
|
public function testAcceptsEnumLiteralsAsInputArgumentsToSubscriptions() : void
|
||||||
|
@ -1049,7 +1049,7 @@ class IntrospectionTest extends TestCase
|
|||||||
'field' => [
|
'field' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'args' => ['complex' => ['type' => $TestInputObject]],
|
'args' => ['complex' => ['type' => $TestInputObject]],
|
||||||
'resolve' => function ($_, $args) {
|
'resolve' => static function ($_, $args) {
|
||||||
return json_encode($args['complex']);
|
return json_encode($args['complex']);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Type;
|
namespace GraphQL\Tests\Type;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Error\InvariantViolation;
|
use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Type\Definition\InputObjectType;
|
use GraphQL\Type\Definition\InputObjectType;
|
||||||
use GraphQL\Type\Definition\InterfaceType;
|
use GraphQL\Type\Definition\InterfaceType;
|
||||||
@ -460,8 +461,8 @@ class ResolutionTest extends TestCase
|
|||||||
$eager = new EagerResolution([]);
|
$eager = new EagerResolution([]);
|
||||||
$emptyDescriptor = $eager->getDescriptor();
|
$emptyDescriptor = $eager->getDescriptor();
|
||||||
|
|
||||||
$typeLoader = function ($name) {
|
$typeLoader = static function () {
|
||||||
throw new \Exception('This should be never called for empty descriptor');
|
throw new Exception('This should be never called for empty descriptor');
|
||||||
};
|
};
|
||||||
|
|
||||||
$lazy = new LazyResolution($emptyDescriptor, $typeLoader);
|
$lazy = new LazyResolution($emptyDescriptor, $typeLoader);
|
||||||
@ -547,7 +548,7 @@ class ResolutionTest extends TestCase
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$invalidTypeLoader = function ($name) {
|
$invalidTypeLoader = static function ($name) {
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'null':
|
case 'null':
|
||||||
return null;
|
return null;
|
||||||
|
@ -28,7 +28,7 @@ class ResolveInfoTest extends TestCase
|
|||||||
|
|
||||||
$author = new ObjectType([
|
$author = new ObjectType([
|
||||||
'name' => 'Author',
|
'name' => 'Author',
|
||||||
'fields' => function () use ($image, &$article) {
|
'fields' => static function () use ($image, &$article) {
|
||||||
return [
|
return [
|
||||||
'id' => ['type' => Type::string()],
|
'id' => ['type' => Type::string()],
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
@ -151,7 +151,7 @@ class ResolveInfoTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'article' => [
|
'article' => [
|
||||||
'type' => $article,
|
'type' => $article,
|
||||||
'resolve' => function (
|
'resolve' => static function (
|
||||||
$value,
|
$value,
|
||||||
$args,
|
$args,
|
||||||
$context,
|
$context,
|
||||||
@ -196,7 +196,7 @@ class ResolveInfoTest extends TestCase
|
|||||||
|
|
||||||
$author = new ObjectType([
|
$author = new ObjectType([
|
||||||
'name' => 'Author',
|
'name' => 'Author',
|
||||||
'fields' => function () use ($image, &$article) {
|
'fields' => static function () use ($image, &$article) {
|
||||||
return [
|
return [
|
||||||
'id' => ['type' => Type::string()],
|
'id' => ['type' => Type::string()],
|
||||||
'name' => ['type' => Type::string()],
|
'name' => ['type' => Type::string()],
|
||||||
@ -324,7 +324,7 @@ class ResolveInfoTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'article' => [
|
'article' => [
|
||||||
'type' => $article,
|
'type' => $article,
|
||||||
'resolve' => function (
|
'resolve' => static function (
|
||||||
$value,
|
$value,
|
||||||
$args,
|
$args,
|
||||||
$context,
|
$context,
|
||||||
|
@ -7,6 +7,7 @@ namespace GraphQL\Tests\Type;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class ScalarSerializationTest extends TestCase
|
class ScalarSerializationTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -176,7 +177,7 @@ class ScalarSerializationTest extends TestCase
|
|||||||
$stringType = Type::string();
|
$stringType = Type::string();
|
||||||
$this->expectException(Error::class);
|
$this->expectException(Error::class);
|
||||||
$this->expectExceptionMessage('String cannot represent non scalar value: instance of stdClass');
|
$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();
|
$idType = Type::id();
|
||||||
$this->expectException(Error::class);
|
$this->expectException(Error::class);
|
||||||
$this->expectExceptionMessage('ID type cannot represent non scalar value: instance of stdClass');
|
$this->expectExceptionMessage('ID type cannot represent non scalar value: instance of stdClass');
|
||||||
$idType->serialize(new \stdClass());
|
$idType->serialize(new stdClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class SchemaTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'fieldName' => [
|
'fieldName' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -90,7 +90,7 @@ class SchemaTest extends TestCase
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'getObject' => [
|
'getObject' => [
|
||||||
'type' => $this->interfaceType,
|
'type' => $this->interfaceType,
|
||||||
'resolve' => function () {
|
'resolve' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Type;
|
namespace GraphQL\Tests\Type;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Error\InvariantViolation;
|
use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Type\Definition\InputObjectType;
|
use GraphQL\Type\Definition\InputObjectType;
|
||||||
use GraphQL\Type\Definition\InterfaceType;
|
use GraphQL\Type\Definition\InterfaceType;
|
||||||
@ -11,6 +12,8 @@ use GraphQL\Type\Definition\ObjectType;
|
|||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
use Throwable;
|
||||||
use function lcfirst;
|
use function lcfirst;
|
||||||
|
|
||||||
class TypeLoaderTest extends TestCase
|
class TypeLoaderTest extends TestCase
|
||||||
@ -55,7 +58,7 @@ class TypeLoaderTest extends TestCase
|
|||||||
'id' => Type::string(),
|
'id' => Type::string(),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'resolveType' => function () {
|
'resolveType' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -69,7 +72,7 @@ class TypeLoaderTest extends TestCase
|
|||||||
'body' => Type::string(),
|
'body' => Type::string(),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'resolveType' => function () {
|
'resolveType' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -152,7 +155,7 @@ class TypeLoaderTest extends TestCase
|
|||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
'fields' => ['a' => Type::string()],
|
'fields' => ['a' => Type::string()],
|
||||||
]),
|
]),
|
||||||
'typeLoader' => function () {
|
'typeLoader' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -253,7 +256,7 @@ class TypeLoaderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$schema = new Schema([
|
$schema = new Schema([
|
||||||
'query' => $this->query,
|
'query' => $this->query,
|
||||||
'typeLoader' => function () {
|
'typeLoader' => static function () {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -267,8 +270,8 @@ class TypeLoaderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$schema = new Schema([
|
$schema = new Schema([
|
||||||
'query' => $this->query,
|
'query' => $this->query,
|
||||||
'typeLoader' => function () {
|
'typeLoader' => static function () {
|
||||||
return new \stdClass();
|
return new stdClass();
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -297,12 +300,12 @@ class TypeLoaderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$schema = new Schema([
|
$schema = new Schema([
|
||||||
'query' => $this->query,
|
'query' => $this->query,
|
||||||
'typeLoader' => function () {
|
'typeLoader' => static function () {
|
||||||
throw new \Exception('This is the exception we are looking for');
|
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');
|
$this->expectExceptionMessage('This is the exception we are looking for');
|
||||||
|
|
||||||
$schema->getType('Node');
|
$schema->getType('Node');
|
||||||
|
@ -66,11 +66,11 @@ class ValidationTest extends TestCase
|
|||||||
|
|
||||||
$this->SomeScalarType = new CustomScalarType([
|
$this->SomeScalarType = new CustomScalarType([
|
||||||
'name' => 'SomeScalar',
|
'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,
|
$types,
|
||||||
Utils::map(
|
Utils::map(
|
||||||
$types,
|
$types,
|
||||||
function ($type) {
|
static function ($type) {
|
||||||
return Type::listOf($type);
|
return Type::listOf($type);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Utils::map(
|
Utils::map(
|
||||||
$types,
|
$types,
|
||||||
function ($type) {
|
static function ($type) {
|
||||||
return Type::nonNull($type);
|
return Type::nonNull($type);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Utils::map(
|
Utils::map(
|
||||||
$types,
|
$types,
|
||||||
function ($type) {
|
static function ($type) {
|
||||||
return Type::nonNull(Type::listOf($type));
|
return Type::nonNull(Type::listOf($type));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -173,19 +173,19 @@ class ValidationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEachCallableThrows(
|
$this->assertEachCallableThrows(
|
||||||
[
|
[
|
||||||
function () {
|
static function () {
|
||||||
return new ObjectType([]);
|
return new ObjectType([]);
|
||||||
},
|
},
|
||||||
function () {
|
static function () {
|
||||||
return new EnumType([]);
|
return new EnumType([]);
|
||||||
},
|
},
|
||||||
function () {
|
static function () {
|
||||||
return new InputObjectType([]);
|
return new InputObjectType([]);
|
||||||
},
|
},
|
||||||
function () {
|
static function () {
|
||||||
return new UnionType([]);
|
return new UnionType([]);
|
||||||
},
|
},
|
||||||
function () {
|
static function () {
|
||||||
return new InterfaceType([]);
|
return new InterfaceType([]);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -347,7 +347,7 @@ class ValidationTest extends TestCase
|
|||||||
implode(
|
implode(
|
||||||
"\n",
|
"\n",
|
||||||
array_map(
|
array_map(
|
||||||
function ($error) {
|
static function ($error) {
|
||||||
return $error->getMessage();
|
return $error->getMessage();
|
||||||
},
|
},
|
||||||
$array
|
$array
|
||||||
@ -581,7 +581,7 @@ class ValidationTest extends TestCase
|
|||||||
$manualSchema2 = $this->schemaWithFieldType(
|
$manualSchema2 = $this->schemaWithFieldType(
|
||||||
new ObjectType([
|
new ObjectType([
|
||||||
'name' => 'IncompleteObject',
|
'name' => 'IncompleteObject',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
@ -989,6 +989,7 @@ class ValidationTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see it('rejects an Enum type with incorrectly named values')
|
* @see it('rejects an Enum type with incorrectly named values')
|
||||||
|
*
|
||||||
* @dataProvider invalidEnumValueName
|
* @dataProvider invalidEnumValueName
|
||||||
*/
|
*/
|
||||||
public function testRejectsAnEnumTypeWithIncorrectlyNamedValues($name, $expectedMessage) : void
|
public function testRejectsAnEnumTypeWithIncorrectlyNamedValues($name, $expectedMessage) : void
|
||||||
@ -1974,7 +1975,7 @@ class ValidationTest extends TestCase
|
|||||||
public function testRejectsDifferentInstancesOfTheSameType() : void
|
public function testRejectsDifferentInstancesOfTheSameType() : void
|
||||||
{
|
{
|
||||||
// Invalid: always creates new instance vs returning one from registry
|
// Invalid: always creates new instance vs returning one from registry
|
||||||
$typeLoader = function ($name) {
|
$typeLoader = static function ($name) {
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'Query':
|
case 'Query':
|
||||||
return new ObjectType([
|
return new ObjectType([
|
||||||
|
@ -20,6 +20,7 @@ use GraphQL\Type\Definition\Type;
|
|||||||
use GraphQL\Utils\AST;
|
use GraphQL\Utils\AST;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class AstFromValueTest extends TestCase
|
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
|
// GraphQL spec does not allow coercing non-integer values to Int to avoid
|
||||||
// accidental data loss.
|
// accidental data loss.
|
||||||
$this->expectException(\Throwable::class);
|
$this->expectException(Throwable::class);
|
||||||
$this->expectExceptionMessage('Int cannot represent non-integer value: 123.5');
|
$this->expectExceptionMessage('Int cannot represent non-integer value: 123.5');
|
||||||
AST::astFromValue(123.5, Type::int());
|
AST::astFromValue(123.5, Type::int());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConvertsIntValuesToASTsCannotRepresentNon32bitsInteger() : void
|
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');
|
$this->expectExceptionMessage('Int cannot represent non 32-bit signed integer value: 1.0E+40');
|
||||||
AST::astFromValue(
|
AST::astFromValue(
|
||||||
1e40,
|
1e40,
|
||||||
@ -165,7 +166,7 @@ class AstFromValueTest extends TestCase
|
|||||||
private function complexValue()
|
private function complexValue()
|
||||||
{
|
{
|
||||||
if (! $this->complexValue) {
|
if (! $this->complexValue) {
|
||||||
$this->complexValue = new \stdClass();
|
$this->complexValue = new stdClass();
|
||||||
$this->complexValue->someArbitrary = 'complexValue';
|
$this->complexValue->someArbitrary = 'complexValue';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,6 +233,7 @@ class AstFromValueTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return ObjectFieldNode
|
* @return ObjectFieldNode
|
||||||
*/
|
*/
|
||||||
private function objectField(string $name, $value)
|
private function objectField(string $name, $value)
|
||||||
@ -257,9 +259,9 @@ class AstFromValueTest extends TestCase
|
|||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
new ObjectValueNode([
|
new ObjectValueNode([
|
||||||
'fields' => [
|
'fields' => [
|
||||||
$this->objectField('foo', new NullValueNode([])),
|
$this->objectField('foo', new NullValueNode([])),
|
||||||
],
|
],
|
||||||
]),
|
]),
|
||||||
AST::astFromValue(['foo' => null], $inputObj)
|
AST::astFromValue(['foo' => null], $inputObj)
|
||||||
);
|
);
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Utils;
|
namespace GraphQL\Tests\Utils;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\GraphQL;
|
use GraphQL\GraphQL;
|
||||||
use GraphQL\Language\AST\EnumTypeDefinitionNode;
|
use GraphQL\Language\AST\EnumTypeDefinitionNode;
|
||||||
@ -51,7 +52,7 @@ class BuildSchemaTest extends TestCase
|
|||||||
');
|
');
|
||||||
|
|
||||||
$root = [
|
$root = [
|
||||||
'add' => function ($root, $args) {
|
'add' => static function ($root, $args) {
|
||||||
return $args['x'] + $args['y'];
|
return $args['x'] + $args['y'];
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -1196,7 +1197,7 @@ interface Hello {
|
|||||||
$decorated = [];
|
$decorated = [];
|
||||||
$calls = [];
|
$calls = [];
|
||||||
|
|
||||||
$typeConfigDecorator = function ($defaultConfig, $node, $allNodesMap) use (&$decorated, &$calls) {
|
$typeConfigDecorator = static function ($defaultConfig, $node, $allNodesMap) use (&$decorated, &$calls) {
|
||||||
$decorated[] = $defaultConfig['name'];
|
$decorated[] = $defaultConfig['name'];
|
||||||
$calls[] = [$defaultConfig, $node, $allNodesMap];
|
$calls[] = [$defaultConfig, $node, $allNodesMap];
|
||||||
|
|
||||||
@ -1207,17 +1208,17 @@ interface Hello {
|
|||||||
$schema->getTypeMap();
|
$schema->getTypeMap();
|
||||||
self::assertEquals(['Query', 'Color', 'Hello'], $decorated);
|
self::assertEquals(['Query', 'Color', 'Hello'], $decorated);
|
||||||
|
|
||||||
list($defaultConfig, $node, $allNodesMap) = $calls[0];
|
[$defaultConfig, $node, $allNodesMap] = $calls[0];
|
||||||
self::assertInstanceOf(ObjectTypeDefinitionNode::class, $node);
|
self::assertInstanceOf(ObjectTypeDefinitionNode::class, $node);
|
||||||
self::assertEquals('Query', $defaultConfig['name']);
|
self::assertEquals('Query', $defaultConfig['name']);
|
||||||
self::assertInstanceOf(\Closure::class, $defaultConfig['fields']);
|
self::assertInstanceOf(Closure::class, $defaultConfig['fields']);
|
||||||
self::assertInstanceOf(\Closure::class, $defaultConfig['interfaces']);
|
self::assertInstanceOf(Closure::class, $defaultConfig['interfaces']);
|
||||||
self::assertArrayHasKey('description', $defaultConfig);
|
self::assertArrayHasKey('description', $defaultConfig);
|
||||||
self::assertCount(5, $defaultConfig);
|
self::assertCount(5, $defaultConfig);
|
||||||
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
||||||
self::assertEquals('My description of Query', $schema->getType('Query')->description);
|
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::assertInstanceOf(EnumTypeDefinitionNode::class, $node);
|
||||||
self::assertEquals('Color', $defaultConfig['name']);
|
self::assertEquals('Color', $defaultConfig['name']);
|
||||||
$enumValue = [
|
$enumValue = [
|
||||||
@ -1236,10 +1237,10 @@ interface Hello {
|
|||||||
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
||||||
self::assertEquals('My description of Color', $schema->getType('Color')->description);
|
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::assertInstanceOf(InterfaceTypeDefinitionNode::class, $node);
|
||||||
self::assertEquals('Hello', $defaultConfig['name']);
|
self::assertEquals('Hello', $defaultConfig['name']);
|
||||||
self::assertInstanceOf(\Closure::class, $defaultConfig['fields']);
|
self::assertInstanceOf(Closure::class, $defaultConfig['fields']);
|
||||||
self::assertArrayHasKey('description', $defaultConfig);
|
self::assertArrayHasKey('description', $defaultConfig);
|
||||||
self::assertCount(4, $defaultConfig);
|
self::assertCount(4, $defaultConfig);
|
||||||
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
self::assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
||||||
@ -1276,7 +1277,7 @@ type World implements Hello {
|
|||||||
$doc = Parser::parse($body);
|
$doc = Parser::parse($body);
|
||||||
$created = [];
|
$created = [];
|
||||||
|
|
||||||
$typeConfigDecorator = function ($config, $node) use (&$created) {
|
$typeConfigDecorator = static function ($config, $node) use (&$created) {
|
||||||
$created[] = $node->name->value;
|
$created[] = $node->name->value;
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
|
@ -7,6 +7,7 @@ namespace GraphQL\Tests\Utils;
|
|||||||
use GraphQL\Utils\MixedStore;
|
use GraphQL\Utils\MixedStore;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class MixedStoreTest extends TestCase
|
class MixedStoreTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -36,8 +37,8 @@ class MixedStoreTest extends TestCase
|
|||||||
'1',
|
'1',
|
||||||
'a',
|
'a',
|
||||||
[],
|
[],
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
function () {
|
static function () {
|
||||||
},
|
},
|
||||||
new MixedStore(),
|
new MixedStore(),
|
||||||
];
|
];
|
||||||
@ -111,7 +112,7 @@ class MixedStoreTest extends TestCase
|
|||||||
$this->assertAcceptsKeyValue([], $value);
|
$this->assertAcceptsKeyValue([], $value);
|
||||||
$this->assertAcceptsKeyValue([null], $value);
|
$this->assertAcceptsKeyValue([null], $value);
|
||||||
$this->assertAcceptsKeyValue([[]], $value);
|
$this->assertAcceptsKeyValue([[]], $value);
|
||||||
$this->assertAcceptsKeyValue([new \stdClass()], $value);
|
$this->assertAcceptsKeyValue([new stdClass()], $value);
|
||||||
$this->assertAcceptsKeyValue(['a', 'b'], $value);
|
$this->assertAcceptsKeyValue(['a', 'b'], $value);
|
||||||
$this->assertAcceptsKeyValue(['a' => 'b'], $value);
|
$this->assertAcceptsKeyValue(['a' => 'b'], $value);
|
||||||
}
|
}
|
||||||
@ -120,10 +121,10 @@ class MixedStoreTest extends TestCase
|
|||||||
public function testAcceptsObjectKeys() : void
|
public function testAcceptsObjectKeys() : void
|
||||||
{
|
{
|
||||||
foreach ($this->getPossibleValues() as $value) {
|
foreach ($this->getPossibleValues() as $value) {
|
||||||
$this->assertAcceptsKeyValue(new \stdClass(), $value);
|
$this->assertAcceptsKeyValue(new stdClass(), $value);
|
||||||
$this->assertAcceptsKeyValue(new MixedStore(), $value);
|
$this->assertAcceptsKeyValue(new MixedStore(), $value);
|
||||||
$this->assertAcceptsKeyValue(
|
$this->assertAcceptsKeyValue(
|
||||||
function () {
|
static function () {
|
||||||
},
|
},
|
||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace GraphQL\Tests\Utils;
|
namespace GraphQL\Tests\Utils;
|
||||||
|
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
|
use LogicException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class QuotedOrListTest extends TestCase
|
class QuotedOrListTest extends TestCase
|
||||||
@ -15,7 +16,7 @@ class QuotedOrListTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testResturnsResultsWhenInputIsEmpty() : void
|
public function testResturnsResultsWhenInputIsEmpty() : void
|
||||||
{
|
{
|
||||||
$this->expectException(\LogicException::class);
|
$this->expectException(LogicException::class);
|
||||||
Utils::quotedOrList([]);
|
Utils::quotedOrList([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ type Query {
|
|||||||
{
|
{
|
||||||
$oddType = new CustomScalarType([
|
$oddType = new CustomScalarType([
|
||||||
'name' => 'Odd',
|
'name' => 'Odd',
|
||||||
'serialize' => function ($value) {
|
'serialize' => static function ($value) {
|
||||||
return $value % 2 === 1 ? $value : null;
|
return $value % 2 === 1 ? $value : null;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -5,16 +5,18 @@ declare(strict_types=1);
|
|||||||
namespace GraphQL\Tests;
|
namespace GraphQL\Tests;
|
||||||
|
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
|
use InvalidArgumentException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class UtilsTest extends TestCase
|
class UtilsTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAssignThrowsExceptionOnMissingRequiredKey() : void
|
public function testAssignThrowsExceptionOnMissingRequiredKey() : void
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$object = new stdClass();
|
||||||
$object->requiredKey = 'value';
|
$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');
|
$this->expectExceptionMessage('Key requiredKey is expected to be set and not to be null');
|
||||||
Utils::assign($object, [], ['requiredKey']);
|
Utils::assign($object, [], ['requiredKey']);
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
|
|||||||
|
|
||||||
$SomeBox = new InterfaceType([
|
$SomeBox = new InterfaceType([
|
||||||
'name' => 'SomeBox',
|
'name' => 'SomeBox',
|
||||||
'fields' => function () use (&$SomeBox) {
|
'fields' => static function () use (&$SomeBox) {
|
||||||
return [
|
return [
|
||||||
'deepBox' => ['type' => $SomeBox],
|
'deepBox' => ['type' => $SomeBox],
|
||||||
'unrelatedField' => ['type' => Type::string()],
|
'unrelatedField' => ['type' => Type::string()],
|
||||||
@ -714,7 +714,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
|
|||||||
$StringBox = new ObjectType([
|
$StringBox = new ObjectType([
|
||||||
'name' => 'StringBox',
|
'name' => 'StringBox',
|
||||||
'interfaces' => [$SomeBox],
|
'interfaces' => [$SomeBox],
|
||||||
'fields' => function () use (&$StringBox, &$IntBox) {
|
'fields' => static function () use (&$StringBox, &$IntBox) {
|
||||||
return [
|
return [
|
||||||
'scalar' => ['type' => Type::string()],
|
'scalar' => ['type' => Type::string()],
|
||||||
'deepBox' => ['type' => $StringBox],
|
'deepBox' => ['type' => $StringBox],
|
||||||
@ -729,7 +729,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
|
|||||||
$IntBox = new ObjectType([
|
$IntBox = new ObjectType([
|
||||||
'name' => 'IntBox',
|
'name' => 'IntBox',
|
||||||
'interfaces' => [$SomeBox],
|
'interfaces' => [$SomeBox],
|
||||||
'fields' => function () use (&$StringBox, &$IntBox) {
|
'fields' => static function () use (&$StringBox, &$IntBox) {
|
||||||
return [
|
return [
|
||||||
'scalar' => ['type' => Type::int()],
|
'scalar' => ['type' => Type::int()],
|
||||||
'deepBox' => ['type' => $IntBox],
|
'deepBox' => ['type' => $IntBox],
|
||||||
@ -797,7 +797,7 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$schema = new Schema([
|
return new Schema([
|
||||||
'query' => new ObjectType([
|
'query' => new ObjectType([
|
||||||
'name' => 'QueryRoot',
|
'name' => 'QueryRoot',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
@ -807,8 +807,6 @@ class OverlappingFieldsCanBeMergedTest extends ValidatorTestCase
|
|||||||
]),
|
]),
|
||||||
'types' => [$IntBox, $StringBox, $NonNullStringBox1Impl, $NonNullStringBox2Impl],
|
'types' => [$IntBox, $StringBox, $NonNullStringBox1Impl, $NonNullStringBox2Impl],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,10 +168,10 @@ class QueryComplexityTest extends QuerySecurityTestCase
|
|||||||
$reportedError = new Error('OtherValidatorError');
|
$reportedError = new Error('OtherValidatorError');
|
||||||
$otherRule = new CustomValidationRule(
|
$otherRule = new CustomValidationRule(
|
||||||
'otherRule',
|
'otherRule',
|
||||||
function (ValidationContext $context) use ($reportedError) {
|
static function (ValidationContext $context) use ($reportedError) {
|
||||||
return [
|
return [
|
||||||
NodeKind::OPERATION_DEFINITION => [
|
NodeKind::OPERATION_DEFINITION => [
|
||||||
'leave' => function () use ($context, $reportedError) {
|
'leave' => static function () use ($context, $reportedError) {
|
||||||
$context->reportError($reportedError);
|
$context->reportError($reportedError);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -14,6 +14,7 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
* @param int $queryDepth
|
* @param int $queryDepth
|
||||||
* @param int $maxQueryDepth
|
* @param int $maxQueryDepth
|
||||||
* @param string[][] $expectedErrors
|
* @param string[][] $expectedErrors
|
||||||
|
*
|
||||||
* @dataProvider queryDataProvider
|
* @dataProvider queryDataProvider
|
||||||
*/
|
*/
|
||||||
public function testSimpleQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
public function testSimpleQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
||||||
@ -23,9 +24,7 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
|
|
||||||
private function buildRecursiveQuery($depth)
|
private function buildRecursiveQuery($depth)
|
||||||
{
|
{
|
||||||
$query = sprintf('query MyQuery { human%s }', $this->buildRecursiveQueryPart($depth));
|
return sprintf('query MyQuery { human%s }', $this->buildRecursiveQueryPart($depth));
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildRecursiveQueryPart($depth)
|
private function buildRecursiveQueryPart($depth)
|
||||||
@ -38,7 +37,7 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
$part = $templates['human'];
|
$part = $templates['human'];
|
||||||
|
|
||||||
for ($i = 1; $i <= $depth; ++$i) {
|
for ($i = 1; $i <= $depth; ++$i) {
|
||||||
$key = ($i % 2 === 1) ? 'human' : 'dog';
|
$key = $i % 2 === 1 ? 'human' : 'dog';
|
||||||
$template = $templates[$key];
|
$template = $templates[$key];
|
||||||
|
|
||||||
$part = sprintf($part, ($key === 'human' ? ' owner ' : '') . $template);
|
$part = sprintf($part, ($key === 'human' ? ' owner ' : '') . $template);
|
||||||
@ -52,6 +51,7 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
* @param int $queryDepth
|
* @param int $queryDepth
|
||||||
* @param int $maxQueryDepth
|
* @param int $maxQueryDepth
|
||||||
* @param string[][] $expectedErrors
|
* @param string[][] $expectedErrors
|
||||||
|
*
|
||||||
* @dataProvider queryDataProvider
|
* @dataProvider queryDataProvider
|
||||||
*/
|
*/
|
||||||
public function testFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
public function testFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
||||||
@ -65,18 +65,17 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
|
|
||||||
private function buildRecursiveUsingFragmentQuery($depth)
|
private function buildRecursiveUsingFragmentQuery($depth)
|
||||||
{
|
{
|
||||||
$query = sprintf(
|
return sprintf(
|
||||||
'query MyQuery { human { ...F1 } } fragment F1 on Human %s',
|
'query MyQuery { human { ...F1 } } fragment F1 on Human %s',
|
||||||
$this->buildRecursiveQueryPart($depth)
|
$this->buildRecursiveQueryPart($depth)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $queryDepth
|
* @param int $queryDepth
|
||||||
* @param int $maxQueryDepth
|
* @param int $maxQueryDepth
|
||||||
* @param string[][] $expectedErrors
|
* @param string[][] $expectedErrors
|
||||||
|
*
|
||||||
* @dataProvider queryDataProvider
|
* @dataProvider queryDataProvider
|
||||||
*/
|
*/
|
||||||
public function testInlineFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
public function testInlineFragmentQueries($queryDepth, $maxQueryDepth = 7, $expectedErrors = []) : void
|
||||||
@ -90,12 +89,10 @@ class QueryDepthTest extends QuerySecurityTestCase
|
|||||||
|
|
||||||
private function buildRecursiveUsingInlineFragmentQuery($depth)
|
private function buildRecursiveUsingInlineFragmentQuery($depth)
|
||||||
{
|
{
|
||||||
$query = sprintf(
|
return sprintf(
|
||||||
'query MyQuery { human { ...on Human %s } }',
|
'query MyQuery { human { ...on Human %s } }',
|
||||||
$this->buildRecursiveQueryPart($depth)
|
$this->buildRecursiveQueryPart($depth)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testComplexityIntrospectionQuery() : void
|
public function testComplexityIntrospectionQuery() : void
|
||||||
|
@ -66,7 +66,7 @@ class QuerySecuritySchema
|
|||||||
self::$humanType = new ObjectType(
|
self::$humanType = new ObjectType(
|
||||||
[
|
[
|
||||||
'name' => 'Human',
|
'name' => 'Human',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'firstName' => ['type' => Type::nonNull(Type::string())],
|
'firstName' => ['type' => Type::nonNull(Type::string())],
|
||||||
'dogs' => [
|
'dogs' => [
|
||||||
@ -75,7 +75,7 @@ class QuerySecuritySchema
|
|||||||
Type::nonNull(self::buildDogType())
|
Type::nonNull(self::buildDogType())
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'complexity' => function ($childrenComplexity, $args) {
|
'complexity' => static function ($childrenComplexity, $args) {
|
||||||
$complexity = isset($args['name']) ? 1 : 10;
|
$complexity = isset($args['name']) ? 1 : 10;
|
||||||
|
|
||||||
return $childrenComplexity + $complexity;
|
return $childrenComplexity + $complexity;
|
||||||
|
@ -52,6 +52,7 @@ abstract class QuerySecurityTestCase extends TestCase
|
|||||||
* @param string $queryString
|
* @param string $queryString
|
||||||
* @param int $max
|
* @param int $max
|
||||||
* @param string[][] $expectedErrors
|
* @param string[][] $expectedErrors
|
||||||
|
*
|
||||||
* @return Error[]
|
* @return Error[]
|
||||||
*/
|
*/
|
||||||
protected function assertDocumentValidator($queryString, $max, array $expectedErrors = []) : array
|
protected function assertDocumentValidator($queryString, $max, array $expectedErrors = []) : array
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Tests\Validator;
|
namespace GraphQL\Tests\Validator;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Type\Definition\CustomScalarType;
|
use GraphQL\Type\Definition\CustomScalarType;
|
||||||
use GraphQL\Type\Definition\Directive;
|
use GraphQL\Type\Definition\Directive;
|
||||||
@ -63,7 +64,7 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
|
|
||||||
$Canine = new InterfaceType([
|
$Canine = new InterfaceType([
|
||||||
'name' => 'Canine',
|
'name' => 'Canine',
|
||||||
'fields' => function () {
|
'fields' => static function () {
|
||||||
return [
|
return [
|
||||||
'name' => [
|
'name' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
@ -110,7 +111,7 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
|
|
||||||
$Cat = new ObjectType([
|
$Cat = new ObjectType([
|
||||||
'name' => 'Cat',
|
'name' => 'Cat',
|
||||||
'fields' => function () use (&$FurColor) {
|
'fields' => static function () use (&$FurColor) {
|
||||||
return [
|
return [
|
||||||
'name' => [
|
'name' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
@ -141,7 +142,7 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
$Human = new ObjectType([
|
$Human = new ObjectType([
|
||||||
'name' => 'Human',
|
'name' => 'Human',
|
||||||
'interfaces' => [$Being, $Intelligent],
|
'interfaces' => [$Being, $Intelligent],
|
||||||
'fields' => function () use (&$Human, $Pet) {
|
'fields' => static function () use (&$Human, $Pet) {
|
||||||
return [
|
return [
|
||||||
'name' => [
|
'name' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
@ -289,26 +290,26 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
|
|
||||||
$invalidScalar = new CustomScalarType([
|
$invalidScalar = new CustomScalarType([
|
||||||
'name' => 'Invalid',
|
'name' => 'Invalid',
|
||||||
'serialize' => function ($value) {
|
'serialize' => static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
},
|
},
|
||||||
'parseLiteral' => function ($node) {
|
'parseLiteral' => static function ($node) {
|
||||||
throw new \Exception('Invalid scalar is always invalid: ' . $node->value);
|
throw new Exception('Invalid scalar is always invalid: ' . $node->value);
|
||||||
},
|
},
|
||||||
'parseValue' => function ($node) {
|
'parseValue' => static function ($node) {
|
||||||
throw new \Exception('Invalid scalar is always invalid: ' . $node);
|
throw new Exception('Invalid scalar is always invalid: ' . $node);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$anyScalar = new CustomScalarType([
|
$anyScalar = new CustomScalarType([
|
||||||
'name' => 'Any',
|
'name' => 'Any',
|
||||||
'serialize' => function ($value) {
|
'serialize' => static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
},
|
},
|
||||||
'parseLiteral' => function ($node) {
|
'parseLiteral' => static function ($node) {
|
||||||
return $node;
|
return $node;
|
||||||
}, // Allows any value
|
}, // Allows any value
|
||||||
'parseValue' => function ($value) {
|
'parseValue' => static function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
}, // Allows any value
|
}, // Allows any value
|
||||||
]);
|
]);
|
||||||
@ -341,7 +342,7 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$testSchema = new Schema([
|
return new Schema([
|
||||||
'query' => $queryRoot,
|
'query' => $queryRoot,
|
||||||
'directives' => [
|
'directives' => [
|
||||||
Directive::includeDirective(),
|
Directive::includeDirective(),
|
||||||
@ -420,8 +421,6 @@ abstract class ValidatorTestCase extends TestCase
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $testSchema;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function expectFailsRule($rule, $queryString, $errors)
|
protected function expectFailsRule($rule, $queryString, $errors)
|
||||||
|
@ -1286,6 +1286,7 @@ class ValuesOfCorrectTypeTest extends ValidatorTestCase
|
|||||||
* @see it('Partial object, unknown field arg')
|
* @see it('Partial object, unknown field arg')
|
||||||
*
|
*
|
||||||
* The sorting of equal elements has changed so that the test fails on php < 7
|
* The sorting of equal elements has changed so that the test fails on php < 7
|
||||||
|
*
|
||||||
* @requires PHP 7.0
|
* @requires PHP 7.0
|
||||||
*/
|
*/
|
||||||
public function testPartialObjectUnknownFieldArg() : void
|
public function testPartialObjectUnknownFieldArg() : void
|
||||||
|
Loading…
Reference in New Issue
Block a user