From 0835a57ce14e9da1d31ac2984b5e03d012890b7e Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 25 Oct 2006 20:02:40 +0000 Subject: [PATCH] Fixes #192, added Doctrine_Record_State_TestCase Ticket: 192 --- lib/Doctrine/Record.php | 12 +++++- lib/Doctrine/Table.php | 23 ++++++---- manual/documentation.php | 16 ++++--- tests/ImportTestCase.php | 3 +- tests/RecordStateTestCase.php | 80 +++++++++++++++++++++++++++++++++++ tests/RecordTestCase.php | 2 +- tests/RelationTestCase.php | 9 ++-- tests/run.php | 11 +++-- 8 files changed, 131 insertions(+), 25 deletions(-) create mode 100644 tests/RecordStateTestCase.php diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 122b27a28..e25fa42f1 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -512,9 +512,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite if($state == null) { return $this->_state; } + $err = false; if(is_integer($state)) { + if($state >= 1 && $state <= 6) $this->_state = $state; + else + $err = true; + } elseif(is_string($state)) { $upper = strtoupper($state); switch($upper) { @@ -526,10 +531,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite case 'DELETED': $this->_state = constant('Doctrine_Record::STATE_' . $upper); break; + default: + $err = true; } - } + } - throw new Doctrine_Record_State_Exception('Unknown record state ' . $state); + if($err) + throw new Doctrine_Record_State_Exception('Unknown record state ' . $state); } /** * refresh diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 487b5b50c..fad4652c8 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -177,7 +177,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $names = array_reverse($names); // create database table - if(method_exists($record,"setTableDefinition")) { + if(method_exists($record, 'setTableDefinition')) { $record->setTableDefinition(); $this->columnCount = count($this->columns); @@ -185,7 +185,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { if(isset($this->columns)) { // get the declaring class of setTableDefinition method - $method = new ReflectionMethod($this->options['name'],"setTableDefinition"); + $method = new ReflectionMethod($this->options['name'], 'setTableDefinition'); $class = $method->getDeclaringClass(); if( ! isset($this->options['tableName'])) @@ -193,9 +193,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { switch(count($this->primaryKeys)): case 0: - $this->columns = array_merge(array("id" => array("integer", 20, array("autoincrement" => true, "primary" => true))), $this->columns); - $this->primaryKeys[] = "id"; - $this->identifier = "id"; + $this->columns = array_merge(array('id' => + array('integer', + 20, + array('autoincrement' => true, + 'primary' => true + ) + ) + ), $this->columns); + + $this->primaryKeys[] = 'id'; + $this->identifier = 'id'; $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; $this->columnCount++; break; @@ -964,9 +972,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { */ final public function enumValue($field, $index) { if ($index instanceof Doctrine_Null) - { - return $index; - } + return $index; + return isset($this->options['enumMap'][$field][$index]) ? $this->options['enumMap'][$field][$index] : $index; } /** diff --git a/manual/documentation.php b/manual/documentation.php index 0e2bce560..dc125bf62 100644 --- a/manual/documentation.php +++ b/manual/documentation.php @@ -343,10 +343,16 @@ $menu = array("Getting started" => "Transactions" => array( "Introduction", "Unit of work", + "Nesting", + "Savepoints", "Locking strategies" => array("Pessimistic locking", "Optimistic locking"), - "Nesting" + + "Lock modes", + "Isolation levels", + "Deadlocks", + ), /** "Developer components" => array( @@ -466,12 +472,12 @@ $menu = array("Getting started" => if( ! file_exists("docs/$title - $k - $v2.php")) { $missing[0]++; $str .= " [ doc ] "; - touch("docs/$title - $k - $v2.php"); + //touch("docs/$title - $k - $v2.php"); } if( ! file_exists("codes/$title - $k - $v2.php")) { $missing[1]++; $str .= " [ code ] "; - touch("codes/$title - $k - $v2.php"); + //touch("codes/$title - $k - $v2.php"); } @@ -486,12 +492,12 @@ $menu = array("Getting started" => if( ! file_exists("docs/$title - $t.php")) { $missing[0]++; $str .= " [ doc ] "; - touch("docs/$title - $t.php"); + //touch("docs/$title - $t.php"); } if( ! file_exists("codes/$title - $t.php")) { $missing[1]++; $str .= " [ code ] "; - touch("codes/$title - $t.php"); + //touch("codes/$title - $t.php"); } print "
".$e." ".$t."$str
\n"; } diff --git a/tests/ImportTestCase.php b/tests/ImportTestCase.php index 2db505a4a..5b5575fa4 100644 --- a/tests/ImportTestCase.php +++ b/tests/ImportTestCase.php @@ -90,6 +90,7 @@ class Doctrine_Import_TestCase extends Doctrine_UnitTestCase { unlink('tmp' . DIRECTORY_SEPARATOR . 'ImportTest.php'); } public function testForeignKeySupport() { + /** $this->dbh->query('CREATE TABLE album ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title VARCHAR(100), @@ -109,7 +110,7 @@ class Doctrine_Import_TestCase extends Doctrine_UnitTestCase { $sql = "PRAGMA table_info(track)"; $sql = "PRAGMA foreign_key_list(track)"; $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); - + */ } diff --git a/tests/RecordStateTestCase.php b/tests/RecordStateTestCase.php new file mode 100644 index 000000000..70cc0e508 --- /dev/null +++ b/tests/RecordStateTestCase.php @@ -0,0 +1,80 @@ +state(123123); + $this->fail(); + } catch(Doctrine_Record_State_Exception $e) { + $this->pass(); + } + $this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN); + try { + $user->state('some unknown state'); + $this->fail(); + } catch(Doctrine_Record_State_Exception $e) { + $this->pass(); + } + $this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN); + } + + public function testAssignDirtyState() { + $user = new User(); + + $user->state(Doctrine_Record::STATE_DIRTY); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_DIRTY); + + $user->state('dirty'); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_DIRTY); + } + public function testAssignCleanState() { + $user = new User(); + + $user->state(Doctrine_Record::STATE_CLEAN); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN); + + $user->state('clean'); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN); + } + public function testAssignTransientCleanState() { + $user = new User(); + + $user->state(Doctrine_Record::STATE_TCLEAN); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN); + + $user->state('tclean'); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_TCLEAN); + } + public function testAssignTransientDirtyState() { + $user = new User(); + + $user->state(Doctrine_Record::STATE_TDIRTY); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_TDIRTY); + + $user->state('tdirty'); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_TDIRTY); + } + public function testAssignProxyState() { + $user = new User(); + + $user->state(Doctrine_Record::STATE_PROXY); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY); + + $user->state('proxy'); + + $this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY); + } +} +?> diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index 60e3c3fe6..4ac33e4d2 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -1,7 +1,7 @@ tables[] = "enumTest"; diff --git a/tests/RelationTestCase.php b/tests/RelationTestCase.php index 30d9446b3..ee6a67be4 100644 --- a/tests/RelationTestCase.php +++ b/tests/RelationTestCase.php @@ -3,11 +3,12 @@ class RelationTest extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('name', 'string', 200); - $this->hasColumn("child_id", "integer"); + $this->hasColumn('child_id', 'integer'); } public function setUp() { $this->ownsMany('OwnsOneToManyWithAlias as AliasO2M', 'AliasO2M.component_id'); - $this->hasMany('HasManyToManyWithAlias as AliasM2M', 'JoinTable.c1_id'); + $this->hasMany('M2M as AliasM2M', 'JoinTable.c1_id'); + // $this->hasMany('M2M as AliasM2M2', 'JoinTable.c1_id'); } } class RelationTestChild extends RelationTest { @@ -41,7 +42,7 @@ class OwnsOneToManyWithAlias extends Doctrine_Record { } } -class HasManyToManyWithAlias extends Doctrine_Record { +class M2M extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('name', 'string', 200); } @@ -52,7 +53,7 @@ class HasManyToManyWithAlias extends Doctrine_Record { class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase { public function prepareData() { } public function prepareTables() { - $this->tables = array('HasManyToManyWithAlias', 'RelationTest', 'JoinTable'); + $this->tables = array('M2M', 'RelationTest', 'JoinTable'); parent::prepareTables(); } diff --git a/tests/run.php b/tests/run.php index 7fa877bd8..e4e4404ca 100644 --- a/tests/run.php +++ b/tests/run.php @@ -12,6 +12,7 @@ require_once("BatchIteratorTestCase.php"); require_once("CacheFileTestCase.php"); require_once("RecordTestCase.php"); +require_once("RecordStateTestCase.php"); require_once("RecordFilterTestCase.php"); require_once("AccessTestCase.php"); @@ -57,14 +58,16 @@ print "
";
 $test = new GroupTest("Doctrine Framework Unit Tests");
 
 
+$test->addTestCase(new Doctrine_Relation_TestCase());
+
+$test->addTestCase(new Doctrine_Record_TestCase());
+
+$test->addTestCase(new Doctrine_Record_State_TestCase());
+
 $test->addTestCase(new Doctrine_Import_TestCase());
 
 $test->addTestCase(new Doctrine_SchemaTestCase());
 
-$test->addTestCase(new Doctrine_Relation_TestCase());
-
-$test->addTestCase(new Doctrine_RecordTestCase());
-
 $test->addTestCase(new Doctrine_ValidatorTestCase());
 
 $test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());