mockTaskwarrior = $this->createMock(Taskwarrior::class); $this->mockTaskwarriorConfig = $this->createMock(Config::class); $this->mockLogger = $this->createMock(Logger::class); } function testConstructorWithConfig() { $this->mockTaskwarriorConfig->expects($this->once()) ->method('getTaskwarriorInstance') ->will($this->returnValue($this->mockTaskwarrior)); $this->taskCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); } function testBuildToDoComponent(){ $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; $startTime = new DateTime('2018-07-04'); $endTime = new DateTime('2018-07-06'); $modifiedTime = new DateTime('2018-08-05'); $categories = array('home', 'test'); $dueDate = new DateTime('2018-08-20'); $description = 'This is a simple todo'; $mockVCalendar = new VCalendar(); $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); $mockVTodo->add('DSTAMP', $startTime); $mockVTodo->add('DUE', $dueDate); $mockVTodo->add('LAST-MODIFIED',$modifiedTime); $mockVTodo->add('DSTART', $startTime); $mockVTodo->add('DTEND', $endTime); $mockVTodo->add('DESCRIPTION', $description); $mockVTodo->add('CATEGORIES', $categories); $this->mockTaskwarrior->expects($this->once())->method('setUUID') ->with($this->equalTo($mockVTodo->UID)); $this->mockTaskwarrior->expects($this->once())->method('setEntryTime') ->with($this->equalTo($mockVTodo->DSTAMP)); $this->mockTaskwarrior->expects($this->once())->method('setEndTime') ->with($this->equalTo($mockVTodo->DTEND)); $this->mockTaskwarrior->expects($this->once())->method('setDueDate') ->with($this->equalTo($mockVTodo->DUE)); $this->mockTaskwarrior->expects($this->once())->method('setSummary') ->with($this->equalTo($mockVTodo->DESCRIPTION)); $this->mockTaskwarrior->expects($this->once())->method('setCategories') ->with($this->equalTo($mockVTodo->CATEGORIES)); $this->mockLogger->expects($this->never())->method('error'); $this ->mockTaskwarriorConfig ->expects($this->once()) ->method('getTaskwarriorInstance') ->will($this->returnValue($this->mockTaskwarrior)); $this ->mockTaskwarrior ->expects($this->once()) ->method('build'); $this ->mockTaskwarrior ->expects($this->once()) ->method('save'); $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); $twCalEvent->importTask($mockVTodo); } /** * @expectedException Sabre\DAV\Exception * * */ function testFailTaskNoComponentDefine(){ $this->mockTaskwarrior->expects($this->never())->method('setUUID'); $this->mockTaskwarrior->expects($this->never())->method('setEntryTime'); $this->mockTaskwarrior->expects($this->never())->method('setEndTime'); $this->mockTaskwarrior->expects($this->never())->method('setDueDate'); $this->mockTaskwarrior->expects($this->never())->method('setSummary'); $this->mockTaskwarrior->expects($this->never())->method('setCategories'); $this->mockTaskwarrior->expects($this->never())->method('build'); $this->mockTaskwarrior->expects($this->never())->method('save'); $this->mockTaskwarrior->expects($this->never())->method('exists'); $this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance') ->willReturn($this->mockTaskwarrior); $this->mockLogger->expects($this->once())->method('error'); $this->mockTaskwarriorConfig->expects($this->once())->method('getLogger') ->willReturn($this->mockLogger); $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); $twCalEvent->importTask(); } /** * @expectedException Sabre\DAV\Exception\BadRequest * * */ function testFailTaskExists(){ $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; $mockVCalendar = new VCalendar(); $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); $expectedErrorMessage = "already exists"; $this->mockTaskwarrior->expects($this->never())->method('setUUID'); $this->mockTaskwarrior->expects($this->never())->method('setEntryTime'); $this->mockTaskwarrior->expects($this->never())->method('setEndTime'); $this->mockTaskwarrior->expects($this->never())->method('setDueDate'); $this->mockTaskwarrior->expects($this->never())->method('setSummary'); $this->mockTaskwarrior->expects($this->never())->method('setCategories'); $this->mockTaskwarrior->expects($this->never())->method('build'); $this->mockTaskwarrior->expects($this->never())->method('save'); $this->mockTaskwarrior->expects($this->once())->method('exists') ->willReturn(true); $this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance') ->willReturn($this->mockTaskwarrior); $this->mockLogger->expects($this->once())->method('error'); $this->mockTaskwarriorConfig->expects($this->once())->method('getLogger') ->willReturn($this->mockLogger); $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); $twCalEvent->importTask($mockVTodo); } } ?>