Include expected type in isValidPHPValue error message

This commit is contained in:
Vladimir Razuvaev 2017-07-03 18:18:50 +07:00
parent e30f2a99cf
commit 445f579f09
4 changed files with 10 additions and 5 deletions

View File

@ -248,7 +248,7 @@ class Values
// a non-null value.
$parseResult = $type->parseValue($value);
if (null === $parseResult) {
$v = json_encode($value);
$v = Utils::printSafe($value);
return [
"Expected type \"{$type->name}\", found $v."
];
@ -256,10 +256,12 @@ class Values
return [];
} catch (\Exception $e) {
return [
"Expected type \"{$type->name}\", found " . Utils::printSafe($value) . ': ' .
$e->getMessage()
];
} catch (\Throwable $e) {
return [
"Expected type \"{$type->name}\", found " . Utils::printSafe($value) . ': ' .
$e->getMessage()
];
}

View File

@ -253,6 +253,9 @@ class Utils
if ('' === $var) {
return '(empty string)';
}
if (is_string($var)) {
return "\"$var\"";
}
if (is_scalar($var)) {
return (string) $var;
}

View File

@ -236,7 +236,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
'{ colorEnum(fromString: "GREEN") }',
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)]
]
);
@ -447,7 +447,7 @@ class EnumTypeTest extends \PHPUnit_Framework_TestCase
[
'data' => ['first' => 'ONE', 'second' => 'TWO', 'third' => null],
'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]]
]]
],

View File

@ -59,7 +59,7 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
$intType->serialize('one');
$this->fail('Expected exception was not thrown');
} 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 {
@ -93,7 +93,7 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
$floatType->serialize('one');
$this->fail('Expected exception was not thrown');
} 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 {