diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php index 596752f71..3d2442c37 100644 --- a/Doctrine/Collection.php +++ b/Doctrine/Collection.php @@ -234,7 +234,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator if(isset($this->relation)) { if($this->relation instanceof Doctrine_ForeignKey) { - $params = array($this->reference->getID()); + $params[] = $this->reference->getIncremented(); $where[] = $this->reference_field." = ?"; if( ! isset($offset)) { @@ -252,7 +252,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } elseif($this->relation instanceof Doctrine_Association) { $asf = $this->relation->getAssociationFactory(); - $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getID(); + $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); $table = $fk->getTable(); $graph = new Doctrine_DQL_Parser($table->getSession()); @@ -344,6 +344,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator if($value !== null) { $this->data[$key]->rawSet($this->reference_field, $value); } else { + $this->data[$key]->rawSet($this->reference_field, $this->reference); } } @@ -363,7 +364,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator if(is_array($record) && isset($record[$name])) { $list[] = $record[$name]; } else { - $list[] = $record->getID(); + $list[] = $record->getIncremented(); } endforeach; return $list; @@ -407,6 +408,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator if(isset($this->reference_field)) $record->rawSet($this->reference_field,$this->reference); + if(in_array($record,$this->data)) { + return false; + } + if(isset($key)) { if(isset($this->data[$key])) return false; @@ -414,10 +419,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $this->data[$key] = $record; return true; } - - if(in_array($record,$this->data)) { - return false; - } if(isset($this->generator)) { $key = $this->generator->getIndex($record); diff --git a/Doctrine/Collection/Batch.php b/Doctrine/Collection/Batch.php index 58fae729e..a5e88105b 100644 --- a/Doctrine/Collection/Batch.php +++ b/Doctrine/Collection/Batch.php @@ -81,7 +81,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { for($i = $e; $i < $e2 && $i < $this->count(); $i++): if($this->data[$i] instanceof Doctrine_Record) - $id = $this->data[$i]->getID(); + $id = $this->data[$i]->getIncremented(); elseif(is_array($this->data[$i])) $id = $this->data[$i][$identifier]; diff --git a/Doctrine/DB.php b/Doctrine/DB.php index 46809dfd4..c081bbd34 100644 --- a/Doctrine/DB.php +++ b/Doctrine/DB.php @@ -129,12 +129,17 @@ class Doctrine_DBStatement extends PDOStatement { /** * @param array $params */ - public function execute(array $params = null) { - $time = microtime(); - $result = parent::execute($params); + public function execute(array $params = array()) { + $time = microtime(); + try { + $result = parent::execute($params); + } catch(PDOException $e) { + throw new Doctrine_Exception($this->queryString." ".$e->__toString()); + } $exectime = (microtime() - $time); $this->dbh->addExecTime($exectime); + return $result; } } diff --git a/Doctrine/DataDict.php b/Doctrine/DataDict.php index 2085f3f2c..0ded6cf52 100644 --- a/Doctrine/DataDict.php +++ b/Doctrine/DataDict.php @@ -37,10 +37,9 @@ class Doctrine_DataDict { $return = true; foreach($a as $sql) { - try { + try { $this->dbh->query($sql); - } catch(PDOException $e) { - + } catch(Exception $e) { $return = $e; } } @@ -71,7 +70,7 @@ class Doctrine_DataDict { case "mbstring": if($length <= 255) return "C2($length)"; - + return "X2"; case "clob": return "XL"; diff --git a/Doctrine/Locking/Manager/Pessimistic.php b/Doctrine/Locking/Manager/Pessimistic.php index fca920a25..b05079bd5 100644 --- a/Doctrine/Locking/Manager/Pessimistic.php +++ b/Doctrine/Locking/Manager/Pessimistic.php @@ -86,7 +86,9 @@ class Doctrine_Locking_Manager_Pessimistic try { $stmt->execute(); $gotLock = true; - } catch(PDOException $pkviolation) { + + // we catch an Exception here instead of PDOException since we might also be catching Doctrine_Exception + } catch(Exception $pkviolation) { // PK violation occured => existing lock! } @@ -112,9 +114,9 @@ class Doctrine_Locking_Manager_Pessimistic $dbh->commit(); } - catch(PDOException $pdoe) + catch(Exception $pdoe) { - $dbh->rollBack(); + $dbh->rollback(); throw new Doctrine_Locking_Exception($pdoe->getMessage()); } diff --git a/Doctrine/Query.php b/Doctrine/Query.php index 8b3e01df9..013110f36 100644 --- a/Doctrine/Query.php +++ b/Doctrine/Query.php @@ -551,7 +551,7 @@ class Doctrine_Query extends Doctrine_Access { // one-to-one relation - $last->internalSet($fk->getLocal(), $record->getID()); + $last->internalSet($fk->getLocal(), $record->getIncremented()); $last->initSingleReference($record, $fk); diff --git a/Doctrine/Record.php b/Doctrine/Record.php index 69b8db9b4..948c54a80 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -65,9 +65,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ protected $table; /** - * @var integer $id the primary key of this object + * @var integer $id the primary keys of this object */ - protected $id; + protected $id = array(); /** * @var array $data the record data */ @@ -266,7 +266,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite if($exists) { if(isset($this->data[$name]) && $this->data[$name] !== self::$null) - $this->id = $this->data[$name]; + $this->id[$name] = $this->data[$name]; } unset($this->data[$name]); @@ -300,10 +300,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite unset($vars['originals']); unset($vars['table']); - if( ! is_array($this->id)) { - $name = $this->table->getIdentifier(); - $this->data = array_merge($this->data, array($name => $this->id)); - } + + $name = $this->table->getIdentifier(); + $this->data = array_merge($this->data, $this->id); foreach($this->data as $k => $v) { if($v instanceof Doctrine_Record) @@ -441,17 +440,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ final public function factoryRefresh() { $data = $this->table->getData(); - $id = $this->id; - + $old = $this->id; + + $this->cleanData(); + $this->prepareIdentifiers(); - if($this->id != $id) + if($this->id != $old) throw new Doctrine_Record_Exception(); $this->data = $data; - $this->cleanData(); - $this->state = Doctrine_Record::STATE_CLEAN; $this->modified = array(); @@ -521,8 +520,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite return $this->data[$name]; } + if(isset($this->id[$name])) + return $this->id[$name]; + if($name === $this->table->getIdentifier()) - return $this->id; + return null; if( ! isset($this->references[$name])) @@ -549,9 +551,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ final public function rawSet($name,$value) { if($value instanceof Doctrine_Record) - $id = $value->getID(); + $id = $value->getIncremented(); - if( ! empty($id)) + if(isset($id)) $value = $id; if(isset($this->data[$name])) { @@ -585,13 +587,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return void */ public function set($name,$value) { + if(is_array($value)) + throw new Exception($value); + if(isset($this->data[$name])) { if($value instanceof Doctrine_Record) { - $id = $value->getID(); + $id = $value->getIncremented(); - if( ! empty($id)) - $value = $value->getID(); + if($id !== null) + $value = $id; } $old = $this->get($name); @@ -747,9 +752,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite continue; } - if($this->data[$v] instanceof Doctrine_Record) - $this->data[$v] = $this->data[$v]->getID(); - + if($this->data[$v] instanceof Doctrine_Record) { + $this->data[$v] = $this->data[$v]->getIncremented(); + } + $a[$v] = $this->data[$v]; } @@ -811,13 +817,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite foreach($r["delete"] as $record) { $query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?" ." AND ".$fk->getLocal()." = ?"; - $this->table->getSession()->execute($query, array($record->getID(),$this->getID())); + $this->table->getSession()->execute($query, array($record->getIncremented(),$this->getIncremented())); } foreach($r["add"] as $record) { $reldao = $asf->create(); $reldao->set($fk->getForeign(),$record); $reldao->set($fk->getLocal(),$this); $reldao->save(); + } $this->originals[$alias] = clone $this->references[$alias]; } @@ -825,7 +832,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite 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]->getID() != $this->references[$alias]->getID()) @@ -877,9 +884,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $found = false; - if($record->getID() !== null) { + $id = $record->getIncremented(); + if( ! empty($id)) { foreach($this->originals[$name] as $k2 => $record2) { - if($record2->getID() == $record->getID()) { + if($record2->getIncremented() === $record->getIncremented()) { $found = true; break; } @@ -892,12 +900,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite } foreach($this->originals[$name] as $k => $record) { - if($record->getID() === null) + $id = $record->getIncremented(); + + if(empty($id)) continue; $found = false; - foreach($new as $k2=>$record2) { - if($record2->getID() == $record->getID()) { + foreach($new as $k2 => $record2) { + if($record2->getIncremented() === $record->getIncremented()) { $found = true; break; } @@ -944,7 +954,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ final public function setID($id = false) { if($id === false) { - $this->id = false; + $this->id = array(); $this->cleanData(); $this->state = Doctrine_Record::STATE_TCLEAN; $this->modified = array(); @@ -954,18 +964,32 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $this->modified = array(); } else { $name = $this->table->getIdentifier(); - $this->id = $id; + + $this->id[$name] = $id; $this->state = Doctrine_Record::STATE_CLEAN; $this->modified = array(); } } /** - * return the primary key(s) this object is pointing at - * @return mixed id + * returns the primary keys of this object + * + * @return array */ final public function getID() { return $this->id; } + /** + * returns the value of autoincremented primary key of this object (if any) + * + * @return integer + */ + final public function getIncremented() { + $id = current($this->id); + if($id === false) + return null; + + return $id; + } /** * getLast * this method is used internally be Doctrine_Query @@ -1134,7 +1158,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $graph = new Doctrine_Query($table->getSession()); $query = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)"; - $coll = $graph->query($query, array($this->getID())); + $coll = $graph->query($query, array($this->getIncremented())); $this->references[$name] = $coll; $this->originals[$name] = clone $coll; diff --git a/Doctrine/Session.php b/Doctrine/Session.php index 97d47419d..87196edac 100644 --- a/Doctrine/Session.php +++ b/Doctrine/Session.php @@ -446,7 +446,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab $this->transaction_level--; if($this->transaction_level == 0) { - + if($this->getAttribute(Doctrine::ATTR_LOCKMODE) == Doctrine::LOCK_OPTIMISTIC) { $this->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionBegin($this); @@ -477,7 +477,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab } catch(PDOException $e) { $this->rollback(); - throw new Doctrine_Exception($e->getMessage()); + throw new Doctrine_Exception($e->__toString()); } $this->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this); @@ -534,9 +534,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab } foreach($inserts as $k => $record) { - $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record); + $table->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record); // listen the onPreInsert event - $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record); + $table->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record); $this->insert($record); @@ -556,9 +556,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab $record->setID(true); // listen the onInsert event - $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record); + $table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record); - $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); + $table->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); } } $this->insert = array(); @@ -610,11 +610,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); - - $ids[] = $record->getID(); } - if(isset($record)) - $record->getTable()->getCache()->deleteMultiple($ids); } $this->update = array(); } @@ -629,7 +625,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab $record = false; $ids = array(); foreach($deletes as $k => $record) { - $ids[] = $record->getID(); + $ids[] = $record->getIncremented(); $record->setID(false); } if($record instanceof Doctrine_Record) { @@ -745,7 +741,6 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab */ private function update(Doctrine_Record $record) { $array = $record->getPrepared(); - if(empty($array)) return false; @@ -760,8 +755,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab case Doctrine_Record::STATE_TDIRTY: $record->save(); default: - $array[$name] = $value->getID(); - $record->set($name, $value->getID()); + $array[$name] = $value->getIncremented(); + $record->set($name, $value->getIncremented()); endswitch; } endforeach; diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 82c46e558..437097b6c 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -34,6 +34,46 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $this->assertEqual($users->count(), 8); } */ + public function testMultipleFetching() { + $count = $this->dbh->count(); + $this->session->getTable('User')->clear(); + $this->session->getTable('Email')->clear(); + $this->session->getTable('Phonenumber')->clear(); + + $users = $this->query->from("User-l.Phonenumber-i, User-l:Email-i")->execute(); + $this->assertEqual(($count + 1),$this->dbh->count()); + $this->assertEqual(count($users), 8); + + $this->assertEqual($users[0]->Phonenumber->count(), 1); + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($users[0]->Phonenumber[0]->phonenumber, "123 123"); + $this->assertEqual(($count + 1), $this->dbh->count()); + + $this->assertEqual($users[1]->Phonenumber->count(), 3); + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($users[1]->Phonenumber[0]->phonenumber, "123 123"); + $this->assertEqual($users[1]->Phonenumber[1]->phonenumber, "456 456"); + $this->assertEqual($users[1]->Phonenumber[2]->phonenumber, "789 789"); + $this->assertEqual(($count + 1), $this->dbh->count()); + + $this->assertEqual($users[7]->Phonenumber->count(), 1); + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($users[7]->Phonenumber[0]->phonenumber, "111 567 333"); + $this->assertEqual(($count + 1), $this->dbh->count()); + + $this->assertTrue($users[0]->Email instanceof Email); + $this->assertEqual($users[0]->Email->address, "zYne@example.com"); + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($users[0]->email_id, $users[0]->Email->id); + $this->assertEqual(($count + 1), $this->dbh->count()); + + $this->assertTrue($users[1]->Email instanceof Email); + $this->assertEqual($users[1]->Email->address, "arnold@example.com"); + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($users[1]->email_id, $users[1]->Email->id); + $this->assertEqual(($count + 1), $this->dbh->count()); + } + public function testConditionParser() { $query = new Doctrine_Query($this->session); @@ -698,45 +738,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $this->assertEqual($count, count($this->dbh)); } - public function testMultipleFetching() { - $count = $this->dbh->count(); - $this->session->getTable('User')->clear(); - $this->session->getTable('Email')->clear(); - $this->session->getTable('Phonenumber')->clear(); - $users = $this->query->from("User-l.Phonenumber-i, User-l:Email-i")->execute(); - $this->assertEqual(($count + 1),$this->dbh->count()); - $this->assertEqual(count($users), 8); - - $this->assertEqual($users[0]->Phonenumber->count(), 1); - $this->assertEqual(($count + 1), $this->dbh->count()); - $this->assertEqual($users[0]->Phonenumber[0]->phonenumber, "123 123"); - $this->assertEqual(($count + 1), $this->dbh->count()); - - $this->assertEqual($users[1]->Phonenumber->count(), 3); - $this->assertEqual(($count + 1), $this->dbh->count()); - $this->assertEqual($users[1]->Phonenumber[0]->phonenumber, "123 123"); - $this->assertEqual($users[1]->Phonenumber[1]->phonenumber, "456 456"); - $this->assertEqual($users[1]->Phonenumber[2]->phonenumber, "789 789"); - $this->assertEqual(($count + 1), $this->dbh->count()); - - $this->assertEqual($users[7]->Phonenumber->count(), 1); - $this->assertEqual(($count + 1), $this->dbh->count()); - $this->assertEqual($users[7]->Phonenumber[0]->phonenumber, "111 567 333"); - $this->assertEqual(($count + 1), $this->dbh->count()); - - $this->assertTrue($users[0]->Email instanceof Email); - $this->assertEqual($users[0]->Email->address, "zYne@example.com"); - $this->assertEqual(($count + 1), $this->dbh->count()); - $this->assertEqual($users[0]->email_id, $users[0]->Email->id); - $this->assertEqual(($count + 1), $this->dbh->count()); - - $this->assertTrue($users[1]->Email instanceof Email); - $this->assertEqual($users[1]->Email->address, "arnold@example.com"); - $this->assertEqual(($count + 1), $this->dbh->count()); - $this->assertEqual($users[1]->email_id, $users[1]->Email->id); - $this->assertEqual(($count + 1), $this->dbh->count()); - } public function testForeignKeyRelationFetching() { $count = $this->dbh->count(); @@ -870,7 +872,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $board->getTable()->clear(); - $board = $board->getTable()->find($board->getID()); + $board = $board->getTable()->find($board->id); $this->assertEqual($board->Threads->count(), 1); $this->assertEqual($board->name, "Doctrine Forum"); $this->assertEqual($board->Category->name, "General discussion"); @@ -1189,5 +1191,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { //$this->assertTrue(isset($values['max'])); } + } ?> diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index d3193a794..94e127810 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -7,6 +7,12 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { parent::prepareTables(); } + public function testReferences2() { + $user = new User(); + $user->Phonenumber[0]->phonenumber = '123 123'; + $this->assertEqual($user->Phonenumber[0]->entity_id, $user); + } + public function testJoinTableSelfReferencing() { $e = new Entity(); $e->name = "Entity test"; @@ -54,8 +60,9 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertEqual($e->Entity[0]->getState(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($e->Entity[1]->getState(), Doctrine_Record::STATE_CLEAN); + - $e = $e->getTable()->find($e->getID()); + $e = $e->getTable()->find($e->id); $this->assertTrue($e->Entity[0] instanceof Entity); $this->assertTrue($e->Entity[1] instanceof Entity); @@ -256,7 +263,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $account = $user->Account; $this->assertTrue($account instanceof Account); $this->assertEqual($account->getState(), Doctrine_Record::STATE_CLEAN); - $this->assertEqual($account->entity_id, $user->getID()); + $this->assertEqual($account->entity_id, $user->id); $this->assertEqual($account->amount, 1000); $this->assertEqual($user->name, "Richard Linklater"); @@ -272,11 +279,11 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertTrue($account instanceof Account); $this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount")); - $this->assertEqual($account->entity_id, $user->getID()); + $this->assertEqual($account->entity_id, $user->id); $this->assertEqual($account->amount, 2000); - $user = $user->getTable()->find($user->getID()); + $user = $user->getTable()->find($user->id); $this->assertEqual($user->getState(), Doctrine_Record::STATE_CLEAN); @@ -286,7 +293,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertEqual($account->getState(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount")); - $this->assertEqual($account->entity_id, $user->getID()); + $this->assertEqual($account->entity_id, $user->id); $this->assertEqual($account->amount, 2000); $this->assertEqual($user->name, "John Rambo"); @@ -512,22 +519,32 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $coll = new Doctrine_Collection($pf); $user->Phonenumber = $coll; - $this->assertTrue($user->Phonenumber->count() == 0); + $this->assertEqual($user->Phonenumber->count(), 0); $user->save(); - unset($user); + + $user->getTable()->clear(); + $user = $this->objTable->find(5); $this->assertEqual($user->Phonenumber->count(), 0); + $this->assertEqual(get_class($user->Phonenumber), "Doctrine_Collection_Immediate"); + + $user->Phonenumber[0]->phonenumber; + $this->assertEqual($user->Phonenumber->count(), 1); + // ADDING REFERENCES $user->Phonenumber[0]->phonenumber = "123 123"; + $this->assertEqual($user->Phonenumber->count(), 1); $user->Phonenumber[1]->phonenumber = "123 123"; + $this->assertEqual($user->Phonenumber->count(), 2); + $user->save(); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); unset($user); $user = $this->objTable->find(5); @@ -536,30 +553,30 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $user->Phonenumber[3]->phonenumber = "123 123"; $user->save(); - $this->assertTrue($user->Phonenumber->count() == 3); + $this->assertEqual($user->Phonenumber->count(), 3); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 3); + $this->assertEqual($user->Phonenumber->count(), 3); // DELETING REFERENCES $user->Phonenumber->delete(); - $this->assertTrue($user->Phonenumber->count() == 0); + $this->assertEqual($user->Phonenumber->count(), 0); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 0); - + $this->assertEqual($user->Phonenumber->count(), 0); + // ADDING REFERENCES WITH STRING KEYS $user->Phonenumber["home"]->phonenumber = "123 123"; $user->Phonenumber["work"]->phonenumber = "444 444"; $user->save(); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); // REPLACING ONE-TO-MANY REFERENCE unset($coll); @@ -586,15 +603,15 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertTrue($user->Email instanceof Email); $this->assertEqual($user->Email->address, "drinker@drinkmore.info"); - $this->assertEqual($user->Email->getID(), $user->email_id); + $this->assertEqual($user->Email->id, $user->email_id); $user = $this->objTable->find(5); $this->assertTrue($user->Email instanceof Email); - $this->assertEqual($user->Email->getID(), $user->email_id); + $this->assertEqual($user->Email->id, $user->email_id); $this->assertEqual($user->Email->getState(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($user->Email->address, "drinker@drinkmore.info"); - $id = $user->Email->getID(); + $id = $user->Email->id; // REPLACING ONE-TO-ONE REFERENCES @@ -744,5 +761,6 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $user = $this->session->getTable("User")->find(4); $this->assertTrue($user->getIterator() instanceof ArrayIterator); } + } ?> diff --git a/tests/SessionTestCase.php b/tests/SessionTestCase.php index 9d6cb0923..5929470f6 100644 --- a/tests/SessionTestCase.php +++ b/tests/SessionTestCase.php @@ -136,11 +136,11 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase { $this->assertEqual(count($user->Group), 2); $user2 = $user; - $user = $this->objTable->find($user->getID()); + $user = $this->objTable->find($user->id); - $this->assertEqual($user->getID(), $user2->getID()); + $this->assertEqual($user->id, $user2->id); - $this->assertTrue(is_numeric($user->getID())); + $this->assertTrue(is_numeric($user->id)); $this->assertTrue(is_numeric($user->email_id)); $this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id)); @@ -176,7 +176,7 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase { $this->session->flush(); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); unset($user); $user = $this->objTable->find(5); @@ -185,19 +185,19 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase { $user->Phonenumber[3]->phonenumber = "123 123"; $this->session->flush(); - $this->assertTrue($user->Phonenumber->count() == 3); + $this->assertEqual($user->Phonenumber->count(), 3); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 3); + $this->assertEqual($user->Phonenumber->count(), 3); // DELETING REFERENCES $user->Phonenumber->delete(); - $this->assertTrue($user->Phonenumber->count() == 0); + $this->assertEqual($user->Phonenumber->count(), 0); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 0); + $this->assertEqual($user->Phonenumber->count(), 0); // ADDING REFERENCES WITH STRING KEYS @@ -207,10 +207,10 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase { $this->assertEqual($user->Phonenumber->count(), 2); $this->session->flush(); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); unset($user); $user = $this->objTable->find(5); - $this->assertTrue($user->Phonenumber->count() == 2); + $this->assertEqual($user->Phonenumber->count(), 2); // REPLACING ONE-TO-MANY REFERENCE @@ -238,7 +238,7 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase { $this->assertTrue($user->Email instanceof Email); $user = $this->objTable->find(5); $this->assertEqual($user->Email->address, "drinker@drinkmore.info"); - $id = $user->Email->getID(); + $id = $user->Email->id; // REPLACING ONE-TO-ONE REFERENCES