/**
  * @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 taskUserTracker()
 {
     $user = new User();
     $task = new Task();
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($this->token));
     $this->token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $tracker = new Tracker($user, $task, new \DateTime('now'));
     $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($tracker));
     $result = $this->twigExtension->userTracker();
     $this->assertEquals($tracker, $result);
 }
 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);
 }
 /**
  * @return Tracker
  */
 public function userTracker()
 {
     $token = $this->securityContext->getToken();
     $user = $token ? $token->getUser() : null;
     return $this->trackerRepository->retrieveUserTracker($user);
 }