Last active
August 29, 2015 14:00
-
-
Save NigelGreenway/0e814a1e744729464365 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
## Specification: | |
## A User needs to be able to manage tasks to help with their workflow and and self management. | |
## They will need the ability to add tasks, update a task and delete a task for themselves only. | |
## Concept: | |
## A user can have a collection of tasks attached to them. | |
## A task must consist of a `Title`, `Description` and a `User` | |
## A task must have a status against it | |
## A task must be recorded when it is completed | |
## A task start and due datetime can be optional | |
## A task can not be deleted | |
## A task can be archived | |
## A task estimated time can be optional represented as 00:00|00h00|00H00 | |
## A task can have time logs | |
# ---- | |
/* | |
* Task Entity test | |
*/ | |
namespace TaskDomain\Test\Entity; | |
use TaskDomain\Entity\Task; | |
use UserDomain\Entity\User; | |
class TaskTest extends \PHPUnit_Framework_TestCase | |
{ | |
private $task; | |
private $assignee; | |
public function setUp() | |
{ | |
$this->user = new User('Firstname', 'Lastname', '[email protected]'); | |
$this->task = new Task('Title', 'Description', $assignee); | |
} | |
public function testTaskHasATitle() { | |
$this->assertEquals('Title', $this->task->title()); | |
} | |
public function testTaskHasADescription() { | |
$this->assertEquals('Description', $this->task->description()); | |
} | |
public function testTaskHasAnAssignee() { | |
$this->assertInstanceOf('UserDomain\Entity\User', $this->task->assignedTo()); | |
} | |
public function testTaskHasAStatusSet() { | |
$this->assertInstanceOf('TaskDomain\Static\TaskStatus', $this->task->status()); | |
$this->assertEquals(1, $this->task->status()); | |
} | |
public function testTaskHasBeenCompleteAndDatetimeHasBeenAdded() { | |
$task = clone $this->task; | |
$task->completed(); | |
$this->assertTrue($task->isCompleted()); | |
$this->assertInstanceOf('\Datetime', $task->getCompletedOn()); | |
} | |
public function testATaskStartDatetimeHasBeenSet() { | |
$task = clone $this->task; | |
$task->setStartDateTime(new \DateTime); | |
$this->assertInstanceOf('\DateTime', $task->getStartDatetime()); | |
} | |
public function testATaskDueDatetimeHasBeenSet() { | |
$task = clone $this->task; | |
$task->setDueDateTime(new \DateTime); | |
$this->assertInstanceOf('\DateTime', $task->getDueDatetime());} | |
public function testTaskIsNotArchived() { | |
$task = clone $this->task; | |
$this->assertFalse($task->isArchived()); | |
} | |
public function testTaskIsArchived() { | |
$task->archived(true); | |
$this->assertTrue($task->isArchived()); | |
} | |
public function testTaskHasAnEstimatedTimeSetAndIsRepresentedCorrectly() { | |
$task = clone $this->task; | |
$task->estimate('01h35'); | |
$this->assertEquals('01h35', $task->estimation()); | |
} | |
} | |
?> | |
<?php | |
/* | |
* Task Entity | |
*/ | |
namespace TaskDomain\Entity; | |
use TaskDomain\Static\TaskStatus; | |
use UserDomain\Entity\User; | |
final class Task | |
{ | |
private $id; | |
private $title; | |
private $description; | |
private $status; | |
private $statusDescripton; | |
private $statusChangeDateTime; | |
private $startDateTime; | |
private $dueDateTime; | |
private $archived = false; | |
private $estimation; | |
private $time = []; | |
private $author; | |
private $assignee; | |
public function __construct($title, $description, User $author, User $assignee) | |
{ | |
$this->title = $title; | |
$this->description = $description; | |
$this->author = $author; | |
$this->assignee = $assignee; | |
$this->status = TaskStatus::NEW; | |
} | |
public static function fqcn() | |
{ | |
return __CLASS__; | |
} | |
public function id() | |
{ | |
return $this->id; | |
} | |
public function title() | |
{ | |
return $title; | |
} | |
public function updateTitle($title) | |
{ | |
$this->title = $title; | |
} | |
public function description() | |
{ | |
return $description; | |
} | |
public function updateDescription($description) | |
{ | |
$this->description = $description; | |
} | |
public function assignTo(User $assignee) | |
{ | |
$this->assignee = $assignee; | |
} | |
public function author() | |
{ | |
return $this->author; | |
} | |
public function assignedTo() | |
{ | |
return $this->assignee; | |
} | |
public function completed() | |
{ | |
$this->status = TaskStatus::COMPLETED; | |
$this->statusChangeDateTime(); | |
} | |
public function closed() | |
{ | |
$this->status = TaskStatus::CLOSED; | |
$this->statusChangeDateTime(); | |
} | |
public function furtherInformationRequired() | |
{ | |
$this->status = TaskStatus::FURTHERINFORMATIONREQUIRED; | |
$this->statusChangeDateTime(); | |
} | |
public function awaitingFeedback() | |
{ | |
$this->status = TaskStatus::AWAITINGFEEDBACK; | |
$this->statusChangeDateTime(); | |
} | |
public function other() | |
{ | |
$this->status = TaskStatus::OTHER; | |
$this->statusChangeDateTime(); | |
} | |
public function statusDescripton($statusDescripton) | |
{ | |
$this->statusDescripton = $statusDescripton; | |
} | |
public function statusChangeDateTime() | |
{ | |
$this->statusChangeDateTime = new \DateTime; | |
} | |
public function startDateTime(\DateTime $startDateTime) | |
{ | |
$this->startDateTime = $startDateTime; | |
} | |
public function startsOn() | |
{ | |
return $this->startDateTime; | |
} | |
public function dueDateTime(\DateTime $dueDateTime) | |
{ | |
$this->dueDateTime = $dueDateTime; | |
} | |
public function isDueOn() | |
{ | |
return $this->dueDateTime; | |
} | |
public function archive() | |
{ | |
$this->archived = true; | |
} | |
public function unArchive() | |
{ | |
$this->archived = false; | |
} | |
public function isArchived() | |
{ | |
return $this->archived; | |
} | |
public function estimate($estimation) | |
{ | |
$this->estimation = $estimation; | |
} | |
public function estimated() | |
{ | |
return $this->estimation; | |
} | |
public function logTime($time) | |
{ | |
$this->time = $time; | |
} | |
public function __toString() | |
{ | |
return $this->title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment