mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 15:59:24 +03:00
Include expected type in isValidPHPValue error message
This commit is contained in:
parent
e30f2a99cf
commit
445f579f09
@ -248,7 +248,7 @@ class Values
|
|||||||
// a non-null value.
|
// a non-null value.
|
||||||
$parseResult = $type->parseValue($value);
|
$parseResult = $type->parseValue($value);
|
||||||
if (null === $parseResult) {
|
if (null === $parseResult) {
|
||||||
$v = json_encode($value);
|
$v = Utils::printSafe($value);
|
||||||
return [
|
return [
|
||||||
"Expected type \"{$type->name}\", found $v."
|
"Expected type \"{$type->name}\", found $v."
|
||||||
];
|
];
|
||||||
@ -256,10 +256,12 @@ class Values
|
|||||||
return [];
|
return [];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return [
|
return [
|
||||||
|
"Expected type \"{$type->name}\", found " . Utils::printSafe($value) . ': ' .
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
];
|
];
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return [
|
return [
|
||||||
|
"Expected type \"{$type->name}\", found " . Utils::printSafe($value) . ': ' .
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,9 @@ class Utils
|
|||||||
if ('' === $var) {
|
if ('' === $var) {
|
||||||
return '(empty string)';
|
return '(empty string)';
|
||||||
}
|
}
|
||||||
|
if (is_string($var)) {
|
||||||
|
return "\"$var\"";
|
||||||
|
}
|
||||||
if (is_scalar($var)) {
|
if (is_scalar($var)) {
|
||||||
return (string) $var;
|
return (string) $var;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'{ colorEnum(fromString: "GREEN") }',
|
'{ colorEnum(fromString: "GREEN") }',
|
||||||
null,
|
null,
|
||||||
[
|
[
|
||||||
'message' => 'Expected a value of type "Color" but received: GREEN',
|
'message' => 'Expected a value of type "Color" but received: "GREEN"',
|
||||||
'locations' => [new SourceLocation(1, 3)]
|
'locations' => [new SourceLocation(1, 3)]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -447,7 +447,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
[
|
[
|
||||||
'data' => ['first' => 'ONE', 'second' => 'TWO', 'third' => null],
|
'data' => ['first' => 'ONE', 'second' => 'TWO', 'third' => null],
|
||||||
'errors' => [[
|
'errors' => [[
|
||||||
'message' => 'Expected a value of type "SimpleEnum" but received: WRONG',
|
'message' => 'Expected a value of type "SimpleEnum" but received: "WRONG"',
|
||||||
'locations' => [['line' => 4, 'column' => 13]]
|
'locations' => [['line' => 4, 'column' => 13]]
|
||||||
]]
|
]]
|
||||||
],
|
],
|
||||||
|
@ -59,7 +59,7 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$intType->serialize('one');
|
$intType->serialize('one');
|
||||||
$this->fail('Expected exception was not thrown');
|
$this->fail('Expected exception was not thrown');
|
||||||
} catch (UserError $e) {
|
} catch (UserError $e) {
|
||||||
$this->assertEquals('Int cannot represent non 32-bit signed integer value: one', $e->getMessage());
|
$this->assertEquals('Int cannot represent non 32-bit signed integer value: "one"', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -93,7 +93,7 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$floatType->serialize('one');
|
$floatType->serialize('one');
|
||||||
$this->fail('Expected exception was not thrown');
|
$this->fail('Expected exception was not thrown');
|
||||||
} catch (UserError $e) {
|
} catch (UserError $e) {
|
||||||
$this->assertEquals('Float cannot represent non numeric value: one', $e->getMessage());
|
$this->assertEquals('Float cannot represent non numeric value: "one"', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user