mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
Allow stringeable objects to be serialized by StringType
Closes #302
(cherry picked from commit c258109
)
This commit is contained in:
parent
e515964a73
commit
c1a62fdb05
@ -40,6 +40,9 @@ represent free-form human-readable text.';
|
||||
if ($value === null) {
|
||||
return 'null';
|
||||
}
|
||||
if (is_object($value) && method_exists($value, '__toString')) {
|
||||
return (string) $value;
|
||||
}
|
||||
if (!is_scalar($value)) {
|
||||
throw new Error("String cannot represent non scalar value: " . Utils::printSafe($value));
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame('true', $stringType->serialize(true));
|
||||
$this->assertSame('false', $stringType->serialize(false));
|
||||
$this->assertSame('null', $stringType->serialize(null));
|
||||
$this->assertSame('2', $stringType->serialize(new ObjectIdStub(2)));
|
||||
}
|
||||
|
||||
public function testSerializesOutputStringsCannotRepresentArray()
|
||||
|
Loading…
Reference in New Issue
Block a user