/** * @param User $user * @param Period $period * @return Timesheet */ private function timesheet(User $user, Period $period) { $worklogs = $this->workLogRepository->listAllByUserAndPeriod($user, $period); $taskList = new TaskList($period, $worklogs, new \DateTimeZone($this->localeSettings->getTimeZone())); $timeSheet = new Timesheet($user, $taskList); return $timeSheet; }
/** * @param int $worklogId * @return Worklog * @throws \RuntimeException if Worklog not found */ private function loadWorklog($worklogId) { $worklog = $this->worklogRepository->get($worklogId); if (null === $worklog) { throw new \RuntimeException('Worklog not found.'); } return $worklog; }
public function testCalculatePerTask() { $task = new Task(); $worklogs = [new Worklog(new TimeSpent(5), new \DateTime('now'), $task, new User()), new Worklog(new TimeSpent(3), new \DateTime('now'), $task, new User())]; $this->worklogRepository->expects($this->once())->method('listAllFilteredByTask')->with($this->equalTo($task))->will($this->returnValue($worklogs)); $total = $this->calculator->calculatePerTask($task); $this->assertEquals(8, $total->getValue()); $this->assertEquals('8s', (string) $total); }
/** * @test */ public function taskWorklogEntries() { $task = new Task(); $worklogs = [new Worklog(new TimeSpent(12), new \DateTime('now'), $task, new User(), 'DESC_ONE'), new Worklog(new TimeSpent(8), new \DateTime('now'), $task, new User(), 'DESC_TWO')]; $this->worklogRepository->expects($this->once())->method('listAllFilteredByTask')->with($task)->will($this->returnValue($worklogs)); $result = $this->twigExtension->taskWorklogEntries($task); $this->assertCount(count($worklogs), $result); $this->assertContainsOnlyInstancesOf('\\RA\\OroCrmTimeLapBundle\\Model\\Worklog', $result); $this->assertEquals($worklogs, $result); }
public function testCreateMonthTimeSheetPerUser() { $task = new Task(); $user = new User(); $currentDateTime = new \DateTime('2014-12-12'); $date = sprintf('%d-%d', $currentDateTime->format('Y'), $currentDateTime->format('m')); $worklogs = new ArrayCollection([new Worklog(new TimeSpent(7200), new \DateTime('2014-12-04'), $task, $user), new Worklog(new TimeSpent(28800), new \DateTime('2014-12-05'), $task, $user), new Worklog(new TimeSpent(13500), new \DateTime('2014-12-06'), $task, $user)]); $this->worklogRepository->expects($this->once())->method('listAllByUserAndPeriod')->with($user, $this->isInstanceOf('\\RA\\OroCrmTimeLapBundle\\Model\\Period'))->will($this->returnValue($worklogs)); $timesheet = $this->service->createMonthTimeSheetPerUser($user, $date); $this->assertInstanceOf('\\RA\\OroCrmTimeLapBundle\\Model\\Timesheet', $timesheet); $this->assertEquals(new TimeSpent(49500), $timesheet->getTotalTimeSpent()); $this->assertEquals(new TimeSpent(13500), $timesheet->getTotalTimeSpentPerDate(new \DateTime('2014-12-06'))); }
/** * @param Tracker $tracker */ private function processStopTracking(Tracker $tracker) { $this->trackerRepository->removeTracker($tracker); $timeSpent = $this->timeSpentFactory->create($tracker->getSpentSeconds()); $worklog = $this->worklogFactory->create($timeSpent, $tracker->getDateStarted(), $tracker->getTask(), $tracker->getUser()); $this->worklogRepository->save($worklog); }
/** * @test */ public function thatWorklogDeletes() { $worklogId = 1; $worklog = new Worklog(new TimeSpent(5), new \DateTime('now'), new Task(), new User(), 'DESC'); $this->worklogRepository->expects($this->once())->method('get')->with($this->equalTo($worklogId))->will($this->returnValue($worklog)); $this->worklogRepository->expects($this->once())->method('delete')->with($this->equalTo($worklog)); $this->service->deleteWorklog($worklogId); }
public function testStopTracking() { $user = new User(); $task = new Task(); $waitTimeInSeconds = 2; $tracker = new Tracker($user, $task); sleep($waitTimeInSeconds); $timeSpent = new TimeSpent($waitTimeInSeconds); $worklog = new Worklog($timeSpent, $tracker->getDateStarted(), $task, $user); $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($tracker)); $this->trackerRepository->expects($this->once())->method('removeTracker')->with($tracker); $this->timeSpentFactory->expects($this->once())->method('create')->with($tracker->getSpentSeconds())->will($this->returnValue($timeSpent)); $this->worklogFactory->expects($this->once())->method('create')->with($timeSpent, $tracker->getDateStarted(), $task, $user)->will($this->returnValue($worklog)); $this->worklogRepository->expects($this->once())->method('save')->with(); $this->service->stopTracking($user); }
/** * Calculate total Time Spent for the Task * @param Task $task * @return TimeSpent */ public function calculatePerTask(Task $task) { $list = $this->worklogRepository->listAllFilteredByTask($task); return $this->calculate($list); }
/** * @param Task $task * @return Collection|Worklog[] */ public function taskWorklogEntries(Task $task) { return $this->worklogRepository->listAllFilteredByTask($task); }