Skip to content
Permalink
Browse files

Implement UUID type.

UUID's are just simple strings as far as PDO drivers would be concerned.
  • Loading branch information...
markstory committed Mar 11, 2013
1 parent 3b63d72 commit fcf070615df6a8ed6a0b1db2ed95ce7e6d49b37d
@@ -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',
@@ -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));
}
}

0 comments on commit fcf0706

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