Skip to content

Commit

Permalink
Implement UUID type.
Browse files Browse the repository at this point in the history
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 fcf0706
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Model/Datasource/Database/Type.php
Expand Up @@ -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',
Expand Down
26 changes: 26 additions & 0 deletions lib/Cake/Test/TestCase/Model/Datasource/Database/TypeTest.php
Expand Up @@ -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.