Remove call to TaskRepository as not used.

This commit is contained in:
Benoît Burnichon
2015-03-24 14:19:29 +01:00
parent 75c62cc4c8
commit 893f78afa1
3 changed files with 75 additions and 58 deletions

View File

@@ -34,7 +34,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface
public function register(SilexApplication $app) public function register(SilexApplication $app)
{ {
$app['manipulator.task'] = $app->share(function (SilexApplication $app) { $app['manipulator.task'] = $app->share(function (SilexApplication $app) {
return new TaskManipulator($app['orm.em'], $app['task-manager.notifier'], $app['translator'], $app['repo.tasks']); return new TaskManipulator($app['orm.em'], $app['task-manager.notifier'], $app['translator']);
}); });
$app['manipulator.user'] = $app->share(function ($app) { $app['manipulator.user'] = $app->share(function ($app) {

View File

@@ -23,19 +23,16 @@ class TaskManipulator implements ManipulatorInterface
{ {
/** @var Notifier */ /** @var Notifier */
private $notifier; private $notifier;
/** @var Objectmanager */ /** @var ObjectManager */
private $om; private $om;
/** @var TranslatorInterface */ /** @var TranslatorInterface */
private $translator; private $translator;
/** @var EntityRepository */
private $repository;
public function __construct(ObjectManager $om, Notifier $notifier, TranslatorInterface $translator, EntityRepository $repo) public function __construct(ObjectManager $om, Notifier $notifier, TranslatorInterface $translator)
{ {
$this->om = $om; $this->om = $om;
$this->notifier = $notifier; $this->notifier = $notifier;
$this->translator = $translator; $this->translator = $translator;
$this->repository = $repo;
} }
/** /**
@@ -178,14 +175,6 @@ class TaskManipulator implements ManipulatorInterface
return $task; return $task;
} }
/**
* {@inheritdoc}
*/
public function getRepository()
{
return $this->om->getRepository('Phraseanet:Task');
}
private function notify($message) private function notify($message)
{ {
try { try {

View File

@@ -5,41 +5,55 @@ namespace Alchemy\Tests\Phrasea\Model\Manipulator;
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator; use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
use Alchemy\Phrasea\TaskManager\Notifier; use Alchemy\Phrasea\TaskManager\Notifier;
use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\Task;
use Doctrine\Common\Persistence\ObjectManager;
class TaskManipulatorTest extends \PhraseanetTestCase class TaskManipulatorTest extends \PhraseanetTestCase
{ {
/** @var Notifier|\PHPUnit_Framework_MockObject_MockObject */
private $notifier;
/** @var TaskManipulator */
private $sut;
public function setUp()
{
parent::setUp();
$this->notifier = $this->createNotifierMock();
$this->sut = new TaskManipulator(self::$DI['app']['orm.em'], $this->notifier, self::$DI['app']['translator']);
}
public function testCreate() public function testCreate()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_CREATE); ->with(Notifier::MESSAGE_CREATE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$this->assertCount(2, $this->findAllTasks()); $this->assertCount(2, $this->findAllTasks());
$task = $manipulator->create('prout', 'bla bla', 'super settings', 0);
$task = $this->sut->create('prout', 'bla bla', 'super settings', 0);
$this->assertEquals('prout', $task->getName()); $this->assertEquals('prout', $task->getName());
$this->assertEquals('bla bla', $task->getJobId()); $this->assertEquals('bla bla', $task->getJobId());
$this->assertEquals('super settings', $task->getSettings()); $this->assertEquals('super settings', $task->getSettings());
$this->assertEquals(0, $task->getPeriod()); $this->assertEquals(0, $task->getPeriod());
$allTasks = $this->findAllTasks(); $allTasks = $this->findAllTasks();
$this->assertCount(3, $allTasks); $this->assertCount(3, $allTasks);
$this->assertContains($task, $allTasks); $this->assertContains($task, $allTasks);
return $task;
} }
public function testUpdate() public function testUpdate()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_UPDATE); ->with(Notifier::MESSAGE_UPDATE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$task = $this->loadTask(); $task = $this->loadTask();
$task->setName('new name'); $task->setName('new name');
$this->assertSame($task, $manipulator->update($task)); $this->assertSame($task, $this->sut->update($task));
self::$DI['app']['orm.em']->clear(); self::$DI['app']['orm.em']->clear();
$updated = self::$DI['app']['orm.em']->find('Phraseanet:Task', 1); $updated = self::$DI['app']['orm.em']->find('Phraseanet:Task', 1);
$this->assertEquals($task, $updated); $this->assertEquals($task, $updated);
@@ -47,60 +61,61 @@ class TaskManipulatorTest extends \PhraseanetTestCase
public function testDelete() public function testDelete()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_DELETE); ->with(Notifier::MESSAGE_DELETE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$task = $this->loadTask(); $task = $this->loadTask();
$manipulator->delete($task); $this->sut->delete($task);
$this->assertNotContains($task, $this->findAllTasks()); $this->assertNotContains($task, $this->findAllTasks());
} }
public function testStart() public function testStart()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_UPDATE); ->with(Notifier::MESSAGE_UPDATE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$task = $this->loadTask(); $task = $this->loadTask();
$task->setStatus(Task::STATUS_STOPPED); $task->setStatus(Task::STATUS_STOPPED);
self::$DI['app']['orm.em']->persist($task); self::$DI['app']['orm.em']->persist($task);
self::$DI['app']['orm.em']->flush(); self::$DI['app']['orm.em']->flush();
$manipulator->start($task);
$this->sut->start($task);
$this->assertEquals(Task::STATUS_STARTED, $task->getStatus()); $this->assertEquals(Task::STATUS_STARTED, $task->getStatus());
} }
public function testStop() public function testStop()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_UPDATE); ->with(Notifier::MESSAGE_UPDATE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$task = $this->loadTask(); $task = $this->loadTask();
$task->setStatus(Task::STATUS_STARTED); $task->setStatus(Task::STATUS_STARTED);
self::$DI['app']['orm.em']->persist($task); self::$DI['app']['orm.em']->persist($task);
self::$DI['app']['orm.em']->flush(); self::$DI['app']['orm.em']->flush();
$manipulator->stop($task);
$this->sut->stop($task);
$this->assertEquals(Task::STATUS_STOPPED, $task->getStatus()); $this->assertEquals(Task::STATUS_STOPPED, $task->getStatus());
} }
public function testResetCrashes() public function testResetCrashes()
{ {
$notifier = $this->createNotifierMock(); $this->notifier
$notifier->expects($this->once()) ->expects($this->once())
->method('notify') ->method('notify')
->with(Notifier::MESSAGE_UPDATE); ->with(Notifier::MESSAGE_UPDATE);
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $notifier, self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$task = $this->loadTask(); $task = $this->loadTask();
$task->setCrashed(42); $task->setCrashed(42);
$manipulator->resetCrashes($task);
$this->sut->resetCrashes($task);
$this->assertEquals(0, $task->getCrashed()); $this->assertEquals(0, $task->getCrashed());
} }
@@ -113,28 +128,41 @@ class TaskManipulatorTest extends \PhraseanetTestCase
->method('get_base_id') ->method('get_base_id')
->will($this->returnValue(42)); ->will($this->returnValue(42));
$manipulator = new TaskManipulator(self::$DI['app']['orm.em'], $this->createNotifierMock(), self::$DI['app']['translator'], self::$DI['app']['repo.tasks']); $task = $this->sut->createEmptyCollectionJob($collection);
$task = $manipulator->createEmptyCollectionJob($collection);
$tasks = self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll(); $tasks = $this->findAllTasks();
$this->assertSame('EmptyCollection', $task->getJobId()); $this->assertSame('EmptyCollection', $task->getJobId());
$this->assertContains($task, $tasks); $this->assertContains($task, $tasks);
$settings = simplexml_load_string($task->getSettings()); $settings = simplexml_load_string($task->getSettings());
$this->assertEquals(42, (int) $settings->bas_id); $this->assertEquals(42, (int) $settings->bas_id);
} }
/**
* @return Task[]
*/
private function findAllTasks() private function findAllTasks()
{ {
return self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll(); /** @var ObjectManager $objectManager */
$objectManager = self::$DI['app']['orm.em'];
return $objectManager->getRepository(Task::class)->findAll();
} }
/**
* @return Task
*/
private function loadTask() private function loadTask()
{ {
return self::$DI['app']['orm.em']->find('Phraseanet:Task', 1); /** @var ObjectManager $objectManager */
$objectManager = self::$DI['app']['orm.em'];
return $objectManager->find(Task::class, 1);
} }
/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createNotifierMock() private function createNotifierMock()
{ {
return $this->getMockBuilder('Alchemy\Phrasea\TaskManager\Notifier') return $this->getMockBuilder(Notifier::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
} }