Skip to content
Permalink
Browse files

Making UuidType marshal empty strings as null

  • Loading branch information...
lorenzo committed Sep 16, 2015
1 parent 437e8c8 commit f64724aced54731a9868af0957ccd6c93ec2e316
Showing with 24 additions and 0 deletions.
  1. +14 −0 src/Database/Type/UuidType.php
  2. +10 −0 tests/TestCase/Database/Type/UuidTypeTest.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;
}
}
@@ -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(''));
}
}

0 comments on commit f64724a

Please sign in to comment.
You can’t perform that action at this time.