Commit bcbdba0e authored by zYne's avatar zYne

New Doctrine_DB enhancements

parent a773997d
......@@ -26,20 +26,23 @@
* @package Doctrine
*/
class Doctrine_DB_EventListener implements Doctrine_DB_EventListener_Interface {
public function onPreQuery(Doctrine_DB $dbh, array $args) { }
public function onQuery(Doctrine_DB $dbh, array $args) { }
public function onPreQuery(Doctrine_DB2 $dbh, array $args) { }
public function onQuery(Doctrine_DB2 $dbh, array $args) { }
public function onPrePrepare(Doctrine_DB $dbh, array $args) { }
public function onPrepare(Doctrine_DB $dbh, array $args) { }
public function onPrePrepare(Doctrine_DB2 $dbh, array $args) { }
public function onPrepare(Doctrine_DB2 $dbh, array $args) { }
public function onPreCommit(Doctrine_DB $dbh) { }
public function onCommit(Doctrine_DB $dbh) { }
public function onPreCommit(Doctrine_DB2 $dbh) { }
public function onCommit(Doctrine_DB2 $dbh) { }
public function onPreRollBack(Doctrine_DB $dbh) { }
public function onRollBack(Doctrine_DB $dbh) { }
public function onPreExec(Doctrine_DB2 $dbh, array $args) { }
public function onExec(Doctrine_DB2 $dbh, array $args) { }
public function onPreBeginTransaction(Doctrine_DB $dbh) { }
public function onBeginTransaction(Doctrine_DB $dbh) { }
public function onPreRollBack(Doctrine_DB2 $dbh) { }
public function onRollBack(Doctrine_DB2 $dbh) { }
public function onPreBeginTransaction(Doctrine_DB2 $dbh) { }
public function onBeginTransaction(Doctrine_DB2 $dbh) { }
public function onPreExecute(Doctrine_DB_Statement $stmt, array $params) { }
public function onExecute(Doctrine_DB_Statement $stmt, array $params) { }
......
......@@ -25,66 +25,102 @@
* @license LGPL
* @package Doctrine
*/
class Doctrine_DB_EventListener_Chain implements Doctrine_DB_EventListener_Interface {
class Doctrine_DB_EventListener_Chain extends Doctrine_Access implements Doctrine_DB_EventListener_Interface {
private $listeners = array();
public function add($listener, $name = null) {
if( ! ($listener instanceof Doctrine_DB_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
throw new Doctrine_DB_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_DB_EventListener_Interface or Doctrine_Overloadable");
public function onPreQuery(Doctrine_DB $dbh, array $args) {
if($name === null)
$this->listeners[] = $listener;
else
$this->listeners[$name] = $listener;
}
public function get($name) {
if( ! isset($this->listeners[$name]))
throw new Doctrine_DB_Exception("Unknown listener $name");
return $this->listeners[$name];
}
public function set($name, $listener) {
if( ! ($listener instanceof Doctrine_DB_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
throw new Doctrine_DB_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_DB_EventListener_Interface or Doctrine_Overloadable");
$this->listeners[$name] = $listener;
}
public function onPreQuery(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onPreQuery($dbh, $args);
}
}
public function onQuery(Doctrine_DB $dbh, array $args) {
public function onQuery(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onPreQuery($dbh, $args);
$listener->onQuery($dbh, $args);
}
}
public function onPreExec(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onPreExec($dbh, $args);
}
}
public function onExec(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onExec($dbh, $args);
}
}
public function onPrePrepare(Doctrine_DB $dbh, array $args) {
public function onPrePrepare(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onPrePrepare($dbh, $args);
}
}
public function onPrepare(Doctrine_DB $dbh, array $args) {
public function onPrepare(Doctrine_DB2 $dbh, array $args) {
foreach($this->listeners as $listener) {
$listener->onPrepare($dbh, $args);
}
}
public function onPreCommit(Doctrine_DB $dbh) {
public function onPreCommit(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onPreCommit($dbh);
}
}
public function onCommit(Doctrine_DB $dbh) {
public function onCommit(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onCommit($dbh);
}
}
public function onPreRollBack(Doctrine_DB $dbh) {
public function onPreRollBack(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onPreRollBack($dbh);
}
}
public function onRollBack(Doctrine_DB $dbh) {
public function onRollBack(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onRollBack($dbh);
}
}
public function onPreBeginTransaction(Doctrine_DB $dbh) {
public function onPreBeginTransaction(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onPreBeginTransaction($dbh);
}
}
public function onBeginTransaction(Doctrine_DB $dbh) {
public function onBeginTransaction(Doctrine_DB2 $dbh) {
foreach($this->listeners as $listener) {
$listener->onBeginTransaction($dbh);
}
}
public function onPreExecute(Doctrine_DB_Statement $stmt, array $params) {
public function onPreExecute(Doctrine_DB_Statement $stmt, array $params) {
foreach($this->listeners as $listener) {
$listener->onPreExecute($stmt, $params);
}
......
......@@ -25,21 +25,24 @@
* @license LGPL
* @package Doctrine
*/
interface Doctrine_DB_EventListener_Interface {
public function onPreQuery(Doctrine_DB $dbh, array $args);
public function onQuery(Doctrine_DB $dbh, array $args);
interface Doctrine_DB_EventListener_Interface {
public function onPreQuery(Doctrine_DB2 $dbh, array $args);
public function onQuery(Doctrine_DB2 $dbh, array $args);
public function onPrePrepare(Doctrine_DB $dbh, array $args);
public function onPrepare(Doctrine_DB $dbh, array $args);
public function onPrePrepare(Doctrine_DB2 $dbh, array $args);
public function onPrepare(Doctrine_DB2 $dbh, array $args);
public function onPreCommit(Doctrine_DB $dbh);
public function onCommit(Doctrine_DB $dbh);
public function onPreExec(Doctrine_DB2 $dbh, array $args);
public function onExec(Doctrine_DB2 $dbh, array $args);
public function onPreRollBack(Doctrine_DB $dbh);
public function onRollBack(Doctrine_DB $dbh);
public function onPreCommit(Doctrine_DB2 $dbh);
public function onCommit(Doctrine_DB2 $dbh);
public function onPreBeginTransaction(Doctrine_DB $dbh);
public function onBeginTransaction(Doctrine_DB $dbh);
public function onPreRollBack(Doctrine_DB2 $dbh);
public function onRollBack(Doctrine_DB2 $dbh);
public function onPreBeginTransaction(Doctrine_DB2 $dbh);
public function onBeginTransaction(Doctrine_DB2 $dbh);
public function onPreExecute(Doctrine_DB_Statement $stmt, array $params);
public function onExecute(Doctrine_DB_Statement $stmt, array $params);
......
......@@ -65,9 +65,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/
protected $dbh;
/**
* @var Doctrine_DB_EventListener_Interface $listener listener for listening events
* @var Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener listener for listening events
*/
protected $listener;
private static $driverMap = array("oracle" => "oci8",
"postgres" => "pgsql",
"oci" => "oci8");
/**
......@@ -83,15 +87,22 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this->password = $password;
$this->listener = new Doctrine_DB_EventListener();
}
/**
* getDBH
*/
public function getDBH() {
return $this->dbh;
}
/**
* getDSN
* returns the data source name
*
* @return string
*/
public function getDSN() {
return $this->dsn;
}
/**
/**
* getUsername
*/
public function getUsername() {
......@@ -103,20 +114,57 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function getPassword() {
return $this->password;
}
/**
* addListener
*
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_DB
*/
public function addListener($listener, $name = null) {
if( ! ($this->listener instanceof Doctrine_DB_EventListener_Chain))
$this->listener = new Doctrine_DB_EventListener_Chain();
$this->listener->add($listener, $name);
return $this;
}
/**
* getListener
*
* @return Doctrine_DB_EventListener_Interface|Doctrine_Overloadable
*/
public function getListener() {
return $this->listener;
}
/**
* setListener
*
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_DB
*/
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_DB_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
throw new Doctrine_DB_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_DB_EventListener_Interface or Doctrine_Overloadable");
$this->listener = $listener;
return $this;
}
/**
/**
* connect
* connects into database
*
* @return boolean
*/
public function connect() {
if($this->isConnected)
if($this->isConnected)
return false;
$this->dbh = new PDO($this->dsn,$this->username,$this->password);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_DBStatement",array($this)));
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_DB_Statement", array($this)));
return true;
}
......@@ -148,6 +196,69 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
}
return self::$instances[$md5];
}
public static function driverName() {
}
/**
* parseDSN
*
* @param string $dsn
* @return array Parsed contents of DSN
*/
function parseDSN($dsn) {
$parts = @parse_url($dsn);
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) {
if( ! isset($parts[$name]))
$parts[$name] = null;
}
if(count($parts) == 0 || ! isset($parts['scheme']))
throw new Doctrine_DB_Exception('Empty data source name');
$drivers = self::getAvailableDrivers();
if(isset(self::$driverMap[$parts['scheme']]))
$parts['scheme'] = self::$driverMap[$parts['scheme']];
if( ! in_array($parts['scheme'], $drivers))
throw new Doctrine_DB_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded');
switch($parts['scheme']) {
case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:';
}
break;
case 'mysql':
case 'informix':
case 'oci8':
case 'mssql':
case 'firebird':
case 'pgsql':
case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/')
throw new Doctrine_DB_Exception('No database availible in data source name');
if(isset($parts['path']))
$parts['database'] = substr($parts['path'], 1);
if( ! isset($parts['host']))
throw new Doctrine_DB_Exception('No hostname set in data source name');
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break;
default:
throw new Doctrine_DB_Exception('Unknown driver '.$parts['scheme']);
}
return $parts;
}
/**
* clear
* clears all instances from the memory
......@@ -182,11 +293,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @param string $statement
*/
public function prepare($statement) {
$this->listener->onPrePrepare($this, $statement);
$args = func_get_args();
$this->listener->onPrePrepare($this, $args);
$stmt = $this->dbh->prepare($statement);
$this->listener->onPrepare($this,$statement);
$this->listener->onPrepare($this, $args);
return $stmt;
}
......@@ -227,11 +340,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return integer
*/
public function exec($statement) {
$this->listener->onPreExec($this, $statement);
$args = func_get_args();
$this->listener->onPreExec($this, $args);
$rows = $this->dbh->exec($statement);
$this->listener->onExec($this, $statement);
$this->listener->onExec($this, $args);
return $rows;
}
......@@ -331,61 +446,6 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function count() {
return count($this->queries);
}
/**
* parseDSN
*
* @param string $dsn
* @return array Parsed contents of DSN
*/
function parseDSN($dsn) {
$parts = @parse_url($dsn);
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) {
if( ! isset($parts[$name]))
$parts[$name] = null;
}
if(count($parts) == 0 || ! isset($parts['scheme']))
throw new Doctrine_DB_Exception('Empty data source name');
$drivers = self::getAvailableDrivers();
if( ! in_array($parts['scheme'], $drivers))
throw new Doctrine_DB_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded');
switch($parts['scheme']) {
case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:';
}
break;
case 'mysql':
case 'informix':
case 'oci8':
case 'mssql':
case 'firebird':
case 'pgsql':
case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/')
throw new Doctrine_DB_Exception('No database availible in data source name');
if(isset($parts['path']))
$parts['database'] = substr($parts['path'], 1);
if( ! isset($parts['host']))
throw new Doctrine_DB_Exception('No hostname set in data source name');
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break;
default:
throw new Doctrine_DB_Exception('Unknown driver '.$parts['scheme']);
}
return $parts;
}
}
<?php
require_once("../draft/DB.php");
class Doctrine_DB_TestLogger implements Doctrine_Overloadable {
private $messages = array();
public function __call($m, $a) {
$this->messages[] = $m;
}
public function pop() {
return array_pop($this->messages);
}
public function getAll() {
return $this->messages;
}
}
class Doctrine_DB_TestValidListener extends Doctrine_DB_EventListener { }
class Doctrine_DB_TestInvalidListener { }
class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
public function prepareData() { }
public function prepareTables() { }
public function init() { }
public function testAddValidEventListener() {
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener);
try {
$ret = $dbh->addListener(new Doctrine_DB_TestLogger());
$this->pass();
$this->assertTrue($ret instanceof Doctrine_DB2);
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_DB_TestLogger);
try {
$ret = $dbh->addListener(new Doctrine_DB_TestValidListener());
$this->pass();
$this->assertTrue($ret instanceof Doctrine_DB2);
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_DB_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_DB_TestValidListener);
try {
$ret = $dbh->addListener(new Doctrine_DB_EventListener_Chain(), 'chain');
$this->pass();
$this->assertTrue($ret instanceof Doctrine_DB2);
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_DB_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_DB_TestValidListener);
$this->assertTrue($dbh->getListener()->get('chain') instanceof Doctrine_DB_EventListener_Chain);
// replacing
try {
$ret = $dbh->addListener(new Doctrine_DB_EventListener_Chain(), 'chain');
$this->pass();
$this->assertTrue($ret instanceof Doctrine_DB2);
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_DB_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_DB_TestValidListener);
$this->assertTrue($dbh->getListener()->get('chain') instanceof Doctrine_DB_EventListener_Chain);
}
public function testListeningEventsWithSingleListener() {
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
$dbh->connect();
$dbh->setListener(new Doctrine_DB_TestLogger());
$dbh->query('CREATE TABLE entity (id INT)');
$listener = $dbh->getListener();
$this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery');
$stmt = $dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$this->assertEqual($listener->pop(), 'onPrepare');
$this->assertEqual($listener->pop(), 'onPrePrepare');
$stmt->execute(array(1));
$this->assertEqual($listener->pop(), 'onExecute');
$this->assertEqual($listener->pop(), 'onPreExecute');
$dbh->exec('DELETE FROM entity');
$this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreExec');
$dbh->beginTransaction();
$this->assertEqual($listener->pop(), 'onBeginTransaction');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction');
$dbh->query('INSERT INTO entity (id) VALUES (1)');
$dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit');
$this->assertEqual($listener->pop(), 'onPreCommit');
$this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery');
$dbh->query('DROP TABLE entity');
}
public function testListeningEventsWithListenerChain() {
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
$dbh->connect();
$dbh->addListener(new Doctrine_DB_TestLogger());
$dbh->addListener(new Doctrine_DB_TestLogger());
$dbh->query('CREATE TABLE entity (id INT)');
$listener = $dbh->getListener()->get(0);
$listener2 = $dbh->getListener()->get(1);
$this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery');
$this->assertEqual($listener2->pop(), 'onQuery');
$this->assertEqual($listener2->pop(), 'onPreQuery');
$stmt = $dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$this->assertEqual($listener->pop(), 'onPrepare');
$this->assertEqual($listener->pop(), 'onPrePrepare');
$this->assertEqual($listener2->pop(), 'onPrepare');
$this->assertEqual($listener2->pop(), 'onPrePrepare');
$stmt->execute(array(1));
$this->assertEqual($listener->pop(), 'onExecute');
$this->assertEqual($listener->pop(), 'onPreExecute');
$this->assertEqual($listener2->pop(), 'onExecute');
$this->assertEqual($listener2->pop(), 'onPreExecute');
$dbh->exec('DELETE FROM entity');
$this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreExec');
$this->assertEqual($listener2->pop(), 'onExec');
$this->assertEqual($listener2->pop(), 'onPreExec');
$dbh->beginTransaction();
$this->assertEqual($listener->pop(), 'onBeginTransaction');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction');
$this->assertEqual($listener2->pop(), 'onBeginTransaction');
$this->assertEqual($listener2->pop(), 'onPreBeginTransaction');
$dbh->query('INSERT INTO entity (id) VALUES (1)');
$dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit');
$this->assertEqual($listener->pop(), 'onPreCommit');
$this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery');
$dbh->query('DROP TABLE entity');
}
public function testSetValidEventListener() {
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
try {
$dbh->setListener(new Doctrine_DB_TestLogger());
$this->pass();
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_TestLogger);
try {
$dbh->setListener(new Doctrine_DB_TestValidListener());
$this->pass();
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_TestValidListener);
try {
$dbh->setListener(new Doctrine_DB_EventListener_Chain());
$this->pass();
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener_Chain);
try {
$dbh->setListener(new Doctrine_DB_EventListener());
$this->pass();
} catch(Doctrine_DB_Exception $e) {
$this->fail();
}
$this->assertTrue($dbh->getListener() instanceof Doctrine_DB_EventListener);
}
public function testSetInvalidEventListener() {
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
try {
$dbh->setListener(new Doctrine_DB_TestInvalidListener());
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
}
}
public function testInvalidDSN() {
try {
$conn = Doctrine_DB2::getConnection('');
$dbh = Doctrine_DB2::getConnection('');
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
}
try {
$conn = Doctrine_DB2::getConnection('unknown');
$dbh = Doctrine_DB2::getConnection('unknown');
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
}
try {
$conn = Doctrine_DB2::getConnection(0);
$dbh = Doctrine_DB2::getConnection(0);
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
......@@ -28,7 +241,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public function testInvalidScheme() {
try {
$conn = Doctrine_DB2::getConnection('unknown://:memory:');
$dbh = Doctrine_DB2::getConnection('unknown://:memory:');
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
......@@ -36,7 +249,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public function testInvalidHost() {
try {
$conn = Doctrine_DB2::getConnection('mysql://user:password@');
$dbh = Doctrine_DB2::getConnection('mysql://user:password@');
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
......@@ -44,36 +257,41 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public function testInvalidDatabase() {
try {
$conn = Doctrine_DB2::getConnection('mysql://user:password@host/');
$dbh = Doctrine_DB2::getConnection('mysql://user:password@host/');
$this->fail();
} catch(Doctrine_DB_Exception $e) {
$this->pass();
}
}
public function testGetConnectionPdoLikeDSN() {
$conn = Doctrine_DB2::getConnection('mysql:host=localhost;dbname=test', 'root', 'password');
$this->assertEqual($conn->getDSN(), 'mysql:host=localhost;dbname=test');
$this->assertEqual($conn->getUsername(), 'root');
$this->assertEqual($conn->getPassword(), 'password');
$dbh = Doctrine_DB2::getConnection('mysql:host=localhost;dbname=test', 'root', 'password');
$this->assertEqual($dbh->getDSN(), 'mysql:host=localhost;dbname=test');
$this->assertEqual($dbh->getUsername(), 'root');
$this->assertEqual($dbh->getPassword(), 'password');
$conn = Doctrine_DB2::getConnection('sqlite::memory:');
$dbh = Doctrine_DB2::getConnection('sqlite::memory:');
$this->assertEqual($conn->getDSN(), 'sqlite::memory:');
$this->assertEqual($conn->getUsername(), null);
$this->assertEqual($conn->getPassword(), null);
$this->assertEqual($dbh->getDSN(), 'sqlite::memory:');
$this->assertEqual($dbh->getUsername(), null);
$this->assertEqual($dbh->getPassword(), null);
}
public function testDriverName() {
}
public function testGetConnectionWithPearLikeDSN() {
$conn = Doctrine_DB2::getConnection('mysql://zYne:password@localhost/test');
$this->assertEqual($conn->getDSN(), 'mysql:host=localhost;dbname=test');
$this->assertEqual($conn->getUsername(), 'zYne');
$this->assertEqual($conn->getPassword(), 'password');
$dbh = Doctrine_DB2::getConnection('mysql://zYne:password@localhost/test');
$this->assertEqual($dbh->getDSN(), 'mysql:host=localhost;dbname=test');
$this->assertEqual($dbh->getUsername(), 'zYne');
$this->assertEqual($dbh->getPassword(), 'password');
$conn = Doctrine_DB2::getConnection('sqlite://:memory:');
$this->assertEqual($conn->getDSN(), 'sqlite::memory:');
$this->assertEqual($conn->getUsername(), null);
$this->assertEqual($conn->getPassword(), null);
$dbh = Doctrine_DB2::getConnection('sqlite://:memory:');
$this->assertEqual($dbh->getDSN(), 'sqlite::memory:');
$this->assertEqual($dbh->getUsername(), null);
$this->assertEqual($dbh->getPassword(), null);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment