From efaaf83e17611af01b12701684ab32ffe694de66 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 4 Jan 2009 16:15:32 +0000 Subject: [PATCH] test and collection cleanup --- .../Common/Collections/Collection.php | 81 +++- lib/Doctrine/ORM/Collection.php | 451 +----------------- lib/Doctrine/ORM/EntityManager.php | 68 +-- .../ORM/Internal/Hydration/ObjectDriver.php | 2 +- lib/Doctrine/ORM/NativeQuery.php | 2 +- lib/Doctrine/ORM/Query.php | 20 +- lib/Doctrine/ORM/Query/CacheHandler.php | 7 +- lib/Doctrine/ORM/UnitOfWork.php | 72 ++- tests/AllTests.php | 1 + tests/Orm/AllTests.php | 4 +- .../CommitOrderCalculatorTest.php | 11 +- tests/Orm/Component/AccessTest.php | 189 -------- tests/Orm/Component/AllTests.php | 32 -- tests/Orm/Component/CollectionTest.php | 130 ----- tests/Orm/Entity/AccessorTest.php | 1 + tests/Orm/Entity/ConstructorTest.php | 3 +- tests/Orm/EntityManagerFactoryTest.php | 35 -- tests/Orm/EntityManagerTest.php | 11 +- tests/Orm/Hydration/BasicHydrationTest.php | 5 +- tests/Orm/Query/IdentifierRecognitionTest.php | 6 + tests/Orm/UnitOfWorkTest.php | 15 +- tests/lib/DoctrineTestInit.php | 6 +- tests/lib/Doctrine_DbalTestCase.php | 19 +- tests/lib/Doctrine_DbalTestSuite.php | 19 +- tests/lib/Doctrine_OrmFunctionalTestCase.php | 3 + tests/lib/Doctrine_OrmFunctionalTestSuite.php | 5 +- tests/lib/Doctrine_OrmTestCase.php | 32 +- tests/lib/Doctrine_OrmTestSuite.php | 25 +- tests/lib/Doctrine_TestCase.php | 4 +- tests/lib/Doctrine_TestSuite.php | 6 +- tests/lib/Doctrine_TestUtil.php | 2 + .../lib/mocks/Doctrine_ClassMetadataMock.php | 3 +- tests/lib/mocks/Doctrine_ConnectionMock.php | 5 +- .../mocks/Doctrine_DatabasePlatformMock.php | 5 +- .../mocks/Doctrine_DriverConnectionMock.php | 3 +- tests/lib/mocks/Doctrine_DriverMock.php | 2 + .../lib/mocks/Doctrine_EntityManagerMock.php | 3 +- .../mocks/Doctrine_EntityPersisterMock.php | 3 + .../mocks/Doctrine_HydratorMockStatement.php | 4 +- .../Doctrine_IdentityIdGeneratorMock.php | 8 +- tests/lib/mocks/Doctrine_SequenceMock.php | 3 +- tests/lib/mocks/Doctrine_UnitOfWorkMock.php | 6 +- tests/models/forum/ForumAdministrator.php | 2 + tests/models/forum/ForumAvatar.php | 7 +- tests/models/forum/ForumBoard.php | 3 + tests/models/forum/ForumCategory.php | 3 + tests/models/forum/ForumEntry.php | 12 +- tests/models/forum/ForumUser.php | 3 +- 48 files changed, 309 insertions(+), 1033 deletions(-) rename tests/Orm/{Internal => }/CommitOrderCalculatorTest.php (82%) delete mode 100644 tests/Orm/Component/AccessTest.php delete mode 100644 tests/Orm/Component/AllTests.php delete mode 100644 tests/Orm/Component/CollectionTest.php delete mode 100644 tests/Orm/EntityManagerFactoryTest.php diff --git a/lib/Doctrine/Common/Collections/Collection.php b/lib/Doctrine/Common/Collections/Collection.php index 0a6a2003a..78ad51798 100644 --- a/lib/Doctrine/Common/Collections/Collection.php +++ b/lib/Doctrine/Common/Collections/Collection.php @@ -18,7 +18,7 @@ * * @author robo */ -class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serializable, ArrayAccess { +class Doctrine_Common_Collections_Collection implements Countable, IteratorAggregate, Serializable, ArrayAccess { /** * An array containing the entries of this collection. * This is the wrapped php array. @@ -205,7 +205,7 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial /** * */ - public function search(Doctrine_ORM_Entity $record) + public function search($record) { return array_search($record, $this->_data, true); } @@ -287,11 +287,6 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial */ public function add($value, $key = null) { - //TODO: really only allow entities? - if ( ! $value instanceof Doctrine_ORM_Entity) { - throw new Doctrine_Record_Exception('Value variable in collection is not an instance of Doctrine_Entity.'); - } - // TODO: Really prohibit duplicates? if (in_array($value, $this->_data, true)) { return false; @@ -306,16 +301,6 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial $this->_data[] = $value; } - if ($this->_hydrationFlag) { - if ($this->_backRefFieldName) { - // set back reference to owner - $value->_internalSetReference($this->_backRefFieldName, $this->_owner); - } - } else { - //TODO: Register collection as dirty with the UoW if necessary - $this->_changed(); - } - return true; } @@ -351,12 +336,36 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial return new ArrayIterator($data); } + /** + * @todo Experiment. Waiting for 5.3 closures. + * Example usage: + * + * $map = $coll->mapElements(function($key, $entity) { + * return array($entity->id, $entity->name); + * }); + * + * or: + * + * $map = $coll->mapElements(function($key, $entity) { + * return array($entity->name, strtoupper($entity->name)); + * }); + * + */ + public function mapElements($lambda) { + $result = array(); + foreach ($this->_data as $key => $entity) { + list($key, $value) = each($lambda($key, $entity)); + $result[$key] = $value; + } + return $result; + } + /** * returns a string representation of this object */ public function __toString() { - return Doctrine_Lib::getCollectionAsString($this); + return __CLASS__ . '@' . spl_object_hash($this); } /** @@ -368,5 +377,39 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial { $this->_data = array(); } + + /* Serializable implementation */ + + /** + * Serializes the collection. + * This method is automatically called when the Collection is serialized. + * + * Part of the implementation of the Serializable interface. + * + * @return array + */ + public function serialize() + { + $vars = get_object_vars($this); + + //TODO + + return serialize($vars); + } + + /** + * Reconstitutes the collection object from it's serialized form. + * This method is automatically called everytime the Collection object is unserialized. + * + * Part of the implementation of the Serializable interface. + * + * @param string $serialized The serialized data + * + * @return void + */ + public function unserialize($serialized) + { + //TODO + } } -?> + diff --git a/lib/Doctrine/ORM/Collection.php b/lib/Doctrine/ORM/Collection.php index beb458219..f33854f0f 100644 --- a/lib/Doctrine/ORM/Collection.php +++ b/lib/Doctrine/ORM/Collection.php @@ -40,14 +40,13 @@ * mapping. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @since 1.0 + * @since 2.0 * @version $Revision: 4930 $ * @author Konsta Vesterinen * @author Roman Borschel - * @todo Add more typical Collection methods. * @todo Rename to PersistentCollection */ -class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializable, ArrayAccess +class Doctrine_ORM_Collection extends Doctrine_Common_Collections_Collection { /** * The base type of the collection. @@ -55,14 +54,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa * @var string */ protected $_entityBaseType; - - /** - * An array containing the entries of this collection. - * This is the wrapped php array. - * - * @var array - */ - protected $_data = array(); /** * A snapshot of the collection at the moment it was fetched from the database. @@ -120,10 +111,10 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa /** * Creates a new persistent collection. */ - public function __construct($entityBaseType, $keyField = null) + public function __construct(Doctrine_ORM_EntityManager $em, $entityBaseType, $keyField = null) { $this->_entityBaseType = $entityBaseType; - $this->_em = Doctrine_ORM_EntityManager::getActiveEntityManager(); + $this->_em = $em; if ($keyField !== null) { if ( ! $this->_em->getClassMetadata($entityBaseType)->hasField($keyField)) { @@ -165,56 +156,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa { return $this->_keyField; } - - /** - * Unwraps the array contained in the Collection instance. - * - * @return array The wrapped array. - */ - public function unwrap() - { - return $this->_data; - } - - /** - * returns the first record in the collection - * - * @return mixed - */ - public function getFirst() - { - return reset($this->_data); - } - - /** - * returns the last record in the collection - * - * @return mixed - */ - public function getLast() - { - return end($this->_data); - } - - /** - * returns the last record in the collection - * - * @return mixed - */ - public function end() - { - return end($this->_data); - } - - /** - * returns the current key - * - * @return mixed - */ - public function key() - { - return key($this->_data); - } /** * INTERNAL: @@ -258,8 +199,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa */ public function remove($key) { - $removed = $this->_data[$key]; - unset($this->_data[$key]); //TODO: Register collection as dirty with the UoW if necessary //$this->_em->getUnitOfWork()->scheduleCollectionUpdate($this); //TODO: delete entity if shouldDeleteOrphans @@ -267,177 +206,7 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa $this->_em->delete($removed); }*/ - return $removed; - } - - /** - * __isset() - * - * @param string $name - * @return boolean whether or not this object contains $name - */ - public function __isset($key) - { - return $this->containsKey($key); - } - - /** - * __unset() - * - * @param string $name - * @since 1.0 - * @return mixed - */ - public function __unset($key) - { - return $this->remove($key); - } - - /** - * Check if an offsetExists. - * - * Part of the ArrayAccess implementation. - * - * @param mixed $offset - * @return boolean whether or not this object contains $offset - */ - public function offsetExists($offset) - { - return $this->containsKey($offset); - } - - /** - * offsetGet an alias of get() - * - * Part of the ArrayAccess implementation. - * - * @see get, __get - * @param mixed $offset - * @return mixed - */ - public function offsetGet($offset) - { - return $this->get($offset); - } - - /** - * Part of the ArrayAccess implementation. - * - * sets $offset to $value - * @see set, __set - * @param mixed $offset - * @param mixed $value - * @return void - */ - public function offsetSet($offset, $value) - { - if ( ! isset($offset)) { - return $this->add($value); - } - return $this->set($offset, $value); - } - - /** - * Part of the ArrayAccess implementation. - * - * unset a given offset - * @see set, offsetSet, __set - * @param mixed $offset - */ - public function offsetUnset($offset) - { - return $this->remove($offset); - } - - /** - * Checks whether the collection contains an entity. - * - * @param mixed $key the key of the element - * @return boolean - */ - public function containsKey($key) - { - return isset($this->_data[$key]); - } - - /** - * Enter description here... - * - * @param unknown_type $entity - * @return unknown - */ - public function contains($entity) - { - return in_array($entity, $this->_data, true); - } - - /** - * Enter description here... - * - * @param unknown_type $otherColl - * @todo Impl - */ - public function containsAll($otherColl) - { - //... - } - - /** - * - */ - public function search(Doctrine_ORM_Entity $record) - { - return array_search($record, $this->_data, true); - } - - /** - * returns a record for given key - * - * Collection also maps referential information to newly created records - * - * @param mixed $key the key of the element - * @return Doctrine_Entity return a specified record - */ - public function get($key) - { - if (isset($this->_data[$key])) { - return $this->_data[$key]; - } - return null; - } - - /** - * Gets all keys. - * (Map method) - * - * @return array - */ - public function getKeys() - { - return array_keys($this->_data); - } - - /** - * Gets all values. - * (Map method) - * - * @return array - */ - public function getValues() - { - return array_values($this->_data); - } - - /** - * Returns the number of records in this collection. - * - * Implementation of the Countable interface. - * - * @return integer The number of records in the collection. - */ - public function count() - { - return count($this->_data); + return parent::remove($key); } /** @@ -450,10 +219,7 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa */ public function set($key, $value) { - if ( ! $value instanceof Doctrine_ORM_Entity) { - throw new Doctrine_Collection_Exception('Value variable in set is not an instance of Doctrine_Entity'); - } - $this->_data[$key] = $value; + parent::set($key, $value); //TODO: Register collection as dirty with the UoW if necessary $this->_changed(); } @@ -467,23 +233,8 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa */ public function add($value, $key = null) { - if ( ! $value instanceof $this->_entityBaseType) { - throw new Doctrine_Exception('Invalid instance.'); - } - - // TODO: Really prohibit duplicates? - if (in_array($value, $this->_data, true)) { - return false; - } - - if (isset($key)) { - if (isset($this->_data[$key])) { - return false; - } - $this->_data[$key] = $value; - } else { - $this->_data[] = $value; - } + $result = parent::add($value, $key); + if ( ! $result) return $result; // EARLY EXIT if ($this->_hydrationFlag) { if ($this->_backRefFieldName) { @@ -507,6 +258,7 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa */ public function addAll($otherCollection) { + parent::addAll($otherCollection); //... //TODO: Register collection as dirty with the UoW if necessary //$this->_changed(); @@ -577,75 +329,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa return $this; } - /** - * Creates an array representation of the collection. - * - * @param boolean $deep - * @return array - */ - public function toArray($deep = false, $prefixKey = false) - { - $data = array(); - foreach ($this as $key => $record) { - $key = $prefixKey ? get_class($record) . '_' .$key:$key; - $data[$key] = $record->toArray($deep, $prefixKey); - } - - return $data; - } - - /** - * Checks whether the collection is empty. - * - * @return boolean TRUE if the collection is empty, FALSE otherwise. - */ - public function isEmpty() - { - // Note: Little "trick". Empty arrays evaluate to FALSE. No need to count(). - return ! (bool)$this->_data; - } - - /** - * Populate a Collection from an array of data. - * - * @param string $array - * @return void - */ - public function fromArray($array, $deep = true) - { - $data = array(); - foreach ($array as $rowKey => $row) { - $this[$rowKey]->fromArray($row, $deep); - } - } - - /** - * Synchronizes a Collection with data from an array. - * - * it expects an array representation of a Doctrine_Collection similar to the return - * value of the toArray() method. It will create Dectrine_Records that don't exist - * on the collection, update the ones that do and remove the ones missing in the $array - * - * @param array $array representation of a Doctrine_Collection - */ - public function synchronizeFromArray(array $array) - { - foreach ($this as $key => $record) { - if (isset($array[$key])) { - $record->synchronizeFromArray($array[$key]); - unset($array[$key]); - } else { - // remove records that don't exist in the array - $this->remove($key); - } - } - - // create new records for each new row in the array - foreach ($array as $rowKey => $row) { - $this[$rowKey]->fromArray($row); - } - } - /** * INTERNAL: * getDeleteDiff @@ -679,45 +362,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa } return 1; } - - /** - * - * @param $deep - */ - /*public function free($deep = false) - { - foreach ($this->getData() as $key => $record) { - if ( ! ($record instanceof Doctrine_Null)) { - $record->free($deep); - } - } - - $this->_data = array(); - - if ($this->_owner) { - $this->_owner->free($deep); - $this->_owner = null; - } - }*/ - - /** - * getIterator - * - * @return object ArrayIterator - */ - public function getIterator() - { - $data = $this->_data; - return new ArrayIterator($data); - } - - /** - * returns a string representation of this object - */ - public function __toString() - { - return Doctrine_Lib::getCollectionAsString($this); - } /** * INTERNAL: Gets the association mapping of the collection. @@ -729,30 +373,6 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa return $this->relation; } - /** - * @todo Experiment. Waiting for 5.3 closures. - * Example usage: - * - * $map = $coll->mapElements(function($key, $entity) { - * return array($entity->id, $entity->name); - * }); - * - * or: - * - * $map = $coll->mapElements(function($key, $entity) { - * return array($entity->name, strtoupper($entity->name)); - * }); - * - */ - public function mapElements($lambda) { - $result = array(); - foreach ($this->_data as $key => $entity) { - list($key, $value) = each($lambda($key, $entity)); - $result[$key] = $value; - } - return $result; - } - /** * Clears the collection. * @@ -767,7 +387,7 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa $this->_em->delete($entity); } }*/ - $this->_data = array(); + parent::clear(); } private function _changed() @@ -776,55 +396,4 @@ class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializa $this->_em->getUnitOfWork()->scheduleCollectionUpdate($this); }*/ } - - /* Serializable implementation */ - - /** - * Serializes the collection. - * This method is automatically called when the Collection is serialized. - * - * Part of the implementation of the Serializable interface. - * - * @return array - */ - public function serialize() - { - $vars = get_object_vars($this); - - unset($vars['reference']); - unset($vars['relation']); - unset($vars['expandable']); - unset($vars['expanded']); - unset($vars['generator']); - - return serialize($vars); - } - - /** - * Reconstitutes the collection object from it's serialized form. - * This method is automatically called everytime the Collection object is unserialized. - * - * Part of the implementation of the Serializable interface. - * - * @param string $serialized The serialized data - * - * @return void - */ - public function unserialize($serialized) - { - $manager = Doctrine_ORM_EntityManager::getActiveEntityManager(); - $connection = $manager->getConnection(); - - $array = unserialize($serialized); - - foreach ($array as $name => $values) { - $this->$name = $values; - } - - $keyColumn = isset($array['keyField']) ? $array['keyField'] : null; - - if ($keyColumn !== null) { - $this->_keyField = $keyColumn; - } - } } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 7b1e56d22..f0c22702e 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -131,16 +131,28 @@ class Doctrine_ORM_EntityManager * @var EventManager */ private $_eventManager; + + /** + * The maintained (cached) Id generators. + * + * @var + */ private $_idGenerators = array(); + + /** Whether the EntityManager is closed or not. */ private $_closed = false; /** - * Creates a new EntityManager that operates on the given database connection. + * Creates a new EntityManager that operates on the given database connection + * and uses the given Configuration and EventManager implementations. * - * @param Doctrine_Connection $conn + * @param Doctrine\DBAL\Connection $conn * @param string $name */ - protected function __construct(Doctrine_DBAL_Connection $conn, $name, Doctrine_ORM_Configuration $config, + protected function __construct( + Doctrine_DBAL_Connection $conn, + $name, + Doctrine_ORM_Configuration $config, Doctrine_Common_EventManager $eventManager) { $this->_conn = $conn; @@ -183,7 +195,7 @@ class Doctrine_ORM_EntityManager } /** - * Starts a database transaction. + * Starts a transaction on the underlying connection. */ public function beginTransaction() { @@ -191,11 +203,11 @@ class Doctrine_ORM_EntityManager } /** - * Commits a running database transaction. + * Commits a running transaction. * This causes a flush() of the EntityManager if the flush mode is set to * AUTO or COMMIT. * - * @return unknown + * @return boolean */ public function commit() { @@ -275,7 +287,7 @@ class Doctrine_ORM_EntityManager { if ( ! isset($this->_persisters[$entityName])) { $class = $this->getClassMetadata($entityName); - if ($class->getInheritanceType() == Doctrine_ORM_Mapping_ClassMetadata::INHERITANCE_TYPE_JOINED) { + if ($class->isInheritanceTypeJoined()) { $persister = new Doctrine_EntityPersister_JoinedSubclass($this, $class); } else { $persister = new Doctrine_ORM_Persisters_StandardEntityPersister($this, $class); @@ -288,8 +300,8 @@ class Doctrine_ORM_EntityManager /** * Detaches an entity from the manager. It's lifecycle is no longer managed. * - * @param Doctrine_Entity $entity - * @return unknown + * @param Doctrine\ORM\Entity $entity + * @return boolean */ public function detach(Doctrine_ORM_Entity $entity) { @@ -342,11 +354,11 @@ class Doctrine_ORM_EntityManager /** * Finds an Entity by its identifier. - * This is just a convenient shortcut for getRepository()->find(). + * This is just a convenient shortcut for getRepository($entityName)->find($id). * * @param string $entityName * @param mixed $identifier - * @return Doctrine::ORM::Entity + * @return Doctrine\ORM\Entity */ public function find($entityName, $identifier) { @@ -391,23 +403,19 @@ class Doctrine_ORM_EntityManager } /** - * Clears the persistence context, detaching all entities. - * - * @return void - * @todo package:orm + * Clears the persistence context, effectively detaching all managed entities. */ public function clear($entityName = null) { if ($entityName === null) { $this->_unitOfWork->detachAll(); } else { - //... + //TODO } } /** * Closes the EntityManager. - * */ public function close() { @@ -418,7 +426,6 @@ class Doctrine_ORM_EntityManager * Saves the given entity, persisting it's state. * * @param Doctrine\ORM\Entity $entity - * @return void */ public function save(Doctrine_ORM_Entity $entity) { @@ -430,10 +437,9 @@ class Doctrine_ORM_EntityManager } /** - * Removes the given entity from the persistent store. + * Deletes the persistent state of the given entity. * * @param Doctrine\ORM\Entity $entity - * @return void */ public function delete(Doctrine_ORM_Entity $entity) { @@ -448,8 +454,7 @@ class Doctrine_ORM_EntityManager * Refreshes the persistent state of the entity from the database, * overriding any local changes that have not yet been persisted. * - * @param Doctrine::ORM::Entity $entity - * @return void + * @param Doctrine\ORM\Entity $entity * @todo FIX Impl */ public function refresh(Doctrine_ORM_Entity $entity) @@ -462,8 +467,8 @@ class Doctrine_ORM_EntityManager /** * Creates a copy of the given entity. Can create a shallow or a deep copy. * - * @param Doctrine::ORM::Entity $entity The entity to copy. - * @return Doctrine::ORM::Entity The new entity. + * @param Doctrine\ORM\Entity $entity The entity to copy. + * @return Doctrine\ORM\Entity The new entity. */ public function copy(Doctrine_ORM_Entity $entity, $deep = false) { @@ -474,7 +479,7 @@ class Doctrine_ORM_EntityManager * Gets the repository for an Entity. * * @param string $entityName The name of the Entity. - * @return Doctrine::ORM::EntityRepository The repository. + * @return Doctrine\ORM\EntityRepository The repository. */ public function getRepository($entityName) { @@ -497,7 +502,7 @@ class Doctrine_ORM_EntityManager /** * Checks if the instance is managed by the EntityManager. * - * @param Doctrine::ORM::Entity $entity + * @param Doctrine\ORM\Entity $entity * @return boolean TRUE if this EntityManager currently manages the given entity * (and has it in the identity map), FALSE otherwise. */ @@ -552,6 +557,8 @@ class Doctrine_ORM_EntityManager /** * Checks whether this EntityManager is the currently active one. * + * Note:This is only useful in scenarios where {@link ActiveEntity}s are used. + * * @return boolean */ public function isActive() @@ -562,7 +569,7 @@ class Doctrine_ORM_EntityManager /** * Makes this EntityManager the currently active one. * - * @return void + * Note: This is only useful in scenarios where {@link ActiveEntity}s are used. */ public function activate() { @@ -582,7 +589,10 @@ class Doctrine_ORM_EntityManager * @param EventManager $eventManager The EventManager instance to use. * @return EntityManager The created EntityManager. */ - public static function create($conn, $name, Doctrine_ORM_Configuration $config = null, + public static function create( + $conn, + $name, + Doctrine_ORM_Configuration $config = null, Doctrine_Common_EventManager $eventManager = null) { if (is_array($conn)) { @@ -607,6 +617,8 @@ class Doctrine_ORM_EntityManager /** * Static lookup to get the currently active EntityManager. * + * Note: Used by {@link ActiveEntity}s to actively lookup an EntityManager. + * * @return Doctrine\ORM\EntityManager */ public static function getActiveEntityManager() diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php index 6165b23a0..ef4c18582 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php @@ -55,7 +55,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver public function getElementCollection($component) { - $coll = new Doctrine_ORM_Collection($component); + $coll = new Doctrine_ORM_Collection($this->_em, $component); $this->_collections[] = $coll; return $coll; } diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index 3880c30b8..ace51c094 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -1,6 +1,6 @@ . */ -#namespace Doctrine::ORM; +#namespace Doctrine\ORM; /** * A Doctrine_ORM_Query object represents a DQL query. It is used to query databases for @@ -28,7 +28,7 @@ * and is dbms independant. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 1.0 * @version $Revision: 3938 $ * @author Guilherme Blanco @@ -60,17 +60,17 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract const HYDRATE_NONE = 5; /** - * @var Doctrine_ORM_EntityManager The entity manager used by this query object. + * @var Doctrine\ORM\EntityManager The entity manager used by this query object. */ protected $_entityManager; /** - * @var Doctrine_ORM_Internal_Hydration The hydrator object used to hydrate query results. + * @var Doctrine\ORM\Internal\Hydrator The hydrator object used to hydrate query results. */ protected $_hydrator; /** - * @var Doctrine_ORM_Query_ParserResult The parser result that holds DQL => SQL information. + * @var Doctrine\ORM\Query\ParserResult The parser result that holds DQL => SQL information. */ protected $_parserResult; @@ -120,20 +120,19 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract /** * Initializes a new instance of the Query class. * - * @param EntityManager $entityManager + * @param Doctrine\ORM\EntityManager $entityManager */ public function __construct(Doctrine_ORM_EntityManager $entityManager) { $this->_entityManager = $entityManager; $this->_hydrator = new Doctrine_ORM_Internal_Hydration_StandardHydrator($entityManager); - $this->free(); } /** * Retrieves the assocated EntityManager to this Doctrine_ORM_Query * - * @return Doctrine_EntityManager + * @return Doctrine\ORM\EntityManager */ public function getEntityManager() { @@ -143,7 +142,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract /** * Returns the hydrator associated with this query object * - * @return Doctrine_ORM_Internal_Hydration The hydrator associated with this query object + * @return Doctrine\ORM\Internal\StandardHydrator The hydrator associated with this query object */ public function getHydrator() { @@ -166,7 +165,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract * * @param string $params Parameters * @param int $hydrationMode Hydration mode - * @return mixed Array or Doctrine_Collection or false if no result. + * @return mixed Array or Doctrine\Common\Collection or false if no result. */ public function fetchOne($params = array(), $hydrationMode = null) { @@ -191,7 +190,6 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract * @param string $query DQL query * @param array $params prepared statement parameters * @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD - * @see Doctrine::FETCH_* constants * @return mixed */ public function query($query, $params = array(), $hydrationMode = null) diff --git a/lib/Doctrine/ORM/Query/CacheHandler.php b/lib/Doctrine/ORM/Query/CacheHandler.php index 59b9af762..d271f99ef 100644 --- a/lib/Doctrine/ORM/Query/CacheHandler.php +++ b/lib/Doctrine/ORM/Query/CacheHandler.php @@ -1,5 +1,4 @@ . */ +#namespace Doctrine\ORM\Query; + /** * Doctrine_ORM_Query_CacheHandler * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.com - * @since 1.0 + * @link www.doctrine-project.com + * @since 2.0 * @version $Revision: 1393 $ * @author Guilherme Blanco * @author Konsta Vesterinen diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 22585bc45..0f468e59a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -650,19 +650,28 @@ class Doctrine_ORM_UnitOfWork public function getEntityState($entity) { $oid = spl_object_hash($entity); - return isset($this->_entityStates[$oid]) ? $this->_entityStates[$oid] : self::STATE_NEW; + if ( ! isset($this->_entityStates[$oid])) { + if (isset($this->_entityIdentifiers[$oid])) { + $this->_entityStates[$oid] = self::STATE_DETACHED; + } else { + $this->_entityStates[$oid] = self::STATE_NEW; + } + } + return $this->_entityStates[$oid]; } /** - * Removes an entity from the identity map. + * Removes an entity from the identity map. This effectively detaches the + * entity from the persistence management of Doctrine. * * @param Doctrine\ORM\Entity $entity * @return boolean */ public function removeFromIdentityMap($entity) { + $oid = spl_object_hash($entity); $classMetadata = $this->_em->getClassMetadata(get_class($entity)); - $idHash = $this->getIdentifierHash($this->_entityIdentifiers[spl_object_hash($entity)]); + $idHash = $this->getIdentifierHash($this->_entityIdentifiers[$oid]); if ($idHash === '') { throw new Doctrine_Exception("Entity with oid '" . spl_object_hash($entity) . "' has no identity and therefore can't be removed from the identity map."); @@ -670,6 +679,7 @@ class Doctrine_ORM_UnitOfWork $className = $classMetadata->getRootClassName(); if (isset($this->_identityMap[$className][$idHash])) { unset($this->_identityMap[$className][$idHash]); + $this->_entityStates[$oid] = self::STATE_DETACHED; return true; } @@ -677,7 +687,7 @@ class Doctrine_ORM_UnitOfWork } /** - * Finds an entity in the identity map by its identifier hash. + * Gets an entity in the identity map by its identifier hash. * * @param string $idHash * @param string $rootClassName @@ -692,8 +702,8 @@ class Doctrine_ORM_UnitOfWork * Tries to get an entity by its identifier hash. If no entity is found for * the given hash, FALSE is returned. * - * @param $idHash - * @param $rootClassName + * @param string $idHash + * @param string $rootClassName * @return mixed The found entity or FALSE. */ public function tryGetByIdHash($idHash, $rootClassName) @@ -760,7 +770,7 @@ class Doctrine_ORM_UnitOfWork /** * Saves an entity as part of the current unit of work. * - * @param Doctrine_ORM_Entity $entity The entity to save. + * @param Doctrine\ORM\Entity $entity The entity to save. */ public function save($entity) { @@ -775,7 +785,7 @@ class Doctrine_ORM_UnitOfWork foreach ($commitOrder as $class) { $this->_executeInserts($class); } - // remove them from _newEntities + // remove them from _newEntities and _dataChangeSets $this->_newEntities = array_diff_key($this->_newEntities, $insertNow); $this->_dataChangeSets = array_diff_key($this->_dataChangeSets, $insertNow); } @@ -786,8 +796,8 @@ class Doctrine_ORM_UnitOfWork * This method is internally called during save() cascades as it tracks * the already visited entities to prevent infinite recursions. * - * @param Doctrine_ORM_Entity $entity The entity to save. - * @param array $visited The already visited entities. + * @param Doctrine\ORM\Entity $entity The entity to save. + * @param array $visited The already visited entities. */ private function _doSave($entity, array &$visited, array &$insertNow) { @@ -909,33 +919,61 @@ class Doctrine_ORM_UnitOfWork } } + /** + * Cascades the delete operation to associated entities. + * + * @param Doctrine\ORM\Entity $entity + */ private function _cascadeDelete($entity) { - + $class = $this->_em->getClassMetadata(get_class($entity)); + foreach ($class->getAssociationMappings() as $assocMapping) { + if ( ! $assocMapping->isCascadeDelete()) { + continue; + } + $relatedEntities = $class->getReflectionProperty($assocMapping->getSourceFieldName()) + ->getValue($entity); + if ($relatedEntities instanceof Doctrine_ORM_Collection && + count($relatedEntities) > 0) { + foreach ($relatedEntities as $relatedEntity) { + $this->_doDelete($relatedEntity, $visited, $insertNow); + } + } else if (is_object($relatedEntities)) { + $this->_doDelete($relatedEntities, $visited, $insertNow); + } + } } - + + /** + * Gets the CommitOrderCalculator used by the UnitOfWork to order commits. + * + * @return Doctrine\ORM\Internal\CommitOrderCalculator + */ public function getCommitOrderCalculator() { return $this->_commitOrderCalculator; } + /** + * Closes the UnitOfWork. + */ public function close() { //... $this->_commitOrderCalculator->clear(); } - public function scheduleCollectionUpdate(Doctrine_Collection $coll) + public function scheduleCollectionUpdate(Doctrine_ORM_Collection $coll) { $this->_collectionUpdates[] = $coll; } - public function isCollectionScheduledForUpdate(Doctrine_Collection $coll) + public function isCollectionScheduledForUpdate(Doctrine_ORM_Collection $coll) { //... } - public function scheduleCollectionDeletion(Doctrine_Collection $coll) + public function scheduleCollectionDeletion(Doctrine_ORM_Collection $coll) { //TODO: if $coll is already scheduled for recreation ... what to do? // Just remove $coll from the scheduled recreations? @@ -1097,7 +1135,9 @@ class Doctrine_ORM_UnitOfWork * INTERNAL: * For hydration purposes only. * - * Adds a managed collection to the UnitOfWork. + * Adds a managed collection to the UnitOfWork. On commit time, the UnitOfWork + * checks all these managed collections for modifications and then initiates + * the appropriate database synchronization. * * @param Doctrine\ORM\Collection $coll */ diff --git a/tests/AllTests.php b/tests/AllTests.php index e243bfb4d..d22a41e5b 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -1,4 +1,5 @@ addTestSuite('Orm_UnitOfWorkTest'); $suite->addTestSuite('Orm_EntityManagerTest'); $suite->addTestSuite('Orm_EntityPersisterTest'); + $suite->addTestSuite('Orm_CommitOrderCalculatorTest'); - $suite->addTest(Orm_Component_AllTests::suite()); $suite->addTest(Orm_Query_AllTests::suite()); $suite->addTest(Orm_Hydration_AllTests::suite()); $suite->addTest(Orm_Entity_AllTests::suite()); diff --git a/tests/Orm/Internal/CommitOrderCalculatorTest.php b/tests/Orm/CommitOrderCalculatorTest.php similarity index 82% rename from tests/Orm/Internal/CommitOrderCalculatorTest.php rename to tests/Orm/CommitOrderCalculatorTest.php index 184e99d8f..21a1161f3 100644 --- a/tests/Orm/Internal/CommitOrderCalculatorTest.php +++ b/tests/Orm/CommitOrderCalculatorTest.php @@ -8,20 +8,21 @@ require_once 'lib/DoctrineTestInit.php'; * can have many valid orderings, so you may want to build a graph that has only * 1 valid order to simplify your tests. */ -class Orm_Internal_CommitOrderCalculatorTest extends Doctrine_OrmTestCase +class Orm_CommitOrderCalculatorTest extends Doctrine_OrmTestCase { private $_calc; protected function setUp() { - $this->_calc = new Doctrine_Internal_CommitOrderCalculator(); + $this->_calc = new Doctrine_ORM_Internal_CommitOrderCalculator(); } - + + /** Helper to create an array of nodes */ private function _createNodes(array $names) { $nodes = array(); foreach ($names as $name) { - $node = new Doctrine_Internal_CommitOrderNode($name, $this->_calc); + $node = new Doctrine_ORM_Internal_CommitOrderNode($name, $this->_calc); $nodes[$name] = $node; $this->_calc->addNode($node->getClass(), $node); } @@ -46,6 +47,4 @@ class Orm_Internal_CommitOrderCalculatorTest extends Doctrine_OrmTestCase $this->assertSame($correctOrder, $sorted); } - - } diff --git a/tests/Orm/Component/AccessTest.php b/tests/Orm/Component/AccessTest.php deleted file mode 100644 index da1394879..000000000 --- a/tests/Orm/Component/AccessTest.php +++ /dev/null @@ -1,189 +0,0 @@ -. - */ - -/** - * Testcase for basic accessor/mutator functionality. - * - * @package Doctrine - * @author Bjarte Stien Karlsen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 2.0 - * @version $Revision: 3754 $ - */ -require_once 'lib/DoctrineTestInit.php'; - -class AccessStub extends Doctrine_Access {} - -class Orm_Component_AccessTest extends Doctrine_OrmTestCase -{ - - private $user; - - public function setUp() - { - parent::setUp(); - $this->user = new ForumUser(); - } - - /*public function testAccessorOverridePerformance() { - $this->user->username; - $start = microtime(true); - for ($i = 0; $i < 1; $i++) { - $this->user->username; - } - $end = microtime(true); - echo ($end - $start) . " seconds" . PHP_EOL; - }*/ - - /** - * @test - */ - public function shouldMarkEmptyFieldAsNotSetOnNewRecord() - { - $this->assertFalse(isset($this->user->username)); - $this->assertFalse(isset($this->user['username'])); - } - - /** - * @test - */ - public function shouldMarkNonExistantFieldAsNotSetOnNewRecord() - { - $this->assertFalse(isset($this->user->rat)); - $this->assertFalse(isset($this->user['rat'])); - } - - /** - * @test - */ - public function shouldSetSingleValueInRecord() - { - $this->user->username = 'meus'; - $this->assertEquals('meus', $this->user->username); - $this->assertEquals('meus', $this->user['username']); - } - - - /** - * @test - */ - public function shouldSetSingleValueInRecordWithOffset() - { - $this->user['username'] ='meus'; - $this->assertEquals('meus', $this->user->username); - $this->assertEquals('meus', $this->user['username']); - } - - - /** - * @test - * @expectedException Doctrine_ORM_Exceptions_EntityException - */ - public function shouldNotBeAbleToSetNonExistantField() - { - $this->user->rat = 'meus'; - } - - /** - * @test - * @expectedException Doctrine_ORM_Exceptions_EntityException - */ - public function shouldNotBeAbleToSetNonExistantFieldWithOffset() - { - $this->user['rat'] = 'meus'; - } - - - /** - * @test - */ - public function newCollectionShouldBeEmpty() - { - $col = new Doctrine_Collection('ForumUser'); - $this->assertEquals(0, count($col)); - $this->assertFalse(isset($coll[0])); - } - - /** - * @test - */ - public function shouldBeAbleToUnsetWithOffsetFromCollection() - { - $col = new Doctrine_Collection('ForumUser'); - $col[0] = new ForumUser(); - $this->assertTrue(isset($col[0])); - unset($col[0]); - $this->assertFalse(isset($col[0])); - } - /** - * @test - */ - - public function shouldBeAbleToUnsetFromCollection() - { - $col = new Doctrine_Collection('ForumUser'); - $col->test = new ForumUser(); - $this->assertTrue(isset($col->test)); - unset($col->test); - $this->assertFalse(isset($col->test)); - } - - /** - * @test - * @expectedException Doctrine_Exception - */ - public function shouldNotBeAbleToUseContainsWhenNotImplemented() - { - $stub = new AccessStub(); - isset($stub['foo']); - } - - /** - * @test - * @expectedException Doctrine_Exception - */ - public function shouldNotBeAbleToUseSetWhenNotImplemented() - { - $stub = new AccessStub(); - $stub['foo'] = 'foo'; - } - - /** - * @test - * @expectedException Doctrine_Exception - */ - public function shouldNotBeAbleToUseUnsetWhenNotImplemented() - { - $stub = new AccessStub(); - unset($stub['foo']); - } - - /** - * @test - * @expectedException Doctrine_Exception - */ - public function shouldNotBeAbleToUseGetWhenNotImplemented() - { - $stub = new AccessStub(); - $stub['foo']; - } -} diff --git a/tests/Orm/Component/AllTests.php b/tests/Orm/Component/AllTests.php deleted file mode 100644 index 08e3f55e5..000000000 --- a/tests/Orm/Component/AllTests.php +++ /dev/null @@ -1,32 +0,0 @@ -addTestSuite('Orm_Component_AccessTest'); - $suite->addTestSuite('Orm_Component_CollectionTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Component_AllTests::main') { - Orm_Component_AllTests::main(); -} diff --git a/tests/Orm/Component/CollectionTest.php b/tests/Orm/Component/CollectionTest.php deleted file mode 100644 index ab85af23c..000000000 --- a/tests/Orm/Component/CollectionTest.php +++ /dev/null @@ -1,130 +0,0 @@ -. - */ - -/** - * Doctrine - * the base class of Doctrine framework - * - * @package Doctrine - * @author Bjarte Stien Karlsen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 2.0 - * @version $Revision: 3754 $ - */ -require_once 'lib/DoctrineTestInit.php'; - -class Orm_Component_CollectionTest extends Doctrine_OrmTestCase -{ - - private $coll; - - public function setUp() - { - parent::setUp(); - - $this->coll = new Doctrine_ORM_Collection('ForumUser'); - - //we create a CmsUser with username as key column and add a user to it - $cmsColl = new Doctrine_ORM_Collection('CmsUser', 'username'); - $user = new CmsUser(); - $user->username ='test'; - $cmsColl[] = $user; - $this->cmsColl = $cmsColl; - $this->cmsUser = $user; - - } - - /** - * @test - */ - public function shouldHaveBlankAsDefaultKeyColumn() - { - $this->assertEquals('', $this->coll->getKeyField()); - } - - - /** - * @test - */ - public function shouldUseSpecifiedKeyColumn() - { - $coll = new Doctrine_ORM_Collection('ForumUser', 'id'); - $this->assertEquals('id', $coll->getKeyField()); - } - - /** - * This test is currently failing. I do not understand why it should be - * possible to set this to something that is not valid. - * - * @test - * @expectedException Doctrine_Exception - */ - public function shouldThrowExceptionIfNonValidFieldSetAsKey() - { - $coll = new Doctrine_ORM_Collection('ForumUser', 'xxNonValidFieldxx'); - } - - /** - * @test - */ - public function shouldSerializeEmptyCollection() - { - $serialized = serialize($this->coll); - $this->assertTrue(is_string($serialized)); - } - - /** - * @test - */ - public function shouldUnserializeEmptyCollectionIntoObject() - { - $serialized = serialize($this->coll); - $coll = unserialize($serialized); - $this->assertEquals('Doctrine_ORM_Collection', get_class($coll)); - } - - /** - * @test - */ - /*public function shouldSetKeyColumnWhenAddingNewRowAsArray() - { - $this->assertTrue(isset($this->cmsColl['test'])); - $this->assertEquals($this->cmsUser, $this->cmsColl['test']); - }*/ - - - /** - * @test - */ - /*public function shouldSerializeAndUnserializeCollectionWithData() - { - $serialized = serialize($this->cmsColl); - $coll = unserialize($serialized); - - $this->assertEquals('username', $coll->getKeyField()); - $this->assertTrue(isset($coll['test'])); - $user = $coll['test']; - $this->assertTrue($user instanceOf CmsUser); - $this->assertEquals('test', $user['username']); - }*/ - -} diff --git a/tests/Orm/Entity/AccessorTest.php b/tests/Orm/Entity/AccessorTest.php index 964226e95..971e13573 100644 --- a/tests/Orm/Entity/AccessorTest.php +++ b/tests/Orm/Entity/AccessorTest.php @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/tests/Orm/EntityManagerFactoryTest.php b/tests/Orm/EntityManagerFactoryTest.php deleted file mode 100644 index 52bfa885b..000000000 --- a/tests/Orm/EntityManagerFactoryTest.php +++ /dev/null @@ -1,35 +0,0 @@ - 'mock', 'user' => '', 'password' => ''); - - protected function tearDown() { - parent::tearDown(); - } - - private function _createNamedManager($name) - { - return $this->_emf->createEntityManager($this->_mockOptions, $name); - } - - /*public function testBindingEntityToNamedManager() - { - $myEM = $this->_createNamedManager('myEM'); - $this->_emf->bindEntityToManager('SomeEntity', 'myEM'); - $this->assertSame($myEM, $this->_emf->getEntityManager('SomeEntity')); - $this->_emf->releaseEntityManager($myEM); - } - - public function testStaticLookup() - { - $this->assertTrue(Doctrine_EntityManagerFactory::getManager() instanceof Doctrine_EntityManager); - }*/ - -} \ No newline at end of file diff --git a/tests/Orm/EntityManagerTest.php b/tests/Orm/EntityManagerTest.php index 7ef9d9282..ed05be45d 100644 --- a/tests/Orm/EntityManagerTest.php +++ b/tests/Orm/EntityManagerTest.php @@ -1,13 +1,20 @@ _em = $this->_getTestEntityManager(); + } + public function testSettingInvalidFlushModeThrowsException() { $prev = $this->_em->getFlushMode(); diff --git a/tests/Orm/Hydration/BasicHydrationTest.php b/tests/Orm/Hydration/BasicHydrationTest.php index a80e91add..47f629eb2 100644 --- a/tests/Orm/Hydration/BasicHydrationTest.php +++ b/tests/Orm/Hydration/BasicHydrationTest.php @@ -6,10 +6,13 @@ require_once 'lib/DoctrineTestInit.php'; require_once 'lib/mocks/Doctrine_HydratorMockStatement.php'; class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase -{ +{ + private $_em; + protected function setUp() { parent::setUp(); + $this->_em = $this->_getTestEntityManager(); } /** Getter for the hydration mode dataProvider */ diff --git a/tests/Orm/Query/IdentifierRecognitionTest.php b/tests/Orm/Query/IdentifierRecognitionTest.php index da17737d7..535ca456f 100755 --- a/tests/Orm/Query/IdentifierRecognitionTest.php +++ b/tests/Orm/Query/IdentifierRecognitionTest.php @@ -36,6 +36,12 @@ require_once 'lib/DoctrineTestInit.php'; */ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase { + private $_em; + + protected function setUp() { + parent::setUp(); + $this->_em = $this->_getTestEntityManager(); + } public function testSingleAliasDeclarationIsSupported() { diff --git a/tests/Orm/UnitOfWorkTest.php b/tests/Orm/UnitOfWorkTest.php index 350f65fa7..cf91d84d0 100644 --- a/tests/Orm/UnitOfWorkTest.php +++ b/tests/Orm/UnitOfWorkTest.php @@ -1,4 +1,7 @@ _connectionMock = new Doctrine_ConnectionMock(array()); $this->_emMock = Doctrine_EntityManagerMock::create($this->_connectionMock, "uowMockEm"); - // SUT $this->_unitOfWork = new Doctrine_UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); @@ -136,6 +134,7 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase // Fake managed state $this->_unitOfWork->setEntityState($user2, Doctrine_ORM_UnitOfWork::STATE_MANAGED); + // Fake original entity date $this->_unitOfWork->setOriginalEntityData($user1, array( 'id' => 1, 'username' => 'roman' )); @@ -143,8 +142,10 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase 'id' => 2, 'username' => 'jon' )); + // Go $this->_unitOfWork->computeDataChangeSet(array($user1, $user2)); + // Verify $user1ChangeSet = $this->_unitOfWork->getDataChangeSet($user1); $this->assertTrue(is_array($user1ChangeSet)); $this->assertEquals(2, count($user1ChangeSet)); diff --git a/tests/lib/DoctrineTestInit.php b/tests/lib/DoctrineTestInit.php index 5501434c0..fdf4197ad 100644 --- a/tests/lib/DoctrineTestInit.php +++ b/tests/lib/DoctrineTestInit.php @@ -1,8 +1,10 @@ sharedFixture['conn'])) { - $this->_conn = $this->sharedFixture['conn']; - } else { - $this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection(); - $this->_conn = $this->sharedFixture['conn']; - } - } } \ No newline at end of file diff --git a/tests/lib/Doctrine_DbalTestSuite.php b/tests/lib/Doctrine_DbalTestSuite.php index cd3ec889a..f3554ec97 100644 --- a/tests/lib/Doctrine_DbalTestSuite.php +++ b/tests/lib/Doctrine_DbalTestSuite.php @@ -1,19 +1,10 @@ -sharedFixture['conn'] = Doctrine_TestUtil::getConnection(); - } - - protected function tearDown() - {} +{ } \ No newline at end of file diff --git a/tests/lib/Doctrine_OrmFunctionalTestCase.php b/tests/lib/Doctrine_OrmFunctionalTestCase.php index bdff985df..32735f758 100644 --- a/tests/lib/Doctrine_OrmFunctionalTestCase.php +++ b/tests/lib/Doctrine_OrmFunctionalTestCase.php @@ -1,4 +1,7 @@ sharedFixture['em'])) { - $this->_em = $this->sharedFixture['em']; - } else { - $config = new Doctrine_ORM_Configuration(); - $eventManager = new Doctrine_Common_EventManager(); - $connectionOptions = array( + /** + * Creates an EntityManager for testing purposes. + * + * @return Doctrine\ORM\EntityManager + */ + protected function _getTestEntityManager($conf = null, $eventManager = null) { + $config = new Doctrine_ORM_Configuration(); + $eventManager = new Doctrine_Common_EventManager(); + $connectionOptions = array( 'driverClass' => 'Doctrine_DriverMock', 'wrapperClass' => 'Doctrine_ConnectionMock', 'user' => 'john', - 'password' => 'wayne' - ); - $em = Doctrine_ORM_EntityManager::create($connectionOptions, 'mockEM', $config, $eventManager); - $this->_em = $em; - } - $this->_em->activate(); + 'password' => 'wayne' + ); + return Doctrine_ORM_EntityManager::create($connectionOptions, 'mockEM', $config, $eventManager); } } diff --git a/tests/lib/Doctrine_OrmTestSuite.php b/tests/lib/Doctrine_OrmTestSuite.php index cb81e1a8c..4461e315f 100644 --- a/tests/lib/Doctrine_OrmTestSuite.php +++ b/tests/lib/Doctrine_OrmTestSuite.php @@ -1,27 +1,10 @@ - 'Doctrine_DriverMock', - 'wrapperClass' => 'Doctrine_ConnectionMock', - 'user' => 'john', - 'password' => 'wayne' - ); - $em = Doctrine_ORM_EntityManager::create($connectionOptions, 'mockEM', $config, $eventManager); - $this->sharedFixture['em'] = $em; - } - - protected function tearDown() - {} } \ No newline at end of file diff --git a/tests/lib/Doctrine_TestCase.php b/tests/lib/Doctrine_TestCase.php index 4d89cdfe9..36a415bf2 100644 --- a/tests/lib/Doctrine_TestCase.php +++ b/tests/lib/Doctrine_TestCase.php @@ -1,8 +1,10 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_ConnectionMock.php b/tests/lib/mocks/Doctrine_ConnectionMock.php index 1866be7ad..75a7d2fb6 100644 --- a/tests/lib/mocks/Doctrine_ConnectionMock.php +++ b/tests/lib/mocks/Doctrine_ConnectionMock.php @@ -1,5 +1,9 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_DatabasePlatformMock.php b/tests/lib/mocks/Doctrine_DatabasePlatformMock.php index 7f9273e45..b21edbefa 100644 --- a/tests/lib/mocks/Doctrine_DatabasePlatformMock.php +++ b/tests/lib/mocks/Doctrine_DatabasePlatformMock.php @@ -1,5 +1,9 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_DriverConnectionMock.php b/tests/lib/mocks/Doctrine_DriverConnectionMock.php index 3c1a56963..ff2a035cd 100644 --- a/tests/lib/mocks/Doctrine_DriverConnectionMock.php +++ b/tests/lib/mocks/Doctrine_DriverConnectionMock.php @@ -1,5 +1,7 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_DriverMock.php b/tests/lib/mocks/Doctrine_DriverMock.php index 91e29916a..6559fb2a0 100644 --- a/tests/lib/mocks/Doctrine_DriverMock.php +++ b/tests/lib/mocks/Doctrine_DriverMock.php @@ -1,5 +1,7 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_EntityPersisterMock.php b/tests/lib/mocks/Doctrine_EntityPersisterMock.php index 65d02dd71..47a65bd63 100644 --- a/tests/lib/mocks/Doctrine_EntityPersisterMock.php +++ b/tests/lib/mocks/Doctrine_EntityPersisterMock.php @@ -1,4 +1,7 @@ _mockPostInsertId = $id; } } -?> + diff --git a/tests/lib/mocks/Doctrine_SequenceMock.php b/tests/lib/mocks/Doctrine_SequenceMock.php index 07ddcbe42..fa7b91da0 100644 --- a/tests/lib/mocks/Doctrine_SequenceMock.php +++ b/tests/lib/mocks/Doctrine_SequenceMock.php @@ -1,5 +1,7 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_UnitOfWorkMock.php b/tests/lib/mocks/Doctrine_UnitOfWorkMock.php index 400a2dd17..eab783d82 100644 --- a/tests/lib/mocks/Doctrine_UnitOfWorkMock.php +++ b/tests/lib/mocks/Doctrine_UnitOfWorkMock.php @@ -1,8 +1,6 @@ mapField(array( diff --git a/tests/models/forum/ForumBoard.php b/tests/models/forum/ForumBoard.php index 33df36708..e47e0e367 100755 --- a/tests/models/forum/ForumBoard.php +++ b/tests/models/forum/ForumBoard.php @@ -1,4 +1,7 @@ mapField(array( @@ -33,4 +28,3 @@ class ForumEntry extends Doctrine_ORM_Entity } -?> \ No newline at end of file diff --git a/tests/models/forum/ForumUser.php b/tests/models/forum/ForumUser.php index 15185228e..3eda669c6 100644 --- a/tests/models/forum/ForumUser.php +++ b/tests/models/forum/ForumUser.php @@ -1,9 +1,8 @@