From d1ed73c6d96423cfa1f6be9d577ee5b6c4b1d5f5 Mon Sep 17 00:00:00 2001 From: doctrine Date: Tue, 6 Jun 2006 20:37:56 +0000 Subject: [PATCH] Doctrine_Table::find now returns false if record is not found (instead of throwing InvalidKeyException) --- Doctrine/Access.php | 9 +++-- Doctrine/Cache/Sqlite.php | 6 ++-- Doctrine/Null.php | 3 ++ Doctrine/Record.php | 12 ++++--- Doctrine/Record/Iterator.php | 2 +- Doctrine/Table.php | 4 +-- ...sTestCase.class.php => AccessTestCase.php} | 0 ...se.class.php => BatchIteratorTestCase.php} | 3 +- ...stCase.class.php => CacheFileTestCase.php} | 3 +- ...Case.class.php => CacheSqliteTestCase.php} | 3 +- ...class.php => CollectionOffsetTestCase.php} | 0 ...tCase.class.php => CollectionTestCase.php} | 0 ...ss.php => CompositePrimaryKeyTestCase.php} | 0 ...ase.class.php => ConfigurableTestCase.php} | 2 +- ...se.class.php => EventListenerTestCase.php} | 2 +- ...Case.class.php => FormBuilderTestCase.php} | 0 ...tCase.class.php => IdentifierTestCase.php} | 0 ...TestCase.class.php => ManagerTestCase.php} | 2 +- ...ryTestCase.class.php => QueryTestCase.php} | 10 ++++-- ...dTestCase.class.php => RecordTestCase.php} | 2 +- ...tCase.class.php => RepositoryTestCase.php} | 0 ...iTestCase.class.php => SenseiTestCase.php} | 0 ...TestCase.class.php => SessionTestCase.php} | 2 +- ...leTestCase.class.php => TableTestCase.php} | 2 +- ...nitTestCase.class.php => UnitTestCase.php} | 0 ...stCase.class.php => ValidatorTestCase.php} | 0 tests/run.php | 33 +++++++++---------- 27 files changed, 56 insertions(+), 44 deletions(-) rename tests/{AccessTestCase.class.php => AccessTestCase.php} (100%) rename tests/{BatchIteratorTestCase.class.php => BatchIteratorTestCase.php} (94%) rename tests/{CacheFileTestCase.class.php => CacheFileTestCase.php} (95%) rename tests/{CacheSqliteTestCase.class.php => CacheSqliteTestCase.php} (96%) rename tests/{CollectionOffsetTestCase.class.php => CollectionOffsetTestCase.php} (100%) rename tests/{CollectionTestCase.class.php => CollectionTestCase.php} (100%) rename tests/{CompositePrimaryKeyTestCase.class.php => CompositePrimaryKeyTestCase.php} (100%) rename tests/{ConfigurableTestCase.class.php => ConfigurableTestCase.php} (96%) rename tests/{EventListenerTestCase.class.php => EventListenerTestCase.php} (90%) rename tests/{FormBuilderTestCase.class.php => FormBuilderTestCase.php} (100%) rename tests/{IdentifierTestCase.class.php => IdentifierTestCase.php} (100%) rename tests/{ManagerTestCase.class.php => ManagerTestCase.php} (93%) rename tests/{QueryTestCase.class.php => QueryTestCase.php} (97%) rename tests/{RecordTestCase.class.php => RecordTestCase.php} (97%) rename tests/{RepositoryTestCase.class.php => RepositoryTestCase.php} (100%) rename tests/{SenseiTestCase.class.php => SenseiTestCase.php} (100%) rename tests/{SessionTestCase.class.php => SessionTestCase.php} (97%) rename tests/{TableTestCase.class.php => TableTestCase.php} (96%) rename tests/{UnitTestCase.class.php => UnitTestCase.php} (100%) rename tests/{ValidatorTestCase.class.php => ValidatorTestCase.php} (100%) diff --git a/Doctrine/Access.php b/Doctrine/Access.php index bf59f423c..080fd0c98 100644 --- a/Doctrine/Access.php +++ b/Doctrine/Access.php @@ -13,11 +13,14 @@ abstract class Doctrine_Access implements ArrayAccess { /** * setArray * @param array $array an array of key => value pairs + * @return Doctrine_Access */ public function setArray(array $array) { foreach($array as $k=>$v): $this->set($k,$v); endforeach; + + return $this; } /** * __set -- an alias of set() @@ -72,11 +75,7 @@ abstract class Doctrine_Access implements ArrayAccess { * @param mixed $offset */ public function offsetUnset($offset) { - if($this instanceof Doctrine_Collection) { - return $this->remove($offset); - } else { - $this->set($offset,null); - } + return $this->remove($offset); } } ?> diff --git a/Doctrine/Cache/Sqlite.php b/Doctrine/Cache/Sqlite.php index 2d8028dd4..44ebc26bc 100644 --- a/Doctrine/Cache/Sqlite.php +++ b/Doctrine/Cache/Sqlite.php @@ -21,15 +21,15 @@ class Doctrine_Cache_Sqlite { */ const DELETE = "DELETE FROM %s WHERE id %s"; /** - * @var Doctrine_Table $table + * @var Doctrine_Table $table the table object this cache container belongs to */ private $table; /** - * @var PDO $dbh + * @var PDO $dbh database handler */ private $dbh; /** - * @var array $fetched an array of fetched primary keys + * @var array $fetched an array of fetched primary keys */ private $fetched = array(); diff --git a/Doctrine/Null.php b/Doctrine/Null.php index 4c4012af7..f0093fbbe 100644 --- a/Doctrine/Null.php +++ b/Doctrine/Null.php @@ -1,6 +1,9 @@ diff --git a/Doctrine/Record.php b/Doctrine/Record.php index b24287637..910bfa998 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -1042,12 +1042,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $this->references[$name] = $table->create(); $this->set($fk->getLocal(),$this->references[$name]); } else { - try { - $this->references[$name] = $table->find($id); - } catch(Doctrine_Find_Exception $e) { + + $record = $table->find($id); + + if($record !== false) + $this->references[$name] = $record; + else $this->references[$name] = $table->create(); + //$this->set($fk->getLocal(),$this->references[$name]); - } + } } elseif ($fk instanceof Doctrine_ForeignKey) { diff --git a/Doctrine/Record/Iterator.php b/Doctrine/Record/Iterator.php index f0ff507a7..415f40c36 100644 --- a/Doctrine/Record/Iterator.php +++ b/Doctrine/Record/Iterator.php @@ -33,7 +33,7 @@ class Doctrine_Record_Iterator extends ArrayIterator { public function current() { $value = parent::current(); - if($value == self::$null) + if($value === self::$null) return null; else return $value; diff --git a/Doctrine/Table.php b/Doctrine/Table.php index 7ee1be612..4b9253afc 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -648,7 +648,7 @@ class Doctrine_Table extends Doctrine_Configurable { $this->data = $stmt->fetch(PDO::FETCH_ASSOC); if($this->data === false) - throw new Doctrine_Find_Exception(); + return false; } return $this->getRecord(); } @@ -827,7 +827,7 @@ class Doctrine_Table extends Doctrine_Configurable { */ public function getTypeOf($column) { if(isset($this->columns[$column])) - return $this->columns[$column][0]; + return $this->columns[$column][0]; } /** * setData diff --git a/tests/AccessTestCase.class.php b/tests/AccessTestCase.php similarity index 100% rename from tests/AccessTestCase.class.php rename to tests/AccessTestCase.php diff --git a/tests/BatchIteratorTestCase.class.php b/tests/BatchIteratorTestCase.php similarity index 94% rename from tests/BatchIteratorTestCase.class.php rename to tests/BatchIteratorTestCase.php index ddbd93367..0cd7d734f 100644 --- a/tests/BatchIteratorTestCase.class.php +++ b/tests/BatchIteratorTestCase.php @@ -1,5 +1,6 @@ session); diff --git a/tests/CacheFileTestCase.class.php b/tests/CacheFileTestCase.php similarity index 95% rename from tests/CacheFileTestCase.class.php rename to tests/CacheFileTestCase.php index 452ad6ad9..64ab875ed 100644 --- a/tests/CacheFileTestCase.class.php +++ b/tests/CacheFileTestCase.php @@ -1,5 +1,6 @@ assertTrue(Doctrine_Manager::getInstance() instanceOf Doctrine_Manager); diff --git a/tests/QueryTestCase.class.php b/tests/QueryTestCase.php similarity index 97% rename from tests/QueryTestCase.class.php rename to tests/QueryTestCase.php index 304d60c99..4ec5808cd 100644 --- a/tests/QueryTestCase.class.php +++ b/tests/QueryTestCase.php @@ -56,17 +56,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $entries[0]->Log_Status->delete(); $this->assertEqual($entries[0]->Log_Status, $entries[1]->Log_Status); $this->assertEqual($entries[0]->Log_Status->getState(), Doctrine_Record::STATE_TCLEAN); - + // clear the identity maps $entries[0]->Log_Status->getTable()->clear(); $entries[0]->getTable()->clear(); - + $entries = $this->session->query("FROM Log_Entry-I.Log_Status-i"); $this->assertEqual($entries->count(), 2); + + $this->assertTrue($entries[0]->Log_Status instanceof Log_Status); + $this->assertEqual($entries[0]->Log_Status->name, null); $this->assertEqual($entries[1]->Log_Status->name, null); + } + public function testOneToOneRelationFetchingWithCustomTableNames() { $entry = new ORM_TestEntry(); $entry->name = 'entry 1'; @@ -687,5 +692,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { //$this->assertTrue(isset($values['max'])); } + } ?> diff --git a/tests/RecordTestCase.class.php b/tests/RecordTestCase.php similarity index 97% rename from tests/RecordTestCase.class.php rename to tests/RecordTestCase.php index 588e6f9a4..43bcbc01e 100644 --- a/tests/RecordTestCase.class.php +++ b/tests/RecordTestCase.php @@ -1,5 +1,5 @@ session->getTable("User"); diff --git a/tests/UnitTestCase.class.php b/tests/UnitTestCase.php similarity index 100% rename from tests/UnitTestCase.class.php rename to tests/UnitTestCase.php diff --git a/tests/ValidatorTestCase.class.php b/tests/ValidatorTestCase.php similarity index 100% rename from tests/ValidatorTestCase.class.php rename to tests/ValidatorTestCase.php diff --git a/tests/run.php b/tests/run.php index ec2611adb..91a8333cc 100644 --- a/tests/run.php +++ b/tests/run.php @@ -1,30 +1,27 @@ addTestCase(new Sensei_UnitTestCase()); - - $test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_SessionTestCase());