diff --git a/src/Executor/Values.php b/src/Executor/Values.php index 441dd04..e3f6023 100644 --- a/src/Executor/Values.php +++ b/src/Executor/Values.php @@ -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() ]; } diff --git a/src/Utils.php b/src/Utils.php index 679e5d2..45b10a0 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -253,6 +253,9 @@ class Utils if ('' === $var) { return '(empty string)'; } + if (is_string($var)) { + return "\"$var\""; + } if (is_scalar($var)) { return (string) $var; } diff --git a/tests/Type/EnumTypeTest.php b/tests/Type/EnumTypeTest.php index 587f195..126d5b7 100644 --- a/tests/Type/EnumTypeTest.php +++ b/tests/Type/EnumTypeTest.php @@ -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]] ]] ], diff --git a/tests/Type/ScalarSerializationTest.php b/tests/Type/ScalarSerializationTest.php index b097a10..23165d7 100644 --- a/tests/Type/ScalarSerializationTest.php +++ b/tests/Type/ScalarSerializationTest.php @@ -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 {