1
0
mirror of synced 2024-12-13 06:46:03 +03:00

small refactorings

This commit is contained in:
romanb 2008-02-16 19:37:51 +00:00
parent be5aac16fd
commit e354e527d5
11 changed files with 36 additions and 39 deletions

View File

@ -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 $name The name of the column to map. Syntax: columnName [as propertyName].
* @param string $type * The property name is optional. If not used the column will be
* @param integer $length * 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 mixed $options
* @param boolean $prepend Whether to prepend or append the new column to the column list. * @param boolean $prepend Whether to prepend or append the new column to the column list.
* By default the column gets appended. * By default the column gets appended.
*
* @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter. * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter.
*/ */
public function mapColumn($name, $type, $length = null, $options = array(), $prepend = false) public function mapColumn($name, $type, $length = null, $options = array(), $prepend = false)
{ {
if (is_string($options)) {
$options = explode('|', $options);
}
foreach ($options as $k => $option) { foreach ($options as $k => $option) {
if (is_numeric($k)) { if (is_numeric($k)) {
if ( ! empty($option)) { if ( ! empty($option) && $option !== false) {
$options[$option] = true; $options[$option] = true;
} }
unset($options[$k]); unset($options[$k]);
@ -598,7 +597,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/** /**
* hasDefaultValues * hasDefaultValues
* returns true if this table has default values, otherwise false * returns true if this class has default values, otherwise false
* *
* @return boolean * @return boolean
*/ */
@ -609,7 +608,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/** /**
* getDefaultValueOf * getDefaultValueOf
* returns the default value(if any) for given column * returns the default value(if any) for given field
* *
* @param string $fieldName * @param string $fieldName
* @return mixed * @return mixed

View File

@ -20,8 +20,7 @@
*/ */
/** /**
* Doctrine * Testcase for basic accessor/mutator functionality.
* the base class of Doctrine framework
* *
* @package Doctrine * @package Doctrine
* @author Bjarte Stien Karlsen <doctrine@bjartek.org> * @author Bjarte Stien Karlsen <doctrine@bjartek.org>
@ -32,6 +31,8 @@
*/ */
require_once 'lib/DoctrineTestInit.php'; require_once 'lib/DoctrineTestInit.php';
class AccessStub extends Doctrine_Access {}
class Orm_Component_AccessTest extends Doctrine_OrmTestCase class Orm_Component_AccessTest extends Doctrine_OrmTestCase
{ {
@ -66,7 +67,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
*/ */
public function shouldSetSingleValueInRecord() public function shouldSetSingleValueInRecord()
{ {
$this->user->username ='meus'; $this->user->username = 'meus';
$this->assertEquals('meus', $this->user->username); $this->assertEquals('meus', $this->user->username);
$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() 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() 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( $this->user->setArray(array(
'rat' => 'meus', 'rat' => 'meus',
'id' => 22)); 'id' => 22));
} }
@ -139,7 +140,6 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
$col = new Doctrine_Collection('ForumUser'); $col = new Doctrine_Collection('ForumUser');
$this->assertEquals(0, count($col)); $this->assertEquals(0, count($col));
$this->assertFalse(isset($coll[0])); $this->assertFalse(isset($coll[0]));
$this->assertFalse(isset($coll[0]));
} }
/** /**
@ -218,5 +218,3 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
$stub['foo']; $stub['foo'];
} }
} }
class AccessStub extends Doctrine_Access {}

View File

@ -21,9 +21,9 @@ class Orm_Component_AllTests
{ {
$suite = new Doctrine_TestSuite('Doctrine Orm Component'); $suite = new Doctrine_TestSuite('Doctrine Orm Component');
// $suite->addTestSuite('Orm_Component_TestTest'); //$suite->addTestSuite('Orm_Component_TestTest');
$suite->addTestSuite('Orm_Component_AccessTest'); $suite->addTestSuite('Orm_Component_AccessTest');
$suite->addTestSuite('Orm_Component_CollectionTest'); $suite->addTestSuite('Orm_Component_CollectionTest');
return $suite; return $suite;
} }

View File

@ -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:{}}}'; $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); $coll = unserialize($serializedFormCollection);
$this->assertEquals(Doctrine_Collection, get_class($coll)); $this->assertEquals('Doctrine_Collection', get_class($coll));
} }
/** /**

View File

@ -1,7 +1,7 @@
<?php <?php
class CustomPK extends Doctrine_Record { class CustomPK extends Doctrine_Record {
public static function initMetadata($class) { public static function initMetadata($class) {
$class->setColumn('uid', 'integer',11, 'autoincrement|primary'); $class->setColumn('uid', 'integer',11, array('autoincrement' => true, 'primary' => true));
$class->setColumn('name', 'string',255); $class->setColumn('name', 'string',255);
} }
} }

View File

@ -1,9 +1,9 @@
<?php <?php
class Email extends Doctrine_Record class Email extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setColumn('address', 'string', 150, 'email|unique'); $class->setColumn('address', 'string', 150, array('email', 'unique' => true));
} }

View File

@ -3,8 +3,8 @@ class EntityReference extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setColumn('entity1', 'integer', null, 'primary'); $class->setColumn('entity1', 'integer', null, array('primary' => true));
$class->setColumn('entity2', 'integer', null, 'primary'); $class->setColumn('entity2', 'integer', null, array('primary' => true));
} }
} }

View File

@ -3,7 +3,7 @@ class Error extends Doctrine_Record {
public static function initMetadata($class) { public static function initMetadata($class) {
$class->setColumn('message', 'string',200); $class->setColumn('message', 'string',200);
$class->setColumn('code', 'integer',11); $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')); $class->hasMany('Description', array('local' => 'file_md5', 'foreign' => 'file_md5'));
} }
} }

View File

@ -3,8 +3,8 @@ class MysqlTestRecord extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setColumn('name', 'string', null, 'primary'); $class->setColumn('name', 'string', null, array('primary' => true));
$class->setColumn('code', 'integer', null, 'primary'); $class->setColumn('code', 'integer', null, array('primary' => true));
$class->setTableOption('type', 'INNODB'); $class->setTableOption('type', 'INNODB');
} }

View File

@ -3,7 +3,7 @@ class NestReference extends Doctrine_Record
{ {
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->setColumn('parent_id', 'integer', 4, 'primary'); $class->setColumn('parent_id', 'integer', 4, array('primary' => true));
$class->setColumn('child_id', 'integer', 4, 'primary'); $class->setColumn('child_id', 'integer', 4, array('primary' => true));
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
class NotNullTest extends Doctrine_Record { class NotNullTest extends Doctrine_Record {
public static function initMetadata($class) { public static function initMetadata($class) {
$class->setColumn('name', 'string', 100, 'notnull'); $class->setColumn('name', 'string', 100, array('notnull' => true));
$class->setColumn('type', 'integer', 11); $class->setColumn('type', 'integer', 11);
} }
} }