diff --git a/src/Database/Type/UuidType.php b/src/Database/Type/UuidType.php index eb62a423af3..767d80a3e0c 100644 --- a/src/Database/Type/UuidType.php +++ b/src/Database/Type/UuidType.php @@ -79,4 +79,18 @@ public function newId() { return Text::uuid(); } + + /** + * Marshalls request data into a PHP string + * + * @param mixed $value The value to convert. + * @return string|null Converted value. + */ + public function marshal($value) + { + if ($value === null || $value === '') { + return null; + } + return (string)$value; + } } diff --git a/tests/TestCase/Database/Type/UuidTypeTest.php b/tests/TestCase/Database/Type/UuidTypeTest.php index 45b5b3c71fa..3c52146bb3f 100644 --- a/tests/TestCase/Database/Type/UuidTypeTest.php +++ b/tests/TestCase/Database/Type/UuidTypeTest.php @@ -91,4 +91,14 @@ public function testNewId() $this->assertRegExp('/^[a-f0-9-]+$/', $one, 'Should quack like a uuid'); $this->assertRegExp('/^[a-f0-9-]+$/', $two, 'Should quack like a uuid'); } + + /** + * Tests that marshalling an empty string results in null + * + * @return void + */ + public function testMarshalEmptyString() + { + $this->assertNull($this->type->marshal('')); + } }