Skip to content

Commit f64724a

Browse files
committed
Making UuidType marshal empty strings as null
1 parent 437e8c8 commit f64724a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Database/Type/UuidType.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,18 @@ public function newId()
7979
{
8080
return Text::uuid();
8181
}
82+
83+
/**
84+
* Marshalls request data into a PHP string
85+
*
86+
* @param mixed $value The value to convert.
87+
* @return string|null Converted value.
88+
*/
89+
public function marshal($value)
90+
{
91+
if ($value === null || $value === '') {
92+
return null;
93+
}
94+
return (string)$value;
95+
}
8296
}

tests/TestCase/Database/Type/UuidTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,14 @@ public function testNewId()
9191
$this->assertRegExp('/^[a-f0-9-]+$/', $one, 'Should quack like a uuid');
9292
$this->assertRegExp('/^[a-f0-9-]+$/', $two, 'Should quack like a uuid');
9393
}
94+
95+
/**
96+
* Tests that marshalling an empty string results in null
97+
*
98+
* @return void
99+
*/
100+
public function testMarshalEmptyString()
101+
{
102+
$this->assertNull($this->type->marshal(''));
103+
}
94104
}

0 commit comments

Comments
 (0)