Commit 7b52c80c authored by zYne's avatar zYne

Refactored Doctrine_Connection: separated into two different classes...

Refactored Doctrine_Connection: separated into two different classes Doctrine_Connection and Doctrine_Transaction
parent 8edafac8
...@@ -511,7 +511,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -511,7 +511,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) { if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
} else } else
...@@ -544,7 +544,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -544,7 +544,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) { if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
} else } else
...@@ -579,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -579,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record; $this->data[$value] = $record;
unset($this->data[$k]); unset($this->data[$k]);
...@@ -591,6 +591,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -591,6 +591,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* loadRelated * loadRelated
* *
* @param mixed $name * @param mixed $name
* @return boolean
*/ */
public function loadRelated($name = null) { public function loadRelated($name = null) {
$query = new Doctrine_Query($this->table->getConnection()); $query = new Doctrine_Query($this->table->getConnection());
......
...@@ -87,12 +87,12 @@ abstract class Doctrine_Configurable { ...@@ -87,12 +87,12 @@ abstract class Doctrine_Configurable {
break; break;
case Doctrine::ATTR_LOCKMODE: case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) { if($this instanceof Doctrine_Connection) {
if($this->getState() != Doctrine_Connection::STATE_OPEN) if($this->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) { } elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) { foreach($this as $connection) {
if($connection->getState() != Doctrine_Connection::STATE_OPEN) if($connection->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} }
} else { } else {
......
...@@ -28,62 +28,18 @@ ...@@ -28,62 +28,18 @@
*/ */
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate { abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate {
/** /**
* Doctrine_Connection is in open state when it is opened and there are no active transactions * @var $dbh the database handler
*/
const STATE_OPEN = 0;
/**
* Doctrine_Connection is in closed state when it is closed
*/
const STATE_CLOSED = 1;
/**
* Doctrine_Connection is in active state when it has one active transaction
*/
const STATE_ACTIVE = 2;
/**
* Doctrine_Connection is in busy state when it has multiple active transactions
*/
const STATE_BUSY = 3;
/**
* @var $dbh the database handle
*/ */
private $dbh; private $dbh;
/** /**
* @see Doctrine_Connection::STATE_* constants * @var Doctrine_Transaction $tx the transaction object
* @var boolean $state the current state of the connection
*/
private $state = 0;
/**
* @var integer $transaction_level the nesting level of transactions, used by transaction methods
*/ */
private $transaction_level = 0; private $tx;
/** /**
* @var array $tables an array containing all the initialized Doctrine_Table objects * @var array $tables an array containing all the initialized Doctrine_Table objects
* keys representing Doctrine_Table component names and values as Doctrine_Table objects * keys representing Doctrine_Table component names and values as Doctrine_Table objects
*/ */
protected $tables = array(); protected $tables = array();
/**
* @var Doctrine_Validator $validator transaction validator
*/
protected $validator;
/**
* @var array $update two dimensional pending update list, the records in
* this list will be updated when transaction is committed
*/
protected $update = array();
/**
* @var array $insert two dimensional pending insert list, the records in
* this list will be inserted when transaction is committed
*/
protected $insert = array();
/**
* @var array $delete two dimensional pending delete list, the records in
* this list will be deleted when transaction is committed
*/
protected $delete = array();
/** /**
* the constructor * the constructor
* *
...@@ -92,7 +48,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -92,7 +48,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
public function __construct(Doctrine_Manager $manager,PDO $pdo) { public function __construct(Doctrine_Manager $manager,PDO $pdo) {
$this->dbh = $pdo; $this->dbh = $pdo;
$this->state = Doctrine_Connection::STATE_OPEN;
$this->tx = new Doctrine_Transaction($this);
$this->setParent($manager); $this->setParent($manager);
...@@ -102,13 +59,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -102,13 +59,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this); $this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
} }
/** /**
* returns the state of this connection * getTransaction
*
* returns the current transaction object
* *
* @see Doctrine_Connection::STATE_* constants * @return Doctrine_Transaction
* @return integer the connection state
*/ */
public function getState() { public function getTransaction() {
return $this->state; return $this->tx;
} }
/** /**
* returns the manager that created this connection * returns the manager that created this connection
...@@ -439,7 +397,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -439,7 +397,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return integer * @return integer
*/ */
public function getTransactionLevel() { public function getTransactionLevel() {
return $this->transaction_level; return $this->tx->getTransactionLevel();
} }
/** /**
* beginTransaction * beginTransaction
...@@ -447,18 +405,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -447,18 +405,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return void * @return void
*/ */
public function beginTransaction() { public function beginTransaction() {
if($this->transaction_level == 0) { $this->tx->beginTransaction();
if($this->getAttribute(Doctrine::ATTR_LOCKMODE) == Doctrine::LOCK_PESSIMISTIC) {
$this->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionBegin($this);
$this->dbh->beginTransaction();
$this->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionBegin($this);
}
$this->state = Doctrine_Connection::STATE_ACTIVE;
} else {
$this->state = Doctrine_Connection::STATE_BUSY;
}
$this->transaction_level++;
} }
/** /**
* commits the current transaction * commits the current transaction
...@@ -468,53 +415,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -468,53 +415,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return void * @return void
*/ */
public function commit() { public function commit() {
$this->tx->commit();
$this->transaction_level--;
if($this->transaction_level == 0) {
if($this->getAttribute(Doctrine::ATTR_LOCKMODE) == Doctrine::LOCK_OPTIMISTIC) {
$this->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionBegin($this);
$this->dbh->beginTransaction();
$this->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionBegin($this);
}
if($this->getAttribute(Doctrine::ATTR_VLD))
$this->validator = new Doctrine_Validator();
try {
$this->bulkInsert();
$this->bulkUpdate();
$this->bulkDelete();
if($this->getAttribute(Doctrine::ATTR_VLD)) {
if($this->validator->hasErrors()) {
$this->rollback();
throw new Doctrine_Validator_Exception($this->validator);
}
}
$this->dbh->commit();
} catch(PDOException $e) {
$this->rollback();
throw new Doctrine_Exception($e->__toString());
}
$this->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this);
$this->delete = array();
$this->state = Doctrine_Connection::STATE_OPEN;
$this->validator = null;
} elseif($this->transaction_level == 1)
$this->state = Doctrine_Connection::STATE_ACTIVE;
} }
/** /**
* rollback * rollback
...@@ -526,69 +427,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -526,69 +427,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return void * @return void
*/ */
public function rollback() { public function rollback() {
$this->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionRollback($this); $this->tx->rollback();
$this->transaction_level = 0;
$this->dbh->rollback();
$this->state = Doctrine_Connection::STATE_OPEN;
$this->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionRollback($this);
}
/**
* bulkInsert
* inserts all the objects in the pending insert list into database
* @return void
*/
public function bulkInsert() {
if(empty($this->insert))
return false;
foreach($this->insert as $name => $inserts) {
if( ! isset($inserts[0]))
continue;
$record = $inserts[0];
$table = $record->getTable();
$seq = $table->getSequenceName();
$increment = false;
$keys = $table->getPrimaryKeys();
$id = null;
if(count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
$increment = true;
}
foreach($inserts as $k => $record) {
$table->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
// listen the onPreInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record);
$this->insert($record);
if($increment) {
if($k == 0) {
// record uses auto_increment column
$id = $this->dbh->lastInsertID();
if( ! $id)
$id = $table->getMaxIdentifier();
}
$record->assignIdentifier($id);
$id++;
} else
$record->assignIdentifier(true);
// listen the onInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);
$table->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
}
$this->insert = array();
return true;
} }
/** /**
* returns maximum identifier values * returns maximum identifier values
...@@ -616,56 +455,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -616,56 +455,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
return $values; return $values;
} }
/**
* bulkUpdate
* updates all objects in the pending update list
*
* @return void
*/
public function bulkUpdate() {
foreach($this->update as $name => $updates) {
$ids = array();
foreach($updates as $k => $record) {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
// listen the onPreUpdate event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record);
$this->update($record);
// listen the onUpdate event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record);
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
}
$this->update = array();
}
/**
* bulkDelete
* deletes all records from the pending delete list
*
* @return void
*/
public function bulkDelete() {
foreach($this->delete as $name => $deletes) {
$record = false;
$ids = array();
foreach($deletes as $k => $record) {
$ids[] = $record->getIncremented();
$record->assignIdentifier(false);
}
if($record instanceof Doctrine_Record) {
$table = $record->getTable();
$params = substr(str_repeat("?, ",count($ids)),0,-2);
$query = "DELETE FROM ".$record->getTable()->getTableName()." WHERE ".$table->getIdentifier()." IN(".$params.")";
$this->execute($query,$ids);
$record->getTable()->getCache()->deleteMultiple($ids);
}
}
$this->delete = array();
}
/** /**
* saves a collection * saves a collection
* *
...@@ -703,11 +492,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -703,11 +492,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function save(Doctrine_Record $record) { public function save(Doctrine_Record $record) {
switch($record->getState()): switch($record->getState()):
case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TDIRTY:
$this->addInsert($record); $this->tx->addInsert($record);
break; break;
case Doctrine_Record::STATE_DIRTY: case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY: case Doctrine_Record::STATE_PROXY:
$this->addUpdate($record); $this->tx->addUpdate($record);
break; break;
case Doctrine_Record::STATE_CLEAN: case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_TCLEAN:
...@@ -760,111 +549,97 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -760,111 +549,97 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $saveLater; return $saveLater;
} }
/** /**
* updates the given record * deletes all related composites
* this method is always called internally when a record is deleted
* *
* @param Doctrine_Record $record * @return void
* @return boolean
*/ */
private function update(Doctrine_Record $record) { final public function deleteComposites(Doctrine_Record $record) {
$array = $record->getPrepared(); foreach($record->getTable()->getRelations() as $fk) {
switch($fk->getType()):
if(empty($array)) case Doctrine_Relation::ONE_COMPOSITE:
return false; case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($record->getTable()->getAlias($fk->getTable()->getComponentName()));
$set = array(); $obj->delete();
foreach($array as $name => $value): break;
$set[] = $name." = ?";
if($value instanceof Doctrine_Record) {
switch($value->getState()):
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save();
default:
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
endswitch; endswitch;
} }
endforeach;
if(isset($this->validator)) {
if( ! $this->validator->validateRecord($record)) {
return false;
} }
} /**
* saveAssociations
$params = array_values($array); * save the associations of many-to-many relations
$id = $record->obtainIdentifier(); * this method also deletes associations that do not exist anymore
* @return void
*/
if( ! is_array($id)) final public function saveAssociations(Doctrine_Record $record) {
$id = array($id); foreach($record->getTable()->table->getRelations() as $rel):
$table = $rel->getTable();
$id = array_values($id); $name = $table->getComponentName();
$params = array_merge($params, $id); $alias = $this->table->getAlias($name);
$sql = "UPDATE ".$record->getTable()->getTableName()." SET ".implode(", ",$set)." WHERE ".implode(" = ? AND ",$record->getTable()->getPrimaryKeys())." = ?"; if($rel instanceof Doctrine_Association) {
switch($rel->getType()):
case Doctrine_Relation::MANY_COMPOSITE:
break;
case Doctrine_Relation::MANY_AGGREGATE:
$asf = $rel->getAssociationFactory();
$stmt = $this->dbh->prepare($sql); if($record->hasReference($alias)) {
$stmt->execute($params);
$record->assignIdentifier(true); $new = $record->getReference($alias);
return true; if( ! $this->hasOriginalsFor($alias)) {
$record->loadReference($alias);
} }
/**
* inserts a record into database
*
* @param Doctrine_Record $record
* @return boolean
*/
private function insert(Doctrine_Record $record) {
$array = $record->getPrepared();
if(empty($array)) $r = Doctrine_Relation::getDeleteOperations($this->originals[$alias],$new);
return false;
$seq = $record->getTable()->getSequenceName();
if( ! empty($seq)) { foreach($r as $record) {
$id = $this->getNextID($seq); $query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?"
$name = $record->getTable()->getIdentifier(); ." AND ".$fk->getLocal()." = ?";
$array[$name] = $id; $this->table->getConnection()->execute($query, array($record->getIncremented(),$this->getIncremented()));
} }
if(isset($this->validator)) { $r = Doctrine_Relation::getInsertOperations($this->originals[$alias],$new);
if( ! $this->validator->validateRecord($record)) { foreach($r as $record) {
return false; $reldao = $asf->create();
$reldao->set($fk->getForeign(),$record);
$reldao->set($fk->getLocal(),$this);
$reldao->save();
} }
$this->originals[$alias] = clone $this->references[$alias];
} }
break;
endswitch;
} elseif($fk instanceof Doctrine_ForeignKey ||
$fk instanceof Doctrine_LocalKey) {
switch($fk->getType()):
case Doctrine_Relation::ONE_COMPOSITE:
if(isset($this->originals[$alias]) && $this->originals[$alias]->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
$this->originals[$alias]->delete();
$strfields = join(", ", array_keys($array)); break;
$strvalues = substr(str_repeat("?, ",count($array)),0,-2); case Doctrine_Relation::MANY_COMPOSITE:
$sql = "INSERT INTO ".$record->getTable()->getTableName()." (".$strfields.") VALUES (".$strvalues.")"; if(isset($this->references[$alias])) {
$new = $this->references[$alias];
$stmt = $this->dbh->prepare($sql); if( ! isset($this->originals[$alias]))
$this->loadReference($alias);
$stmt->execute(array_values($array)); $r = Doctrine_Relation::getDeleteOperations($this->originals[$alias], $new);
return true; foreach($r as $record) {
$record->delete();
}
$this->originals[$alias] = clone $this->references[$alias];
} }
/**
* deletes all related composites
* this method is always called internally when a record is deleted
*
* @return void
*/
final public function deleteComposites(Doctrine_Record $record) {
foreach($record->getTable()->getRelations() as $fk) {
switch($fk->getType()):
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($record->getTable()->getAlias($fk->getTable()->getComponentName()));
$obj->delete();
break; break;
endswitch; endswitch;
} }
endforeach;
} }
/** /**
* deletes this data access object and all the related composites * deletes this data access object and all the related composites
...@@ -882,7 +657,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -882,7 +657,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->beginTransaction(); $this->beginTransaction();
$this->deleteComposites($record); $this->deleteComposites($record);
$this->addDelete($record); $this->tx->addDelete($record);
$this->commit(); $this->commit();
return true; return true;
...@@ -891,55 +666,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -891,55 +666,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return false; return false;
endswitch; endswitch;
} }
/**
* adds record into pending insert list
* @param Doctrine_Record $record
*/
public function addInsert(Doctrine_Record $record) {
$name = $record->getTable()->getComponentName();
$this->insert[$name][] = $record;
}
/**
* adds record into penging update list
* @param Doctrine_Record $record
*/
public function addUpdate(Doctrine_Record $record) {
$name = $record->getTable()->getComponentName();
$this->update[$name][] = $record;
}
/**
* adds record into pending delete list
* @param Doctrine_Record $record
*/
public function addDelete(Doctrine_Record $record) {
$name = $record->getTable()->getComponentName();
$this->delete[$name][] = $record;
}
/**
* returns the pending insert list
*
* @return array
*/
public function getInserts() {
return $this->insert;
}
/**
* returns the pending update list
*
* @return array
*/
public function getUpdates() {
return $this->update;
}
/**
* returns the pending delete list
*
* @return array
*/
public function getDeletes() {
return $this->delete;
}
/** /**
* returns a string representation of this object * returns a string representation of this object
* @return string * @return string
......
...@@ -73,16 +73,16 @@ class Doctrine_Lib { ...@@ -73,16 +73,16 @@ class Doctrine_Lib {
*/ */
public static function getConnectionStateAsString($state) { public static function getConnectionStateAsString($state) {
switch($state): switch($state):
case Doctrine_Connection::STATE_OPEN: case Doctrine_Transaction::STATE_OPEN:
return "open"; return "open";
break; break;
case Doctrine_Connection::STATE_CLOSED: case Doctrine_Transaction::STATE_CLOSED:
return "closed"; return "closed";
break; break;
case Doctrine_Connection::STATE_BUSY: case Doctrine_Transaction::STATE_BUSY:
return "busy"; return "busy";
break; break;
case Doctrine_Connection::STATE_ACTIVE: case Doctrine_Transaction::STATE_ACTIVE:
return "active"; return "active";
break; break;
endswitch; endswitch;
......
...@@ -1112,6 +1112,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1112,6 +1112,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function hasReference($name) { public function hasReference($name) {
return isset($this->references[$name]); return isset($this->references[$name]);
} }
/**
* obtainReference
*
* @param string $name
*/
public function obtainReference($name) {
if(isset($this->references[$name]))
return $this->references[$name];
throw new Doctrine_Record_Exception("Unknown reference $name");
}
/** /**
* initalizes a one-to-one relation * initalizes a one-to-one relation
* *
......
...@@ -313,8 +313,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -313,8 +313,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->connection->getIterator() instanceof ArrayIterator); $this->assertTrue($this->connection->getIterator() instanceof ArrayIterator);
} }
public function testGetState() { public function testGetState() {
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getState()), "open"); $this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getTransaction()->getState()), "open");
} }
public function testGetTables() { public function testGetTables() {
$this->assertTrue(is_array($this->connection->getTables())); $this->assertTrue(is_array($this->connection->getTables()));
...@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testTransactions() { public function testTransactions() {
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->commit(); $this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->connection->beginTransaction(); $this->connection->beginTransaction();
...@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testRollback() { public function testRollback() {
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1); $this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->rollback(); $this->connection->rollback();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0); $this->assertEqual($this->connection->getTransactionLevel(),0);
} }
public function testNestedTransactions() { public function testNestedTransactions() {
$this->assertEqual($this->connection->getTransactionLevel(),0); $this->assertEqual($this->connection->getTransactionLevel(),0);
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1); $this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_BUSY); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_BUSY);
$this->assertEqual($this->connection->getTransactionLevel(),2); $this->assertEqual($this->connection->getTransactionLevel(),2);
$this->connection->commit(); $this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransactionLevel(),1); $this->assertEqual($this->connection->getTransactionLevel(),1);
$this->connection->commit(); $this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN); $this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0); $this->assertEqual($this->connection->getTransactionLevel(),0);
} }
} }
......
...@@ -30,7 +30,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -30,7 +30,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->connection->clear(); $this->connection->clear();
} }
/**
public function testBracktExplode() { public function testBracktExplode() {
$str = "item OR item || item"; $str = "item OR item || item";
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")"); $parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")");
...@@ -1274,6 +1274,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -1274,6 +1274,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max'])); //$this->assertTrue(isset($values['max']));
} }
*/
} }
?> ?>
...@@ -4,6 +4,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { ...@@ -4,6 +4,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "ValidatorTest"; $this->tables[] = "ValidatorTest";
parent::prepareTables(); parent::prepareTables();
} }
public function testIsValidType() { public function testIsValidType() {
$var = "123"; $var = "123";
$this->assertTrue(Doctrine_Validator::isValidType($var,"string")); $this->assertTrue(Doctrine_Validator::isValidType($var,"string"));
...@@ -144,6 +145,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { ...@@ -144,6 +145,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
} }
public function testSave() { public function testSave() {
$this->manager->setAttribute(Doctrine::ATTR_VLD, true); $this->manager->setAttribute(Doctrine::ATTR_VLD, true);
$user = $this->connection->getTable("User")->find(4); $user = $this->connection->getTable("User")->find(4);
......
...@@ -32,7 +32,12 @@ require_once("ImportTestCase.php"); ...@@ -32,7 +32,12 @@ require_once("ImportTestCase.php");
error_reporting(E_ALL); error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_AccessTestCase()); $test->addTestCase(new Doctrine_AccessTestCase());
...@@ -41,14 +46,14 @@ $test->addTestCase(new Doctrine_EventListenerTestCase()); ...@@ -41,14 +46,14 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_TableTestCase()); $test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_Collection_OffsetTestCase()); $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); $test->addTestCase(new Doctrine_PessimisticLockingTestCase());
...@@ -71,12 +76,10 @@ $test->addTestCase(new Doctrine_SchemaTestCase()); ...@@ -71,12 +76,10 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase()); $test->addTestCase(new Doctrine_ImportTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
*/
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
......
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