This commit is contained in:
parent
e6d7127f5c
commit
c1511dd391
@ -142,6 +142,7 @@ final class Doctrine
|
||||
const ATTR_DRIVER_NAME = 16;
|
||||
const ATTR_STRINGIFY_FETCHES = 17;
|
||||
const ATTR_MAX_COLUMN_LEN = 18;
|
||||
|
||||
/**
|
||||
* Doctrine constants
|
||||
*/
|
||||
@ -194,6 +195,8 @@ final class Doctrine
|
||||
const ATTR_CACHE_LIFESPAN = 151;
|
||||
const ATTR_LOAD_REFERENCES = 153;
|
||||
const ATTR_RECORD_LISTENER = 154;
|
||||
const ATTR_THROW_EXCEPTIONS = 155;
|
||||
|
||||
|
||||
/**
|
||||
* LIMIT CONSTANTS
|
||||
@ -354,10 +357,6 @@ final class Doctrine
|
||||
* constant for composite identifier
|
||||
*/
|
||||
const IDENTIFIER_COMPOSITE = 4;
|
||||
|
||||
const ACCESSOR_BOTH = 0;
|
||||
const ACCESSOR_SET = 1;
|
||||
const ACCESSOR_GET = 2;
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
|
@ -137,6 +137,7 @@ abstract class Doctrine_Configurable extends Doctrine_Object
|
||||
case Doctrine::ATTR_DECIMAL_PLACES:
|
||||
case Doctrine::ATTR_LOAD_REFERENCES:
|
||||
case Doctrine::ATTR_RECORD_LISTENER:
|
||||
case Doctrine::ATTR_THROW_EXCEPTIONS:
|
||||
|
||||
break;
|
||||
case Doctrine::ATTR_SEQCOL_NAME:
|
||||
|
@ -687,19 +687,24 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::CONN_PREPARE, $statement);
|
||||
try {
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::CONN_PREPARE, $statement);
|
||||
|
||||
$this->getAttribute(Doctrine::ATTR_LISTENER)->prePrepare($event);
|
||||
$this->getAttribute(Doctrine::ATTR_LISTENER)->prePrepare($event);
|
||||
|
||||
$stmt = false;
|
||||
$stmt = false;
|
||||
|
||||
if ( ! $event->skipOperation) {
|
||||
$stmt = $this->dbh->prepare($statement);
|
||||
}
|
||||
if ( ! $event->skipOperation) {
|
||||
$stmt = $this->dbh->prepare($statement);
|
||||
}
|
||||
|
||||
$this->getAttribute(Doctrine::ATTR_LISTENER)->postPrepare($event);
|
||||
$this->getAttribute(Doctrine::ATTR_LISTENER)->postPrepare($event);
|
||||
|
||||
return new Doctrine_Connection_Statement($this, $stmt);
|
||||
return new Doctrine_Connection_Statement($this, $stmt);
|
||||
} catch(Doctrine_Adapter_Exception $e) {
|
||||
} catch(PDOException $e) { }
|
||||
|
||||
$this->rethrowException($e, $this);
|
||||
}
|
||||
/**
|
||||
* query
|
||||
@ -791,7 +796,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
} catch(Doctrine_Adapter_Exception $e) {
|
||||
} catch(PDOException $e) { }
|
||||
|
||||
$this->rethrowException($e);
|
||||
$this->rethrowException($e, $this);
|
||||
}
|
||||
/**
|
||||
* exec
|
||||
@ -826,15 +831,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
} catch(Doctrine_Adapter_Exception $e) {
|
||||
} catch(PDOException $e) { }
|
||||
|
||||
$this->rethrowException($e);
|
||||
$this->rethrowException($e, $this);
|
||||
}
|
||||
/**
|
||||
* rethrowException
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception
|
||||
*/
|
||||
private function rethrowException(Exception $e)
|
||||
public function rethrowException(Exception $e, $invoker)
|
||||
{
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR);
|
||||
|
||||
$this->getListener()->preError($event);
|
||||
|
||||
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
|
||||
|
||||
$exc = new $name($e->getMessage(), (int) $e->getCode());
|
||||
@ -843,7 +852,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
}
|
||||
$exc->processErrorInfo($e->errorInfo);
|
||||
|
||||
throw $exc;
|
||||
if ($this->getAttribute(Doctrine::ATTR_THROW_EXCEPTIONS)) {
|
||||
throw $exc;
|
||||
}
|
||||
|
||||
$this->getListener()->postError($event);
|
||||
}
|
||||
/**
|
||||
* hasTable
|
||||
|
@ -213,15 +213,23 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
|
||||
*/
|
||||
public function execute($params = null)
|
||||
{
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
|
||||
$this->_conn->getListener()->preExecute($event);
|
||||
try {
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
|
||||
$this->_conn->getListener()->preStmtExecute($event);
|
||||
|
||||
if ( ! $event->skipOperation) {
|
||||
$this->_stmt->execute($params);
|
||||
$this->_conn->incrementQueryCount();
|
||||
if ( ! $event->skipOperation) {
|
||||
$this->_stmt->execute($params);
|
||||
$this->_conn->incrementQueryCount();
|
||||
}
|
||||
|
||||
$this->_conn->getListener()->postStmtExecute($event);
|
||||
|
||||
return $this;
|
||||
} catch (PDOException $e) {
|
||||
} catch (Doctrine_Adapter_Exception $e) {
|
||||
}
|
||||
|
||||
$this->_conn->getListener()->postExecute($event);
|
||||
$this->_conn->rethrowException($e, $this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class Doctrine_Event
|
||||
const CONN_PREPARE = 3;
|
||||
const CONN_CONNECT = 4;
|
||||
const CONN_CLOSE = 5;
|
||||
const CONN_ERROR = 6;
|
||||
|
||||
const STMT_EXECUTE = 10;
|
||||
const STMT_FETCH = 11;
|
||||
|
@ -34,22 +34,6 @@ Doctrine::autoload('Doctrine_EventListener_Interface');
|
||||
*/
|
||||
class Doctrine_EventListener implements Doctrine_EventListener_Interface
|
||||
{
|
||||
public function onLoad(Doctrine_Record $record)
|
||||
{ }
|
||||
public function onPreLoad(Doctrine_Record $record)
|
||||
{ }
|
||||
|
||||
public function onSleep(Doctrine_Record $record)
|
||||
{ }
|
||||
|
||||
public function onWakeUp(Doctrine_Record $record)
|
||||
{ }
|
||||
|
||||
public function onEvict(Doctrine_Record $record)
|
||||
{ }
|
||||
public function onPreEvict(Doctrine_Record $record)
|
||||
{ }
|
||||
|
||||
public function preClose(Doctrine_Event $event)
|
||||
{ }
|
||||
public function postClose(Doctrine_Event $event)
|
||||
@ -114,6 +98,11 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface
|
||||
public function postExec(Doctrine_Event $event)
|
||||
{ }
|
||||
|
||||
public function preError(Doctrine_Event $event)
|
||||
{ }
|
||||
public function postError(Doctrine_Event $event)
|
||||
{ }
|
||||
|
||||
public function preFetch(Doctrine_Event $event)
|
||||
{ }
|
||||
public function postFetch(Doctrine_Event $event)
|
||||
@ -124,8 +113,8 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface
|
||||
public function postFetchAll(Doctrine_Event $event)
|
||||
{ }
|
||||
|
||||
public function preExecute(Doctrine_Event $event)
|
||||
public function preStmtExecute(Doctrine_Event $event)
|
||||
{ }
|
||||
public function postExecute(Doctrine_Event $event)
|
||||
public function postStmtExecute(Doctrine_Event $event)
|
||||
{ }
|
||||
}
|
||||
|
@ -332,6 +332,19 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
|
||||
}
|
||||
}
|
||||
|
||||
public function preError(Doctrine_Event $event)
|
||||
{
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->preError($event);
|
||||
}
|
||||
}
|
||||
public function postError(Doctrine_Event $event)
|
||||
{
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->postError($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function preFetch(Doctrine_Event $event)
|
||||
{
|
||||
foreach ($this->listeners as $listener) {
|
||||
@ -359,17 +372,17 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
|
||||
}
|
||||
}
|
||||
|
||||
public function preExecute(Doctrine_Event $event)
|
||||
public function preStmtExecute(Doctrine_Event $event)
|
||||
{
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->preExecute($event);
|
||||
$listener->preStmtExecute($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function postExecute(Doctrine_Event $event)
|
||||
public function postStmtExecute(Doctrine_Event $event)
|
||||
{
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->postExecute($event);
|
||||
$listener->postStmtExecute($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,12 +55,15 @@ interface Doctrine_EventListener_Interface
|
||||
public function preExec(Doctrine_Event $event);
|
||||
public function postExec(Doctrine_Event $event);
|
||||
|
||||
public function preError(Doctrine_Event $event);
|
||||
public function postError(Doctrine_Event $event);
|
||||
|
||||
public function preFetch(Doctrine_Event $event);
|
||||
public function postFetch(Doctrine_Event $event);
|
||||
|
||||
public function preFetchAll(Doctrine_Event $event);
|
||||
public function postFetchAll(Doctrine_Event $event);
|
||||
|
||||
public function preExecute(Doctrine_Event $event);
|
||||
public function postExecute(Doctrine_Event $event);
|
||||
public function preStmtExecute(Doctrine_Event $event);
|
||||
public function postStmtExecute(Doctrine_Event $event);
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
Doctrine::ATTR_LOAD_REFERENCES => true,
|
||||
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
|
||||
Doctrine::ATTR_RECORD_LISTENER => new Doctrine_Record_Listener(),
|
||||
Doctrine::ATTR_THROW_EXCEPTIONS => true,
|
||||
Doctrine::ATTR_LOCKMODE => 1,
|
||||
Doctrine::ATTR_VLD => false,
|
||||
Doctrine::ATTR_AUTO_LENGTH_VLD => true,
|
||||
|
@ -520,6 +520,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE);
|
||||
|
||||
$this->preUnserialize($event);
|
||||
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
$connection = $manager->getConnectionForComponent(get_class($this));
|
||||
|
||||
@ -541,7 +545,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
$this->prepareIdentifiers($this->exists());
|
||||
|
||||
$this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onWakeUp($this);
|
||||
$this->postUnserialize($event);
|
||||
}
|
||||
/**
|
||||
* getState
|
||||
@ -633,8 +637,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
$this->_state = Doctrine_Record::STATE_CLEAN;
|
||||
|
||||
$this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
|
@ -63,6 +63,29 @@ class Doctrine_Search
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function updateIndex(Doctrine_Record $record)
|
||||
{
|
||||
$fields = $this->getOption('fields');
|
||||
$class = $this->getOption('className');
|
||||
$name = $record->getTable()->getComponentName();
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$data = $record->get($field);
|
||||
|
||||
$terms = $this->analyze($data);
|
||||
|
||||
foreach ($terms as $pos => $term) {
|
||||
$index = new $class();
|
||||
|
||||
$index->keyword = $term;
|
||||
$index->position = $pos;
|
||||
$index->field = $field;
|
||||
$index->$name = $record;
|
||||
|
||||
$index->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
public function buildDefinition(Doctrine_Table $table)
|
||||
{
|
||||
|
||||
@ -111,9 +134,5 @@ class Doctrine_Search
|
||||
if ( ! $this->_options['generateFiles']) {
|
||||
eval($def);
|
||||
}
|
||||
/**
|
||||
print "<pre>";
|
||||
print_r(htmlentities($def));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -283,8 +283,7 @@ class Doctrine_Search_Analyzer_Standard implements Doctrine_Search_Analyzer_Inte
|
||||
continue;
|
||||
}
|
||||
|
||||
$pos = strpos($text, $term);
|
||||
$ret[$pos] = $lower;
|
||||
$ret[$i] = $lower;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
|
@ -49,26 +49,8 @@ class Doctrine_Search_Listener extends Doctrine_Record_Listener
|
||||
}
|
||||
public function postInsert(Doctrine_Event $event)
|
||||
{
|
||||
$fields = $this->_search->getOption('fields');
|
||||
$class = $this->_search->getOption('className');
|
||||
$record = $event->getInvoker();
|
||||
$name = $record->getTable()->getComponentName();
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$data = $record->get($field);
|
||||
|
||||
$terms = $this->_search->analyze($data);
|
||||
|
||||
foreach ($terms as $pos => $term) {
|
||||
$index = new $class();
|
||||
|
||||
$index->keyword = $term;
|
||||
$index->position = $pos;
|
||||
$index->field = $field;
|
||||
$index->$name = $record;
|
||||
|
||||
$index->save();
|
||||
}
|
||||
}
|
||||
$this->_search->updateIndex($record);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
* Doctrine_Db_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @subpackage Doctrine_Db
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
@ -33,125 +32,127 @@
|
||||
*/
|
||||
class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
protected $dbh;
|
||||
|
||||
public function prepareData() { }
|
||||
public function prepareTables() { }
|
||||
public function init() { }
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function prepareTables()
|
||||
{ }
|
||||
|
||||
public function init()
|
||||
{ }
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$this->dbh = Doctrine_Manager::getInstance()->openConnection(array('sqlite::memory:'));
|
||||
$this->dbh->exec('CREATE TABLE entity (id INTEGER, name TEXT)');
|
||||
$this->conn = Doctrine_Manager::getInstance()->openConnection(array('sqlite::memory:'));
|
||||
$this->conn->exec('CREATE TABLE entity (id INTEGER, name TEXT)');
|
||||
|
||||
$this->dbh->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
|
||||
$this->dbh->exec("INSERT INTO entity (id, name) VALUES (2, 'John')");
|
||||
$this->conn->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
|
||||
$this->conn->exec("INSERT INTO entity (id, name) VALUES (2, 'John')");
|
||||
|
||||
|
||||
$this->assertEqual($this->dbh->getAttribute(Doctrine::ATTR_DRIVER_NAME), 'sqlite');
|
||||
$this->assertEqual($this->conn->getAttribute(Doctrine::ATTR_DRIVER_NAME), 'sqlite');
|
||||
}
|
||||
|
||||
public function testAddValidEventListener()
|
||||
{
|
||||
$this->dbh->setListener(new Doctrine_EventListener());
|
||||
$this->conn->setListener(new Doctrine_EventListener());
|
||||
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener);
|
||||
try {
|
||||
$ret = $this->dbh->addListener(new Doctrine_Connection_TestLogger());
|
||||
$ret = $this->conn->addListener(new Doctrine_Connection_TestLogger());
|
||||
$this->pass();
|
||||
$this->assertTrue($ret instanceof Doctrine_Connection);
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
|
||||
try {
|
||||
$ret = $this->dbh->addListener(new Doctrine_Connection_TestValidListener());
|
||||
$ret = $this->conn->addListener(new Doctrine_Connection_TestValidListener());
|
||||
$this->pass();
|
||||
$this->assertTrue($ret instanceof Doctrine_Connection);
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->conn->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
|
||||
try {
|
||||
$ret = $this->dbh->addListener(new Doctrine_EventListener_Chain(), 'chain');
|
||||
$ret = $this->conn->addListener(new Doctrine_EventListener_Chain(), 'chain');
|
||||
$this->pass();
|
||||
$this->assertTrue($ret instanceof Doctrine_Connection);
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->conn->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->conn->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
|
||||
|
||||
// replacing
|
||||
|
||||
try {
|
||||
$ret = $this->dbh->addListener(new Doctrine_EventListener_Chain(), 'chain');
|
||||
$ret = $this->conn->addListener(new Doctrine_EventListener_Chain(), 'chain');
|
||||
$this->pass();
|
||||
$this->assertTrue($ret instanceof Doctrine_Connection);
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->conn->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->conn->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
|
||||
}
|
||||
|
||||
public function testListeningEventsWithSingleListener()
|
||||
{
|
||||
$this->dbh->setListener(new Doctrine_Connection_TestLogger());
|
||||
$listener = $this->dbh->getListener();
|
||||
$stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
|
||||
$this->conn->setListener(new Doctrine_Connection_TestLogger());
|
||||
$listener = $this->conn->getListener();
|
||||
$stmt = $this->conn->prepare('INSERT INTO entity (id) VALUES(?)');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postPrepare');
|
||||
$this->assertEqual($listener->pop(), 'prePrepare');
|
||||
|
||||
$stmt->execute(array(1));
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postExecute');
|
||||
$this->assertEqual($listener->pop(), 'preExecute');
|
||||
$this->assertEqual($listener->pop(), 'postStmtExecute');
|
||||
$this->assertEqual($listener->pop(), 'preStmtExecute');
|
||||
|
||||
$this->dbh->exec('DELETE FROM entity');
|
||||
$this->conn->exec('DELETE FROM entity');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postExec');
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
|
||||
$this->dbh->beginTransaction();
|
||||
$this->conn->beginTransaction();
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postTransactionBegin');
|
||||
$this->assertEqual($listener->pop(), 'preTransactionBegin');
|
||||
|
||||
$this->dbh->exec('INSERT INTO entity (id) VALUES (1)');
|
||||
$this->conn->exec('INSERT INTO entity (id) VALUES (1)');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postExec');
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
|
||||
$this->dbh->commit();
|
||||
$this->conn->commit();
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postTransactionCommit');
|
||||
$this->assertEqual($listener->pop(), 'preTransactionCommit');
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testListeningQueryEventsWithListenerChain()
|
||||
{
|
||||
$this->dbh->exec('DROP TABLE entity');
|
||||
$this->conn->exec('DROP TABLE entity');
|
||||
|
||||
$this->dbh->addListener(new Doctrine_Connection_TestLogger());
|
||||
$this->dbh->addListener(new Doctrine_Connection_TestLogger());
|
||||
$this->conn->addListener(new Doctrine_Connection_TestLogger());
|
||||
$this->conn->addListener(new Doctrine_Connection_TestLogger());
|
||||
|
||||
$this->dbh->exec('CREATE TABLE entity (id INT)');
|
||||
$this->conn->exec('CREATE TABLE entity (id INT)');
|
||||
|
||||
$listener = $this->dbh->getListener()->get(0);
|
||||
$listener2 = $this->dbh->getListener()->get(1);
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$listener2 = $this->conn->getListener()->get(1);
|
||||
$this->assertEqual($listener->pop(), 'postExec');
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
|
||||
@ -162,9 +163,9 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
public function testListeningPrepareEventsWithListenerChain()
|
||||
{
|
||||
|
||||
$stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
|
||||
$listener = $this->dbh->getListener()->get(0);
|
||||
$listener2 = $this->dbh->getListener()->get(1);
|
||||
$stmt = $this->conn->prepare('INSERT INTO entity (id) VALUES(?)');
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$listener2 = $this->conn->getListener()->get(1);
|
||||
$this->assertEqual($listener->pop(), 'postPrepare');
|
||||
$this->assertEqual($listener->pop(), 'prePrepare');
|
||||
|
||||
@ -173,18 +174,72 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$stmt->execute(array(1));
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postExecute');
|
||||
$this->assertEqual($listener->pop(), 'preExecute');
|
||||
$this->assertEqual($listener->pop(), 'postStmtExecute');
|
||||
$this->assertEqual($listener->pop(), 'preStmtExecute');
|
||||
|
||||
$this->assertEqual($listener2->pop(), 'postExecute');
|
||||
$this->assertEqual($listener2->pop(), 'preExecute');
|
||||
$this->assertEqual($listener2->pop(), 'postStmtExecute');
|
||||
$this->assertEqual($listener2->pop(), 'preStmtExecute');
|
||||
}
|
||||
|
||||
public function testListeningErrorHandlingMethodsOnExec()
|
||||
{
|
||||
$this->conn->setAttribute(Doctrine::ATTR_THROW_EXCEPTIONS, false);
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$this->conn->exec('DELETE FROM unknown');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postError');
|
||||
$this->assertEqual($listener->pop(), 'preError');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
}
|
||||
|
||||
public function testListeningErrorHandlingMethodsOnQuery()
|
||||
{
|
||||
$this->conn->setAttribute(Doctrine::ATTR_THROW_EXCEPTIONS, false);
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$this->conn->execute('DELETE FROM unknown');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postError');
|
||||
$this->assertEqual($listener->pop(), 'preError');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'preQuery');
|
||||
}
|
||||
|
||||
public function testListeningErrorHandlingMethodsOnPrepare()
|
||||
{
|
||||
$this->conn->setAttribute(Doctrine::ATTR_THROW_EXCEPTIONS, false);
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
|
||||
$this->conn->prepare('INSERT INTO unknown (id) VALUES (?)');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postError');
|
||||
$this->assertEqual($listener->pop(), 'preError');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'prePrepare');
|
||||
}
|
||||
|
||||
public function testListeningErrorHandlingMethodsOnStatementExecute()
|
||||
{
|
||||
$this->conn->setAttribute(Doctrine::ATTR_THROW_EXCEPTIONS, false);
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
|
||||
$stmt = $this->conn->prepare('INSERT INTO entity (id) VALUES (?)');
|
||||
|
||||
$stmt->execute(array(1, 2, 3));
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postError');
|
||||
$this->assertEqual($listener->pop(), 'preError');
|
||||
|
||||
$this->assertEqual($listener->pop(), 'preStmtExecute');
|
||||
$this->assertEqual($listener->pop(), 'postPrepare');
|
||||
$this->assertEqual($listener->pop(), 'prePrepare');
|
||||
}
|
||||
|
||||
public function testListeningExecEventsWithListenerChain()
|
||||
{
|
||||
$this->dbh->exec('DELETE FROM entity');
|
||||
$listener = $this->dbh->getListener()->get(0);
|
||||
$listener2 = $this->dbh->getListener()->get(1);
|
||||
$this->conn->exec('DELETE FROM entity');
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$listener2 = $this->conn->getListener()->get(1);
|
||||
$this->assertEqual($listener->pop(), 'postExec');
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
|
||||
@ -194,18 +249,18 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testListeningTransactionEventsWithListenerChain()
|
||||
{
|
||||
$this->dbh->beginTransaction();
|
||||
$listener = $this->dbh->getListener()->get(0);
|
||||
$listener2 = $this->dbh->getListener()->get(1);
|
||||
$this->conn->beginTransaction();
|
||||
$listener = $this->conn->getListener()->get(0);
|
||||
$listener2 = $this->conn->getListener()->get(1);
|
||||
$this->assertEqual($listener->pop(), 'postTransactionBegin');
|
||||
$this->assertEqual($listener->pop(), 'preTransactionBegin');
|
||||
|
||||
$this->assertEqual($listener2->pop(), 'postTransactionBegin');
|
||||
$this->assertEqual($listener2->pop(), 'preTransactionBegin');
|
||||
|
||||
$this->dbh->exec('INSERT INTO entity (id) VALUES (1)');
|
||||
$this->conn->exec('INSERT INTO entity (id) VALUES (1)');
|
||||
|
||||
$this->dbh->commit();
|
||||
$this->conn->commit();
|
||||
|
||||
$this->assertEqual($listener->pop(), 'postTransactionCommit');
|
||||
$this->assertEqual($listener->pop(), 'preTransactionCommit');
|
||||
@ -213,44 +268,46 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($listener->pop(), 'postExec');
|
||||
$this->assertEqual($listener->pop(), 'preExec');
|
||||
|
||||
$this->dbh->exec('DROP TABLE entity');
|
||||
$this->conn->exec('DROP TABLE entity');
|
||||
}
|
||||
|
||||
public function testSetValidEventListener()
|
||||
{
|
||||
try {
|
||||
$this->dbh->setListener(new Doctrine_Connection_TestLogger());
|
||||
$this->conn->setListener(new Doctrine_Connection_TestLogger());
|
||||
$this->pass();
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Connection_TestLogger);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_Connection_TestLogger);
|
||||
try {
|
||||
$this->dbh->setListener(new Doctrine_Connection_TestValidListener());
|
||||
$this->conn->setListener(new Doctrine_Connection_TestValidListener());
|
||||
$this->pass();
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Connection_TestValidListener);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_Connection_TestValidListener);
|
||||
try {
|
||||
$this->dbh->setListener(new Doctrine_EventListener_Chain());
|
||||
$this->conn->setListener(new Doctrine_EventListener_Chain());
|
||||
$this->pass();
|
||||
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener_Chain);
|
||||
try {
|
||||
$this->dbh->setListener(new Doctrine_EventListener());
|
||||
$this->conn->setListener(new Doctrine_EventListener());
|
||||
$this->pass();
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->fail();
|
||||
}
|
||||
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener);
|
||||
$this->assertTrue($this->conn->getListener() instanceof Doctrine_EventListener);
|
||||
}
|
||||
|
||||
public function testSetInvalidEventListener()
|
||||
{
|
||||
try {
|
||||
$this->dbh->setListener(new Doctrine_Connection_TestInvalidListener());
|
||||
$this->conn->setListener(new Doctrine_Connection_TestInvalidListener());
|
||||
$this->fail();
|
||||
} catch(Doctrine_EventListener_Exception $e) {
|
||||
$this->pass();
|
||||
@ -260,19 +317,19 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
try {
|
||||
$this->dbh = $manager->openConnection('');
|
||||
$this->conn = $manager->openConnection('');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
try {
|
||||
$this->dbh = $manager->openConnection('unknown');
|
||||
$this->conn = $manager->openConnection('unknown');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
}
|
||||
try {
|
||||
$this->dbh = $manager->openConnection(0);
|
||||
$this->conn = $manager->openConnection(0);
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
@ -282,7 +339,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
try {
|
||||
$this->dbh = $manager->openConnection('unknown://:memory:');
|
||||
$this->conn = $manager->openConnection('unknown://:memory:');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
@ -292,7 +349,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
try {
|
||||
$this->dbh = $manager->openConnection('mysql://user:password@');
|
||||
$this->conn = $manager->openConnection('mysql://user:password@');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
@ -302,7 +359,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
try {
|
||||
$this->dbh = $manager->openConnection('mysql://user:password@host/');
|
||||
$this->conn = $manager->openConnection('mysql://user:password@host/');
|
||||
$this->fail();
|
||||
} catch(Doctrine_Exception $e) {
|
||||
$this->pass();
|
||||
@ -311,17 +368,17 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
/**
|
||||
public function testGetConnectionPdoLikeDSN()
|
||||
{
|
||||
$this->dbh = Doctrine_Manager::openConnection(array('mysql:host=localhost;dbname=test', 'root', 'password'));
|
||||
$this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
|
||||
$this->assertEqual($this->dbh->getOption('username'), 'root');
|
||||
$this->assertEqual($this->dbh->getOption('password'), 'password');
|
||||
$this->conn = Doctrine_Manager::openConnection(array('mysql:host=localhost;dbname=test', 'root', 'password'));
|
||||
$this->assertEqual($this->conn->getOption('dsn'), 'mysql:host=localhost;dbname=test');
|
||||
$this->assertEqual($this->conn->getOption('username'), 'root');
|
||||
$this->assertEqual($this->conn->getOption('password'), 'password');
|
||||
|
||||
|
||||
$this->dbh = Doctrine_Connection::getConnection('sqlite::memory:');
|
||||
$this->conn = Doctrine_Connection::getConnection('sqlite::memory:');
|
||||
|
||||
$this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
|
||||
$this->assertEqual($this->dbh->getOption('username'), false);
|
||||
$this->assertEqual($this->dbh->getOption('password'), false);
|
||||
$this->assertEqual($this->conn->getOption('dsn'), 'sqlite::memory:');
|
||||
$this->assertEqual($this->conn->getOption('username'), false);
|
||||
$this->assertEqual($this->conn->getOption('password'), false);
|
||||
}
|
||||
public function testDriverName()
|
||||
{
|
||||
@ -330,17 +387,17 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testGetConnectionWithPearLikeDSN()
|
||||
{
|
||||
$this->dbh = Doctrine_Connection::getConnection('mysql://zYne:password@localhost/test');
|
||||
$this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
|
||||
$this->assertEqual($this->dbh->getOption('username'), 'zYne');
|
||||
$this->assertEqual($this->dbh->getOption('password'), 'password');
|
||||
$this->conn = Doctrine_Connection::getConnection('mysql://zYne:password@localhost/test');
|
||||
$this->assertEqual($this->conn->getOption('dsn'), 'mysql:host=localhost;dbname=test');
|
||||
$this->assertEqual($this->conn->getOption('username'), 'zYne');
|
||||
$this->assertEqual($this->conn->getOption('password'), 'password');
|
||||
|
||||
|
||||
$this->dbh = Doctrine_Connection::getConnection('sqlite://:memory:');
|
||||
$this->conn = Doctrine_Connection::getConnection('sqlite://:memory:');
|
||||
|
||||
$this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
|
||||
$this->assertEqual($this->dbh->getOption('username'), false);
|
||||
$this->assertEqual($this->dbh->getOption('password'), false);
|
||||
$this->assertEqual($this->conn->getOption('dsn'), 'sqlite::memory:');
|
||||
$this->assertEqual($this->conn->getOption('username'), false);
|
||||
$this->assertEqual($this->conn->getOption('password'), false);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ class Doctrine_Search_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$e->save();
|
||||
}
|
||||
|
||||
public function testQuerying()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
@ -73,6 +74,21 @@ class Doctrine_Search_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->assertEqual($array[0]['title'], 'Once there was an ORM framework');
|
||||
}
|
||||
|
||||
public function testUsingWordRange()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->select('t.title, i.*')
|
||||
->from('SearchTest t')
|
||||
->innerJoin('t.SearchTestIndex i')
|
||||
->where('i.keyword = ? OR i.keyword = ?');
|
||||
|
||||
$array = $q->execute(array('orm', 'framework'), Doctrine_Hydrate::HYDRATE_ARRAY);
|
||||
|
||||
$this->assertEqual($array[0]['title'], 'Once there was an ORM framework');
|
||||
}
|
||||
|
||||
public function testQueryingReturnsEmptyArrayForStopKeyword()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
@ -86,6 +102,7 @@ class Doctrine_Search_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->assertEqual(count($array), 0);
|
||||
}
|
||||
|
||||
public function testQueryingReturnsEmptyArrayForUnknownKeyword()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
|
||||
|
||||
$test->addTestCase(new Doctrine_Ticket330_TestCase());
|
||||
*/
|
||||
/** */
|
||||
/** */
|
||||
// Connection drivers (not yet fully tested)
|
||||
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
|
||||
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
|
||||
@ -315,7 +315,7 @@ $test->addTestCase(new Doctrine_Record_ZeroValues_TestCase());
|
||||
$test->addTestCase(new Doctrine_Query_Cache_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Cache_Apc_TestCase());
|
||||
|
||||
/**
|
||||
$test->addTestCase(new Doctrine_Cache_Memcache_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Cache_Sqlite_TestCase());
|
||||
@ -327,11 +327,12 @@ $test->addTestCase(new Doctrine_Template_TestCase());
|
||||
$test->addTestCase(new Doctrine_Import_Builder_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Search_TestCase());
|
||||
*/
|
||||
//$test->addTestCase(new Doctrine_IntegrityAction_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_AuditLog_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
|
||||
//$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
|
||||
|
||||
// Cache tests
|
||||
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
|
||||
|
Loading…
Reference in New Issue
Block a user