refactor: leverage Task and TaskManager external api methods to create task
refactor: remove uneeded configuration
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Monolog\Logger;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
||||
use Aerex\TaskwarriorPlugin\iCalEventProcessor;
|
||||
use Aerex\TaskwarriorPlugin\Config;
|
||||
use DavidBadura\Taskwarrior\Task;
|
||||
use DateTime;
|
||||
|
||||
|
||||
@@ -23,13 +24,14 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
private $mockTaskwarriorConfig;
|
||||
|
||||
/***
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \PHPUnit_Framework__MockObject
|
||||
*/
|
||||
private $mockLogger;
|
||||
|
||||
function setup(){
|
||||
|
||||
$this->mockTaskwarrior = $this->createMock(Taskwarrior::class);
|
||||
$this->mockTaskwarrior = $this->createMock(TaskwarriorManager::class);
|
||||
$this->mockTask = $this->createMock(Task::class);
|
||||
$this->mockTaskwarriorConfig = $this->createMock(Config::class);
|
||||
$this->mockLogger = $this->createMock(Logger::class);
|
||||
|
||||
@@ -62,34 +64,30 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
$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->mockTaskwarrior->expects($this->exactly(4))
|
||||
->method('parseiCalDateTime')
|
||||
->will($this->onConsecutiveCalls($startTime, $startTime, $modifiedTime, $endTime));
|
||||
|
||||
$this->mockTaskwarrior->expects($this->once())->method('createTask')->with($this->equalTo($uuid))
|
||||
->willReturn($this->mockTask);
|
||||
$this->mockTask->expects($this->once())->method('setDue')->with($this->equalTo($dueDate));
|
||||
$this->mockTask->expects($this->once())->method('setDescription')->with($this->equalTo($description));
|
||||
$this->mockTaskwarrior->expects($this->once())->method('convertToStringArray')->with($this->equalTo($mockVTodo->CATEGORIES))
|
||||
->willReturn($categories);
|
||||
|
||||
$this->mockTask->expects($this->once())->method('setTags')
|
||||
->with($this->equalTo($categories));
|
||||
|
||||
$this->mockTaskwarrior->expects($this->exactly(4))
|
||||
->method('setValue');
|
||||
|
||||
$this->mockLogger->expects($this->never())->method('error');
|
||||
|
||||
$this
|
||||
->mockTaskwarriorConfig
|
||||
$this->mockTaskwarriorConfig
|
||||
->expects($this->once())
|
||||
->method('getTaskwarriorInstance')
|
||||
->will($this->returnValue($this->mockTaskwarrior));
|
||||
|
||||
|
||||
|
||||
$this
|
||||
->mockTaskwarrior
|
||||
->expects($this->once())
|
||||
->method('build');
|
||||
|
||||
$this
|
||||
->mockTaskwarrior
|
||||
->expects($this->once())
|
||||
@@ -106,7 +104,7 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
function testFailTaskNoComponentDefine(){
|
||||
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setUUID');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setEntryTime');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setEndTime');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setDueDate');
|
||||
@@ -129,11 +127,14 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
function testFailTaskExists(){
|
||||
$uuid = '9f353281-1051-4c45-92db-462f5d353c76';
|
||||
|
||||
@@ -141,7 +142,7 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
$mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]);
|
||||
$expectedErrorMessage = "already exists";
|
||||
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setUUID');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('createTask');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setEntryTime');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setEndTime');
|
||||
$this->mockTaskwarrior->expects($this->never())->method('setDueDate');
|
||||
@@ -165,6 +166,8 @@ class iCalEventProcessorTest extends \PHPUnit\Framework\TestCase {
|
||||
$twCalEvent->importTask($mockVTodo);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user