add done & delete

This commit is contained in:
DavidBadura 2015-02-05 22:00:30 +00:00
parent 28b61adc99
commit dad551a72a
3 changed files with 151 additions and 6 deletions

View File

@ -9,6 +9,11 @@ use JMS\Serializer\Annotation as JMS;
*/ */
class Task class Task
{ {
const STATUS_PENDING = 'pending';
const STATUS_COMPLETED = 'completed';
const STATUS_DELETED = 'deleted';
const STATUS_WAITING = 'waiting';
/** /**
* @var string * @var string
* *
@ -23,6 +28,21 @@ class Task
*/ */
private $description; private $description;
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $status;
/**
*
*/
public function __construct()
{
$this->status = self::STATUS_PENDING;
}
/** /**
* @return string * @return string
*/ */
@ -54,4 +74,52 @@ class Task
{ {
$this->description = $description; $this->description = $description;
} }
/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* @param string $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return bool
*/
public function isPending()
{
return $this->status == self::STATUS_PENDING;
}
/**
* @return bool
*/
public function isCompleted()
{
return $this->status == self::STATUS_COMPLETED;
}
/**
* @return bool
*/
public function isWaiting()
{
return $this->status == self::STATUS_WAITING;
}
/**
* @return bool
*/
public function isDeleted()
{
return $this->status == self::STATUS_DELETED;
}
} }

View File

@ -3,9 +3,8 @@
namespace DavidBadura\Taskwarrior; namespace DavidBadura\Taskwarrior;
use JMS\Serializer\SerializerBuilder; use JMS\Serializer\SerializerBuilder;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder;
/** /**
* @author David Badura <d.a.badura@gmail.com> * @author David Badura <d.a.badura@gmail.com>
@ -98,12 +97,26 @@ class Taskwarrior
return $result; return $result;
} }
/**
* @param string $filter
* @return Task[]
*/
public function filterPending($filter = '')
{
return $this->filter($filter . ' status:pending');
}
/** /**
* @param Task $task * @param Task $task
*/ */
public function delete(Task $task) public function delete(Task $task)
{ {
// todo if (!$task->getUuid()) {
return;
}
$this->command('delete', $task->getUuid());
$task->setStatus(Task::STATUS_DELETED);
} }
/** /**
@ -111,7 +124,12 @@ class Taskwarrior
*/ */
public function done(Task $task) public function done(Task $task)
{ {
// todo if (!$task->getUuid()) {
return;
}
$this->command('done', $task->getUuid());
$task->setStatus(Task::STATUS_COMPLETED);
} }
/** /**

View File

@ -116,6 +116,65 @@ class TaskwarriorTest extends \PHPUnit_Framework_TestCase
$this->assertCount(2, $this->taskwarrior->filter()); $this->assertCount(2, $this->taskwarrior->filter());
} }
public function testPending()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskwarrior->save($task1);
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
$this->assertTrue($task1->isPending());
$this->taskwarrior->clear();
$result = $this->taskwarrior->find($task1->getUuid());
$this->assertEquals(Task::STATUS_PENDING, $result->getStatus());
$this->assertTrue($result->isPending());
$this->assertCount(1, $this->taskwarrior->filterPending());
}
public function testDelete()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->assertCount(0, $this->taskwarrior->filter());
$this->taskwarrior->save($task1);
$this->assertCount(1, $this->taskwarrior->filter());
$this->assertCount(1, $this->taskwarrior->filterPending());
$this->assertFalse($task1->isDeleted());
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
$this->taskwarrior->delete($task1);
$this->assertCount(1, $this->taskwarrior->filter());
$this->assertCount(0, $this->taskwarrior->filterPending());
$this->assertTrue($task1->isDeleted());
$this->assertEquals(Task::STATUS_DELETED, $task1->getStatus());
}
public function testCompleted()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->assertCount(0, $this->taskwarrior->filter());
$this->taskwarrior->save($task1);
$this->assertCount(1, $this->taskwarrior->filter());
$this->assertCount(1, $this->taskwarrior->filterPending());
$this->assertFalse($task1->isCompleted());
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
$this->taskwarrior->done($task1);
$this->assertCount(1, $this->taskwarrior->filter());
$this->assertCount(0, $this->taskwarrior->filterPending());
$this->assertTrue($task1->isCompleted());
$this->assertEquals(Task::STATUS_COMPLETED, $task1->getStatus());
}
public function testModifyDescription() public function testModifyDescription()
{ {
$task1 = new Task(); $task1 = new Task();