From e354e527d5b054724aadd4cd99207ac190949f44 Mon Sep 17 00:00:00 2001 From: romanb Date: Sat, 16 Feb 2008 19:37:51 +0000 Subject: [PATCH] small refactorings --- lib/Doctrine/ClassMetadata.php | 25 ++++++++++++------------- tests/Orm/Component/AccessTest.php | 16 +++++++--------- tests/Orm/Component/AllTests.php | 6 +++--- tests/Orm/Component/CollectionTest.php | 2 +- tests_old/models/CustomPK.php | 2 +- tests_old/models/Email.php | 6 +++--- tests_old/models/EntityReference.php | 4 ++-- tests_old/models/Error.php | 2 +- tests_old/models/MysqlTestRecord.php | 4 ++-- tests_old/models/NestReference.php | 4 ++-- tests_old/models/NotNullTest.php | 4 ++-- 11 files changed, 36 insertions(+), 39 deletions(-) diff --git a/lib/Doctrine/ClassMetadata.php b/lib/Doctrine/ClassMetadata.php index e013e9996..f543af5b8 100644 --- a/lib/Doctrine/ClassMetadata.php +++ b/lib/Doctrine/ClassMetadata.php @@ -480,25 +480,24 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab } /** - * addMappedColumn + * Maps a column of the class' database table to a property of the entity. * - * @param string $name - * @param string $type - * @param integer $length + * @param string $name The name of the column to map. Syntax: columnName [as propertyName]. + * The property name is optional. If not used the column will be + * mapped to a property with the same name. + * @param string $type The type of the column. + * @param integer $length The length of the column. * @param mixed $options - * @param boolean $prepend Whether to prepend or append the new column to the column list. - * By default the column gets appended. + * @param boolean $prepend Whether to prepend or append the new column to the column list. + * By default the column gets appended. + * * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter. */ public function mapColumn($name, $type, $length = null, $options = array(), $prepend = false) { - if (is_string($options)) { - $options = explode('|', $options); - } - foreach ($options as $k => $option) { if (is_numeric($k)) { - if ( ! empty($option)) { + if ( ! empty($option) && $option !== false) { $options[$option] = true; } unset($options[$k]); @@ -598,7 +597,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab /** * hasDefaultValues - * returns true if this table has default values, otherwise false + * returns true if this class has default values, otherwise false * * @return boolean */ @@ -609,7 +608,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab /** * getDefaultValueOf - * returns the default value(if any) for given column + * returns the default value(if any) for given field * * @param string $fieldName * @return mixed diff --git a/tests/Orm/Component/AccessTest.php b/tests/Orm/Component/AccessTest.php index da01e18c8..7a431d6d5 100644 --- a/tests/Orm/Component/AccessTest.php +++ b/tests/Orm/Component/AccessTest.php @@ -20,8 +20,7 @@ */ /** - * Doctrine - * the base class of Doctrine framework + * Testcase for basic accessor/mutator functionality. * * @package Doctrine * @author Bjarte Stien Karlsen @@ -32,6 +31,8 @@ */ require_once 'lib/DoctrineTestInit.php'; +class AccessStub extends Doctrine_Access {} + class Orm_Component_AccessTest extends Doctrine_OrmTestCase { @@ -66,7 +67,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase */ public function shouldSetSingleValueInRecord() { - $this->user->username ='meus'; + $this->user->username = 'meus'; $this->assertEquals('meus', $this->user->username); $this->assertEquals('meus', $this->user['username']); } @@ -106,7 +107,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase */ public function shouldNotBeAbleToSetNonExistantField() { - $this->user->rat ='meus'; + $this->user->rat = 'meus'; } /** @@ -115,7 +116,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase */ public function shouldNotBeAbleToSetNonExistantFieldWithOffset() { - $this->user['rat'] ='meus'; + $this->user['rat'] = 'meus'; } /** @@ -126,7 +127,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase { $this->user->setArray(array( 'rat' => 'meus', - 'id' => 22)); + 'id' => 22)); } @@ -139,7 +140,6 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase $col = new Doctrine_Collection('ForumUser'); $this->assertEquals(0, count($col)); $this->assertFalse(isset($coll[0])); - $this->assertFalse(isset($coll[0])); } /** @@ -218,5 +218,3 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase $stub['foo']; } } - -class AccessStub extends Doctrine_Access {} diff --git a/tests/Orm/Component/AllTests.php b/tests/Orm/Component/AllTests.php index 49a898ce3..a8ef3b86d 100644 --- a/tests/Orm/Component/AllTests.php +++ b/tests/Orm/Component/AllTests.php @@ -21,9 +21,9 @@ class Orm_Component_AllTests { $suite = new Doctrine_TestSuite('Doctrine Orm Component'); -// $suite->addTestSuite('Orm_Component_TestTest'); - $suite->addTestSuite('Orm_Component_AccessTest'); - $suite->addTestSuite('Orm_Component_CollectionTest'); + //$suite->addTestSuite('Orm_Component_TestTest'); + $suite->addTestSuite('Orm_Component_AccessTest'); + $suite->addTestSuite('Orm_Component_CollectionTest'); return $suite; } diff --git a/tests/Orm/Component/CollectionTest.php b/tests/Orm/Component/CollectionTest.php index 154ce571b..416fd0277 100644 --- a/tests/Orm/Component/CollectionTest.php +++ b/tests/Orm/Component/CollectionTest.php @@ -98,7 +98,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase { $serializedFormCollection='C:19:"Doctrine_Collection":158:{a:7:{s:4:"data";a:0:{}s:7:"_mapper";s:9:"ForumUser";s:9:"_snapshot";a:0:{}s:14:"referenceField";N;s:9:"keyColumn";N;s:8:"_locator";N;s:10:"_resources";a:0:{}}}'; $coll = unserialize($serializedFormCollection); - $this->assertEquals(Doctrine_Collection, get_class($coll)); + $this->assertEquals('Doctrine_Collection', get_class($coll)); } /** diff --git a/tests_old/models/CustomPK.php b/tests_old/models/CustomPK.php index fc91d3a88..bb1c39865 100644 --- a/tests_old/models/CustomPK.php +++ b/tests_old/models/CustomPK.php @@ -1,7 +1,7 @@ setColumn('uid', 'integer',11, 'autoincrement|primary'); + $class->setColumn('uid', 'integer',11, array('autoincrement' => true, 'primary' => true)); $class->setColumn('name', 'string',255); } } diff --git a/tests_old/models/Email.php b/tests_old/models/Email.php index 92a6f5db9..2ff644c49 100644 --- a/tests_old/models/Email.php +++ b/tests_old/models/Email.php @@ -1,9 +1,9 @@ setColumn('address', 'string', 150, 'email|unique'); + $class->setColumn('address', 'string', 150, array('email', 'unique' => true)); } diff --git a/tests_old/models/EntityReference.php b/tests_old/models/EntityReference.php index 4bfcca2dd..b7be1fea4 100644 --- a/tests_old/models/EntityReference.php +++ b/tests_old/models/EntityReference.php @@ -3,8 +3,8 @@ class EntityReference extends Doctrine_Record { public static function initMetadata($class) { - $class->setColumn('entity1', 'integer', null, 'primary'); - $class->setColumn('entity2', 'integer', null, 'primary'); + $class->setColumn('entity1', 'integer', null, array('primary' => true)); + $class->setColumn('entity2', 'integer', null, array('primary' => true)); } } diff --git a/tests_old/models/Error.php b/tests_old/models/Error.php index 556d91d78..1edf191a8 100644 --- a/tests_old/models/Error.php +++ b/tests_old/models/Error.php @@ -3,7 +3,7 @@ class Error extends Doctrine_Record { public static function initMetadata($class) { $class->setColumn('message', 'string',200); $class->setColumn('code', 'integer',11); - $class->setColumn('file_md5', 'string',32, 'primary'); + $class->setColumn('file_md5', 'string',32, array('primary' => true)); $class->hasMany('Description', array('local' => 'file_md5', 'foreign' => 'file_md5')); } } diff --git a/tests_old/models/MysqlTestRecord.php b/tests_old/models/MysqlTestRecord.php index 3b4d094cc..d7629098a 100644 --- a/tests_old/models/MysqlTestRecord.php +++ b/tests_old/models/MysqlTestRecord.php @@ -3,8 +3,8 @@ class MysqlTestRecord extends Doctrine_Record { public static function initMetadata($class) { - $class->setColumn('name', 'string', null, 'primary'); - $class->setColumn('code', 'integer', null, 'primary'); + $class->setColumn('name', 'string', null, array('primary' => true)); + $class->setColumn('code', 'integer', null, array('primary' => true)); $class->setTableOption('type', 'INNODB'); } diff --git a/tests_old/models/NestReference.php b/tests_old/models/NestReference.php index d05aace07..aae25cc32 100644 --- a/tests_old/models/NestReference.php +++ b/tests_old/models/NestReference.php @@ -3,7 +3,7 @@ class NestReference extends Doctrine_Record { public static function initMetadata($class) { - $class->setColumn('parent_id', 'integer', 4, 'primary'); - $class->setColumn('child_id', 'integer', 4, 'primary'); + $class->setColumn('parent_id', 'integer', 4, array('primary' => true)); + $class->setColumn('child_id', 'integer', 4, array('primary' => true)); } } diff --git a/tests_old/models/NotNullTest.php b/tests_old/models/NotNullTest.php index 733f128e0..feb3b471f 100644 --- a/tests_old/models/NotNullTest.php +++ b/tests_old/models/NotNullTest.php @@ -1,7 +1,7 @@ setColumn('name', 'string', 100, 'notnull'); - $class->setColumn('type', 'integer', 11); + $class->setColumn('name', 'string', 100, array('notnull' => true)); + $class->setColumn('type', 'integer', 11); } }