/** * {@inheritdoc} */ public function updateWorklog($worklogId, $timeSpent, \DateTime $dateStarted, $description = null) { $worklog = $this->loadWorklog($worklogId); $timeSpent = $this->timeSpentFactory->createFromString($timeSpent); $worklog->update($timeSpent, $dateStarted, $description); $this->worklogRepository->save($worklog); }
/** * @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); }
/** * @test */ public function thatWorklogUpdates() { $worklogId = 1; $timeSpentInputString = '10m'; $timeSpentInSeconds = 600; $dateStarted = new \DateTime('now'); $dateStarted->sub(new \DateInterval('P2D')); $description = 'UPDATED DESC'; $timeSpent = new TimeSpent($timeSpentInSeconds); $worklog = new Worklog(new TimeSpent(300), new \DateTime('now'), new Task(), new User(), 'DESC'); $this->worklogRepository->expects($this->once())->method('get')->with($this->equalTo($worklogId))->will($this->returnValue($worklog)); $this->timeSpentFactory->expects($this->once())->method('createFromString')->with($timeSpentInputString)->will($this->returnValue($timeSpent)); $this->worklogRepository->expects($this->once())->method('save')->with($this->equalTo($worklog)); $this->service->updateWorklog($worklogId, $timeSpentInputString, $dateStarted, $description); $this->assertEquals($timeSpent, $worklog->getTimeSpent()); $this->assertEquals($dateStarted, $worklog->getDateStarted()); $this->assertEquals($description, $worklog->getDescription()); }