diff --git a/lib/Cake/Model/Datasource/Database/Type.php b/lib/Cake/Model/Datasource/Database/Type.php index 3b884b71cd5..d6ce3d90410 100644 --- a/lib/Cake/Model/Datasource/Database/Type.php +++ b/lib/Cake/Model/Datasource/Database/Type.php @@ -52,6 +52,7 @@ class Type { 'integer' => ['callback' => 'intval', 'pdo' => PDO::PARAM_INT], 'biginteger' => ['callback' => 'intval', 'pdo' => PDO::PARAM_INT], 'string' => ['callback' => 'strval'], + 'uuid' => ['callback' => 'strval'], 'text' => ['callback' => 'strval'], 'boolean' => [ 'callback' => '\Cake\Model\Datasource\Database\Type::boolval', diff --git a/lib/Cake/Test/TestCase/Model/Datasource/Database/TypeTest.php b/lib/Cake/Test/TestCase/Model/Datasource/Database/TypeTest.php index 568c803a7a5..1558ce36871 100644 --- a/lib/Cake/Test/TestCase/Model/Datasource/Database/TypeTest.php +++ b/lib/Cake/Test/TestCase/Model/Datasource/Database/TypeTest.php @@ -332,4 +332,30 @@ public function testBooleanToPHP() { $this->assertFalse($type->toPHP('false', $driver)); } +/** + * Tests uuid from database are converted correctly to PHP + * + * @return void + */ + public function testUuidToPHP() { + $type = Type::build('uuid'); + $string = 'abc123-de456-fg789'; + $driver = $this->getMock('\Cake\Model\Datasource\Database\Driver'); + $this->assertEquals($string, $type->toPHP($string, $driver)); + $this->assertEquals('3', $type->toPHP(3, $driver)); + $this->assertEquals('3.14159', $type->toPHP(3.14159, $driver)); + } + +/** + * Tests integers from PHP are converted correctly to statement value + * + * @return void + */ + public function testUuidToStatement() { + $type = Type::build('uuid'); + $string = 'abc123-def456-ghi789'; + $driver = $this->getMock('\Cake\Model\Datasource\Database\Driver'); + $this->assertEquals(PDO::PARAM_STR, $type->toStatement($string, $driver)); + } + }