add done & delete
This commit is contained in:
		
							
								
								
									
										68
									
								
								src/Task.php
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								src/Task.php
									
									
									
									
									
								
							| @@ -9,6 +9,11 @@ use JMS\Serializer\Annotation as JMS; | ||||
|  */ | ||||
| class Task | ||||
| { | ||||
|     const STATUS_PENDING = 'pending'; | ||||
|     const STATUS_COMPLETED = 'completed'; | ||||
|     const STATUS_DELETED = 'deleted'; | ||||
|     const STATUS_WAITING = 'waiting'; | ||||
|  | ||||
|     /** | ||||
|      * @var string | ||||
|      * | ||||
| @@ -23,6 +28,21 @@ class Task | ||||
|      */ | ||||
|     private $description; | ||||
|  | ||||
|     /** | ||||
|      * @var string | ||||
|      * | ||||
|      * @JMS\Type(name="string") | ||||
|      */ | ||||
|     private $status; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->status = self::STATUS_PENDING; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
| @@ -54,4 +74,52 @@ class Task | ||||
|     { | ||||
|         $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; | ||||
|     } | ||||
| } | ||||
| @@ -3,9 +3,8 @@ | ||||
| namespace DavidBadura\Taskwarrior; | ||||
|  | ||||
| use JMS\Serializer\SerializerBuilder; | ||||
| use Symfony\Component\Process\ProcessBuilder; | ||||
| use Symfony\Component\Filesystem\Filesystem; | ||||
|  | ||||
| use Symfony\Component\Process\ProcessBuilder; | ||||
|  | ||||
| /** | ||||
|  * @author David Badura <d.a.badura@gmail.com> | ||||
| @@ -25,7 +24,7 @@ class Taskwarrior | ||||
|     /** | ||||
|      * @param string $taskrc | ||||
|      * @param string $taskData | ||||
|      * @param array  $rcOptions | ||||
|      * @param array $rcOptions | ||||
|      */ | ||||
|     public function __construct($taskrc = '~/.taskrc', $taskData = '~/.task', $rcOptions = []) | ||||
|     { | ||||
| @@ -98,12 +97,26 @@ class Taskwarrior | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $filter | ||||
|      * @return Task[] | ||||
|      */ | ||||
|     public function filterPending($filter = '') | ||||
|     { | ||||
|         return $this->filter($filter . ' status:pending'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param 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) | ||||
|     { | ||||
|         // todo | ||||
|         if (!$task->getUuid()) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $this->command('done', $task->getUuid()); | ||||
|         $task->setStatus(Task::STATUS_COMPLETED); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -167,7 +185,7 @@ class Taskwarrior | ||||
|     /** | ||||
|      * @param string $command | ||||
|      * @param string $filter | ||||
|      * @param array  $options | ||||
|      * @param array $options | ||||
|      * @return string | ||||
|      * @throws TaskwarriorException | ||||
|      */ | ||||
|   | ||||
| @@ -116,6 +116,65 @@ class TaskwarriorTest extends \PHPUnit_Framework_TestCase | ||||
|         $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() | ||||
|     { | ||||
|         $task1 = new Task(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user