mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 14:26:08 +03:00
Merge pull request #367 from simPod/phpstan-strict
Use PHPStan strict rules
This commit is contained in:
commit
6cce6742eb
@ -18,6 +18,7 @@
|
|||||||
"phpbench/phpbench": "^0.14.0",
|
"phpbench/phpbench": "^0.14.0",
|
||||||
"phpstan/phpstan": "^0.10.3",
|
"phpstan/phpstan": "^0.10.3",
|
||||||
"phpstan/phpstan-phpunit": "^0.10.0",
|
"phpstan/phpstan-phpunit": "^0.10.0",
|
||||||
|
"phpstan/phpstan-strict-rules": "^0.10.1",
|
||||||
"phpunit/phpunit": "^7.2",
|
"phpunit/phpunit": "^7.2",
|
||||||
"psr/http-message": "^1.0",
|
"psr/http-message": "^1.0",
|
||||||
"react/promise": "2.*"
|
"react/promise": "2.*"
|
||||||
|
@ -5,6 +5,11 @@ parameters:
|
|||||||
- %currentWorkingDirectory%/src
|
- %currentWorkingDirectory%/src
|
||||||
- %currentWorkingDirectory%/tests
|
- %currentWorkingDirectory%/tests
|
||||||
|
|
||||||
|
ignoreErrors:
|
||||||
|
- "~Construct empty\\(\\) is not allowed\\. Use more strict comparison~"
|
||||||
|
- "~(Method|Property) .+::.+(\\(\\))? (has parameter \\$\\w+ with no|has no return|has no) typehint specified~"
|
||||||
|
|
||||||
includes:
|
includes:
|
||||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||||
- vendor/phpstan/phpstan-phpunit/rules.neon
|
- vendor/phpstan/phpstan-phpunit/rules.neon
|
||||||
|
- vendor/phpstan/phpstan-strict-rules/rules.neon
|
||||||
|
@ -258,14 +258,14 @@ class Executor
|
|||||||
$rawVariableValues ?: []
|
$rawVariableValues ?: []
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($coercedVariableValues['errors']) {
|
if (empty($coercedVariableValues['errors'])) {
|
||||||
$errors = array_merge($errors, $coercedVariableValues['errors']);
|
|
||||||
} else {
|
|
||||||
$variableValues = $coercedVariableValues['coerced'];
|
$variableValues = $coercedVariableValues['coerced'];
|
||||||
|
} else {
|
||||||
|
$errors = array_merge($errors, $coercedVariableValues['errors']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($errors) {
|
if (! empty($errors)) {
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +322,7 @@ class Executor
|
|||||||
if ($data !== null) {
|
if ($data !== null) {
|
||||||
$data = (array) $data;
|
$data = (array) $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ExecutionResult($data, $this->exeContext->errors);
|
return new ExecutionResult($data, $this->exeContext->errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +355,7 @@ class Executor
|
|||||||
null,
|
null,
|
||||||
function ($error) {
|
function ($error) {
|
||||||
$this->exeContext->addError($error);
|
$this->exeContext->addError($error);
|
||||||
|
|
||||||
return $this->exeContext->promises->createFulfilled(null);
|
return $this->exeContext->promises->createFulfilled(null);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -362,6 +364,7 @@ class Executor
|
|||||||
return $result;
|
return $result;
|
||||||
} catch (Error $error) {
|
} catch (Error $error) {
|
||||||
$this->exeContext->addError($error);
|
$this->exeContext->addError($error);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -586,10 +589,12 @@ class Executor
|
|||||||
if ($promise) {
|
if ($promise) {
|
||||||
return $promise->then(static function ($resolvedResult) use ($responseName, $results) {
|
return $promise->then(static function ($resolvedResult) use ($responseName, $results) {
|
||||||
$results[$responseName] = $resolvedResult;
|
$results[$responseName] = $resolvedResult;
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$results[$responseName] = $result;
|
$results[$responseName] = $result;
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
@ -599,6 +604,7 @@ class Executor
|
|||||||
return self::fixResultsIfEmptyArray($resolvedResults);
|
return self::fixResultsIfEmptyArray($resolvedResults);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::fixResultsIfEmptyArray($result);
|
return self::fixResultsIfEmptyArray($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,15 +1034,20 @@ class Executor
|
|||||||
*/
|
*/
|
||||||
private function promiseReduce(array $values, callable $callback, $initialValue)
|
private function promiseReduce(array $values, callable $callback, $initialValue)
|
||||||
{
|
{
|
||||||
return array_reduce($values, function ($previous, $value) use ($callback) {
|
return array_reduce(
|
||||||
$promise = $this->getPromise($previous);
|
$values,
|
||||||
if ($promise) {
|
function ($previous, $value) use ($callback) {
|
||||||
return $promise->then(static function ($resolved) use ($callback, $value) {
|
$promise = $this->getPromise($previous);
|
||||||
return $callback($resolved, $value);
|
if ($promise) {
|
||||||
});
|
return $promise->then(static function ($resolved) use ($callback, $value) {
|
||||||
}
|
return $callback($resolved, $value);
|
||||||
return $callback($previous, $value);
|
});
|
||||||
}, $initialValue);
|
}
|
||||||
|
|
||||||
|
return $callback($previous, $value);
|
||||||
|
},
|
||||||
|
$initialValue
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1326,6 +1337,7 @@ class Executor
|
|||||||
&$result
|
&$result
|
||||||
) {
|
) {
|
||||||
$subFieldNodes = $this->collectSubFields($returnType, $fieldNodes);
|
$subFieldNodes = $this->collectSubFields($returnType, $fieldNodes);
|
||||||
|
|
||||||
return $this->executeFields($returnType, $result, $path, $subFieldNodes);
|
return $this->executeFields($returnType, $result, $path, $subFieldNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1353,6 +1365,7 @@ class Executor
|
|||||||
}
|
}
|
||||||
$this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes;
|
$this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->subFieldCache[$returnType][$fieldNodes];
|
return $this->subFieldCache[$returnType][$fieldNodes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ class Values
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($directiveNode) {
|
if ($directiveNode !== null) {
|
||||||
return self::getArgumentValues($directiveDef, $directiveNode, $variableValues);
|
return self::getArgumentValues($directiveDef, $directiveNode, $variableValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,12 +251,12 @@ class Visitor
|
|||||||
$inArray = $stack['inArray'];
|
$inArray = $stack['inArray'];
|
||||||
$stack = $stack['prev'];
|
$stack = $stack['prev'];
|
||||||
} else {
|
} else {
|
||||||
$key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
$key = $parent !== null ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
||||||
$node = $parent ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
$node = $parent !== null ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
||||||
if ($node === null || $node === $UNDEFINED) {
|
if ($node === null || $node === $UNDEFINED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($parent) {
|
if ($parent !== null) {
|
||||||
$path[] = $key;
|
$path[] = $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ class Visitor
|
|||||||
$keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: [];
|
$keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: [];
|
||||||
$index = -1;
|
$index = -1;
|
||||||
$edits = [];
|
$edits = [];
|
||||||
if ($parent) {
|
if ($parent !== null) {
|
||||||
$ancestors[] = $parent;
|
$ancestors[] = $parent;
|
||||||
}
|
}
|
||||||
$parent = $node;
|
$parent = $node;
|
||||||
@ -464,7 +464,7 @@ class Visitor
|
|||||||
|
|
||||||
if ($fn) {
|
if ($fn) {
|
||||||
$result = call_user_func_array($fn, func_get_args());
|
$result = call_user_func_array($fn, func_get_args());
|
||||||
if ($result) {
|
if ($result !== null) {
|
||||||
$typeInfo->leave($node);
|
$typeInfo->leave($node);
|
||||||
if ($result instanceof Node) {
|
if ($result instanceof Node) {
|
||||||
$typeInfo->enter($result);
|
$typeInfo->enter($result);
|
||||||
|
@ -21,7 +21,7 @@ class InputObjectField
|
|||||||
/** @var string|null */
|
/** @var string|null */
|
||||||
public $description;
|
public $description;
|
||||||
|
|
||||||
/** @var callable|InputType */
|
/** @var mixed */
|
||||||
public $type;
|
public $type;
|
||||||
|
|
||||||
/** @var InputValueDefinitionNode|null */
|
/** @var InputValueDefinitionNode|null */
|
||||||
|
@ -173,7 +173,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
|
|||||||
$interfaces = $this->config['interfaces'] ?? [];
|
$interfaces = $this->config['interfaces'] ?? [];
|
||||||
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
|
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
|
||||||
|
|
||||||
if ($interfaces && ! is_array($interfaces)) {
|
if ($interfaces !== null && ! is_array($interfaces)) {
|
||||||
throw new InvariantViolation(
|
throw new InvariantViolation(
|
||||||
sprintf('%s interfaces must be an Array or a callable which returns an Array.', $this->name)
|
sprintf('%s interfaces must be an Array or a callable which returns an Array.', $this->name)
|
||||||
);
|
);
|
||||||
|
@ -152,7 +152,7 @@ abstract class Type implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public static function isBuiltInType(Type $type)
|
public static function isBuiltInType(Type $type)
|
||||||
{
|
{
|
||||||
return in_array($type->name, array_keys(self::getAllBuiltInTypes()));
|
return in_array($type->name, array_keys(self::getAllBuiltInTypes()), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,10 +51,7 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType,
|
|||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isPossibleType(Type $type) : bool
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function isPossibleType(Type $type)
|
|
||||||
{
|
{
|
||||||
if (! $type instanceof ObjectType) {
|
if (! $type instanceof ObjectType) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -571,25 +571,25 @@ EOD;
|
|||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => static function ($d) {
|
'resolve' => static function ($d) {
|
||||||
return in_array(DirectiveLocation::QUERY, $d->locations) ||
|
return in_array(DirectiveLocation::QUERY, $d->locations, true) ||
|
||||||
in_array(DirectiveLocation::MUTATION, $d->locations) ||
|
in_array(DirectiveLocation::MUTATION, $d->locations, true) ||
|
||||||
in_array(DirectiveLocation::SUBSCRIPTION, $d->locations);
|
in_array(DirectiveLocation::SUBSCRIPTION, $d->locations, true);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'onFragment' => [
|
'onFragment' => [
|
||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => static function ($d) {
|
'resolve' => static function ($d) {
|
||||||
return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations) ||
|
return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations, true) ||
|
||||||
in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations) ||
|
in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations, true) ||
|
||||||
in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations);
|
in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations, true);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'onField' => [
|
'onField' => [
|
||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => static function ($d) {
|
'resolve' => static function ($d) {
|
||||||
return in_array(DirectiveLocation::FIELD, $d->locations);
|
return in_array(DirectiveLocation::FIELD, $d->locations, true);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -414,7 +414,7 @@ class AST
|
|||||||
$fieldName = $field->name;
|
$fieldName = $field->name;
|
||||||
$fieldNode = $fieldNodes[$fieldName] ?? null;
|
$fieldNode = $fieldNodes[$fieldName] ?? null;
|
||||||
|
|
||||||
if (! $fieldNode || self::isMissingVariable($fieldNode->value, $variables)) {
|
if ($fieldNode === null || self::isMissingVariable($fieldNode->value, $variables)) {
|
||||||
if ($field->defaultValueExists()) {
|
if ($field->defaultValueExists()) {
|
||||||
$coercedObj[$fieldName] = $field->defaultValue;
|
$coercedObj[$fieldName] = $field->defaultValue;
|
||||||
} elseif ($field->getType() instanceof NonNull) {
|
} elseif ($field->getType() instanceof NonNull) {
|
||||||
@ -424,7 +424,11 @@ class AST
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldValue = self::valueFromAST($fieldNode ? $fieldNode->value : null, $field->getType(), $variables);
|
$fieldValue = self::valueFromAST(
|
||||||
|
$fieldNode !== null ? $fieldNode->value : null,
|
||||||
|
$field->getType(),
|
||||||
|
$variables
|
||||||
|
);
|
||||||
|
|
||||||
if ($undefined === $fieldValue) {
|
if ($undefined === $fieldValue) {
|
||||||
// Invalid: intentionally return no value.
|
// Invalid: intentionally return no value.
|
||||||
|
@ -371,7 +371,7 @@ class BreakingChangesFinder
|
|||||||
)) ||
|
)) ||
|
||||||
// moving from non-null to nullable of the same underlying type is safe
|
// moving from non-null to nullable of the same underlying type is safe
|
||||||
! ($newType instanceof NonNull) &&
|
! ($newType instanceof NonNull) &&
|
||||||
self::isChangeSafeForInputObjectFieldOrFieldArg($oldType->getWrappedType(), $newType);
|
self::isChangeSafeForInputObjectFieldOrFieldArg($oldType->getWrappedType(), $newType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -496,7 +496,7 @@ class BreakingChangesFinder
|
|||||||
return $arg->name === $oldArgDef->name;
|
return $arg->name === $oldArgDef->name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ($newArgDef) {
|
if ($newArgDef !== null) {
|
||||||
$isSafe = self::isChangeSafeForInputObjectFieldOrFieldArg(
|
$isSafe = self::isChangeSafeForInputObjectFieldOrFieldArg(
|
||||||
$oldArgDef->getType(),
|
$oldArgDef->getType(),
|
||||||
$newArgDef->getType()
|
$newArgDef->getType()
|
||||||
@ -536,7 +536,7 @@ class BreakingChangesFinder
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($oldArgDef) {
|
if ($oldArgDef !== null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,12 +584,13 @@ class BreakingChangesFinder
|
|||||||
$oldInterfaces = $oldType->getInterfaces();
|
$oldInterfaces = $oldType->getInterfaces();
|
||||||
$newInterfaces = $newType->getInterfaces();
|
$newInterfaces = $newType->getInterfaces();
|
||||||
foreach ($oldInterfaces as $oldInterface) {
|
foreach ($oldInterfaces as $oldInterface) {
|
||||||
if (Utils::find(
|
$interface = Utils::find(
|
||||||
$newInterfaces,
|
$newInterfaces,
|
||||||
static function (InterfaceType $interface) use ($oldInterface) {
|
static function (InterfaceType $interface) use ($oldInterface) : bool {
|
||||||
return $interface->name === $oldInterface->name;
|
return $interface->name === $oldInterface->name;
|
||||||
}
|
}
|
||||||
)) {
|
);
|
||||||
|
if ($interface !== null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,12 +851,14 @@ class BreakingChangesFinder
|
|||||||
$oldInterfaces = $oldType->getInterfaces();
|
$oldInterfaces = $oldType->getInterfaces();
|
||||||
$newInterfaces = $newType->getInterfaces();
|
$newInterfaces = $newType->getInterfaces();
|
||||||
foreach ($newInterfaces as $newInterface) {
|
foreach ($newInterfaces as $newInterface) {
|
||||||
if (Utils::find(
|
$interface = Utils::find(
|
||||||
$oldInterfaces,
|
$oldInterfaces,
|
||||||
static function (InterfaceType $interface) use ($newInterface) {
|
static function (InterfaceType $interface) use ($newInterface) : bool {
|
||||||
return $interface->name === $newInterface->name;
|
return $interface->name === $newInterface->name;
|
||||||
}
|
}
|
||||||
)) {
|
);
|
||||||
|
|
||||||
|
if ($interface !== null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class SchemaExtender
|
|||||||
*/
|
*/
|
||||||
protected static function checkExtensionNode(Type $type, Node $node) : void
|
protected static function checkExtensionNode(Type $type, Node $node) : void
|
||||||
{
|
{
|
||||||
switch ($node->kind ?? null) {
|
switch ($node->kind) {
|
||||||
case NodeKind::OBJECT_TYPE_EXTENSION:
|
case NodeKind::OBJECT_TYPE_EXTENSION:
|
||||||
if (! ($type instanceof ObjectType)) {
|
if (! ($type instanceof ObjectType)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -589,7 +589,7 @@ class SchemaExtender
|
|||||||
|
|
||||||
foreach ($schemaExtension->operationTypes as $operationType) {
|
foreach ($schemaExtension->operationTypes as $operationType) {
|
||||||
$operation = $operationType->operation;
|
$operation = $operationType->operation;
|
||||||
if ($operationTypes[$operation]) {
|
if (isset($operationTypes[$operation])) {
|
||||||
throw new Error('Must provide only one ' . $operation . ' type in schema.');
|
throw new Error('Must provide only one ' . $operation . ' type in schema.');
|
||||||
}
|
}
|
||||||
$operationTypes[$operation] = static::$astBuilder->buildType($operationType->type);
|
$operationTypes[$operation] = static::$astBuilder->buildType($operationType->type);
|
||||||
|
@ -210,6 +210,7 @@ class TypeInfo
|
|||||||
$typeMap = self::extractTypes($arg->getType(), $typeMap);
|
$typeMap = self::extractTypes($arg->getType(), $typeMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $typeMap;
|
return $typeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +310,7 @@ class TypeInfo
|
|||||||
return $arg->name === $node->name->value;
|
return $arg->name === $node->name->value;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ($argDef) {
|
if ($argDef !== null) {
|
||||||
$argType = $argDef->getType();
|
$argType = $argDef->getType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class KnownArgumentNamesOnDirectives extends ValidationRule
|
|||||||
|
|
||||||
foreach ($directiveNode->arguments as $argNode) {
|
foreach ($directiveNode->arguments as $argNode) {
|
||||||
$argName = $argNode->name->value;
|
$argName = $argNode->name->value;
|
||||||
if (in_array($argName, $knownArgs)) {
|
if (in_array($argName, $knownArgs, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +37,25 @@ class KnownDirectives extends ValidationRule
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$locationsMap[$def->name->value] = array_map(static function ($name) {
|
$locationsMap[$def->name->value] = array_map(
|
||||||
return $name->value;
|
static function ($name) {
|
||||||
}, $def->locations);
|
return $name->value;
|
||||||
|
},
|
||||||
|
$def->locations
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
NodeKind::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context, $locationsMap) {
|
NodeKind::DIRECTIVE => function (
|
||||||
|
DirectiveNode $node,
|
||||||
|
$key,
|
||||||
|
$parent,
|
||||||
|
$path,
|
||||||
|
$ancestors
|
||||||
|
) use (
|
||||||
|
$context,
|
||||||
|
$locationsMap
|
||||||
|
) {
|
||||||
$name = $node->name->value;
|
$name = $node->name->value;
|
||||||
$locations = $locationsMap[$name] ?? null;
|
$locations = $locationsMap[$name] ?? null;
|
||||||
|
|
||||||
@ -51,12 +64,13 @@ class KnownDirectives extends ValidationRule
|
|||||||
self::unknownDirectiveMessage($name),
|
self::unknownDirectiveMessage($name),
|
||||||
[$node]
|
[$node]
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
||||||
|
|
||||||
if (! $candidateLocation || in_array($candidateLocation, $locations)) {
|
if (! $candidateLocation || in_array($candidateLocation, $locations, true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$context->reportError(
|
$context->reportError(
|
||||||
|
@ -29,7 +29,7 @@ class QueryComplexity extends QuerySecurityRule
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
private $maxQueryComplexity;
|
private $maxQueryComplexity;
|
||||||
|
|
||||||
/** @var mixed[]|null */
|
/** @var mixed[]|null */
|
||||||
private $rawVariableValues = [];
|
private $rawVariableValues = [];
|
||||||
|
|
||||||
/** @var ArrayObject */
|
/** @var ArrayObject */
|
||||||
@ -86,7 +86,7 @@ class QueryComplexity extends QuerySecurityRule
|
|||||||
}
|
}
|
||||||
|
|
||||||
$context->reportError(
|
$context->reportError(
|
||||||
new Error($this->maxQueryComplexityErrorMessage(
|
new Error(self::maxQueryComplexityErrorMessage(
|
||||||
$this->getMaxQueryComplexity(),
|
$this->getMaxQueryComplexity(),
|
||||||
$complexity
|
$complexity
|
||||||
))
|
))
|
||||||
@ -193,7 +193,7 @@ class QueryComplexity extends QuerySecurityRule
|
|||||||
$this->getRawVariableValues()
|
$this->getRawVariableValues()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($variableValuesResult['errors']) {
|
if (! empty($variableValuesResult['errors'])) {
|
||||||
throw new Error(implode(
|
throw new Error(implode(
|
||||||
"\n\n",
|
"\n\n",
|
||||||
array_map(
|
array_map(
|
||||||
@ -207,16 +207,17 @@ class QueryComplexity extends QuerySecurityRule
|
|||||||
$variableValues = $variableValuesResult['coerced'];
|
$variableValues = $variableValuesResult['coerced'];
|
||||||
|
|
||||||
if ($directiveNode->name->value === 'include') {
|
if ($directiveNode->name->value === 'include') {
|
||||||
$directive = Directive::includeDirective();
|
$directive = Directive::includeDirective();
|
||||||
$directiveArgs = Values::getArgumentValues($directive, $directiveNode, $variableValues);
|
/** @var bool $directiveArgsIf */
|
||||||
|
$directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues)['if'];
|
||||||
|
|
||||||
return ! $directiveArgs['if'];
|
return ! $directiveArgsIf;
|
||||||
}
|
}
|
||||||
|
|
||||||
$directive = Directive::skipDirective();
|
$directive = Directive::skipDirective();
|
||||||
$directiveArgs = Values::getArgumentValues($directive, $directiveNode, $variableValues);
|
$directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues);
|
||||||
|
|
||||||
return $directiveArgs['if'];
|
return $directiveArgsIf['if'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +249,7 @@ class QueryComplexity extends QuerySecurityRule
|
|||||||
$rawVariableValues
|
$rawVariableValues
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($variableValuesResult['errors']) {
|
if (! empty($variableValuesResult['errors'])) {
|
||||||
throw new Error(implode(
|
throw new Error(implode(
|
||||||
"\n\n",
|
"\n\n",
|
||||||
array_map(
|
array_map(
|
||||||
|
@ -36,7 +36,7 @@ class QueryDepth extends QuerySecurityRule
|
|||||||
}
|
}
|
||||||
|
|
||||||
$context->reportError(
|
$context->reportError(
|
||||||
new Error($this->maxQueryDepthErrorMessage($this->getMaxQueryDepth(), $maxDepth))
|
new Error(self::maxQueryDepthErrorMessage($this->getMaxQueryDepth(), $maxDepth))
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -36,7 +36,7 @@ class VariablesInAllowedPosition extends ValidationRule
|
|||||||
$varName = $node->name->value;
|
$varName = $node->name->value;
|
||||||
$varDef = $this->varDefMap[$varName] ?? null;
|
$varDef = $this->varDefMap[$varName] ?? null;
|
||||||
|
|
||||||
if (! $varDef || ! $type) {
|
if ($varDef === null || $type === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +98,12 @@ class ValidationContext
|
|||||||
{
|
{
|
||||||
$usages = $this->recursiveVariableUsages[$operation] ?? null;
|
$usages = $this->recursiveVariableUsages[$operation] ?? null;
|
||||||
|
|
||||||
if (! $usages) {
|
if ($usages === null) {
|
||||||
$usages = $this->getVariableUsages($operation);
|
$usages = $this->getVariableUsages($operation);
|
||||||
$fragments = $this->getRecursivelyReferencedFragments($operation);
|
$fragments = $this->getRecursivelyReferencedFragments($operation);
|
||||||
|
|
||||||
$tmp = [$usages];
|
$tmp = [$usages];
|
||||||
for ($i = 0; $i < count($fragments); $i++) {
|
foreach ($fragments as $i => $fragment) {
|
||||||
$tmp[] = $this->getVariableUsages($fragments[$i]);
|
$tmp[] = $this->getVariableUsages($fragments[$i]);
|
||||||
}
|
}
|
||||||
$usages = call_user_func_array('array_merge', $tmp);
|
$usages = call_user_func_array('array_merge', $tmp);
|
||||||
@ -120,7 +120,7 @@ class ValidationContext
|
|||||||
{
|
{
|
||||||
$usages = $this->variableUsages[$node] ?? null;
|
$usages = $this->variableUsages[$node] ?? null;
|
||||||
|
|
||||||
if (! $usages) {
|
if ($usages === null) {
|
||||||
$newUsages = [];
|
$newUsages = [];
|
||||||
$typeInfo = new TypeInfo($this->schema);
|
$typeInfo = new TypeInfo($this->schema);
|
||||||
Visitor::visit(
|
Visitor::visit(
|
||||||
@ -154,15 +154,15 @@ class ValidationContext
|
|||||||
{
|
{
|
||||||
$fragments = $this->recursivelyReferencedFragments[$operation] ?? null;
|
$fragments = $this->recursivelyReferencedFragments[$operation] ?? null;
|
||||||
|
|
||||||
if (! $fragments) {
|
if ($fragments === null) {
|
||||||
$fragments = [];
|
$fragments = [];
|
||||||
$collectedNames = [];
|
$collectedNames = [];
|
||||||
$nodesToVisit = [$operation];
|
$nodesToVisit = [$operation];
|
||||||
while (! empty($nodesToVisit)) {
|
while (! empty($nodesToVisit)) {
|
||||||
$node = array_pop($nodesToVisit);
|
$node = array_pop($nodesToVisit);
|
||||||
$spreads = $this->getFragmentSpreads($node);
|
$spreads = $this->getFragmentSpreads($node);
|
||||||
for ($i = 0; $i < count($spreads); $i++) {
|
foreach ($spreads as $spread) {
|
||||||
$fragName = $spreads[$i]->name->value;
|
$fragName = $spread->name->value;
|
||||||
|
|
||||||
if (! empty($collectedNames[$fragName])) {
|
if (! empty($collectedNames[$fragName])) {
|
||||||
continue;
|
continue;
|
||||||
@ -190,14 +190,14 @@ class ValidationContext
|
|||||||
public function getFragmentSpreads(HasSelectionSet $node)
|
public function getFragmentSpreads(HasSelectionSet $node)
|
||||||
{
|
{
|
||||||
$spreads = $this->fragmentSpreads[$node] ?? null;
|
$spreads = $this->fragmentSpreads[$node] ?? null;
|
||||||
if (! $spreads) {
|
if ($spreads === null) {
|
||||||
$spreads = [];
|
$spreads = [];
|
||||||
/** @var SelectionSetNode[] $setsToVisit */
|
/** @var SelectionSetNode[] $setsToVisit */
|
||||||
$setsToVisit = [$node->selectionSet];
|
$setsToVisit = [$node->selectionSet];
|
||||||
while (! empty($setsToVisit)) {
|
while (! empty($setsToVisit)) {
|
||||||
$set = array_pop($setsToVisit);
|
$set = array_pop($setsToVisit);
|
||||||
|
|
||||||
for ($i = 0; $i < count($set->selections); $i++) {
|
for ($i = 0, $selectionCount = count($set->selections); $i < $selectionCount; $i++) {
|
||||||
$selection = $set->selections[$i];
|
$selection = $set->selections[$i];
|
||||||
if ($selection->kind === NodeKind::FRAGMENT_SPREAD) {
|
if ($selection->kind === NodeKind::FRAGMENT_SPREAD) {
|
||||||
$spreads[] = $selection;
|
$spreads[] = $selection;
|
||||||
|
@ -153,7 +153,7 @@ class DeferredFieldsTest extends TestCase
|
|||||||
return Utils::filter(
|
return Utils::filter(
|
||||||
$this->storyDataSource,
|
$this->storyDataSource,
|
||||||
static function ($story) use ($category) {
|
static function ($story) use ($category) {
|
||||||
return in_array($category['id'], $story['categoryIds']);
|
return in_array($category['id'], $story['categoryIds'], true);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ class ReactPromiseAdapterTest extends TestCase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->markTestSkipped('react/promise package must be installed to run GraphQL\Tests\Executor\Promise\ReactPromiseAdapterTest');
|
self::markTestSkipped('react/promise package must be installed to run GraphQL\Tests\Executor\Promise\ReactPromiseAdapterTest');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsThenableReturnsTrueWhenAReactPromiseIsGiven() : void
|
public function testIsThenableReturnsTrueWhenAReactPromiseIsGiven() : void
|
||||||
|
@ -260,14 +260,14 @@ class SyncPromiseTest extends TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$promise->reject(new Exception('other-reason'));
|
$promise->reject(new Exception('other-reason'));
|
||||||
$this->fail('Expected exception not thrown');
|
self::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');
|
self::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());
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$promise->resolve($promise);
|
$promise->resolve($promise);
|
||||||
$this->fail('Expected exception not thrown');
|
self::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);
|
||||||
@ -345,7 +345,7 @@ class SyncPromiseTest extends TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$promise->reject('a');
|
$promise->reject('a');
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (Error $e) {
|
} catch (Error $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
@ -145,7 +145,7 @@ class LexerTest extends TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->lexOne($str);
|
$this->lexOne($str);
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $error) {
|
} catch (SyntaxError $error) {
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
||||||
@ -175,7 +175,7 @@ class LexerTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$lexer = new Lexer($source);
|
$lexer = new Lexer($source);
|
||||||
$lexer->advance();
|
$lexer->advance();
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $error) {
|
} catch (SyntaxError $error) {
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
||||||
@ -197,7 +197,7 @@ class LexerTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$lexer = new Lexer($source);
|
$lexer = new Lexer($source);
|
||||||
$lexer->advance();
|
$lexer->advance();
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $error) {
|
} catch (SyntaxError $error) {
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
||||||
@ -671,7 +671,7 @@ class LexerTest extends TestCase
|
|||||||
$this->expectExceptionMessage('Syntax Error: Invalid number, expected digit but got: "b"');
|
$this->expectExceptionMessage('Syntax Error: Invalid number, expected digit but got: "b"');
|
||||||
try {
|
try {
|
||||||
$lexer->advance();
|
$lexer->advance();
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $error) {
|
} catch (SyntaxError $error) {
|
||||||
self::assertEquals([$this->loc(1, 3)], $error->getLocations());
|
self::assertEquals([$this->loc(1, 3)], $error->getLocations());
|
||||||
throw $error;
|
throw $error;
|
||||||
|
@ -86,7 +86,7 @@ fragment MissingOn Type
|
|||||||
) : void {
|
) : void {
|
||||||
try {
|
try {
|
||||||
Parser::parse($str);
|
Parser::parse($str);
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $e) {
|
} catch (SyntaxError $e) {
|
||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($stringRepresentation, (string) $e);
|
self::assertEquals($stringRepresentation, (string) $e);
|
||||||
@ -108,7 +108,7 @@ fragment MissingOn Type
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Parser::parse(new Source('query', 'MyQuery.graphql'));
|
Parser::parse(new Source('query', 'MyQuery.graphql'));
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (SyntaxError $error) {
|
} catch (SyntaxError $error) {
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
"Syntax Error: Expected {, found <EOF>\n\nMyQuery.graphql (1:6)\n1: query\n ^\n",
|
"Syntax Error: Expected {, found <EOF>\n\nMyQuery.graphql (1:6)\n1: query\n ^\n",
|
||||||
@ -503,7 +503,7 @@ GRAPHQL
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
self::assertEquals($expected, $this->nodeToArray($result));
|
self::assertEquals($expected, self::nodeToArray($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -575,7 +575,7 @@ GRAPHQL
|
|||||||
'kind' => NodeKind::NULL,
|
'kind' => NodeKind::NULL,
|
||||||
'loc' => ['start' => 0, 'end' => 4],
|
'loc' => ['start' => 0, 'end' => 4],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseValue('null'))
|
self::nodeToArray(Parser::parseValue('null'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ GRAPHQL
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseValue('[123 "abc"]'))
|
self::nodeToArray(Parser::parseValue('[123 "abc"]'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,7 +621,7 @@ GRAPHQL
|
|||||||
'value' => 'String',
|
'value' => 'String',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseType('String'))
|
self::nodeToArray(Parser::parseType('String'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,7 +640,7 @@ GRAPHQL
|
|||||||
'value' => 'MyType',
|
'value' => 'MyType',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseType('MyType'))
|
self::nodeToArray(Parser::parseType('MyType'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +663,7 @@ GRAPHQL
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseType('[MyType]'))
|
self::nodeToArray(Parser::parseType('[MyType]'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,7 +686,7 @@ GRAPHQL
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseType('MyType!'))
|
self::nodeToArray(Parser::parseType('MyType!'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ GRAPHQL
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$this->nodeToArray(Parser::parseType('[MyType!]'))
|
self::nodeToArray(Parser::parseType('[MyType!]'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,8 +225,8 @@ class RequestParsingTest extends TestCase
|
|||||||
'operationName' => $operation,
|
'operationName' => $operation,
|
||||||
];
|
];
|
||||||
$parsed = [
|
$parsed = [
|
||||||
'raw' => $this->parseRawMultipartFormdataRequest($post),
|
'raw' => $this->parseRawMultipartFormDataRequest($post),
|
||||||
'psr' => $this->parsePsrMultipartFormdataRequest($post),
|
'psr' => $this->parsePsrMultipartFormDataRequest($post),
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($parsed as $method => $parsedBody) {
|
foreach ($parsed as $method => $parsedBody) {
|
||||||
@ -395,7 +395,7 @@ class RequestParsingTest extends TestCase
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->parsePsrRequest('application/json', json_encode(null));
|
$this->parsePsrRequest('application/json', json_encode(null));
|
||||||
$this->fail('Expected exception not thrown');
|
self::fail('Expected exception not thrown');
|
||||||
} catch (InvariantViolation $e) {
|
} catch (InvariantViolation $e) {
|
||||||
// Expecting parsing exception to be thrown somewhere else:
|
// Expecting parsing exception to be thrown somewhere else:
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
|
@ -67,7 +67,7 @@ class RequestValidationTest extends TestCase
|
|||||||
if (! empty($errors[0])) {
|
if (! empty($errors[0])) {
|
||||||
self::assertEquals($expectedMessage, $errors[0]->getMessage());
|
self::assertEquals($expectedMessage, $errors[0]->getMessage());
|
||||||
} else {
|
} else {
|
||||||
$this->fail('Expected error not returned');
|
self::fail('Expected error not returned');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class StarWarsSchema
|
|||||||
];
|
];
|
||||||
},
|
},
|
||||||
'resolveType' => static function ($obj) use (&$humanType, &$droidType) {
|
'resolveType' => static function ($obj) use (&$humanType, &$droidType) {
|
||||||
return StarWarsData::getHuman($obj['id']) ? $humanType : $droidType;
|
return StarWarsData::getHuman($obj['id']) === null ? $droidType : $humanType;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -1599,14 +1599,14 @@ class DefinitionTest extends TestCase
|
|||||||
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());
|
self::fail('List is expected to accept type: ' . get_class($type) . ', but got error: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($badTypes as $badType) {
|
foreach ($badTypes as $badType) {
|
||||||
$typeStr = Utils::printSafe($badType);
|
$typeStr = Utils::printSafe($badType);
|
||||||
try {
|
try {
|
||||||
Type::listOf($badType);
|
Type::listOf($badType);
|
||||||
$this->fail(sprintf('List should not accept %s', $typeStr));
|
self::fail(sprintf('List should not accept %s', $typeStr));
|
||||||
} catch (InvariantViolation $e) {
|
} catch (InvariantViolation $e) {
|
||||||
self::assertEquals(sprintf('Expected %s to be a GraphQL type.', $typeStr), $e->getMessage());
|
self::assertEquals(sprintf('Expected %s to be a GraphQL type.', $typeStr), $e->getMessage());
|
||||||
}
|
}
|
||||||
@ -1640,14 +1640,14 @@ class DefinitionTest extends TestCase
|
|||||||
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());
|
self::fail('NonNull is expected to accept type: ' . get_class($type) . ', but got error: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($notNullableTypes as $badType) {
|
foreach ($notNullableTypes as $badType) {
|
||||||
$typeStr = Utils::printSafe($badType);
|
$typeStr = Utils::printSafe($badType);
|
||||||
try {
|
try {
|
||||||
Type::nonNull($badType);
|
Type::nonNull($badType);
|
||||||
$this->fail(sprintf('Nulls should not accept %s', $typeStr));
|
self::fail(sprintf('Nulls should not accept %s', $typeStr));
|
||||||
} catch (InvariantViolation $e) {
|
} catch (InvariantViolation $e) {
|
||||||
self::assertEquals(sprintf('Expected %s to be a GraphQL nullable type.', $typeStr), $e->getMessage());
|
self::assertEquals(sprintf('Expected %s to be a GraphQL nullable type.', $typeStr), $e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ class SchemaTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowsHumanReableErrorIfSchemaTypesIsNotDefined() : void
|
public function testThrowsHumanReableErrorIfSchemaTypesIsNotDefined() : void
|
||||||
{
|
{
|
||||||
$this->markTestSkipped("Can't check interface implementations without full schema scan");
|
self::markTestSkipped("Can't check interface implementations without full schema scan");
|
||||||
|
|
||||||
$this->expectException(InvariantViolation::class);
|
$this->expectException(InvariantViolation::class);
|
||||||
$this->expectExceptionMessage(
|
$this->expectExceptionMessage(
|
||||||
|
@ -201,7 +201,7 @@ class ValidationTest extends TestCase
|
|||||||
foreach ($closures as $index => $factory) {
|
foreach ($closures as $index => $factory) {
|
||||||
try {
|
try {
|
||||||
$factory();
|
$factory();
|
||||||
$this->fail('Expected exception not thrown for entry ' . $index);
|
self::fail('Expected exception not thrown for entry ' . $index);
|
||||||
} catch (InvariantViolation $e) {
|
} catch (InvariantViolation $e) {
|
||||||
self::assertEquals($expectedError, $e->getMessage(), 'Error in callable #' . $index);
|
self::assertEquals($expectedError, $e->getMessage(), 'Error in callable #' . $index);
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ class ValidationTest extends TestCase
|
|||||||
);
|
);
|
||||||
foreach ($array as $index => $error) {
|
foreach ($array as $index => $error) {
|
||||||
if (! isset($messages[$index]) || ! $error instanceof Error) {
|
if (! isset($messages[$index]) || ! $error instanceof Error) {
|
||||||
$this->fail('Received unexpected error: ' . $error->getMessage());
|
self::fail('Received unexpected error: ' . $error->getMessage());
|
||||||
}
|
}
|
||||||
self::assertEquals($messages[$index]['message'], $error->getMessage());
|
self::assertEquals($messages[$index]['message'], $error->getMessage());
|
||||||
$errorLocations = [];
|
$errorLocations = [];
|
||||||
@ -1189,7 +1189,7 @@ class ValidationTest extends TestCase
|
|||||||
public function testRejectsAnObjectImplementingTheSameInterfaceTwiceDueToExtension() : void
|
public function testRejectsAnObjectImplementingTheSameInterfaceTwiceDueToExtension() : void
|
||||||
{
|
{
|
||||||
$this->expectNotToPerformAssertions();
|
$this->expectNotToPerformAssertions();
|
||||||
$this->markTestIncomplete('extend does not work this way (yet).');
|
self::markTestIncomplete('extend does not work this way (yet).');
|
||||||
$schema = BuildSchema::build('
|
$schema = BuildSchema::build('
|
||||||
type Query {
|
type Query {
|
||||||
field: AnotherObject
|
field: AnotherObject
|
||||||
|
@ -164,7 +164,7 @@ class SchemaExtenderTest extends TestCase
|
|||||||
'someInterface' => [
|
'someInterface' => [
|
||||||
'args' => [
|
'args' => [
|
||||||
'id' => [
|
'id' => [
|
||||||
'type' => Type::nonNull(Type::ID()),
|
'type' => Type::nonNull(Type::id()),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'type' => $SomeInterfaceType,
|
'type' => $SomeInterfaceType,
|
||||||
@ -218,7 +218,7 @@ class SchemaExtenderTest extends TestCase
|
|||||||
$ast->definitions = array_values(array_filter(
|
$ast->definitions = array_values(array_filter(
|
||||||
$ast->definitions instanceof NodeList ? iterator_to_array($ast->definitions->getIterator()) : $ast->definitions,
|
$ast->definitions instanceof NodeList ? iterator_to_array($ast->definitions->getIterator()) : $ast->definitions,
|
||||||
function (Node $node) : bool {
|
function (Node $node) : bool {
|
||||||
return ! in_array(Printer::doPrint($node), $this->testSchemaDefinitions);
|
return ! in_array(Printer::doPrint($node), $this->testSchemaDefinitions, true);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -1578,14 +1578,14 @@ class SchemaExtenderTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMaintainsConfigurationOfTheOriginalSchemaObject()
|
public function testMaintainsConfigurationOfTheOriginalSchemaObject()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('allowedLegacyNames currently not supported');
|
self::markTestSkipped('allowedLegacyNames currently not supported');
|
||||||
|
|
||||||
$testSchemaWithLegacyNames = new Schema(
|
$testSchemaWithLegacyNames = new Schema(
|
||||||
[
|
[
|
||||||
'query' => new ObjectType([
|
'query' => new ObjectType([
|
||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
'fields' => static function () {
|
'fields' => static function () {
|
||||||
return ['id' => ['type' => Type::ID()]];
|
return ['id' => ['type' => Type::id()]];
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
]/*,
|
]/*,
|
||||||
@ -1607,7 +1607,7 @@ class SchemaExtenderTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAddsToTheConfigurationOfTheOriginalSchemaObject()
|
public function testAddsToTheConfigurationOfTheOriginalSchemaObject()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('allowedLegacyNames currently not supported');
|
self::markTestSkipped('allowedLegacyNames currently not supported');
|
||||||
|
|
||||||
$testSchemaWithLegacyNames = new Schema(
|
$testSchemaWithLegacyNames = new Schema(
|
||||||
[
|
[
|
||||||
|
@ -43,7 +43,7 @@ class ValidationTest extends ValidatorTestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$this->expectInvalid(
|
$this->expectInvalid(
|
||||||
$this->getTestSchema(),
|
self::getTestSchema(),
|
||||||
null,
|
null,
|
||||||
$doc,
|
$doc,
|
||||||
[$expectedError]
|
[$expectedError]
|
||||||
@ -59,6 +59,6 @@ class ValidationTest extends ValidatorTestCase
|
|||||||
'locations' => [['line' => 1, 'column' => 2]],
|
'locations' => [['line' => 1, 'column' => 2]],
|
||||||
];
|
];
|
||||||
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
||||||
$this->expectValid($this->getTestSchema(), [], $query);
|
$this->expectValid(self::getTestSchema(), [], $query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user