public function testCreates() { $taskEntity = new TaskEntity(); $taskEntity->setId(1); $anotherTaskEntity = new TaskEntity(); $anotherTaskEntity->setId(2); $user = new User(); $period = new Period(new \DateTime('2014-12-01'), new \DateTime('2014-12-31')); $worklogs = new ArrayCollection([new Worklog(new TimeSpent(60), new \DateTime('2014-12-02'), $taskEntity, $user), new Worklog(new TimeSpent(120), new \DateTime('2014-12-03'), $taskEntity, $user), new Worklog(new TimeSpent(180), new \DateTime('2014-12-04'), $anotherTaskEntity, $user)]); $taskList = new TaskList($period, $worklogs, new \DateTimeZone('UTC')); $this->assertEquals($period, $taskList->getPeriod()); $this->assertInstanceOf('\\Traversable', $taskList->getIterator()); $this->assertFalse($taskList->isEmpty()); $this->assertCount(2, $taskList->getIterator()); foreach ($taskList as $each) { $this->assertInstanceOf('\\RA\\OroCrmTimeLapBundle\\Model\\TimeSheet\\Task', $each); } }
public function testStartTrackingWhenUserTrackingOtherTask() { $user = new User(); $task = new Task(); $task->setId(1); $otherTask = new Task(); $otherTask->setId(2); $waitTimeInSeconds = 2; $trackerOfOtherTask = new Tracker($user, $otherTask); sleep($waitTimeInSeconds); $tracker = new Tracker($user, $task); $timeSpent = new TimeSpent($tracker->getSpentSeconds()); $worklog = new Worklog($timeSpent, $trackerOfOtherTask->getDateStarted(), $trackerOfOtherTask->getTask(), $trackerOfOtherTask->getUser()); $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($trackerOfOtherTask)); $this->timeSpentFactory->expects($this->once())->method('create')->with($trackerOfOtherTask->getSpentSeconds())->will($this->returnValue($timeSpent)); $this->worklogFactory->expects($this->once())->method('create')->with($timeSpent, $trackerOfOtherTask->getDateStarted(), $otherTask, $user)->will($this->returnValue($worklog)); $this->trackerFactory->expects($this->once())->method('create')->with($user, $task)->will($this->returnValue($tracker)); $this->trackerRepository->expects($this->once())->method('save')->with($tracker); $this->trackerRepository->expects($this->once())->method('removeTracker')->with($trackerOfOtherTask); $this->worklogRepository->expects($this->once())->method('save')->with($worklog); $this->service->startTracking($user, $task); }
/** * @test */ public function testListAllFilteredByTask() { $taskId = 1; $task = new Task(); $task->setId($taskId); $worklogs = [$this->worklog()]; $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork)); $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister)); $this->entityPersister->expects($this->once())->method('loadAll')->with(['task' => $taskId], null, null, null)->will($this->returnValue($worklogs)); $result = $this->repository->listAllFilteredByTask($task); $this->assertTrue(is_array($result)); $this->assertEquals($worklogs, $result); }