/**
  * {@inheritdoc}
  */
 public function logWork($timeSpent, \DateTime $dateStarted, Task $task, User $user, $description = null)
 {
     $timeSpent = $this->timeSpentFactory->createFromString($timeSpent);
     $worklog = $this->worklogFactory->create($timeSpent, $dateStarted, $task, $user, $description);
     $this->worklogRepository->save($worklog);
     return $worklog->getId();
 }
 /**
  * @test
  */
 public function thatLogsWork()
 {
     $timeSpentInputString = '10m';
     $timeSpentInSeconds = 600;
     $dateStarted = new \DateTime('now');
     $description = 'DESC';
     $task = new Task();
     $user = new User();
     $timeSpent = new TimeSpent($timeSpentInSeconds);
     $worklog = new Worklog($timeSpent, $dateStarted, $task, $user, $description);
     $this->timeSpentFactory->expects($this->once())->method('createFromString')->with('10m')->will($this->returnValue($timeSpent));
     $this->worklogFactory->expects($this->once())->method('create')->with()->will($this->returnValue($worklog));
     $this->worklogRepository->expects($this->once())->method('save')->with($worklog);
     $this->service->logWork($timeSpentInputString, $dateStarted, $task, $user, $description);
 }
 /**
  * @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);
 }
 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);
 }