Commit 613d08f9 authored by romanb's avatar romanb

Merged dbal bugfixes from 0.11.

parent 7ffd4140
...@@ -272,14 +272,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -272,14 +272,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* *
* @param string $entityName Name of the entity class the metadata info is used for. * @param string $entityName Name of the entity class the metadata info is used for.
*/ */
public function __construct($entityName, Doctrine_Connection $conn) public function __construct($entityName, Doctrine_EntityManager $em)
{ {
$this->_entityName = $entityName; $this->_entityName = $entityName;
$this->_rootEntityName = $entityName; $this->_rootEntityName = $entityName;
$this->_conn = $conn; $this->_conn = $em;
$this->_parser = new Doctrine_Relation_Parser($this); $this->_parser = new Doctrine_Relation_Parser($this);
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->setConfigurableParent($this->_conn);
} }
/** /**
...@@ -289,6 +287,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -289,6 +287,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{ {
return $this->_conn; return $this->_conn;
} }
public function getEntityManager()
{
return $this->_conn;
}
/** /**
* getComponentName * getComponentName
...@@ -598,7 +601,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -598,7 +601,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this->_columnCount++; $this->_columnCount++;
} }
/**
* Gets the default length for a field type.
*
* @param unknown_type $type
* @return unknown
*/
private function _getDefaultLength($type) private function _getDefaultLength($type)
{ {
switch ($type) { switch ($type) {
...@@ -625,6 +634,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -625,6 +634,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return 25; return 25;
} }
} }
/**
* Maps an embedded value object.
*
* @todo Implementation.
*/
public function mapEmbeddedValue()
{
//...
}
/** /**
* setColumn * setColumn
...@@ -956,11 +975,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -956,11 +975,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->getColumnDefinition($columnName); return $this->getColumnDefinition($columnName);
} }
/**
* Gets the mapping information for a field.
*
* @param string $fieldName
* @return array
*/
public function getMappingForField($fieldName) public function getMappingForField($fieldName)
{ {
$columnName = $this->getColumnName($fieldName); $columnName = $this->getColumnName($fieldName);
return $this->getColumnDefinition($columnName); return $this->getColumnDefinition($columnName);
} }
...@@ -974,7 +998,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -974,7 +998,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{ {
return $this->getTypeOfColumn($this->getColumnName($fieldName)); return $this->getTypeOfColumn($this->getColumnName($fieldName));
} }
/**
* Gets the type of a field.
*
* @param string $fieldName
* @return string
*/
public function getTypeOfField($fieldName) public function getTypeOfField($fieldName)
{ {
return $this->getTypeOfColumn($this->getColumnName($fieldName)); return $this->getTypeOfColumn($this->getColumnName($fieldName));
...@@ -1022,7 +1052,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1022,7 +1052,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function addNamedQuery($name, $query) public function addNamedQuery($name, $query)
{ {
//...
} }
public function bindRelation($args, $type) public function bindRelation($args, $type)
...@@ -1622,7 +1652,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -1622,7 +1652,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function setTableName($tableName) public function setTableName($tableName)
{ {
$this->setTableOption('tableName', $this->_conn->formatter->getTableName($tableName)); $this->setTableOption('tableName', $this->_conn->getConnection()
->formatter->getTableName($tableName));
} }
/** /**
......
...@@ -44,9 +44,9 @@ class Doctrine_ClassMetadata_Factory ...@@ -44,9 +44,9 @@ class Doctrine_ClassMetadata_Factory
* @param $conn The connection to use. * @param $conn The connection to use.
* @param $driver The metadata driver to use. * @param $driver The metadata driver to use.
*/ */
public function __construct(Doctrine_Connection $conn, $driver) public function __construct(Doctrine_EntityManager $em, $driver)
{ {
$this->_conn = $conn; $this->_conn = $em;
$this->_driver = $driver; $this->_driver = $driver;
} }
......
...@@ -31,9 +31,12 @@ ...@@ -31,9 +31,12 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Rename to EntityCollection
*/ */
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
{ {
protected $_entityBaseType;
/** /**
* An array containing the records of this collection. * An array containing the records of this collection.
* *
...@@ -101,10 +104,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -101,10 +104,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $keyColumn The field name that will be used as the key * @param string $keyColumn The field name that will be used as the key
* in the collection. * in the collection.
*/ */
public function __construct($mapper, $keyField = null) public function __construct($entityBaseType, $keyField = null)
{ {
if (is_string($mapper)) { if (is_string($entityBaseType)) {
$mapper = Doctrine_Manager::getInstance()->getMapper($mapper); $this->_entityBaseType = $entityBaseType;
$mapper = Doctrine_EntityManager::getManager($entityBaseType)->getEntityPersister($entityBaseType);
} }
$this->_mapper = $mapper; $this->_mapper = $mapper;
...@@ -204,16 +208,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -204,16 +208,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
public function unserialize($serialized) public function unserialize($serialized)
{ {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_EntityManager::getManager();
$connection = $manager->getCurrentConnection(); $connection = $manager->getConnection();
$array = unserialize($serialized); $array = unserialize($serialized);
foreach ($array as $name => $values) { foreach ($array as $name => $values) {
$this->$name = $values; $this->$name = $values;
} }
$this->_mapper = $connection->getMapper($this->_mapper); $this->_mapper = $manager->getEntityPersister($this->_entityBaseType);
$keyColumn = isset($array['keyField']) ? $array['keyField'] : null; $keyColumn = isset($array['keyField']) ? $array['keyField'] : null;
if ($keyColumn === null) { if ($keyColumn === null) {
...@@ -506,6 +510,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -506,6 +510,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
public function add($record, $key = null) public function add($record, $key = null)
{ {
/** @TODO Use raw getters/setters */
if ( ! $record instanceof Doctrine_Entity) { if ( ! $record instanceof Doctrine_Entity) {
throw new Doctrine_Record_Exception('Value variable in set is not an instance of Doctrine_Entity.'); throw new Doctrine_Record_Exception('Value variable in set is not an instance of Doctrine_Entity.');
} }
......
This diff is collapsed.
...@@ -55,8 +55,8 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection ...@@ -55,8 +55,8 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection
$col = explode('select', $select); $col = explode('select', $select);
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' . $sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' . 'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset . $select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . $offset .
'AND ' . ($offset + $limit - 1); 'AND ' . ($offset + $limit - 1);
return $sql; return $sql;
} }
......
...@@ -44,7 +44,7 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common ...@@ -44,7 +44,7 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler * @param PDO|Doctrine_Adapter $adapter database handler
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) public function __construct()
{ {
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
Doctrine::autoload('Doctrine_Connection');
/** /**
* Doctrine_Connection_Oracle * Doctrine_Connection_Oracle
* *
...@@ -80,39 +80,59 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection ...@@ -80,39 +80,59 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"'); $this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
} }
/** /**
* Adds an driver-specific LIMIT clause to the query * Adds an driver-specific LIMIT clause to the query
* *
* @param string $query query to modify * @param string $query query to modify
* @param integer $limit limit the number of rows * @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset * @param integer $offset start reading from given offset
* @return string the modified query * @return string the modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{ {
/** return $this->_createLimitSubquery($query, $limit, $offset);
$e = explode("select ",strtolower($query)); }
$e2 = explode(" from ",$e[1]);
$fields = $e2[0]; private function _createLimitSubquery($query, $limit, $offset, $column = null)
*/ {
$limit = (int) $limit; $limit = (int) $limit;
$offset = (int) $offset; $offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) { if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) { if ( ! preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual"; $query .= " FROM dual";
} }
if ($limit > 0) { if ($limit > 0) {
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database $max = $offset + $limit;
$max = $offset + $limit; $column = $column === null ? '*' : $column;
if ($offset > 0) { if ($offset > 0) {
$min = $offset + 1; $min = $offset + 1;
$query = 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' . $query $query = 'SELECT b.'.$column.' FROM ('.
. ') a WHERE ROWNUM <= ' . $max . ') WHERE dctrn_rownum >= ' . $min; 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
} else { . $query . ') a '.
$query = 'SELECT a.* FROM (' . $query .') a WHERE ROWNUM <= ' . $max; ') b '.
} 'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} } else {
} $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
return $query; }
}
}
return $query;
}
/**
* Creates the SQL for Oracle that can be used in the subquery for the limit-subquery
* algorithm.
*/
public function modifyLimitSubquery(Doctrine_ClassMetadata $rootClass, $query, $limit = false,
$offset = false, $isManip = false)
{
// NOTE: no composite key support
$columnNames = $rootClass->getIdentifierColumnNames();
if (count($columnNames) > 1) {
throw new Doctrine_Connection_Exception("Composite keys in LIMIT queries are "
. "currently not supported.");
}
$column = $columnNames[0];
return $this->_createLimitSubquery($query, $limit, $offset, $column);
} }
} }
\ No newline at end of file
...@@ -25,18 +25,21 @@ ...@@ -25,18 +25,21 @@
* *
* Some terminology: * Some terminology:
* *
* <b>New entity</b>: From the point of view of the unitOfWork is an entity that * <b>New entity</b>: A new entity is an entity that already has an identity but
* already has an identity but is not yet persisted into the database. This * is not yet persisted into the database. This is usually the case for all
* is usually the case for all newly saved entities that use a SEQUENCE id * newly saved entities that use a SEQUENCE id generator. Entities with an
* generator. Entities with an IDENTITY id generator get persisted as soon * IDENTITY id generator get persisted as soon as they're saved in order to
* as they're saved in order to obtain the identifier. Therefore entities that * obtain the identifier. Therefore entities that use an IDENTITY id generator
* use an IDENTITY id generator never appear in the list of new entities of the UoW. * never appear in the list of new entities of the UoW.
* *
* <b>Dirty entity</b>: ... * <b>Dirty entity</b>: A dirty entity is a managed entity whose values have
* been altered.
* *
* <b>Removed entity</b>: ... * <b>Removed entity</b>: A removed entity is a managed entity that is scheduled
* for deletion from the database.
* *
* <b>Clean entity</b>: ... * <b>Clean entity</b>: A clean entity is a managed entity that has been fetched
* from the database and whose values have not yet been altered.
* *
* @package Doctrine * @package Doctrine
* @subpackage Connection * @subpackage Connection
...@@ -226,7 +229,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -226,7 +229,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$index = max(array_keys($tree)); $index = max(array_keys($tree));
} }
$rels = $mapper->getTable()->getRelations(); $rels = $mapper->getClassMetadata()->getRelations();
// group relations // group relations
...@@ -355,7 +358,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -355,7 +358,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/** /**
* @param integer $oid object identifier * @param integer $oid object identifier
* @return boolean whether ot not the operation was successful * @return boolean whether ot not the operation was successful
* @deprecated * @deprecated The new implementation of detach() should remove the entity
* from the identity map.
*/ */
public function detach(Doctrine_Entity $entity) public function detach(Doctrine_Entity $entity)
{ {
...@@ -371,6 +375,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -371,6 +375,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* Detaches all currently managed entities. * Detaches all currently managed entities.
* *
* @return integer The number of detached entities. * @return integer The number of detached entities.
* @todo Deprecated. The new implementation should remove all entities from
* the identity map.
*/ */
public function detachAll() public function detachAll()
{ {
...@@ -401,11 +407,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -401,11 +407,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return true; return true;
} }
/**
* Enter description here...
*
* @param unknown_type $entityName
* @todo unify with detachAll()
*/
public function clearIdentitiesForEntity($entityName) public function clearIdentitiesForEntity($entityName)
{ {
$this->_identityMap[$entityName] = array(); $this->_identityMap[$entityName] = array();
} }
/**
* Removes an entity from the identity map.
*
* @param Doctrine_Entity $entity
* @return unknown
* @todo This will be the new detach().
*/
public function unregisterIdentity(Doctrine_Entity $entity) public function unregisterIdentity(Doctrine_Entity $entity)
{ {
$idHash = $this->getIdentifierHash($entity->identifier()); $idHash = $this->getIdentifierHash($entity->identifier());
...@@ -422,6 +441,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -422,6 +441,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false; return false;
} }
/**
* Finds an entity in the identity map by its identifier hash.
*
* @param unknown_type $idHash
* @param unknown_type $rootClassName
* @return unknown
*/
public function getByIdHash($idHash, $rootClassName) public function getByIdHash($idHash, $rootClassName)
{ {
return $this->_identityMap[$rootClassName][$idHash]; return $this->_identityMap[$rootClassName][$idHash];
...@@ -435,6 +461,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -435,6 +461,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false; return false;
} }
/**
* Gets the identifier hash for a set of identifier values.
*
* @param array $id
* @return string
*/
public function getIdentifierHash(array $id) public function getIdentifierHash(array $id)
{ {
return implode(' ', $id); return implode(' ', $id);
...@@ -448,15 +480,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -448,15 +480,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/ */
public function contains(Doctrine_Entity $entity) public function contains(Doctrine_Entity $entity)
{ {
$id = implode(' ', $entity->identifier()); $idHash = $this->getIdentifierHash($entity->identifier());
if ( ! $id) { if ( ! $idHash) {
return false; return false;
} }
return isset($this->_identityMap[ return isset($this->_identityMap
$entity->getClassMetadata()->getRootClassName() [$entity->getClassMetadata()->getRootClassName()]
][$id]); [$idHash]);
} }
/**
* Checks whether an identifier hash exists in the identity map.
*
* @param string $idHash
* @param string $rootClassName
* @return boolean
*/
public function containsIdHash($idHash, $rootClassName) public function containsIdHash($idHash, $rootClassName)
{ {
return isset($this->_identityMap[$rootClassName][$idHash]); return isset($this->_identityMap[$rootClassName][$idHash]);
......
This diff is collapsed.
...@@ -23,6 +23,11 @@ class Doctrine_Entity_Exception extends Doctrine_Exception ...@@ -23,6 +23,11 @@ class Doctrine_Entity_Exception extends Doctrine_Exception
return new self("Invalid value. The value of a reference in a ManyToMany " return new self("Invalid value. The value of a reference in a ManyToMany "
. "association must be a Collection."); . "association must be a Collection.");
} }
public static function invalidField($field)
{
return new self("Invalid field: '$field'.");
}
} }
?> ?>
\ No newline at end of file
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
class Doctrine_EntityRepository class Doctrine_EntityRepository
{ {
protected $_entityName; protected $_entityName;
protected $_conn; protected $_em;
protected $_classMetadata; protected $_classMetadata;
public function __construct($entityName, Doctrine_ClassMetadata $classMetadata) public function __construct($entityName, Doctrine_ClassMetadata $classMetadata)
{ {
$this->_entityName = $entityName; $this->_entityName = $entityName;
$this->_conn = $classMetadata->getConnection(); $this->_em = $classMetadata->getConnection();
$this->_classMetadata = $classMetadata; $this->_classMetadata = $classMetadata;
} }
...@@ -59,7 +59,7 @@ class Doctrine_EntityRepository ...@@ -59,7 +59,7 @@ class Doctrine_EntityRepository
if ( ! empty($alias)) { if ( ! empty($alias)) {
$alias = ' ' . trim($alias); $alias = ' ' . trim($alias);
} }
return Doctrine_Query::create($this->_conn)->from($this->_entityName . $alias); return Doctrine_Query::create($this->_em)->from($this->_entityName . $alias);
} }
/** /**
...@@ -69,7 +69,7 @@ class Doctrine_EntityRepository ...@@ -69,7 +69,7 @@ class Doctrine_EntityRepository
*/ */
public function clear() public function clear()
{ {
$this->_conn->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName()); $this->_em->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
} }
/** /**
...@@ -170,7 +170,7 @@ class Doctrine_EntityRepository ...@@ -170,7 +170,7 @@ class Doctrine_EntityRepository
*/ */
public function findByDql($dql, array $params = array(), $hydrationMode = null) public function findByDql($dql, array $params = array(), $hydrationMode = null)
{ {
$query = new Doctrine_Query($this->_conn); $query = new Doctrine_Query($this->_em);
$component = $this->getComponentName(); $component = $this->getComponentName();
$dql = 'FROM ' . $component . ' WHERE ' . $dql; $dql = 'FROM ' . $component . ' WHERE ' . $dql;
......
...@@ -63,7 +63,7 @@ abstract class Doctrine_Hydrator_Abstract ...@@ -63,7 +63,7 @@ abstract class Doctrine_Hydrator_Abstract
* *
* @param Doctrine_Connection|null $connection * @param Doctrine_Connection|null $connection
*/ */
public function __construct(Doctrine_Connection $em) public function __construct(Doctrine_EntityManager $em)
{ {
$this->_em = $em; $this->_em = $em;
$this->_nullObject = Doctrine_Null::$INSTANCE; $this->_nullObject = Doctrine_Null::$INSTANCE;
......
...@@ -43,7 +43,7 @@ class Doctrine_Hydrator_RecordDriver ...@@ -43,7 +43,7 @@ class Doctrine_Hydrator_RecordDriver
/** The EntityManager */ /** The EntityManager */
private $_em; private $_em;
public function __construct(Doctrine_Connection $em) public function __construct(Doctrine_EntityManager $em)
{ {
$this->_nullObject = Doctrine_Null::$INSTANCE; $this->_nullObject = Doctrine_Null::$INSTANCE;
$this->_em = $em; $this->_em = $em;
...@@ -93,7 +93,7 @@ class Doctrine_Hydrator_RecordDriver ...@@ -93,7 +93,7 @@ class Doctrine_Hydrator_RecordDriver
public function getElement(array $data, $className) public function getElement(array $data, $className)
{ {
return $this->_em->createEntity2($className, $data); return $this->_em->createEntity($className, $data);
} }
public function addRelatedIndexedElement(Doctrine_Entity $entity1, $property, public function addRelatedIndexedElement(Doctrine_Entity $entity1, $property,
......
...@@ -375,6 +375,10 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -375,6 +375,10 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// Parse each column name only once. Cache the results. // Parse each column name only once. Cache the results.
if ( ! isset($cache[$key])) { if ( ! isset($cache[$key])) {
// check ignored names. fastest solution for now. if we get more we'll start
// to introduce a list.
if ($key == 'doctrine_rownum') continue;
// cache general information like the column name <-> field name mapping // cache general information like the column name <-> field name mapping
$e = explode('__', $key); $e = explode('__', $key);
$columnName = strtolower(array_pop($e)); $columnName = strtolower(array_pop($e));
......
...@@ -680,7 +680,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -680,7 +680,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/ */
public function getMapper($componentName) public function getMapper($componentName)
{ {
return $this->getConnectionForComponent($componentName)->getMapper($componentName); return $this->getConnectionForComponent($componentName)->getEntityPersister($componentName);
} }
/** /**
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
* @version $Revision: 3406 $ * @version $Revision: 3406 $
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 2.0 * @since 2.0
* @todo Move all finder stuff to EntityRepository.
* @todo Rename to "EntityPersister" or similar. * @todo Rename to "EntityPersister" or similar.
*/ */
class Doctrine_Mapper class Doctrine_Mapper
...@@ -69,6 +68,12 @@ class Doctrine_Mapper ...@@ -69,6 +68,12 @@ class Doctrine_Mapper
*/ */
private $_entityListeners = array(); private $_entityListeners = array();
/**
* Enter description here...
*
* @var unknown_type
* @todo To EntityManager.
*/
private $_dataTemplate = array(); private $_dataTemplate = array();
...@@ -121,6 +126,7 @@ class Doctrine_Mapper ...@@ -121,6 +126,7 @@ class Doctrine_Mapper
* @param $array an array where keys are field names and * @param $array an array where keys are field names and
* values representing field values * values representing field values
* @return Doctrine_Entity the created record object * @return Doctrine_Entity the created record object
* @todo To EntityManager.
*/ */
public function create(array $array = array()) public function create(array $array = array())
{ {
...@@ -158,24 +164,16 @@ class Doctrine_Mapper ...@@ -158,24 +164,16 @@ class Doctrine_Mapper
} }
} }
public function detach(Doctrine_Entity $entity)
{
return $this->_conn->unitOfWork->detach($entity);
}
/** /**
* Executes a named query. * Enter description here...
* *
* @param string $queryName The name that was used when storing the query. * @param Doctrine_Entity $entity
* @param array $params The query parameters. * @return unknown
* @return mixed The result. * @todo To EntityManager
* @deprecated
*/ */
public function executeNamedQuery($queryName, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD) public function detach(Doctrine_Entity $entity)
{ {
return Doctrine_Manager::getInstance() return $this->_conn->unitOfWork->detach($entity);
->createNamedQuery($queryName)
->execute($params, $hydrationMode);
} }
/** /**
...@@ -184,6 +182,7 @@ class Doctrine_Mapper ...@@ -184,6 +182,7 @@ class Doctrine_Mapper
* *
* @return void * @return void
* @todo what about a more descriptive name? clearIdentityMap? * @todo what about a more descriptive name? clearIdentityMap?
* @todo To EntityManager
*/ */
public function clear() public function clear()
{ {
...@@ -197,6 +196,7 @@ class Doctrine_Mapper ...@@ -197,6 +196,7 @@ class Doctrine_Mapper
* @param Doctrine_Entity $record record to be added * @param Doctrine_Entity $record record to be added
* @return boolean * @return boolean
* @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps. * @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps.
* @todo Remove.
*/ */
public function addRecord(Doctrine_Entity $record) public function addRecord(Doctrine_Entity $record)
{ {
...@@ -213,6 +213,7 @@ class Doctrine_Mapper ...@@ -213,6 +213,7 @@ class Doctrine_Mapper
* *
* @return boolean TRUE if the entity was previously not managed and is now managed, * @return boolean TRUE if the entity was previously not managed and is now managed,
* FALSE otherwise (the entity is already managed). * FALSE otherwise (the entity is already managed).
* @todo Remove.
*/ */
public function manage(Doctrine_Entity $record) public function manage(Doctrine_Entity $record)
{ {
...@@ -244,6 +245,7 @@ class Doctrine_Mapper ...@@ -244,6 +245,7 @@ class Doctrine_Mapper
* returns a new record. * returns a new record.
* *
* @return Doctrine_Entity * @return Doctrine_Entity
* @todo To EntityManager.
*/ */
public function getRecord(array $data) public function getRecord(array $data)
{ {
...@@ -310,6 +312,7 @@ class Doctrine_Mapper ...@@ -310,6 +312,7 @@ class Doctrine_Mapper
* applyInheritance * applyInheritance
* @param $where query where part to be modified * @param $where query where part to be modified
* @return string query where part with column aggregation inheritance added * @return string query where part with column aggregation inheritance added
* @todo What to do with this? Remove if possible.
*/ */
final public function applyInheritance($where) final public function applyInheritance($where)
{ {
...@@ -357,6 +360,8 @@ class Doctrine_Mapper ...@@ -357,6 +360,8 @@ class Doctrine_Mapper
* for the field can be skipped. Used i.e. during hydration to * for the field can be skipped. Used i.e. during hydration to
* improve performance on large and/or complex results. * improve performance on large and/or complex results.
* @return mixed prepared value * @return mixed prepared value
* @todo To EntityManager. Make private and use in createEntity().
* .. Or, maybe better: Move to hydrator for performance reasons.
*/ */
public function prepareValue($fieldName, $value, $typeHint = null) public function prepareValue($fieldName, $value, $typeHint = null)
{ {
...@@ -398,43 +403,6 @@ class Doctrine_Mapper ...@@ -398,43 +403,6 @@ class Doctrine_Mapper
} }
return $value; return $value;
} }
/**
* Hydrates the given data into the entity.
*
*/
/*public function hydrate(Doctrine_Entity $entity, array $data)
{
$this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data);
$this->_extractIdentifier(true);
}*/
/**
* getTree
*
* getter for associated tree
*
* @return mixed if tree return instance of Doctrine_Tree, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function getTree()
{
return $this->_classMetadata->getTree();
}
/**
* isTree
*
* determine if table acts as tree
*
* @return mixed if tree return true, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function isTree()
{
return $this->_classMetadata->isTree();
}
/** /**
* getComponentName * getComponentName
...@@ -729,26 +697,11 @@ class Doctrine_Mapper ...@@ -729,26 +697,11 @@ class Doctrine_Mapper
return true; return true;
} }
public function executeQuery(Doctrine_Query $query)
{
}
public function getTable()
{
return $this->_classMetadata;
}
public function getClassMetadata() public function getClassMetadata()
{ {
return $this->_classMetadata; return $this->_classMetadata;
} }
public function dump()
{
var_dump($this->_invokedMethods);
}
public function free() public function free()
{ {
$this->_mappingStrategy = null; $this->_mappingStrategy = null;
...@@ -759,8 +712,6 @@ class Doctrine_Mapper ...@@ -759,8 +712,6 @@ class Doctrine_Mapper
return $this->_mappingStrategy; return $this->_mappingStrategy;
} }
public function getFieldName($columnName) public function getFieldName($columnName)
{ {
return $this->_mappingStrategy->getFieldName($columnName); return $this->_mappingStrategy->getFieldName($columnName);
......
...@@ -1129,7 +1129,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1129,7 +1129,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$modifyLimit = true; $modifyLimit = true;
if ( ! empty($this->_sqlParts['limit']) || ! empty($this->_sqlParts['offset'])) { if ( ! empty($this->_sqlParts['limit']) || ! empty($this->_sqlParts['offset'])) {
if ($needsSubQuery) { if ($needsSubQuery) {
$subquery = $this->getLimitSubquery(); $subquery = $this->getLimitSubquery();
// what about composite keys? // what about composite keys?
...@@ -1138,7 +1137,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1138,7 +1137,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
switch (strtolower($this->_conn->getDriverName())) { switch (strtolower($this->_conn->getDriverName())) {
case 'mysql': case 'mysql':
// mysql doesn't support LIMIT in subqueries // mysql doesn't support LIMIT in subqueries
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN); $list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
$subquery = implode(', ', array_map(array($this->_conn, 'quote'), $list)); $subquery = implode(', ', array_map(array($this->_conn, 'quote'), $list));
break; break;
case 'pgsql': case 'pgsql':
...@@ -1192,18 +1191,18 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1192,18 +1191,18 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
*/ */
public function getLimitSubquery() public function getLimitSubquery()
{ {
$map = reset($this->_queryComponents); $map = reset($this->_queryComponents);
$table = $map['table']; $table = $map['table'];
$componentAlias = key($this->_queryComponents); $componentAlias = key($this->_queryComponents);
// get short alias // get short alias
$alias = $this->getTableAlias($componentAlias); $alias = $this->getTableAlias($componentAlias);
// what about composite keys? // what about composite keys?
$idFieldNames = (array)$table->getIdentifier(); $idFieldNames = (array)$table->getIdentifier();
$primaryKey = $alias . '.' . $table->getColumnName($idFieldNames[0]); $primaryKey = $alias . '.' . $table->getColumnName($idFieldNames[0]);
// initialize the base of the subquery // initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey); $subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey);
$driverName = $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME); $driverName = $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME);
...@@ -1261,7 +1260,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1261,7 +1260,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$subquery .= ( ! empty($this->_sqlParts['orderby']))? ' ORDER BY ' . implode(', ', $this->_sqlParts['orderby']) : ''; $subquery .= ( ! empty($this->_sqlParts['orderby']))? ' ORDER BY ' . implode(', ', $this->_sqlParts['orderby']) : '';
// add driver specific limit clause // add driver specific limit clause
$subquery = $this->_conn->modifyLimitQuery($subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']); $subquery = $this->_conn->modifyLimitSubquery($table, $subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']);
$parts = $this->_tokenizer->quoteExplode($subquery, ' ', "'", "'"); $parts = $this->_tokenizer->quoteExplode($subquery, ' ', "'", "'");
...@@ -1643,7 +1642,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1643,7 +1642,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this->_sqlParts['from'][] = $queryPart; $this->_sqlParts['from'][] = $queryPart;
//echo "<br /><br />" . $table->getComponentName() . "---3---" . $name . "<br /><br />"; //echo "<br /><br />" . $table->getComponentName() . "---3---" . $name . "<br /><br />";
$this->_queryComponents[$componentAlias] = array( $this->_queryComponents[$componentAlias] = array(
'table' => $table, 'mapper' => $this->_conn->getMapper($name), 'map' => null); 'table' => $table, 'mapper' => $this->_conn->getEntityPersister($name), 'map' => null);
return $table; return $table;
} }
......
...@@ -530,7 +530,7 @@ abstract class Doctrine_Query_Abstract ...@@ -530,7 +530,7 @@ abstract class Doctrine_Query_Abstract
{ {
$table = $this->_conn->getMetadata($componentName); $table = $this->_conn->getMetadata($componentName);
$tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName()); $tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName());
$customJoins = $this->_conn->getMapper($componentName)->getCustomJoins(); $customJoins = $this->_conn->getEntityPersister($componentName)->getCustomJoins();
$sql = ''; $sql = '';
foreach ($customJoins as $componentName => $joinType) { foreach ($customJoins as $componentName => $joinType) {
$joinedTable = $this->_conn->getMetadata($componentName); $joinedTable = $this->_conn->getMetadata($componentName);
...@@ -1051,12 +1051,12 @@ abstract class Doctrine_Query_Abstract ...@@ -1051,12 +1051,12 @@ abstract class Doctrine_Query_Abstract
$e = explode('.', $components[0]); $e = explode('.', $components[0]);
if (count($e) === 1) { if (count($e) === 1) {
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($e[0]); $queryComponents[$alias]['mapper'] = $this->_conn->getMapper($e[0]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable(); $queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getClassMetadata();
} else { } else {
$queryComponents[$alias]['parent'] = $e[0]; $queryComponents[$alias]['parent'] = $e[0];
$queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]); $queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]);
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($queryComponents[$alias]['relation']->getForeignComponentName()); $queryComponents[$alias]['mapper'] = $this->_conn->getMapper($queryComponents[$alias]['relation']->getForeignComponentName());
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable(); $queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getClassMetadata();
} }
if (isset($components[1])) { if (isset($components[1])) {
$queryComponents[$alias]['agg'] = $components[1]; $queryComponents[$alias]['agg'] = $components[1];
......
...@@ -154,7 +154,7 @@ abstract class Doctrine_Relation implements ArrayAccess ...@@ -154,7 +154,7 @@ abstract class Doctrine_Relation implements ArrayAccess
} }
} }
$this->definition = $def; $this->definition = $def;
$this->_foreignMapper = $this->getTable()->getConnection()->getMapper($def['class']); $this->_foreignMapper = $this->getTable()->getConnection()->getEntityPersister($def['class']);
} }
/** /**
...@@ -257,9 +257,8 @@ abstract class Doctrine_Relation implements ArrayAccess ...@@ -257,9 +257,8 @@ abstract class Doctrine_Relation implements ArrayAccess
*/ */
final public function getTable() final public function getTable()
{ {
return Doctrine_Manager::getInstance() return Doctrine_EntityManager::getManager($this->definition['class'])
->getConnectionForComponent($this->definition['class']) ->getClassMetadata($this->definition['class']);
->getMetadata($this->definition['class']);
} }
/** /**
......
...@@ -271,7 +271,7 @@ class Doctrine_Relation_Parser ...@@ -271,7 +271,7 @@ class Doctrine_Relation_Parser
*/ */
public function getImpl(array &$def, $key) public function getImpl(array &$def, $key)
{ {
$conn = $this->_table->getConnection(); $em = $this->_table->getEntityManager();
if (in_array('Doctrine_Template', class_parents($def[$key]))) { if (in_array('Doctrine_Template', class_parents($def[$key]))) {
$impl = $this->_table->getImpl($def[$key]); $impl = $this->_table->getImpl($def[$key]);
if ($impl === null) { if ($impl === null) {
...@@ -280,7 +280,7 @@ class Doctrine_Relation_Parser ...@@ -280,7 +280,7 @@ class Doctrine_Relation_Parser
$def[$key] = $impl; $def[$key] = $impl;
} }
return $conn->getMetadata($def[$key]); return $em->getClassMetadata($def[$key]);
} }
protected function _isTemplate($className) protected function _isTemplate($className)
......
...@@ -41,6 +41,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase ...@@ -41,6 +41,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->user = new ForumUser(); $this->user = new ForumUser();
} }
...@@ -57,10 +58,10 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase ...@@ -57,10 +58,10 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/** /**
* @test * @test
*/ */
public function shouldMarkExistingFieldAsSetOnNewRecord() public function shouldMarkEmptyFieldAsNotSetOnNewRecord()
{ {
$this->assertTrue(isset($this->user->username)); $this->assertFalse(isset($this->user->username));
$this->assertTrue(isset($this->user['username'])); $this->assertFalse(isset($this->user['username']));
} }
/** /**
...@@ -113,7 +114,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase ...@@ -113,7 +114,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/** /**
* @test * @test
* @expectedException Doctrine_Record_Exception * @expectedException Doctrine_Entity_Exception
*/ */
public function shouldNotBeAbleToSetNonExistantField() public function shouldNotBeAbleToSetNonExistantField()
{ {
...@@ -122,7 +123,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase ...@@ -122,7 +123,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/** /**
* @test * @test
* @expectedException Doctrine_Record_Exception * @expectedException Doctrine_Entity_Exception
*/ */
public function shouldNotBeAbleToSetNonExistantFieldWithOffset() public function shouldNotBeAbleToSetNonExistantFieldWithOffset()
{ {
...@@ -131,14 +132,13 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase ...@@ -131,14 +132,13 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/** /**
* @test * @test
* @expectedException Doctrine_Record_Exception * @expectedException Doctrine_Entity_Exception
*/ */
public function shouldNotBeAbleToSetNonExistantFieldAsPartInSetArray() public function shouldNotBeAbleToSetNonExistantFieldAsPartInSetArray()
{ {
$this->user->setArray(array( $this->user->setArray(array(
'rat' => 'meus', 'rat' => 'meus',
'id' => 22)); 'id' => 22));
} }
......
...@@ -6,7 +6,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) { ...@@ -6,7 +6,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once 'lib/DoctrineTestInit.php'; require_once 'lib/DoctrineTestInit.php';
// Tests // Tests
require_once 'Orm/Component/TestTest.php';
require_once 'Orm/Component/AccessTest.php'; require_once 'Orm/Component/AccessTest.php';
require_once 'Orm/Component/CollectionTest.php'; require_once 'Orm/Component/CollectionTest.php';
...@@ -21,7 +20,6 @@ class Orm_Component_AllTests ...@@ -21,7 +20,6 @@ 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_AccessTest'); $suite->addTestSuite('Orm_Component_AccessTest');
$suite->addTestSuite('Orm_Component_CollectionTest'); $suite->addTestSuite('Orm_Component_CollectionTest');
......
...@@ -40,6 +40,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase ...@@ -40,6 +40,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->coll = new Doctrine_Collection('ForumUser'); $this->coll = new Doctrine_Collection('ForumUser');
//we create a CmsUser with username as key column and add a user to it //we create a CmsUser with username as key column and add a user to it
......
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_Component_TestTest extends Doctrine_OrmTestCase
{
protected function setUp()
{
parent::setUp();
$this->loadFixtures('forum', 'common', array('users', 'admins'));
}
public function testTest()
{
$this->assertEquals(0, 0);
}
public function testFixture()
{
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u");
$this->assertEquals(2, count($forumUsers));
$forumUsers[0]->delete();
unset($forumUsers[0]);
$this->assertEquals(1, count($forumUsers));
}
public function testFixture2()
{
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u");
$this->assertEquals(2, count($forumUsers));
}
public function testFixture3()
{
$forumAdmins = $this->sharedFixture['connection']->query("FROM ForumAdministrator adm");
$this->assertEquals(1, count($forumAdmins));
$forumAdmins[0]->delete();
}
}
\ No newline at end of file
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_EntityManagerTest extends Doctrine_OrmTestCase
{
protected function setUp() {
parent::setUp();
}
protected function tearDown() {
Doctrine_EntityManager::unbindAllManagers();
Doctrine_EntityManager::releaseAllManagers();
parent::tearDown();
}
public function testInstantiationRegistersInstanceInStaticMap()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testStaticGetManagerThrowsExceptionIfNoManagerAvailable()
{
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail("Expected exception not thrown.");
} catch (Doctrine_EntityManager_Exception $ex) {}
}
public function testBindingValidEntityToNamedManager()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock(null), 'myEM');
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testBindingEntityToInvalidManagerThrowsExceptionOnRetrieval()
{
// will work. we don't check the existence of the EM during binding
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
// exception on access
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail();
} catch (Doctrine_EntityManager_Exception $ex) {}
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -8,8 +8,9 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase ...@@ -8,8 +8,9 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->_user = new ForumUser(); $this->_user = new ForumUser();
$this->_unitOfWork = $this->sharedFixture['connection']->unitOfWork; $this->_unitOfWork = $em->getUnitOfWork();
} }
protected function tearDown() { protected function tearDown() {
......
...@@ -5,8 +5,10 @@ require_once 'Doctrine_TestCase.php'; ...@@ -5,8 +5,10 @@ require_once 'Doctrine_TestCase.php';
require_once 'Doctrine_TestUtil.php'; require_once 'Doctrine_TestUtil.php';
require_once 'Doctrine_DbalTestCase.php'; require_once 'Doctrine_DbalTestCase.php';
require_once 'Doctrine_OrmTestCase.php'; require_once 'Doctrine_OrmTestCase.php';
require_once 'Doctrine_OrmFunctionalTestCase.php';
require_once 'Doctrine_TestSuite.php'; require_once 'Doctrine_TestSuite.php';
require_once 'Doctrine_OrmTestSuite.php'; require_once 'Doctrine_OrmTestSuite.php';
require_once 'Doctrine_OrmFunctionalTestSuite.php';
require_once 'Doctrine_DbalTestSuite.php'; require_once 'Doctrine_DbalTestSuite.php';
require_once '../lib/Doctrine.php'; require_once '../lib/Doctrine.php';
......
...@@ -5,118 +5,5 @@ ...@@ -5,118 +5,5 @@
*/ */
class Doctrine_OrmTestCase extends Doctrine_TestCase class Doctrine_OrmTestCase extends Doctrine_TestCase
{ {
/**
* The currently loaded model names of the fixtures for the testcase.
*/
private $_loadedFixtures = array();
/**
* All loaded fixtures during test execution. Common fixture cache.
*/
private static $_fixtures = array();
/**
* The names of all tables that were already exported. Each table is exported
* only once. Then it's just filled & erased for each testmethod in a testcase
* that uses one or more fixtures.
*/
private static $_exportedTables = array();
/**
* setUp()
*
* Note: This setUp() and the one of DbalTestCase currently look identical. However,
* please dont pull this method up. In the future with a separation of Dbal/Orm
* this setUp() will take care of a ORM connection/session/manager initialization
* and the DBAL setUp() will take care of just a DBAL connection.
*/
protected function setUp()
{
// Setup a db connection if there is none, yet. This makes it possible
// to run tests that use a connection standalone.
if ( ! isset($this->sharedFixture['connection'])) {
$this->sharedFixture['connection'] = Doctrine_TestUtil::getConnection();
}
}
/**
* Loads a data fixture into the database. This method must only be called
* from within the setUp() method of testcases. The database will then be
* populated with fresh data of all loaded fixtures for each test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param string $name The name of the fixture to load from the specified package.
*/
protected function loadFixture($package, $scenario, $name)
{
$uniqueName = $package . '/' . $scenario . '/' . $name;
if ( ! isset(self::$_fixtures[$uniqueName])) {
// load fixture file
$fixtureFile = 'fixtures'
. DIRECTORY_SEPARATOR . $package
. DIRECTORY_SEPARATOR . $scenario
. DIRECTORY_SEPARATOR . $name
. '.php';
require $fixtureFile;
self::$_fixtures[$uniqueName] = $fixture;
}
$fixture = self::$_fixtures[$uniqueName];
$this->_loadedFixtures[] = $fixture['model'];
$conn = $this->sharedFixture['connection'];
$classMetadata = $conn->getClassMetadata($fixture['model']);
$tableName = $classMetadata->getTableName();
if ( ! in_array($tableName, self::$_exportedTables)) {
$conn->export->exportClasses(array($fixture['model']));
self::$_exportedTables[] = $tableName;
}
foreach ($fixture['rows'] as $row) {
$conn->insert($tableName, $row);
}
}
/**
* Loads multiple fixtures of the same package and scenario.
* This method must only be called from within the setUp() method of testcases.
* The database will then be populated with fresh data of all loaded fixtures for each
* test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param array $names The names of the fixtures to load from the specified package.
*/
protected function loadFixtures($package, $scenario, array $names)
{
foreach ($names as $name) {
$this->loadFixture($package, $scenario, $name);
}
}
/**
* Sweeps the database tables of all used fixtures.
*/
protected function tearDown()
{
$conn = $this->sharedFixture['connection'];
foreach (array_reverse($this->_loadedFixtures) as $model) {
$conn->exec("DELETE FROM " . $conn->getClassMetadata($model)->getTableName());
}
}
} }
\ No newline at end of file
...@@ -8,11 +8,5 @@ ...@@ -8,11 +8,5 @@
*/ */
class Doctrine_OrmTestSuite extends Doctrine_TestSuite class Doctrine_OrmTestSuite extends Doctrine_TestSuite
{ {
protected function setUp()
{
$this->sharedFixture['connection'] = Doctrine_TestUtil::getConnection();
}
protected function tearDown()
{}
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ class CmsUser extends Doctrine_Entity ...@@ -4,6 +4,7 @@ class CmsUser extends Doctrine_Entity
public static function initMetadata($class) public static function initMetadata($class)
{ {
$class->mapColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); $class->mapColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$class->mapColumn('status', 'string', 50);
$class->mapColumn('username', 'string', 255); $class->mapColumn('username', 'string', 255);
$class->mapColumn('name', 'string', 255); $class->mapColumn('name', 'string', 255);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment