public function testCreate()
 {
     $user = new User();
     $task = new Task();
     $timeTrackingRecord = new Tracker($user, $task);
     $this->assertNull($timeTrackingRecord->getId());
     $this->assertEquals($user, $timeTrackingRecord->getUser());
     $this->assertEquals($task, $timeTrackingRecord->getTask());
     $this->assertGreaterThanOrEqual(new \DateTime('now', new \DateTimeZone('UTC')), $timeTrackingRecord->getDateStarted());
 }
 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);
 }