From 8fe26a1a21e3a96e470b5712bc9d392239e8308f Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 18 Jul 2017 00:25:45 +0700 Subject: [PATCH] String and ID types should not try to convert non-scalar values to string (#121) --- src/Type/Definition/IDType.php | 8 ++++++++ src/Type/Definition/StringType.php | 8 ++++++++ tests/Type/ScalarSerializationTest.php | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/Type/Definition/IDType.php b/src/Type/Definition/IDType.php index b45cfeb..89f4ff2 100644 --- a/src/Type/Definition/IDType.php +++ b/src/Type/Definition/IDType.php @@ -1,8 +1,10 @@ assertSame('-1.1', $stringType->serialize(-1.1)); $this->assertSame('true', $stringType->serialize(true)); $this->assertSame('false', $stringType->serialize(false)); + $this->assertSame('null', $stringType->serialize(null)); + + try { + $stringType->serialize([]); + $this->fail('Expected exception was not thrown'); + } catch (UserError $e) { + $this->assertEquals('String cannot represent non scalar value: array', $e->getMessage()); + } + + try { + $stringType->serialize(new \stdClass()); + $this->fail('Expected exception was not thrown'); + } catch (UserError $e) { + $this->assertEquals('String cannot represent non scalar value: instance of stdClass', $e->getMessage()); + } } /**