Skip to content
Permalink
Browse files

Implementing DboMysql::getVersion()

  • Loading branch information...
lorenzo committed Oct 15, 2010
1 parent b847945 commit 09e06d52b9b6cef4402d23f17b99bf3ec4b2f9cf
@@ -796,8 +796,17 @@ function fetchResult() {
*
* @return string The database encoding
*/
function getEncoding() {
return mysql_client_encoding($this->connection);
public function getEncoding() {
return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value;
}
/**
* Gets the version string of the database server
*
* @return string The database encoding
*/
public function getVersion() {
return $this->_execute('SELECT VERSION() as mysql_version')->fetchObject()->mysql_version;
}
/**
@@ -862,4 +862,26 @@ public function testListSources() {
$tables = $db->listSources();
$this->assertEqual($tables, array('cake_table', 'another_table'));
}

/**
* Tests that getVersion method sends the correct query for getting the mysql version
* @return void
*/
public function testGetVersion() {
$db = $this->getMock('DboMysql', array('connect', '_execute'));
$queryResult = $this->getMock('PDOStatement');

$db->expects($this->once())
->method('_execute')
->with('SELECT VERSION() as mysql_version')
->will($this->returnValue($queryResult));
$result = new StdClass;
$result->mysql_version = '5.1';
$queryResult->expects($this->once())
->method('fetchObject')
->will($this->returnValue($result));

$version = $db->getVersion();
$this->assertEqual('5.1', $version);
}
}

0 comments on commit 09e06d5

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