Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
persistent must be cast to a boolean
Browse files Browse the repository at this point in the history
Otherwise PDO doens't respect the value - allegedly
  • Loading branch information
AD7six committed Mar 28, 2015
1 parent 69ff74a commit cb75d8d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Wrapper/CakePHP/V2/DbDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public function getDatasource()
return 'Database/' . ucfirst($engine);
}

/**
* getPersistent
*
* Cast the string value in the dsn to a bool
*
* @return bool
*/
public function getPersistent()
{
return (bool)$this->dsn->persistent;
}

/**
* parse a url as a database dsn
*
Expand Down
36 changes: 36 additions & 0 deletions tests/TestCase/Wrapper/CakePHP/V2/DbDsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,42 @@ public function testDefaults($url, $expected)
$this->assertSame($url, $return, 'The dsn should parse back to the same url');
}

/**
* testPersistentCasting
*
* Persistent need to be a bool otherwise PDO may ignore the value
*
* @return void
*/
public function testPersistentCasting() {
$string = "mysql://root:password@localhost/dbname?persistent=0";
$expected = [
'datasource' => 'Database/Mysql',
'host' => 'localhost',
'port' => 3306,
'login' => 'root',
'password' => 'password',
'database' => 'dbname',
'persistent' => false
];
$result = DbDsn::parse($string);
$this->assertSame($expected, $result);

$string = "mysql://root:password@localhost/dbname?persistent=1";
$expected = [
'datasource' => 'Database/Mysql',
'host' => 'localhost',
'port' => 3306,
'login' => 'root',
'password' => 'password',
'database' => 'dbname',
'persistent' => true
];
$result = DbDsn::parse($string);
$this->assertSame($expected, $result);

}

/**
* defaultsProvider
*
Expand Down

0 comments on commit cb75d8d

Please sign in to comment.