From 7ab2e58609fa4d3031dd76a17be9a4edc5bb5bd2 Mon Sep 17 00:00:00 2001 From: meus Date: Mon, 30 Jul 2007 19:01:16 +0000 Subject: [PATCH] added setSubclasses to abstractRecord. Fixed classes in tests. added some more output to the Test.php script --- lib/Doctrine/Record/Abstract.php | 14 ++++++++++++++ tests/Test.php | 15 ++++++++++----- tests/classes.php | 7 ++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/Record/Abstract.php b/lib/Doctrine/Record/Abstract.php index 3638dbbf6..f628f6ce4 100644 --- a/lib/Doctrine/Record/Abstract.php +++ b/lib/Doctrine/Record/Abstract.php @@ -95,6 +95,20 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access { $this->_table->setOption('inheritanceMap', $map); } + + public function setSubclasses($map){ + if(isset($map[get_class($this)])){ + $this->_table->setOption('inheritanceMap', $map[get_class($this)]); + return; + } + $this->_table->setOption('subclasses', array_keys($map)); + $conn = $this->_table->getConnection(); + foreach($map as $key => $value){ + $table = $conn->getTable($key); +// $table->setOption('inheritanceMap', $value); + } + } + /** * attribute * sets or retrieves an option diff --git a/tests/Test.php b/tests/Test.php index 2f732cc5c..586be143f 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -66,7 +66,12 @@ class UnitTestCase if ($value == $value2) { $this->_passed++; } else { - $this->_fail(); + $seperator = "
"; + if(PHP_SAPI === "cli"){ + $seperator = "\n"; + } + $message = "$seperator Value1: $value $seperator != $seperator Value2: $value2 $seperator"; + $this->_fail($message); } } @@ -107,11 +112,11 @@ class UnitTestCase { $this->_passed++; } - public function fail() + public function fail($message = "") { - $this->_fail(); + $this->_fail($message); } - public function _fail() + public function _fail($message = "") { $trace = debug_backtrace(); array_shift($trace); @@ -126,7 +131,7 @@ class UnitTestCase } $errorMessage = $class->getName() . ' : method ' . $stack['function'] . ' failed on line ' . $line; - $this->_messages[] = $errorMessage; + $this->_messages[] = $errorMessage . " " . $message; break; } $line = $stack['line']; diff --git a/tests/classes.php b/tests/classes.php index 4b27c1c22..a502c96a5 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -21,7 +21,8 @@ class Entity extends Doctrine_Record $this->hasColumn('created', 'integer',11); $this->hasColumn('updated', 'integer',11); $this->hasColumn('email_id', 'integer'); - $this->option('subclasses', array('User','Group')); +// $this->option('subclasses', array('User','Group')); + $this->setSubclasses(array("User" => array("type" => 0), "Group" => array("type" => 1))); } } class FieldNameTest extends Doctrine_Record @@ -83,7 +84,7 @@ class Group extends Entity { public function setUp() { parent::setUp(); $this->hasMany('User', 'Groupuser.user_id'); - $this->option('inheritanceMap', array('type' => 1)); +// $this->option('inheritanceMap', array('type' => 1)); } } class Error extends Doctrine_Record { @@ -114,7 +115,7 @@ class User extends Entity $this->ownsMany('Album', 'Album.user_id'); $this->ownsMany('Book', 'Book.user_id'); $this->hasMany('Group', 'Groupuser.group_id'); - $this->option('inheritanceMap', array('type' => 0)); +// $this->option('inheritanceMap', array('type' => 0)); } /** Custom validation */ public function validate()