mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
Use PHPStan strict rules
Two rules excluded: missing type hints and empty() usage
This commit is contained in:
parent
0070cb4039
commit
90d0156291
@ -18,6 +18,7 @@
|
||||
"phpbench/phpbench": "^0.14.0",
|
||||
"phpstan/phpstan": "^0.10.3",
|
||||
"phpstan/phpstan-phpunit": "^0.10.0",
|
||||
"phpstan/phpstan-strict-rules": "^0.10.1",
|
||||
"phpunit/phpunit": "^7.2",
|
||||
"psr/http-message": "^1.0",
|
||||
"react/promise": "2.*"
|
||||
|
@ -5,6 +5,11 @@ parameters:
|
||||
- %currentWorkingDirectory%/src
|
||||
- %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:
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
- vendor/phpstan/phpstan-phpunit/rules.neon
|
||||
- vendor/phpstan/phpstan-strict-rules/rules.neon
|
||||
|
@ -258,14 +258,14 @@ class Executor
|
||||
$rawVariableValues ?: []
|
||||
);
|
||||
|
||||
if ($coercedVariableValues['errors']) {
|
||||
$errors = array_merge($errors, $coercedVariableValues['errors']);
|
||||
} else {
|
||||
if (empty($coercedVariableValues['errors'])) {
|
||||
$variableValues = $coercedVariableValues['coerced'];
|
||||
} else {
|
||||
$errors = array_merge($errors, $coercedVariableValues['errors']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
if (! empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@ -322,6 +322,7 @@ class Executor
|
||||
if ($data !== null) {
|
||||
$data = (array) $data;
|
||||
}
|
||||
|
||||
return new ExecutionResult($data, $this->exeContext->errors);
|
||||
}
|
||||
|
||||
@ -354,6 +355,7 @@ class Executor
|
||||
null,
|
||||
function ($error) {
|
||||
$this->exeContext->addError($error);
|
||||
|
||||
return $this->exeContext->promises->createFulfilled(null);
|
||||
}
|
||||
);
|
||||
@ -362,6 +364,7 @@ class Executor
|
||||
return $result;
|
||||
} catch (Error $error) {
|
||||
$this->exeContext->addError($error);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -586,10 +589,12 @@ class Executor
|
||||
if ($promise) {
|
||||
return $promise->then(static function ($resolvedResult) use ($responseName, $results) {
|
||||
$results[$responseName] = $resolvedResult;
|
||||
|
||||
return $results;
|
||||
});
|
||||
}
|
||||
$results[$responseName] = $result;
|
||||
|
||||
return $results;
|
||||
},
|
||||
[]
|
||||
@ -599,6 +604,7 @@ class Executor
|
||||
return self::fixResultsIfEmptyArray($resolvedResults);
|
||||
});
|
||||
}
|
||||
|
||||
return self::fixResultsIfEmptyArray($result);
|
||||
}
|
||||
|
||||
@ -1028,15 +1034,20 @@ class Executor
|
||||
*/
|
||||
private function promiseReduce(array $values, callable $callback, $initialValue)
|
||||
{
|
||||
return array_reduce($values, function ($previous, $value) use ($callback) {
|
||||
return array_reduce(
|
||||
$values,
|
||||
function ($previous, $value) use ($callback) {
|
||||
$promise = $this->getPromise($previous);
|
||||
if ($promise) {
|
||||
return $promise->then(static function ($resolved) use ($callback, $value) {
|
||||
return $callback($resolved, $value);
|
||||
});
|
||||
}
|
||||
|
||||
return $callback($previous, $value);
|
||||
}, $initialValue);
|
||||
},
|
||||
$initialValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1326,6 +1337,7 @@ class Executor
|
||||
&$result
|
||||
) {
|
||||
$subFieldNodes = $this->collectSubFields($returnType, $fieldNodes);
|
||||
|
||||
return $this->executeFields($returnType, $result, $path, $subFieldNodes);
|
||||
}
|
||||
|
||||
@ -1353,6 +1365,7 @@ class Executor
|
||||
}
|
||||
$this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes;
|
||||
}
|
||||
|
||||
return $this->subFieldCache[$returnType][$fieldNodes];
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ class Values
|
||||
}
|
||||
);
|
||||
|
||||
if ($directiveNode) {
|
||||
if ($directiveNode !== null) {
|
||||
return self::getArgumentValues($directiveDef, $directiveNode, $variableValues);
|
||||
}
|
||||
}
|
||||
|
@ -251,12 +251,12 @@ class Visitor
|
||||
$inArray = $stack['inArray'];
|
||||
$stack = $stack['prev'];
|
||||
} else {
|
||||
$key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
||||
$node = $parent ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
||||
$key = $parent !== null ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
|
||||
$node = $parent !== null ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot;
|
||||
if ($node === null || $node === $UNDEFINED) {
|
||||
continue;
|
||||
}
|
||||
if ($parent) {
|
||||
if ($parent !== null) {
|
||||
$path[] = $key;
|
||||
}
|
||||
}
|
||||
@ -321,7 +321,7 @@ class Visitor
|
||||
$keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: [];
|
||||
$index = -1;
|
||||
$edits = [];
|
||||
if ($parent) {
|
||||
if ($parent !== null) {
|
||||
$ancestors[] = $parent;
|
||||
}
|
||||
$parent = $node;
|
||||
@ -464,7 +464,7 @@ class Visitor
|
||||
|
||||
if ($fn) {
|
||||
$result = call_user_func_array($fn, func_get_args());
|
||||
if ($result) {
|
||||
if ($result !== null) {
|
||||
$typeInfo->leave($node);
|
||||
if ($result instanceof Node) {
|
||||
$typeInfo->enter($result);
|
||||
|
@ -21,7 +21,7 @@ class InputObjectField
|
||||
/** @var string|null */
|
||||
public $description;
|
||||
|
||||
/** @var callable|InputType */
|
||||
/** @var mixed */
|
||||
public $type;
|
||||
|
||||
/** @var InputValueDefinitionNode|null */
|
||||
|
@ -173,7 +173,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NamedType
|
||||
$interfaces = $this->config['interfaces'] ?? [];
|
||||
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
|
||||
|
||||
if ($interfaces && ! is_array($interfaces)) {
|
||||
if ($interfaces !== null && ! is_array($interfaces)) {
|
||||
throw new InvariantViolation(
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isPossibleType(Type $type)
|
||||
public function isPossibleType(Type $type) : bool
|
||||
{
|
||||
if (! $type instanceof ObjectType) {
|
||||
return false;
|
||||
|
@ -571,25 +571,25 @@ EOD;
|
||||
'deprecationReason' => 'Use `locations`.',
|
||||
'type' => Type::nonNull(Type::boolean()),
|
||||
'resolve' => static function ($d) {
|
||||
return in_array(DirectiveLocation::QUERY, $d->locations) ||
|
||||
in_array(DirectiveLocation::MUTATION, $d->locations) ||
|
||||
in_array(DirectiveLocation::SUBSCRIPTION, $d->locations);
|
||||
return in_array(DirectiveLocation::QUERY, $d->locations, true) ||
|
||||
in_array(DirectiveLocation::MUTATION, $d->locations, true) ||
|
||||
in_array(DirectiveLocation::SUBSCRIPTION, $d->locations, true);
|
||||
},
|
||||
],
|
||||
'onFragment' => [
|
||||
'deprecationReason' => 'Use `locations`.',
|
||||
'type' => Type::nonNull(Type::boolean()),
|
||||
'resolve' => static function ($d) {
|
||||
return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations) ||
|
||||
in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations) ||
|
||||
in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations);
|
||||
return in_array(DirectiveLocation::FRAGMENT_SPREAD, $d->locations, true) ||
|
||||
in_array(DirectiveLocation::INLINE_FRAGMENT, $d->locations, true) ||
|
||||
in_array(DirectiveLocation::FRAGMENT_DEFINITION, $d->locations, true);
|
||||
},
|
||||
],
|
||||
'onField' => [
|
||||
'deprecationReason' => 'Use `locations`.',
|
||||
'type' => Type::nonNull(Type::boolean()),
|
||||
'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;
|
||||
$fieldNode = $fieldNodes[$fieldName] ?? null;
|
||||
|
||||
if (! $fieldNode || self::isMissingVariable($fieldNode->value, $variables)) {
|
||||
if ($fieldNode === null || self::isMissingVariable($fieldNode->value, $variables)) {
|
||||
if ($field->defaultValueExists()) {
|
||||
$coercedObj[$fieldName] = $field->defaultValue;
|
||||
} elseif ($field->getType() instanceof NonNull) {
|
||||
@ -424,7 +424,11 @@ class AST
|
||||
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) {
|
||||
// Invalid: intentionally return no value.
|
||||
|
@ -496,7 +496,7 @@ class BreakingChangesFinder
|
||||
return $arg->name === $oldArgDef->name;
|
||||
}
|
||||
);
|
||||
if ($newArgDef) {
|
||||
if ($newArgDef !== null) {
|
||||
$isSafe = self::isChangeSafeForInputObjectFieldOrFieldArg(
|
||||
$oldArgDef->getType(),
|
||||
$newArgDef->getType()
|
||||
@ -536,7 +536,7 @@ class BreakingChangesFinder
|
||||
}
|
||||
);
|
||||
|
||||
if ($oldArgDef) {
|
||||
if ($oldArgDef !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -584,12 +584,13 @@ class BreakingChangesFinder
|
||||
$oldInterfaces = $oldType->getInterfaces();
|
||||
$newInterfaces = $newType->getInterfaces();
|
||||
foreach ($oldInterfaces as $oldInterface) {
|
||||
if (Utils::find(
|
||||
$interface = Utils::find(
|
||||
$newInterfaces,
|
||||
static function (InterfaceType $interface) use ($oldInterface) {
|
||||
static function (InterfaceType $interface) use ($oldInterface) : bool {
|
||||
return $interface->name === $oldInterface->name;
|
||||
}
|
||||
)) {
|
||||
);
|
||||
if ($interface !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -850,12 +851,14 @@ class BreakingChangesFinder
|
||||
$oldInterfaces = $oldType->getInterfaces();
|
||||
$newInterfaces = $newType->getInterfaces();
|
||||
foreach ($newInterfaces as $newInterface) {
|
||||
if (Utils::find(
|
||||
$interface = Utils::find(
|
||||
$oldInterfaces,
|
||||
static function (InterfaceType $interface) use ($newInterface) {
|
||||
static function (InterfaceType $interface) use ($newInterface) : bool {
|
||||
return $interface->name === $newInterface->name;
|
||||
}
|
||||
)) {
|
||||
);
|
||||
|
||||
if ($interface !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ class SchemaExtender
|
||||
*/
|
||||
protected static function checkExtensionNode(Type $type, Node $node) : void
|
||||
{
|
||||
switch ($node->kind ?? null) {
|
||||
switch ($node->kind) {
|
||||
case NodeKind::OBJECT_TYPE_EXTENSION:
|
||||
if (! ($type instanceof ObjectType)) {
|
||||
throw new Error(
|
||||
@ -589,7 +589,7 @@ class SchemaExtender
|
||||
|
||||
foreach ($schemaExtension->operationTypes as $operationType) {
|
||||
$operation = $operationType->operation;
|
||||
if ($operationTypes[$operation]) {
|
||||
if (isset($operationTypes[$operation])) {
|
||||
throw new Error('Must provide only one ' . $operation . ' type in schema.');
|
||||
}
|
||||
$operationTypes[$operation] = static::$astBuilder->buildType($operationType->type);
|
||||
|
@ -210,6 +210,7 @@ class TypeInfo
|
||||
$typeMap = self::extractTypes($arg->getType(), $typeMap);
|
||||
}
|
||||
}
|
||||
|
||||
return $typeMap;
|
||||
}
|
||||
|
||||
@ -309,7 +310,7 @@ class TypeInfo
|
||||
return $arg->name === $node->name->value;
|
||||
}
|
||||
);
|
||||
if ($argDef) {
|
||||
if ($argDef !== null) {
|
||||
$argType = $argDef->getType();
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class KnownArgumentNamesOnDirectives extends ValidationRule
|
||||
|
||||
foreach ($directiveNode->arguments as $argNode) {
|
||||
$argName = $argNode->name->value;
|
||||
if (in_array($argName, $knownArgs)) {
|
||||
if (in_array($argName, $knownArgs, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,25 @@ class KnownDirectives extends ValidationRule
|
||||
continue;
|
||||
}
|
||||
|
||||
$locationsMap[$def->name->value] = array_map(static function ($name) {
|
||||
$locationsMap[$def->name->value] = array_map(
|
||||
static function ($name) {
|
||||
return $name->value;
|
||||
}, $def->locations);
|
||||
},
|
||||
$def->locations
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
$locations = $locationsMap[$name] ?? null;
|
||||
|
||||
@ -51,12 +64,13 @@ class KnownDirectives extends ValidationRule
|
||||
self::unknownDirectiveMessage($name),
|
||||
[$node]
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
||||
|
||||
if (! $candidateLocation || in_array($candidateLocation, $locations)) {
|
||||
if (! $candidateLocation || in_array($candidateLocation, $locations, true)) {
|
||||
return;
|
||||
}
|
||||
$context->reportError(
|
||||
|
@ -86,7 +86,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
}
|
||||
|
||||
$context->reportError(
|
||||
new Error($this->maxQueryComplexityErrorMessage(
|
||||
new Error(self::maxQueryComplexityErrorMessage(
|
||||
$this->getMaxQueryComplexity(),
|
||||
$complexity
|
||||
))
|
||||
@ -193,7 +193,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
$this->getRawVariableValues()
|
||||
);
|
||||
|
||||
if ($variableValuesResult['errors']) {
|
||||
if (! empty($variableValuesResult['errors'])) {
|
||||
throw new Error(implode(
|
||||
"\n\n",
|
||||
array_map(
|
||||
@ -208,15 +208,16 @@ class QueryComplexity extends QuerySecurityRule
|
||||
|
||||
if ($directiveNode->name->value === 'include') {
|
||||
$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();
|
||||
$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
|
||||
);
|
||||
|
||||
if ($variableValuesResult['errors']) {
|
||||
if (! empty($variableValuesResult['errors'])) {
|
||||
throw new Error(implode(
|
||||
"\n\n",
|
||||
array_map(
|
||||
|
@ -36,7 +36,7 @@ class QueryDepth extends QuerySecurityRule
|
||||
}
|
||||
|
||||
$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;
|
||||
$varDef = $this->varDefMap[$varName] ?? null;
|
||||
|
||||
if (! $varDef || ! $type) {
|
||||
if ($varDef === null || $type === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -98,12 +98,12 @@ class ValidationContext
|
||||
{
|
||||
$usages = $this->recursiveVariableUsages[$operation] ?? null;
|
||||
|
||||
if (! $usages) {
|
||||
if ($usages === null) {
|
||||
$usages = $this->getVariableUsages($operation);
|
||||
$fragments = $this->getRecursivelyReferencedFragments($operation);
|
||||
|
||||
$tmp = [$usages];
|
||||
for ($i = 0; $i < count($fragments); $i++) {
|
||||
foreach ($fragments as $i => $fragment) {
|
||||
$tmp[] = $this->getVariableUsages($fragments[$i]);
|
||||
}
|
||||
$usages = call_user_func_array('array_merge', $tmp);
|
||||
@ -120,7 +120,7 @@ class ValidationContext
|
||||
{
|
||||
$usages = $this->variableUsages[$node] ?? null;
|
||||
|
||||
if (! $usages) {
|
||||
if ($usages === null) {
|
||||
$newUsages = [];
|
||||
$typeInfo = new TypeInfo($this->schema);
|
||||
Visitor::visit(
|
||||
@ -154,15 +154,15 @@ class ValidationContext
|
||||
{
|
||||
$fragments = $this->recursivelyReferencedFragments[$operation] ?? null;
|
||||
|
||||
if (! $fragments) {
|
||||
if ($fragments === null) {
|
||||
$fragments = [];
|
||||
$collectedNames = [];
|
||||
$nodesToVisit = [$operation];
|
||||
while (! empty($nodesToVisit)) {
|
||||
$node = array_pop($nodesToVisit);
|
||||
$spreads = $this->getFragmentSpreads($node);
|
||||
for ($i = 0; $i < count($spreads); $i++) {
|
||||
$fragName = $spreads[$i]->name->value;
|
||||
foreach ($spreads as $spread) {
|
||||
$fragName = $spread->name->value;
|
||||
|
||||
if (! empty($collectedNames[$fragName])) {
|
||||
continue;
|
||||
@ -190,14 +190,14 @@ class ValidationContext
|
||||
public function getFragmentSpreads(HasSelectionSet $node)
|
||||
{
|
||||
$spreads = $this->fragmentSpreads[$node] ?? null;
|
||||
if (! $spreads) {
|
||||
if ($spreads === null) {
|
||||
$spreads = [];
|
||||
/** @var SelectionSetNode[] $setsToVisit */
|
||||
$setsToVisit = [$node->selectionSet];
|
||||
while (! empty($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];
|
||||
if ($selection->kind === NodeKind::FRAGMENT_SPREAD) {
|
||||
$spreads[] = $selection;
|
||||
|
@ -153,7 +153,7 @@ class DeferredFieldsTest extends TestCase
|
||||
return Utils::filter(
|
||||
$this->storyDataSource,
|
||||
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;
|
||||
}
|
||||
|
||||
$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
|
||||
|
@ -260,14 +260,14 @@ class SyncPromiseTest extends TestCase
|
||||
|
||||
try {
|
||||
$promise->reject(new Exception('other-reason'));
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (Throwable $e) {
|
||||
self::assertEquals('Cannot change rejection reason', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$promise->resolve('anything');
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (Throwable $e) {
|
||||
self::assertEquals('Cannot resolve rejected promise', $e->getMessage());
|
||||
}
|
||||
@ -316,7 +316,7 @@ class SyncPromiseTest extends TestCase
|
||||
|
||||
try {
|
||||
$promise->resolve($promise);
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (Throwable $e) {
|
||||
self::assertEquals('Cannot resolve promise with self', $e->getMessage());
|
||||
self::assertEquals(SyncPromise::PENDING, $promise->state);
|
||||
@ -345,7 +345,7 @@ class SyncPromiseTest extends TestCase
|
||||
|
||||
try {
|
||||
$promise->reject('a');
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (Error $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
|
@ -145,7 +145,7 @@ class LexerTest extends TestCase
|
||||
|
||||
try {
|
||||
$this->lexOne($str);
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $error) {
|
||||
self::assertEquals(
|
||||
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
||||
@ -175,7 +175,7 @@ class LexerTest extends TestCase
|
||||
try {
|
||||
$lexer = new Lexer($source);
|
||||
$lexer->advance();
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $error) {
|
||||
self::assertEquals(
|
||||
'Syntax Error: Cannot parse the unexpected character "?".' . "\n" .
|
||||
@ -197,7 +197,7 @@ class LexerTest extends TestCase
|
||||
try {
|
||||
$lexer = new Lexer($source);
|
||||
$lexer->advance();
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $error) {
|
||||
self::assertEquals(
|
||||
'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"');
|
||||
try {
|
||||
$lexer->advance();
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $error) {
|
||||
self::assertEquals([$this->loc(1, 3)], $error->getLocations());
|
||||
throw $error;
|
||||
|
@ -86,7 +86,7 @@ fragment MissingOn Type
|
||||
) : void {
|
||||
try {
|
||||
Parser::parse($str);
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $e) {
|
||||
self::assertEquals($expectedMessage, $e->getMessage());
|
||||
self::assertEquals($stringRepresentation, (string) $e);
|
||||
@ -108,7 +108,7 @@ fragment MissingOn Type
|
||||
{
|
||||
try {
|
||||
Parser::parse(new Source('query', 'MyQuery.graphql'));
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (SyntaxError $error) {
|
||||
self::assertEquals(
|
||||
"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,
|
||||
'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',
|
||||
],
|
||||
],
|
||||
$this->nodeToArray(Parser::parseType('String'))
|
||||
self::nodeToArray(Parser::parseType('String'))
|
||||
);
|
||||
}
|
||||
|
||||
@ -640,7 +640,7 @@ GRAPHQL
|
||||
'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,
|
||||
];
|
||||
$parsed = [
|
||||
'raw' => $this->parseRawMultipartFormdataRequest($post),
|
||||
'psr' => $this->parsePsrMultipartFormdataRequest($post),
|
||||
'raw' => $this->parseRawMultipartFormDataRequest($post),
|
||||
'psr' => $this->parsePsrMultipartFormDataRequest($post),
|
||||
];
|
||||
|
||||
foreach ($parsed as $method => $parsedBody) {
|
||||
@ -395,7 +395,7 @@ class RequestParsingTest extends TestCase
|
||||
{
|
||||
try {
|
||||
$this->parsePsrRequest('application/json', json_encode(null));
|
||||
$this->fail('Expected exception not thrown');
|
||||
self::fail('Expected exception not thrown');
|
||||
} catch (InvariantViolation $e) {
|
||||
// Expecting parsing exception to be thrown somewhere else:
|
||||
self::assertEquals(
|
||||
|
@ -67,7 +67,7 @@ class RequestValidationTest extends TestCase
|
||||
if (! empty($errors[0])) {
|
||||
self::assertEquals($expectedMessage, $errors[0]->getMessage());
|
||||
} 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) {
|
||||
return StarWarsData::getHuman($obj['id']) ? $humanType : $droidType;
|
||||
return StarWarsData::getHuman($obj['id']) === null ? $droidType : $humanType;
|
||||
},
|
||||
]);
|
||||
|
||||
|
@ -1599,14 +1599,14 @@ class DefinitionTest extends TestCase
|
||||
try {
|
||||
Type::listOf($type);
|
||||
} 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) {
|
||||
$typeStr = Utils::printSafe($badType);
|
||||
try {
|
||||
Type::listOf($badType);
|
||||
$this->fail(sprintf('List should not accept %s', $typeStr));
|
||||
self::fail(sprintf('List should not accept %s', $typeStr));
|
||||
} catch (InvariantViolation $e) {
|
||||
self::assertEquals(sprintf('Expected %s to be a GraphQL type.', $typeStr), $e->getMessage());
|
||||
}
|
||||
@ -1640,14 +1640,14 @@ class DefinitionTest extends TestCase
|
||||
try {
|
||||
Type::nonNull($type);
|
||||
} 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) {
|
||||
$typeStr = Utils::printSafe($badType);
|
||||
try {
|
||||
Type::nonNull($badType);
|
||||
$this->fail(sprintf('Nulls should not accept %s', $typeStr));
|
||||
self::fail(sprintf('Nulls should not accept %s', $typeStr));
|
||||
} catch (InvariantViolation $e) {
|
||||
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
|
||||
{
|
||||
$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->expectExceptionMessage(
|
||||
|
@ -201,7 +201,7 @@ class ValidationTest extends TestCase
|
||||
foreach ($closures as $index => $factory) {
|
||||
try {
|
||||
$factory();
|
||||
$this->fail('Expected exception not thrown for entry ' . $index);
|
||||
self::fail('Expected exception not thrown for entry ' . $index);
|
||||
} catch (InvariantViolation $e) {
|
||||
self::assertEquals($expectedError, $e->getMessage(), 'Error in callable #' . $index);
|
||||
}
|
||||
@ -356,7 +356,7 @@ class ValidationTest extends TestCase
|
||||
);
|
||||
foreach ($array as $index => $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());
|
||||
$errorLocations = [];
|
||||
@ -1189,7 +1189,7 @@ class ValidationTest extends TestCase
|
||||
public function testRejectsAnObjectImplementingTheSameInterfaceTwiceDueToExtension() : void
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
$this->markTestIncomplete('extend does not work this way (yet).');
|
||||
self::markTestIncomplete('extend does not work this way (yet).');
|
||||
$schema = BuildSchema::build('
|
||||
type Query {
|
||||
field: AnotherObject
|
||||
|
@ -165,7 +165,7 @@ class SchemaExtenderTest extends TestCase
|
||||
'someInterface' => [
|
||||
'args' => [
|
||||
'id' => [
|
||||
'type' => Type::nonNull(Type::ID()),
|
||||
'type' => Type::nonNull(Type::id()),
|
||||
],
|
||||
],
|
||||
'type' => $SomeInterfaceType,
|
||||
@ -219,7 +219,7 @@ class SchemaExtenderTest extends TestCase
|
||||
$ast->definitions = array_values(array_filter(
|
||||
$ast->definitions instanceof NodeList ? iterator_to_array($ast->definitions->getIterator()) : $ast->definitions,
|
||||
function (Node $node) : bool {
|
||||
return ! in_array(Printer::doPrint($node), $this->testSchemaDefinitions);
|
||||
return ! in_array(Printer::doPrint($node), $this->testSchemaDefinitions, true);
|
||||
}
|
||||
));
|
||||
|
||||
@ -1579,14 +1579,14 @@ class SchemaExtenderTest extends TestCase
|
||||
*/
|
||||
public function testMaintainsConfigurationOfTheOriginalSchemaObject()
|
||||
{
|
||||
$this->markTestSkipped('allowedLegacyNames currently not supported');
|
||||
self::markTestSkipped('allowedLegacyNames currently not supported');
|
||||
|
||||
$testSchemaWithLegacyNames = new Schema(
|
||||
[
|
||||
'query' => new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => static function () {
|
||||
return ['id' => ['type' => Type::ID()]];
|
||||
return ['id' => ['type' => Type::id()]];
|
||||
},
|
||||
]),
|
||||
]/*,
|
||||
@ -1608,7 +1608,7 @@ class SchemaExtenderTest extends TestCase
|
||||
*/
|
||||
public function testAddsToTheConfigurationOfTheOriginalSchemaObject()
|
||||
{
|
||||
$this->markTestSkipped('allowedLegacyNames currently not supported');
|
||||
self::markTestSkipped('allowedLegacyNames currently not supported');
|
||||
|
||||
$testSchemaWithLegacyNames = new Schema(
|
||||
[
|
||||
|
@ -43,7 +43,7 @@ class ValidationTest extends ValidatorTestCase
|
||||
];
|
||||
|
||||
$this->expectInvalid(
|
||||
$this->getTestSchema(),
|
||||
self::getTestSchema(),
|
||||
null,
|
||||
$doc,
|
||||
[$expectedError]
|
||||
@ -59,6 +59,6 @@ class ValidationTest extends ValidatorTestCase
|
||||
'locations' => [['line' => 1, 'column' => 2]],
|
||||
];
|
||||
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
||||
$this->expectValid($this->getTestSchema(), [], $query);
|
||||
$this->expectValid(self::getTestSchema(), [], $query);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user