From 13e661c4b03dadc7778b35ed5f17f97392e9e933 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 27 Feb 2014 17:37:57 +0100 Subject: [PATCH] Remove ManipulatorInterface::getRepository method --- .../Phrasea/NativeAuthentication.php | 8 +++++-- .../AuthenticationManagerServiceProvider.php | 2 +- .../Provider/ManipulatorServiceProvider.php | 6 +++--- .../Model/Manipulator/ACLManipulator.php | 8 ------- .../Manipulator/ManipulatorInterface.php | 6 ------ .../Manipulator/RegistrationManipulator.php | 21 ++++++------------- .../Model/Manipulator/TaskManipulator.php | 6 +++++- .../Model/Manipulator/UserManipulator.php | 18 +++++++--------- .../Phrasea/NativeAuthenticationTest.php | 14 ++++++------- .../RegistrationManipulatorTest.php | 12 +++++------ .../Model/Manipulator/TaskManipulatorTest.php | 16 +++++++------- .../Model/Manipulator/UserManipulatorTest.php | 4 ++-- tests/classes/PhraseanetTestCase.php | 7 +++++++ 13 files changed, 58 insertions(+), 70 deletions(-) diff --git a/lib/Alchemy/Phrasea/Authentication/Phrasea/NativeAuthentication.php b/lib/Alchemy/Phrasea/Authentication/Phrasea/NativeAuthentication.php index 3b4c082aba..aab144f653 100644 --- a/lib/Alchemy/Phrasea/Authentication/Phrasea/NativeAuthentication.php +++ b/lib/Alchemy/Phrasea/Authentication/Phrasea/NativeAuthentication.php @@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Authentication\Exception\AccountLockedException; use Alchemy\Phrasea\Model\Manipulator\UserManipulator; use Alchemy\Phrasea\Model\Entities\User; +use Doctrine\ORM\EntityRepository; use Symfony\Component\HttpFoundation\Request; class NativeAuthentication implements PasswordAuthenticationInterface @@ -25,12 +26,15 @@ class NativeAuthentication implements PasswordAuthenticationInterface private $encoder; /** @var OldPasswordEncoder */ private $oldEncoder; + /** @var EntityRepository */ + private $repository; - public function __construct(PasswordEncoder $encoder, OldPasswordEncoder $oldEncoder, UserManipulator $userManipulator) + public function __construct(PasswordEncoder $encoder, OldPasswordEncoder $oldEncoder, UserManipulator $userManipulator, EntityRepository $repo) { $this->userManipulator = $userManipulator; $this->encoder = $encoder; $this->oldEncoder = $oldEncoder; + $this->repository = $repo; } /** @@ -38,7 +42,7 @@ class NativeAuthentication implements PasswordAuthenticationInterface */ public function getUsrId($username, $password, Request $request) { - if (null === $user = $this->userManipulator->getRepository()->findRealUserByLogin($username)) { + if (null === $user = $this->repository->findRealUserByLogin($username)) { return null; } diff --git a/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php index 2008549513..4d286f01e5 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php @@ -107,7 +107,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface }); $app['auth.password-checker'] = $app->share(function (Application $app) { - return new NativeAuthentication($app['auth.password-encoder'], $app['auth.old-password-encoder'], $app['manipulator.user']); + return new NativeAuthentication($app['auth.password-encoder'], $app['auth.old-password-encoder'], $app['manipulator.user'], $app['repo.users']); }); $app['auth.native'] = $app->share(function (Application $app) { diff --git a/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php index a2bb2c8996..7a10ca0d2f 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php @@ -24,11 +24,11 @@ class ManipulatorServiceProvider implements ServiceProviderInterface public function register(SilexApplication $app) { $app['manipulator.task'] = $app->share(function (SilexApplication $app) { - return new TaskManipulator($app['EM'], $app['task-manager.notifier'], $app['translator']); + return new TaskManipulator($app['EM'], $app['task-manager.notifier'], $app['translator'], $app['repo.tasks']); }); $app['manipulator.user'] = $app->share(function ($app) { - return new UserManipulator($app['model.user-manager'], $app['auth.password-encoder'], $app['geonames.connector']); + return new UserManipulator($app['model.user-manager'], $app['auth.password-encoder'], $app['geonames.connector'], $app['repo.users']); }); $app['manipulator.acl'] = $app->share(function ($app) { @@ -40,7 +40,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface }); $app['manipulator.registration'] = $app->share(function ($app) { - return new RegistrationManipulator($app, $app['EM'], $app['acl'], $app['phraseanet.appbox']); + return new RegistrationManipulator($app, $app['EM'], $app['acl'], $app['phraseanet.appbox'], $app['repo.registrations']); }); } diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php index eb78cabc63..291eeeb33a 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php @@ -29,14 +29,6 @@ class ACLManipulator implements ManipulatorInterface $this->appbox = $appbox; } - /** - * @throws LogicException - */ - public function getRepository() - { - throw new LogicException('ACL class is not a doctrine entity and therefore it does not have repository.'); - } - /** * Resets rights for users. * diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/ManipulatorInterface.php b/lib/Alchemy/Phrasea/Model/Manipulator/ManipulatorInterface.php index 3e8c6139f8..acdfb625ef 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/ManipulatorInterface.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/ManipulatorInterface.php @@ -18,10 +18,4 @@ use Doctrine\ORM\EntityRepository; */ interface ManipulatorInterface { - /** - * Returns the entity repository. - * - * @return EntityRepository - */ - public function getRepository(); } diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php index 58e6fa4f8c..6561f7384d 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Model\Entities\Registration; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Repositories\RegistrationRepository; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityRepository; class RegistrationManipulator implements ManipulatorInterface { @@ -26,13 +27,13 @@ class RegistrationManipulator implements ManipulatorInterface private $repository; private $aclProvider; - public function __construct(Application $app, EntityManager $em, ACLProvider $aclProvider, \appbox $appbox) + public function __construct(Application $app, EntityManager $em, ACLProvider $aclProvider, \appbox $appbox, EntityRepository $repo) { $this->app = $app; $this->em = $em; $this->appbox = $appbox; $this->aclProvider = $aclProvider; - $this->repository = $this->em->getRepository('Phraseanet:Registration'); + $this->repository = $repo; } /** @@ -92,16 +93,6 @@ class RegistrationManipulator implements ManipulatorInterface $this->em->flush(); } - /** - * Gets Registration Repository. - * - * @return RegistrationRepository - */ - public function getRepository() - { - return $this->repository; - } - /** * Deletes registration for given user. * @@ -112,7 +103,7 @@ class RegistrationManipulator implements ManipulatorInterface */ public function deleteUserRegistrations(User $user, array $collections) { - $qb = $this->getRepository()->createQueryBuilder('d'); + $qb = $this->repository->createQueryBuilder('d'); $qb->delete('Phraseanet:Registration', 'd'); $qb->where($qb->expr()->eq('d.user', ':user')); $qb->setParameter(':user', $user->getId()); @@ -132,7 +123,7 @@ class RegistrationManipulator implements ManipulatorInterface */ public function deleteOldRegistrations() { - $qb = $this->getRepository()->createQueryBuilder('d'); + $qb = $this->repository->createQueryBuilder('d'); $qb->delete('Phraseanet:Registration', 'd'); $qb->where($qb->expr()->lt('d.created', ':date')); $qb->setParameter(':date', new \DateTime('-1 month')); @@ -146,7 +137,7 @@ class RegistrationManipulator implements ManipulatorInterface */ public function deleteRegistrationsOnCollection(\collection $collection) { - $qb = $this->getRepository()->createQueryBuilder('d'); + $qb = $this->repository->createQueryBuilder('d'); $qb->delete('Phraseanet:Registration', 'd'); $qb->where($qb->expr()->eq('d.baseId', ':base')); $qb->setParameter(':base', $collection->get_base_id()); diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/TaskManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/TaskManipulator.php index 89849b577d..41b9967ec0 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/TaskManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/TaskManipulator.php @@ -16,6 +16,7 @@ use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\TaskManager\Job\EmptyCollectionJob; use Alchemy\Phrasea\TaskManager\Notifier; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityRepository; use Symfony\Component\Translation\TranslatorInterface; class TaskManipulator implements ManipulatorInterface @@ -26,12 +27,15 @@ class TaskManipulator implements ManipulatorInterface private $om; /** @var TranslatorInterface */ private $translator; + /** @var EntityRepository */ + private $repository; - public function __construct(ObjectManager $om, Notifier $notifier, TranslatorInterface $translator) + public function __construct(ObjectManager $om, Notifier $notifier, TranslatorInterface $translator, EntityRepository $repo) { $this->om = $om; $this->notifier = $notifier; $this->translator = $translator; + $this->repository = $repo; } /** diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php index 6aac2ff7af..4332088bdc 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php @@ -20,6 +20,7 @@ use Alchemy\Phrasea\Model\Manager\UserManager; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\InvalidArgumentException; +use Doctrine\ORM\EntityRepository; use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; /** @@ -33,20 +34,15 @@ class UserManipulator implements ManipulatorInterface private $manager; /** @var GeonamesConnector */ private $geonamesConnector; + /** @var EntityRepository */ + private $repository; - public function __construct(UserManager $manager, PasswordEncoderInterface $passwordEncoder, GeonamesConnector $connector) + public function __construct(UserManager $manager, PasswordEncoderInterface $passwordEncoder, GeonamesConnector $connector, EntityRepository $repo) { $this->manager = $manager; $this->passwordEncoder = $passwordEncoder; $this->geonamesConnector = $connector; - } - - /** - * @{inheritdoc} - */ - public function getRepository() - { - return $this->manager->getObjectManager()->getRepository('Phraseanet:User'); + $this->repository = $repo; } /** @@ -278,7 +274,7 @@ class UserManipulator implements ManipulatorInterface */ private function doSetLogin(User $user, $login) { - if (null !== $this->getRepository()->findByLogin($login)) { + if (null !== $this->repository->findByLogin($login)) { throw new RuntimeException(sprintf('User with login %s already exists.', $login)); } @@ -300,7 +296,7 @@ class UserManipulator implements ManipulatorInterface throw new InvalidArgumentException(sprintf('Email %s is not legal.', $email)); } - if (null !== $this->getRepository()->findByEmail($email)) { + if (null !== $this->repository->findByEmail($email)) { throw new RuntimeException(sprintf('User with email %s already exists.', $email)); } diff --git a/tests/Alchemy/Tests/Phrasea/Authentication/Phrasea/NativeAuthenticationTest.php b/tests/Alchemy/Tests/Phrasea/Authentication/Phrasea/NativeAuthenticationTest.php index 9c12ac9316..489cf9a74c 100644 --- a/tests/Alchemy/Tests/Phrasea/Authentication/Phrasea/NativeAuthenticationTest.php +++ b/tests/Alchemy/Tests/Phrasea/Authentication/Phrasea/NativeAuthenticationTest.php @@ -19,7 +19,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase $manipulator = $this->getUserManipulatorMock($specialUser); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertNull($auth->getUsrId('a_login', 'a_password', $request)); } @@ -30,7 +30,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase $request = $this->getRequestMock(); $manipulator = $this->getUserManipulatorMock(null); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertNull($auth->getUsrId('a_login', 'a_password', $request)); } @@ -45,7 +45,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase $manipulator = $this->getUserManipulatorMock($mailLockedUser); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); try { $auth->getUsrId('a_login', 'a_password', $request); @@ -85,7 +85,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->will($this->returnValue(true)); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request)); } @@ -120,7 +120,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->will($this->returnValue(false)); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertEquals(false, $auth->getUsrId('a_login', $password, $request)); } @@ -157,7 +157,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->will($this->returnValue(false)); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertEquals(false, $auth->getUsrId('a_login', $password, $request)); } @@ -203,7 +203,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase return true; })); - $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator); + $auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock()); $this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request)); } diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php index f1f58d57f4..cd6770ae27 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php @@ -9,7 +9,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase { public function testCreateRegistration() { - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $registration = $service->createRegistration(self::$DI['user'], self::$DI['collection']); $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\Registration', $registration); @@ -21,7 +21,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase { $registration = self::$DI['registration_1']; - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $service->rejectRegistration($registration); $this->assertFalse($registration->isPending()); @@ -48,13 +48,13 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase self::$DI['app']['acl'] = $aclProviderMock; - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $service->acceptRegistration($registration, true, false); } public function testDeleteRegistrationForUser() { - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $qb = $service->getRepository()->createQueryBuilder('r'); $nbRegistrationBefore = $qb->select('COUNT(r)') ->where($qb->expr()->eq('r.user', ':user')) @@ -68,7 +68,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase public function testDeleteOldRegistrations() { - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $qb = $service->getRepository()->createQueryBuilder('r'); $nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult(); $service->deleteOldRegistrations(); @@ -78,7 +78,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase public function testDeleteRegistrationOnCollection() { - $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox']); + $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $qb = $service->getRepository()->createQueryBuilder('r'); $nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult(); $service->deleteRegistrationsOnCollection(self::$DI['collection']); diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/TaskManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/TaskManipulatorTest.php index 504ca70cbb..a0d921a241 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/TaskManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/TaskManipulatorTest.php @@ -15,7 +15,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_CREATE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $this->assertCount(2, $this->findAllTasks()); $task = $manipulator->create('prout', 'bla bla', 'super settings', 0); $this->assertEquals('prout', $task->getName()); @@ -36,7 +36,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_UPDATE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->loadTask(); $task->setName('new name'); $this->assertSame($task, $manipulator->update($task)); @@ -52,7 +52,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_DELETE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->loadTask(); $manipulator->delete($task); $this->assertNotContains($task, $this->findAllTasks()); @@ -65,7 +65,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_UPDATE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->loadTask(); $task->setStatus(Task::STATUS_STOPPED); self::$DI['app']['EM']->persist($task); @@ -81,7 +81,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_UPDATE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->loadTask(); $task->setStatus(Task::STATUS_STARTED); self::$DI['app']['EM']->persist($task); @@ -97,7 +97,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('notify') ->with(Notifier::MESSAGE_UPDATE); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->loadTask(); $task->setCrashed(42); $manipulator->resetCrashes($task); @@ -106,7 +106,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase public function testGetRepository() { - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $this->createNotifierMock(), self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $this->createNotifierMock(), self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $this->assertSame(self::$DI['app']['EM']->getRepository('Phraseanet:Task'), $manipulator->getRepository()); } @@ -119,7 +119,7 @@ class TaskManipulatorTest extends \PhraseanetTestCase ->method('get_base_id') ->will($this->returnValue(42)); - $manipulator = new TaskManipulator(self::$DI['app']['EM'], $this->createNotifierMock(), self::$DI['app']['translator']); + $manipulator = new TaskManipulator(self::$DI['app']['EM'], $this->createNotifierMock(), self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $manipulator->createEmptyCollectionJob($collection); $tasks = self::$DI['app']['EM']->getRepository('Phraseanet:Task')->findAll(); diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php index 97733677bc..5a0fd0aaca 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php @@ -74,7 +74,7 @@ class UserManipulatorTest extends \PhraseanetTestCase ->getMock(); $user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); - $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector); + $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks']); $manipulator->setGeonameId($user, 4); $this->assertEquals(4, $user->getGeonameId()); @@ -140,7 +140,7 @@ class UserManipulatorTest extends \PhraseanetTestCase $passwordInterface = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface') ->getMock(); $user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); - $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector); + $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks']); $this->setExpectedException( 'Alchemy\Phrasea\Exception\InvalidArgumentException', 'Invalid geonameid -1.' diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index c18ae8029d..8752d7f298 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -656,4 +656,11 @@ abstract class PhraseanetTestCase extends WebTestCase ->disableOriginalConstructor() ->getMock(); } + + protected function createEntityRepositoryMock() + { + return $this->getMockBuilder('Doctrine\ORM\EntityRepository') + ->disableOriginalConstructor() + ->getMock(); + } }