Skip to content

Commit

Permalink
Making UuidType marshal empty strings as null
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 16, 2015
1 parent 437e8c8 commit f64724a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Database/Type/UuidType.php
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions tests/TestCase/Database/Type/UuidTypeTest.php
Expand Up @@ -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.