Revert "[TASK] Make current persistence replaceable"
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Mon, 1 Apr 2013 13:28:26 +0000 (15:28 +0200)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Mon, 1 Apr 2013 13:41:47 +0000 (15:41 +0200)
This reverts commit 4d4b047e8eca2cfd86eef94954066f292277394f.

Conflicts:
Classes/Persistence/Generic/PersistenceManager.php
Tests/Unit/Persistence/RepositoryTest.php

Resolves: #46837
Releases: 6.1
Change-Id: I87914c6786d75ce217993cb6a70721b821bd0647
Reviewed-on: https://review.typo3.org/19488
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
16 files changed:
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php
typo3/sysext/extbase/Classes/Persistence/PersistenceManagerInterface.php
typo3/sysext/extbase/Classes/Persistence/Repository.php
typo3/sysext/extbase/Classes/Persistence/RepositoryInterface.php
typo3/sysext/extbase/Classes/Property/Mapper.php
typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php
typo3/sysext/extbase/Classes/Utility/DebuggerUtility.php
typo3/sysext/extbase/Tests/Unit/Domain/Repository/BackendUserGroupRepositoryTest.php
typo3/sysext/extbase/Tests/Unit/Domain/Repository/BackendUserRepositoryTest.php
typo3/sysext/extbase/Tests/Unit/Domain/Repository/CategoryRepositoryTest.php
typo3/sysext/extbase/Tests/Unit/Domain/Repository/FileMountRepositoryTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/PersistenceManagerTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryResultTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php

index 9b737d8..dbd9f3e 100644 (file)
@@ -71,7 +71,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface {
        protected $reflectionService;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
         */
        protected $persistenceManager;
 
@@ -180,7 +180,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface {
         * @see initialize()
         */
        public function initializePersistence() {
-               $this->persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $this->persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
        }
 
        /**
index 3c7635e..39360ea 100644 (file)
@@ -50,56 +50,11 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
        protected $objectManager;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface
-        */
-       protected $queryFactory;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
-        */
-       protected $defaultQuerySettings = NULL;
-
-       /**
-        * Objects of this repository
-        *
-        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
-        */
-       protected $addedObjects;
-
-       /**
-        * Objects removed but not found in $this->addedObjects at removal time
-        *
-        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
-        */
-       protected $removedObjects;
-
-       public function initializeObject() {
-               $this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $this->removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-       }
-
-       /**
-        * Returns all addedObjects that have been added to this repository with add().
+        * This is an array of registered repository class names.
         *
-        * This is a service method for the persistence manager to get all addedObjects
-        * added to the repository. Those are only objects *added*, not objects
-        * fetched from the underlying storage.
-        *
-        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage the objects
-        */
-       public function getAddedObjects() {
-               return $this->addedObjects;
-       }
-
-       /**
-        * Returns an \TYPO3\CMS\Extbase\Persistence\ObjectStorage with objects remove()d from the repository
-        * that had been persisted to the storage layer before.
-        *
-        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage the objects
+        * @var array
         */
-       public function getRemovedObjects() {
-               return $this->removedObjects;
-       }
+       protected $repositoryClassNames = array();
 
        /**
         * Injects the Persistence Backend
@@ -132,11 +87,13 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface $queryFactory
+        * Registers a repository
+        *
+        * @param string $className The class name of the repository to be reigistered
         * @return void
         */
-       public function injectQueryFactory(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface $queryFactory) {
-               $this->queryFactory = $queryFactory;
+       public function registerRepositoryClassName($className) {
+               $this->repositoryClassNames[] = $className;
        }
 
        /**
@@ -183,7 +140,7 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         *
         * @param mixed $identifier
         * @param string $objectType
-        * @param boolean $useLazyLoading
+        * @param boolean $useLazyLoading Set to TRUE if you want to use lazy loading for this object
         * @return object The object for the identifier if it is known, or NULL
         * @api
         */
@@ -201,10 +158,12 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
        public function persistAll() {
                $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                $removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-
-               $aggregateRootObjects->addAll($this->getAddedObjects());
-               $removedObjects->addAll($this->getRemovedObjects());
-
+               // fetch and inspect objects from all known repositories
+               foreach ($this->repositoryClassNames as $repositoryClassName) {
+                       $repository = $this->objectManager->get($repositoryClassName);
+                       $aggregateRootObjects->addAll($repository->getAddedObjects());
+                       $removedObjects->addAll($repository->getRemovedObjects());
+               }
                foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) {
                        $className = get_class($reconstitutedObject);
                        $delimiter = strpos($className, '_') !== FALSE ? '_' : '\\';
@@ -232,13 +191,11 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         *
         * @param object $object The object to add
         * @return void
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @api
         */
        public function add($object) {
-               $this->addedObjects->attach($object);
-               if ($this->removedObjects->contains($object)) {
-                       $this->removedObjects->detach($object);
-               }
+               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
        }
 
        /**
@@ -246,16 +203,11 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         *
         * @param object $object The object to remove
         * @return void
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @api
         */
        public function remove($object) {
-               if ($this->addedObjects->contains($object)) {
-                       $this->addedObjects->detach($object);
-               }
-
-               if (!$object->_isNew()) {
-                       $this->removedObjects->attach($object);
-               }
+               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
        }
 
        /**
@@ -263,25 +215,20 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         *
         * @param object $object The modified object
         * @return void
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
         * @api
         */
        public function update($object) {
-               $uid = $object->getUid();
-               if ($uid !== NULL) {
-                       $existingObject = $this->getObjectByIdentifier($uid, get_class($object));
-                       $this->replace($existingObject, $object);
-               } else {
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The "modified object" is does not have an existing counterpart in this repository.', 1249479819);
-               }
+               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
        }
 
        /**
         * Injects the Extbase settings, called by Extbase.
         *
         * @param array $settings
-        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @return void
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @api
         */
        public function injectSettings(array $settings) {
@@ -291,8 +238,8 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
        /**
         * Initializes the persistence manager, called by Extbase.
         *
-        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @return void
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @api
         */
        public function initialize() {
@@ -356,61 +303,11 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         *
         * @param string $type
         * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
         * @api
         */
        public function createQueryForType($type) {
-               /** @var $query \TYPO3\CMS\Extbase\Persistence\Generic\Query */
-               $query = $this->queryFactory->create($type);
-               if ($this->defaultQuerySettings !== NULL) {
-                       $query->setQuerySettings(clone $this->defaultQuerySettings);
-               }
-
-               return $query;
-       }
-
-       /**
-        * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings
-        */
-       public function setDefaultQuerySettings($defaultQuerySettings) {
-               $this->defaultQuerySettings = $defaultQuerySettings;
-       }
-
-       /**
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
-        */
-       public function getDefaultQuerySettings() {
-               return $this->defaultQuerySettings;
-       }
-
-       /**
-        * @param $existingObject
-        * @param $newObject
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
-        */
-       public function replace($existingObject, $newObject) {
-               if (get_class($existingObject) !== get_class($newObject)) {
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The existing object and the object given to replace were not of the same type.', 1350243147);
-               }
-
-               $uuid = $this->backend->getIdentifierByObject($existingObject);
-               if ($uuid !== NULL) {
-                       $this->backend->replaceObject($existingObject, $newObject);
-                       $this->session->unregisterReconstitutedObject($existingObject);
-                       $this->session->registerReconstitutedObject($newObject);
-                       if ($this->removedObjects->contains($existingObject)) {
-                               $this->removedObjects->detach($existingObject);
-                               $this->removedObjects->attach($newObject);
-                       } elseif ($this->addedObjects->contains($existingObject)) {
-                               $this->addedObjects->detach($existingObject);
-                               $this->addedObjects->attach($newObject);
-                       }
-               } elseif ($this->addedObjects->contains($existingObject)) {
-                       $this->addedObjects->detach($existingObject);
-                       $this->addedObjects->attach($newObject);
-               } else {
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The "existing object" is unknown to the persistence backend.', 1238068475);
-               }
+               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
        }
 }
 
index 1d139ce..f43e0b3 100644 (file)
@@ -33,23 +33,6 @@ namespace TYPO3\CMS\Extbase\Persistence;
 interface PersistenceManagerInterface {
 
        /**
-        * Injects the Extbase settings, called by Extbase.
-        *
-        * @param array $settings
-        * @return void
-        * @api
-        */
-       public function injectSettings(array $settings);
-
-       /**
-        * Initializes the persistence manager, called by Extbase.
-        *
-        * @return void
-        * @api
-        */
-       public function initialize();
-
-       /**
         * Commits new objects and changes to objects in the current persistence
         * session into the backend
         *
@@ -59,25 +42,6 @@ interface PersistenceManagerInterface {
        public function persistAll();
 
        /**
-        * Clears the in-memory state of the persistence.
-        *
-        * Managed instances become detached, any fetches will
-        * return data directly from the persistence "backend".
-        *
-        * @return void
-        */
-       public function clearState();
-
-       /**
-        * Checks if the given object has ever been persisted.
-        *
-        * @param object $object The object to check
-        * @return boolean TRUE if the object is new, FALSE if the object exists in the repository
-        * @api
-        */
-       public function isNewObject($object);
-
-       /**
         * Returns the (internal) identifier for the object, if it is known to the
         * backend. Otherwise NULL is returned.
         *
@@ -104,35 +68,33 @@ interface PersistenceManagerInterface {
        public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE);
 
        /**
-        * Converts the given object into an array containing the identity of the domain object.
+        * Returns the number of records matching the query.
         *
-        * @param object $object The object to be converted
-        * @return array The identity array in the format array('__identity' => '...')
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
+        * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
+        * @return integer
+        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
         * @api
         */
-       public function convertObjectToIdentityArray($object);
+       public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
 
        /**
-        * Recursively iterates through the given array and turns objects
-        * into arrays containing the identity of the domain object.
+        * Returns the object data matching the $query.
         *
-        * @param array $array The array to be iterated over
-        * @return array The modified array without objects
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
+        * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
+        * @return array
+        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
         * @api
-        * @see convertObjectToIdentityArray()
         */
-       public function convertObjectsToIdentityArrays(array $array);
+       public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
 
        /**
-        * Return a query object for the given type.
+        * Registers a repository
         *
-        * @param string $type
-        * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
-        * @api
+        * @param string $className The class name of the repository to be reigistered
+        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
+        * @return void
         */
-       public function createQueryForType($type);
+       public function registerRepositoryClassName($className);
 
        /**
         * Adds an object to the persistence.
@@ -161,6 +123,73 @@ interface PersistenceManagerInterface {
         * @api
         */
        public function update($object);
+
+       /**
+        * Injects the Extbase settings, called by Extbase.
+        *
+        * @param array $settings
+        * @return void
+        * @api
+        */
+       public function injectSettings(array $settings);
+
+       /**
+        * Initializes the persistence manager, called by Extbase.
+        *
+        * @return void
+        * @api
+        */
+       public function initialize();
+
+       /**
+        * Clears the in-memory state of the persistence.
+        *
+        * Managed instances become detached, any fetches will
+        * return data directly from the persistence "backend".
+        *
+        * @return void
+        */
+       public function clearState();
+
+       /**
+        * Checks if the given object has ever been persisted.
+        *
+        * @param object $object The object to check
+        * @return boolean TRUE if the object is new, FALSE if the object exists in the repository
+        * @api
+        */
+       public function isNewObject($object);
+
+       /**
+        * Converts the given object into an array containing the identity of the domain object.
+        *
+        * @param object $object The object to be converted
+        * @return array The identity array in the format array('__identity' => '...')
+        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
+        * @api
+        */
+       public function convertObjectToIdentityArray($object);
+
+       /**
+        * Recursively iterates through the given array and turns objects
+        * into arrays containing the identity of the domain object.
+        *
+        * @param array $array The array to be iterated over
+        * @return array The modified array without objects
+        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
+        * @api
+        * @see convertObjectToIdentityArray()
+        */
+       public function convertObjectsToIdentityArrays(array $array);
+
+       /**
+        * Return a query object for the given type.
+        *
+        * @param string $type
+        * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
+        * @api
+        */
+       public function createQueryForType($type);
 }
 
 ?>
\ No newline at end of file
index 2b8326b..96a5167 100644 (file)
@@ -35,6 +35,40 @@ namespace TYPO3\CMS\Extbase\Persistence;
 class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface, \TYPO3\CMS\Core\SingletonInterface {
 
        /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\IdentityMap
+        */
+       protected $identityMap;
+
+       /**
+        * Objects of this repository
+        *
+        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+        */
+       protected $addedObjects;
+
+       /**
+        * Objects removed but not found in $this->addedObjects at removal time
+        *
+        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+        */
+       protected $removedObjects;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface
+        */
+       protected $queryFactory;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
+        */
+       protected $backend;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
+        */
+       protected $session;
+
+       /**
         * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
         */
        protected $persistenceManager;
@@ -45,12 +79,9 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
        protected $objectManager;
 
        /**
-        * Warning: if you think you want to set this,
-        * look at RepositoryInterface::ENTITY_CLASSNAME first!
-        *
         * @var string
         */
-       protected $entityClassName;
+       protected $objectType;
 
        /**
         * @var array
@@ -58,13 +89,21 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
        protected $defaultOrderings = array();
 
        /**
-        * Initializes a new Repository.
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        */
+       protected $defaultQuerySettings = NULL;
+
+       /**
+        * Constructs a new Repository
         *
         * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
         * @deprecated since Extbase 6.0.0; will be removed in Extbase 6.2 - Use objectManager to instantiate repository objects instead of GeneralUtility::makeInstance
         */
        public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager = NULL) {
-
+               $this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $nsSeparator = strpos($this->getRepositoryClassName(), '\\') !== FALSE ? '\\\\' : '_';
+               $this->objectType = preg_replace(array('/' . $nsSeparator . 'Repository' . $nsSeparator . '(?!.*' . $nsSeparator . 'Repository' . $nsSeparator . ')/', '/Repository$/'), array($nsSeparator . 'Model' . $nsSeparator, ''), $this->getRepositoryClassName());
                if ($objectManager === NULL) {
                        // Legacy creation, in case the object manager is NOT injected
                        // If ObjectManager IS there, then all properties are automatically injected
@@ -72,58 +111,98 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
                        \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
 
                        $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-                       $this->injectPersistenceManager($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface'));
+                       $this->injectIdentityMap($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap'));
+                       $this->injectQueryFactory($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory'));
+                       $this->injectPersistenceManager($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'));
+                       $this->injectBackend($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface'));
+                       $this->injectSession($this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session'));
                } else {
                        $this->objectManager = $objectManager;
                }
+       }
 
-               if (static::ENTITY_CLASSNAME === NULL) {
-                       $this->entityClassName = preg_replace(array('/\\\Domain\\\Repository\\\/', '/_Domain_Repository_/', '/Repository$/'), array('\\Domain\\Model\\', '_Domain_Model_', ''), get_class($this));
-               } else {
-                       $this->entityClassName = static::ENTITY_CLASSNAME;
-               }
+       /**
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\IdentityMap $identityMap
+        * @return void
+        */
+       public function injectIdentityMap(\TYPO3\CMS\Extbase\Persistence\Generic\IdentityMap $identityMap) {
+               $this->identityMap = $identityMap;
+       }
+
+       /**
+        * Injects the Persistence Backend
+        *
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface $backend The persistence backend
+        * @return void
+        */
+       public function injectBackend(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface $backend) {
+               $this->backend = $backend;
        }
 
        /**
-        * Injects the persistence manager
         *
+        * Injects the Persistence Session
+        *
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\Session $session The persistence session
+        * @return void
+        */
+       public function injectSession(\TYPO3\CMS\Extbase\Persistence\Generic\Session $session) {
+               $this->session = $session;
+       }
+
+       /**
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory $queryFactory
+        * @return void
+        */
+       public function injectQueryFactory(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory $queryFactory) {
+               $this->queryFactory = $queryFactory;
+       }
+
+       /**
         * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
         * @return void
         */
        public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager) {
                $this->persistenceManager = $persistenceManager;
+               $this->persistenceManager->registerRepositoryClassName($this->getRepositoryClassName());
        }
 
        /**
-        * Adds an object to this repository.
+        * Adds an object to this repository
         *
         * @param object $object The object to add
+        * @throws Exception\IllegalObjectTypeException
         * @return void
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         * @api
         */
        public function add($object) {
-               if (!is_object($object) || !($object instanceof $this->entityClassName)) {
-                       $type = (is_object($object) ? get_class($object) : gettype($object));
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The value given to add() was ' . $type . ' , however the ' . get_class($this) . ' can only store ' . $this->entityClassName . ' instances.', 1298403438);
+               if (!$object instanceof $this->objectType) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The object given to add() was not of the type (' . $this->objectType . ') this repository manages.', 1248363335);
+               }
+               $this->addedObjects->attach($object);
+               if ($this->removedObjects->contains($object)) {
+                       $this->removedObjects->detach($object);
                }
-               $this->persistenceManager->add($object);
        }
 
        /**
         * Removes an object from this repository.
         *
         * @param object $object The object to remove
+        * @throws Exception\IllegalObjectTypeException
         * @return void
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         * @api
         */
        public function remove($object) {
-               if (!is_object($object) || !($object instanceof $this->entityClassName)) {
-                       $type = (is_object($object) ? get_class($object) : gettype($object));
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The value given to remove() was ' . $type . ' , however the ' . get_class($this) . ' can only handle ' . $this->entityClassName . ' instances.', 1298403442);
+               if (!$object instanceof $this->objectType) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The object given to remove() was not of the type (' . $this->objectType . ') this repository manages.', 1248363335);
+               }
+               if ($this->addedObjects->contains($object)) {
+                       $this->addedObjects->detach($object);
+               }
+               if (!$object->_isNew()) {
+                       $this->removedObjects->attach($object);
                }
-               $this->persistenceManager->remove($object);
        }
 
        /**
@@ -131,79 +210,102 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         *
         * @param object $existingObject The existing object
         * @param object $newObject The new object
+        * @throws Exception\UnknownObjectException
         * @throws Exception\IllegalObjectTypeException
         * @return void
         * @api
-        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
         */
        public function replace($existingObject, $newObject) {
-               if (!$existingObject instanceof $this->entityClassName) {
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The existing object given to replace was not of the type (' . $this->entityClassName . ') this repository manages.', 1248363434);
+               if (!$existingObject instanceof $this->objectType) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The existing object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363434);
                }
-               if (!$newObject instanceof $this->entityClassName) {
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The new object given to replace was not of the type (' . $this->entityClassName . ') this repository manages.', 1248363439);
+               if (!$newObject instanceof $this->objectType) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The new object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363439);
+               }
+               $uuid = $this->persistenceManager->getIdentifierByObject($existingObject);
+               if ($uuid !== NULL) {
+                       $this->backend->replaceObject($existingObject, $newObject);
+                       $this->session->unregisterReconstitutedObject($existingObject);
+                       $this->session->registerReconstitutedObject($newObject);
+                       if ($this->removedObjects->contains($existingObject)) {
+                               $this->removedObjects->detach($existingObject);
+                               $this->removedObjects->attach($newObject);
+                       } elseif ($this->addedObjects->contains($existingObject)) {
+                               $this->addedObjects->detach($existingObject);
+                               $this->addedObjects->attach($newObject);
+                       }
+               } elseif ($this->addedObjects->contains($existingObject)) {
+                       $this->addedObjects->detach($existingObject);
+                       $this->addedObjects->attach($newObject);
+               } else {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The "existing object" is unknown to the persistence backend.', 1238068475);
                }
-
-               $this->persistenceManager->replace($existingObject, $newObject);
        }
 
        /**
-        * Schedules a modified object for persistence.
+        * Replaces an existing object with the same identifier by the given object
         *
-        * @param object $object The modified object
-        * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
+        * @param object $modifiedObject The modified object
+        * @throws Exception\UnknownObjectException
+        * @throws Exception\IllegalObjectTypeException
+        * @return void
         * @api
         */
-       public function update($object) {
-               if (!is_object($object) || !($object instanceof $this->entityClassName)) {
-                       $type = (is_object($object) ? get_class($object) : gettype($object));
-                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The value given to update() was ' . $type . ' , however the ' . get_class($this) . ' can only store ' . $this->entityClassName . ' instances.', 1249479625);
+       public function update($modifiedObject) {
+               if (!$modifiedObject instanceof $this->objectType) {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException('The modified object given to update() was not of the type (' . $this->objectType . ') this repository manages.', 1249479625);
+               }
+               $uid = $modifiedObject->getUid();
+               if ($uid !== NULL) {
+                       $existingObject = $this->findByUid($uid);
+                       $this->replace($existingObject, $modifiedObject);
+               } else {
+                       throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The "modified object" is does not have an existing counterpart in this repository.', 1249479819);
                }
-
-               $this->persistenceManager->update($object);
        }
 
        /**
-        * Returns all objects of this repository add()ed but not yet persisted to
-        * the storage layer.
+        * Returns all addedObjects that have been added to this repository with add().
+        *
+        * This is a service method for the persistence manager to get all addedObjects
+        * added to the repository. Those are only objects *added*, not objects
+        * fetched from the underlying storage.
         *
-        * @return array An array of objects
-        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
+        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage the objects
         */
        public function getAddedObjects() {
-               return $this->persistenceManager->getAddedObjects();
+               return $this->addedObjects;
        }
 
        /**
-        * Returns an array with objects remove()d from the repository that
-        * had been persisted to the storage layer before.
+        * Returns an \TYPO3\CMS\Extbase\Persistence\ObjectStorage with objects remove()d from the repository
+        * that had been persisted to the storage layer before.
         *
-        * @return array
-        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
+        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage the objects
         */
        public function getRemovedObjects() {
-               return $this->persistenceManager->getRemovedObjects();
+               return $this->removedObjects;
        }
 
        /**
-        * Returns all objects of this repository
+        * Returns all objects of this repository.
         *
-        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The query result
+        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array
         * @api
-        * @see \TYPO3\CMS\Extbase\Persistence\QueryInterface::execute()
         */
        public function findAll() {
-               return $this->createQuery()->execute();
+               $result = $this->createQuery()->execute();
+               return $result;
        }
 
        /**
-        * Counts all objects of this repository
+        * Returns the total number objects of this repository.
         *
-        * @return integer
+        * @return integer The object count
         * @api
         */
        public function countAll() {
-               return $this->createQuery()->count();
+               return $this->createQuery()->execute()->count();
        }
 
        /**
@@ -214,6 +316,7 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @api
         */
        public function removeAll() {
+               $this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                foreach ($this->findAll() as $object) {
                        $this->remove($object);
                }
@@ -225,20 +328,28 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @param integer $uid The identifier of the object to find
         * @return object The matching object if found, otherwise NULL
         * @api
-        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
         */
        public function findByUid($uid) {
-               return $this->findByIdentifier($uid);
+               if ($this->identityMap->hasIdentifier($uid, $this->objectType)) {
+                       $object = $this->identityMap->getObjectByIdentifier($uid, $this->objectType);
+               } else {
+                       $query = $this->createQuery();
+                       $query->getQuerySettings()->setRespectSysLanguage(FALSE);
+                       $query->getQuerySettings()->setRespectStoragePage(FALSE);
+                       $object = $query->matching($query->equals('uid', $uid))->execute()->getFirst();
+               }
+               return $object;
        }
 
        /**
-        * Sets the property names to order results by. Expected like this:
+        * Sets the property names to order the result by per default.
+        * Expected like this:
         * array(
-        *  'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
-        *  'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
+        * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
+        * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
         * )
         *
-        * @param array $defaultOrderings The property names to order by by default
+        * @param array $defaultOrderings The property names to order by
         * @return void
         * @api
         */
@@ -252,10 +363,9 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
         * @return void
         * @api
-        * @deprecated since Extbase 6.0, will be removed in Extbase 7.0
         */
        public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings) {
-               $this->persistenceManager->setDefaultQuerySettings($defaultQuerySettings);
+               $this->defaultQuerySettings = $defaultQuerySettings;
        }
 
        /**
@@ -265,69 +375,52 @@ class Repository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface,
         * @api
         */
        public function createQuery() {
-               $query = $this->persistenceManager->createQueryForType($this->entityClassName);
+               $query = $this->queryFactory->create($this->objectType);
                if ($this->defaultOrderings !== array()) {
                        $query->setOrderings($this->defaultOrderings);
                }
+               if ($this->defaultQuerySettings !== NULL) {
+                       $query->setQuerySettings(clone $this->defaultQuerySettings);
+               }
                return $query;
        }
 
        /**
-        * Magic call method for repository methods.
-        *
-        * Provides three methods
-        *  - findBy<PropertyName>($value, $caseSensitive = TRUE)
-        *  - findOneBy<PropertyName>($value, $caseSensitive = TRUE)
-        *  - countBy<PropertyName>($value, $caseSensitive = TRUE)
-        *
-        * @param string $method Name of the method
-        * @param array $arguments The arguments
+        * Dispatches magic methods (findBy[Property]())
         *
+        * @param string $methodName The name of the magic method
+        * @param string $arguments The arguments of the magic method
         * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
-        *
-        * @return mixed The result of the repository method
+        * @return mixed
         * @api
         */
-       public function __call($method, $arguments) {
-               $query = $this->createQuery();
-               $caseSensitive = isset($arguments[1]) ? (boolean)$arguments[1] : TRUE;
-
-               if (substr($method, 0, 6) === 'findBy' && strlen($method) > 7) {
-                       $propertyName = lcfirst(substr($method, 6));
-                       return $query->matching($query->equals($propertyName, $arguments[0], $caseSensitive))->execute();
-               } elseif (substr($method, 0, 7) === 'countBy' && strlen($method) > 8) {
-                       $propertyName = lcfirst(substr($method, 7));
-                       return $query->matching($query->equals($propertyName, $arguments[0], $caseSensitive))->count();
-               } elseif (substr($method, 0, 9) === 'findOneBy' && strlen($method) > 10) {
-                       $propertyName = lcfirst(substr($method, 9));
-                       return $query->matching($query->equals($propertyName, $arguments[0], $caseSensitive))->execute()->getFirst();
+       public function __call($methodName, $arguments) {
+               if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) {
+                       $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1);
+                       $query = $this->createQuery();
+                       $result = $query->matching($query->equals($propertyName, $arguments[0]))->execute();
+                       return $result;
+               } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
+                       $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1);
+                       $query = $this->createQuery();
+                       $object = $query->matching($query->equals($propertyName, $arguments[0]))->setLimit(1)->execute()->getFirst();
+                       return $object;
+               } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
+                       $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1);
+                       $query = $this->createQuery();
+                       $result = $query->matching($query->equals($propertyName, $arguments[0]))->execute()->count();
+                       return $result;
                }
-
-               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException('The method "' . $method . '" is not supported by the repository.', 1233180480);
+               throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1233180480);
        }
 
        /**
-        * Returns the classname of the entities this repository is managing.
-        *
-        * Note that anything that is an "instanceof" this class is accepted
-        * by the repository.
+        * Returns the class name of this class.
         *
-        * @return string
-        * @api
-        */
-       public function getEntityClassName() {
-               return $this->entityClassName;
-       }
-
-       /**
-        * Finds an object matching the given identifier.
-        *
-        * @param mixed $identifier The identifier of the object to find
-        * @return object The matching object if found, otherwise NULL
-        * @api
+        * @return string Class name of the repository.
         */
-       public function findByIdentifier($identifier) {
-               return $this->persistenceManager->getObjectByIdentifier($identifier, $this->entityClassName);
+       protected function getRepositoryClassName() {
+               return get_class($this);
        }
 }
 
index b1d7b81..96a1fd2 100644 (file)
@@ -53,26 +53,51 @@ interface RepositoryInterface {
        public function remove($object);
 
        /**
-        * Schedules a modified object for persistence.
+        * Replaces an object by another.
         *
-        * @param object $object The modified object
+        * @param object $existingObject The existing object
+        * @param object $newObject The new object
         * @return void
         * @api
         */
-       public function update($object);
+       public function replace($existingObject, $newObject);
+
+       /**
+        * Replaces an existing object with the same identifier by the given object
+        *
+        * @param object $modifiedObject The modified object
+        * @api
+        */
+       public function update($modifiedObject);
+
+       /**
+        * Returns all objects of this repository add()ed but not yet persisted to
+        * the storage layer.
+        *
+        * @return array An array of objects
+        */
+       public function getAddedObjects();
+
+       /**
+        * Returns an array with objects remove()d from the repository that
+        * had been persisted to the storage layer before.
+        *
+        * @return array
+        */
+       public function getRemovedObjects();
 
        /**
         * Returns all objects of this repository.
         *
-        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface The query result
+        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result
         * @api
         */
        public function findAll();
 
        /**
-        * Counts all objects of this repository
+        * Returns the total number objects of this repository.
         *
-        * @return integer
+        * @return integer The object count
         * @api
         */
        public function countAll();
@@ -89,39 +114,34 @@ interface RepositoryInterface {
        /**
         * Finds an object matching the given identifier.
         *
-        * @param mixed $identifier The identifier of the object to find
+        * @param integer $uid The identifier of the object to find
         * @return object The matching object if found, otherwise NULL
         * @api
         */
-       public function findByIdentifier($identifier);
+       public function findByUid($uid);
 
        /**
-        * Sets the property names to order results by. Expected like this:
+        * Sets the property names to order the result by per default.
+        * Expected like this:
         * array(
-        *  'foo' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING,
-        *  'bar' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_DESCENDING
+        * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
+        * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
         * )
         *
-        * @param array $defaultOrderings The property names to order by by default
+        * @param array $defaultOrderings The property names to order by
         * @return void
         * @api
         */
        public function setDefaultOrderings(array $defaultOrderings);
 
        /**
-        * Magic call method for repository methods.
+        * Sets the default query settings to be used in this repository
         *
-        * Provides three methods
-        *  - findBy<PropertyName>($value, $caseSensitive = TRUE)
-        *  - findOneBy<PropertyName>($value, $caseSensitive = TRUE)
-        *  - countBy<PropertyName>($value, $caseSensitive = TRUE)
-        *
-        * @param string $method Name of the method
-        * @param array $arguments The arguments
-        * @return mixed The result of the repository method
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
+        * @return void
         * @api
         */
-       public function __call($method, $arguments);
+       public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings);
 
        /**
         * Returns a query for objects of this repository
@@ -130,23 +150,6 @@ interface RepositoryInterface {
         * @api
         */
        public function createQuery();
-
-       /**
-        * If set in an implementation overrides automatic detection of the
-        * entity class name being managed by the repository.
-        *
-        * @var string
-        * @api
-        */
-       const ENTITY_CLASSNAME = NULL;
-
-       /**
-        * Returns the object type this repository is managing.
-        *
-        * @return string
-        * @api
-        */
-       public function getEntityClassName();
 }
 
 ?>
\ No newline at end of file
index 2b62782..c33b8d3 100644 (file)
@@ -101,10 +101,10 @@ class Mapper implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager $persistenceManager
         * @return void
         */
-       public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager) {
+       public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager $persistenceManager) {
                $this->persistenceManager = $persistenceManager;
        }
 
@@ -353,4 +353,4 @@ class Mapper implements \TYPO3\CMS\Core\SingletonInterface {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 956c74d..fb4a8da 100644 (file)
@@ -154,7 +154,7 @@ class TaskExecutor implements \TYPO3\CMS\Core\SingletonInterface {
         */
        protected function shutdown() {
                // shutdown
-               $persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
                $persistenceManager->persistAll();
                $reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
                $reflectionService->shutdown();
index 302112b..489a4d8 100644 (file)
@@ -51,7 +51,7 @@ class DebuggerUtility {
                'TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService',
                'TYPO3\\CMS\\Extbase\\Object\\ObjectManager',
                'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper',
-               'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface',
+               'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager',
                'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\QueryObjectModelFactory',
                'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'
        );
index c9a3738..ee06158 100644 (file)
@@ -37,7 +37,6 @@ class BackendUserGroupRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        public function initializeObjectSetsRespectStoragePidToFalse() {
                $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $fixture = new \TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository($objectManager);
-               $fixture->injectPersistenceManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'));
                $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
                $querySettings->expects($this->once())->method('setRespectStoragePage')->with(FALSE);
                $objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings')->will($this->returnValue($querySettings));
index 6e4bfea..0cf83d9 100644 (file)
@@ -38,7 +38,6 @@ class BackendUserRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCa
        public function initializeObjectSetsRespectStoragePidToFalse() {
                $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $fixture = new \TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository($objectManager);
-               $fixture->injectPersistenceManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'));
                $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
                $querySettings->expects($this->once())->method('setRespectStoragePage')->with(FALSE);
                $objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings')->will($this->returnValue($querySettings));
index 7fccf03..ef4ac88 100644 (file)
@@ -50,7 +50,6 @@ class CategoryRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManagerInterface */
                $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $fixture = new \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository($objectManager);
-               $fixture->injectPersistenceManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'));
                $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
                $querySettings->expects($this->once())->method('setRespectStoragePage')->with(FALSE);
                $objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings')->will($this->returnValue($querySettings));
index f6f9dda..9514060 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Domain\Repository;
+namespace TYPO3\CMS\Extbase\Domain\Repository;
 
 /***************************************************************
  * Copyright notice
@@ -50,7 +50,6 @@ class FileMountRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManagerInterface */
                $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $fixture = new \TYPO3\CMS\Extbase\Domain\Repository\FileMountRepository($objectManager);
-               $fixture->injectPersistenceManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'));
                $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
                $querySettings->expects($this->once())->method('setRespectStoragePage')->with(FALSE);
                $objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings')->will($this->returnValue($querySettings));
index 08fe72c..2b3630b 100644 (file)
@@ -55,7 +55,6 @@ class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                $persistenceSession->registerReconstitutedObject($entity1);
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
                $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
-               $persistenceManager->initializeObject();
                $mockTypo3DbBackend->expects($this->once())
                        ->method('setAggregateRootObjects')
                        ->with($this->equalTo($aggregateRootObjects));
@@ -86,7 +85,6 @@ class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                $persistenceSession->registerReconstitutedObject($entity1);
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
                $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
-               $persistenceManager->initializeObject();
                $mockTypo3DbBackend->expects($this->once())
                        ->method('setAggregateRootObjects')
                        ->with($this->equalTo($aggregateRootObjects));
index 9851b71..a54ddf1 100644 (file)
@@ -56,7 +56,7 @@ class QueryResultTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @return void
         */
        public function setUp() {
-               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
+               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
                $this->mockPersistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
                $this->mockPersistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
                $this->mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
index f384ac0..85f0174 100644 (file)
@@ -67,7 +67,7 @@ class QueryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->query->injectObjectManager($this->objectManager);
                $this->querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
                $this->query->setQuerySettings($this->querySettings);
-               $this->persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
+               $this->persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
                $this->backend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
                $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
                $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
index 472feb5..1e4b95e 100644 (file)
@@ -41,14 +41,19 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $mockIdentityMap;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
         */
-       protected $mockSession;
+       protected $mockQueryFactory;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
         */
-       protected $mockQueryFactory;
+       protected $mockBackend;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
+        */
+       protected $mockSession;
 
        /**
         * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
@@ -61,9 +66,9 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $mockQuery;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         */
-       protected $mockBackend;
+       protected $querySettings;
 
        /**
         * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
@@ -71,31 +76,22 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $mockQuerySettings;
 
        public function setUp() {
-               $this->mockSession = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session');
                $this->mockIdentityMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
-               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Query', array('equals', 'matching', 'execute', 'comparison', 'setLimit'), array(), '', FALSE);
+               $this->mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
+               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
                $this->mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
                $this->mockQuery->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
-               $this->mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
                $this->mockQueryFactory->expects($this->any())->method('create')->will($this->returnValue($this->mockQuery));
-
-               $configuration = $this->getMock('\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface');
-               $this->mockBackend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('getIdentifierByObject', 'replaceObject'), array($configuration));
-               $this->mockBackend->injectIdentityMap($this->mockIdentityMap);
-               $this->mockBackend->injectQueryFactory($this->mockQueryFactory);
-               $this->mockBackend->expects($this->any())->method('replaceObject');
-
-               $this->mockPersistenceManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager', array('getIdentifierByObject'));
-               $this->mockPersistenceManager->_set('addedObjects', new \TYPO3\CMS\Extbase\Persistence\ObjectStorage);
-               $this->mockPersistenceManager->_set('removedObjects', new \TYPO3\CMS\Extbase\Persistence\ObjectStorage);
-               $this->mockPersistenceManager->injectQueryFactory($this->mockQueryFactory);
-               $this->mockPersistenceManager->injectBackend($this->mockBackend);
-               $this->mockPersistenceManager->injectSession($this->mockSession);
-               $this->mockPersistenceManager->setDefaultQuerySettings($this->mockQuerySettings);
-
+               $this->mockBackend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
+               $this->mockSession = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session');
+               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
                $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $this->repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('dummy'), array($this->mockObjectManager));
+               $this->repository->injectIdentityMap($this->mockIdentityMap);
+               $this->repository->injectQueryFactory($this->mockQueryFactory);
                $this->repository->injectPersistenceManager($this->mockPersistenceManager);
+               $this->repository->injectBackend($this->mockBackend);
+               $this->repository->injectSession($this->mockSession);
        }
 
        /**
@@ -110,7 +106,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function addActuallyAddsAnObjectToTheInternalObjectsArray() {
                $someObject = new \stdClass();
-               $this->repository->_set('entityClassName', get_class($someObject));
+               $this->repository->_set('objectType', get_class($someObject));
                $this->repository->add($someObject);
                $this->assertTrue($this->repository->getAddedObjects()->contains($someObject));
        }
@@ -122,7 +118,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
                $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
                $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $this->repository->_set('entityClassName', get_class($object1));
+               $this->repository->_set('objectType', get_class($object1));
                $this->repository->add($object1);
                $this->repository->add($object2);
                $this->repository->add($object3);
@@ -139,7 +135,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
                $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
                $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $this->repository->_set('entityClassName', get_class($object1));
+               $this->repository->_set('objectType', get_class($object1));
                $this->repository->add($object1);
                $this->repository->add($object2);
                $this->repository->add($object3);
@@ -161,7 +157,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $object = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
                // if the object is not currently add()ed, it is not new
                $object->expects($this->once())->method('_isNew')->will($this->returnValue(FALSE));
-               $this->repository->_set('entityClassName', get_class($object));
+               $this->repository->_set('objectType', get_class($object));
                $this->repository->remove($object);
                $this->assertTrue($this->repository->getRemovedObjects()->contains($object));
        }
@@ -189,41 +185,16 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function constructSetsObjectTypeFromClassName($repositoryClassName, $modelClassName) {
                $mockClassName = 'MockRepository' . uniqid();
-               eval('class ' . $repositoryClassName . ' extends TYPO3\\CMS\\Extbase\\Persistence\\Repository {}');
-               $this->repository = new $repositoryClassName($this->mockObjectManager);
-               $this->repository->injectPersistenceManager($this->mockPersistenceManager);
-               $this->assertEquals($modelClassName, $this->repository->getEntityClassName());
-       }
-
-       /**
-        * dataProvider for createQueryCallsQueryFactoryWithExpectedType
-        *
-        * @return array
-        */
-       public function modelAndRepositoryNamespacedClassNames() {
-               return array(
-                       array('VENDOR\\EXT\\Domain\\Repository', 'BlogRepository', 'VENDOR\\EXT\\Domain\\Model\\Blog'),
-                       array('VENDOR\\EXT\\Domain\\Repository', '_PageRepository', 'VENDOR\\EXT\\Domain\\Model\\_Page'),
-                       array('VENDOR\\Repository\\Domain\\Repository', 'SomeModelRepository', 'VENDOR\\Repository\\Domain\\Model\\SomeModel'),
-                       array('VENDOR\\EXT\\Domain\\Repository', 'RepositoryRepository', 'VENDOR\\EXT\\Domain\\Model\\Repository'),
-                       array('VENDOR\\Repository\\Domain\\Repository', 'RepositoryRepository', 'VENDOR\\Repository\\Domain\\Model\\Repository'),
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider modelAndRepositoryNamespacedClassNames
-        * @param string $namespace
-        * @param string $repositoryClassName
-        * @param string $modelClassName
-        */
-       public function constructSetsObjectTypeFromNamespacedClassName($namespace, $repositoryClassName, $modelClassName) {
-               $mockClassName = 'MockRepository' . uniqid();
-               eval('namespace ' . $namespace . ';  class ' . $repositoryClassName . ' extends \\TYPO3\\CMS\\Extbase\\Persistence\\Repository {}');
-               $namespacedRepositoryClassName = '\\' . $namespace . '\\' . $repositoryClassName;
-               $this->repository = new $namespacedRepositoryClassName($this->mockObjectManager);
-               $this->repository->injectPersistenceManager($this->mockPersistenceManager);
-               $this->assertEquals($modelClassName, $this->repository->getEntityClassName());
+               eval('class ' . $mockClassName . ' extends TYPO3\\CMS\\Extbase\\Persistence\\Repository {
+                       protected function getRepositoryClassName() {
+                               return \'' . $repositoryClassName . '\';
+                       }
+                       public function _getObjectType() {
+                               return $this->objectType;
+                       }
+               }');
+               $this->repository = new $mockClassName($this->mockObjectManager);
+               $this->assertEquals($modelClassName, $this->repository->_getObjectType());
        }
 
        /**
@@ -231,7 +202,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function createQueryCallsQueryFactoryWithExpectedClassName() {
                $this->mockQueryFactory->expects($this->once())->method('create')->with('ExpectedType');
-               $this->repository->_set('entityClassName', 'ExpectedType');
+               $this->repository->_set('objectType', 'ExpectedType');
                $this->repository->createQuery();
        }
 
@@ -239,13 +210,16 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         */
        public function createQueryReturnsQueryWithUnmodifiedDefaultQuerySettings() {
-               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+               $mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
                $mockQuery = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('foo');
-               $mockQuery->setQuerySettings($mockQuerySettings);
+               $mockDefaultQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+               $this->repository->injectQueryFactory($mockQueryFactory);
+               $this->repository->setDefaultQuerySettings($mockDefaultQuerySettings);
+               $mockQueryFactory->expects($this->once())->method('create')->will($this->returnValue($mockQuery));
                $this->repository->createQuery();
                $instanceQuerySettings = $mockQuery->getQuerySettings();
-               $this->assertEquals($this->mockQuerySettings, $instanceQuerySettings);
-               $this->assertNotSame($this->mockQuerySettings, $instanceQuerySettings);
+               $this->assertEquals($mockDefaultQuerySettings, $instanceQuerySettings);
+               $this->assertNotSame($mockDefaultQuerySettings, $instanceQuerySettings);
        }
 
        /**
@@ -263,7 +237,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function findByUidReturnsResultOfGetObjectByIdentifierCall() {
                $fakeUid = '123';
                $object = new \stdClass();
-               $this->repository->_set('entityClassName', 'someObjectType');
+               $this->repository->_set('objectType', 'someObjectType');
                $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(TRUE));
                $this->mockIdentityMap->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));
                $expectedResult = $object;
@@ -282,11 +256,9 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function replaceReplacesReconstitutedEntityByNewObject() {
                $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
                $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-
-               $this->mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('123'));
-               $this->mockBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('123'));
-
-               $this->repository->_set('entityClassName', get_class($newObject));
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $this->repository->_set('objectType', get_class($newObject));
                $this->repository->replace($existingObject, $newObject);
        }
 
@@ -302,19 +274,15 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function replaceRemovesReconstitutedObjectWhichIsMarkedToBeRemoved() {
                $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
                $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-
-               $removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $removedObjects = new \SplObjectStorage();
                $removedObjects->attach($existingObject);
-
-               $this->mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('123'));
-               $this->mockBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('123'));
-
-               $this->repository->_set('entityClassName', get_class($newObject));
-               $this->repository->_get('persistenceManager')->_set('removedObjects', $removedObjects);
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $this->repository->_set('objectType', get_class($newObject));
+               $this->repository->_set('removedObjects', $removedObjects);
                $this->repository->replace($existingObject, $newObject);
-
-               $this->assertFalse($this->repository->getRemovedObjects()->contains($existingObject));
-               $this->assertTrue($this->repository->getRemovedObjects()->contains($newObject));
+               $this->assertFalse($removedObjects->contains($existingObject));
+               $this->assertTrue($removedObjects->contains($newObject));
        }
 
        /**
@@ -328,14 +296,13 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function replaceAddsNewObjectToAddedObjects() {
                $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
                $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-
-               $addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $addedObjects = new \SplObjectStorage();
                $addedObjects->attach($existingObject);
-
-               $this->repository->_set('entityClassName', get_class($newObject));
-               $this->repository->_get('persistenceManager')->_set('addedObjects', $addedObjects);
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));
+               $this->mockBackend->expects($this->never())->method('replaceObject');
+               $this->repository->_set('objectType', get_class($newObject));
+               $this->repository->_set('addedObjects', $addedObjects);
                $this->repository->replace($existingObject, $newObject);
-
                $this->assertFalse($addedObjects->contains($existingObject));
                $this->assertTrue($addedObjects->contains($newObject));
        }
@@ -345,7 +312,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         */
        public function replaceChecksObjectType() {
-               $this->repository->_set('entityClassName', 'ExpectedObjectType');
+               $this->repository->_set('objectType', 'ExpectedObjectType');
                $this->repository->replace(new \stdClass(), new \stdClass());
        }
 
@@ -356,18 +323,12 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $existingObject = new \stdClass();
                $modifiedObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
                $modifiedObject->expects($this->once())->method('getUid')->will($this->returnValue('123'));
-
-               $mockPersistenceManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager', array('getObjectByIdentifier', 'findByUid', 'replace'));
-               $mockPersistenceManager->_set('addedObjects', new \TYPO3\CMS\Extbase\Persistence\ObjectStorage);
-               $mockPersistenceManager->_set('removedObjects', new \TYPO3\CMS\Extbase\Persistence\ObjectStorage);
-               $mockPersistenceManager->injectBackend($this->mockBackend);
-               $mockPersistenceManager->injectSession($this->mockSession);
-               $mockPersistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('123')->will($this->returnValue($existingObject));
-               $mockPersistenceManager->expects($this->once())->method('replace')->with($existingObject, $modifiedObject);
-
-               $this->repository->injectPersistenceManager($mockPersistenceManager);
-               $this->repository->_set('entityClassName', get_class($modifiedObject));
-               $this->repository->update($modifiedObject);
+               /** @var \TYPO3\CMS\Extbase\Persistence\Repository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('findByUid', 'replace'), array($this->mockObjectManager));
+               $repository->expects($this->once())->method('findByUid')->with('123')->will($this->returnValue($existingObject));
+               $repository->expects($this->once())->method('replace')->with($existingObject, $modifiedObject);
+               $repository->_set('objectType', get_class($modifiedObject));
+               $repository->update($modifiedObject);
        }
 
        /**
@@ -377,7 +338,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function updateRejectsUnknownObjects() {
                $someObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
                $someObject->expects($this->once())->method('getUid')->will($this->returnValue(NULL));
-               $this->repository->_set('entityClassName', get_class($someObject));
+               $this->repository->_set('objectType', get_class($someObject));
                $this->repository->update($someObject);
        }
 
@@ -386,7 +347,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         */
        public function updateRejectsObjectsOfWrongType() {
-               $this->repository->_set('entityClassName', 'Foo');
+               $this->repository->_set('objectType', 'Foo');
                $this->repository->update(new \stdClass());
        }
 
@@ -410,7 +371,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
                $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
                $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
-               $this->mockQuery->expects($this->any())->method('setLimit')->with(1)->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('setLimit')->with(1)->will($this->returnValue($this->mockQuery));
                $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
                $this->assertSame($object, $this->repository->findOneByFoo('bar'));
        }
@@ -440,7 +401,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         */
        public function addChecksObjectType() {
-               $this->repository->_set('entityClassName', 'ExpectedObjectType');
+               $this->repository->_set('objectType', 'ExpectedObjectType');
                $this->repository->add(new \stdClass());
        }
 
@@ -449,7 +410,7 @@ class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
         */
        public function removeChecksObjectType() {
-               $this->repository->_set('entityClassName', 'ExpectedObjectType');
+               $this->repository->_set('objectType', 'ExpectedObjectType');
                $this->repository->remove(new \stdClass());
        }
 }