Create todos with an ID
This commit is contained in:
parent
9e75b6f9bb
commit
1f16b4bfe0
2 changed files with 18 additions and 1 deletions
|
@ -13,15 +13,22 @@ class Todo
|
|||
private string $title;
|
||||
private string $state;
|
||||
private bool $important;
|
||||
private int $id;
|
||||
|
||||
public function __construct(string $title, bool $important = false)
|
||||
{
|
||||
$this->validateTitle($title);
|
||||
$this->id = IdManager::generateID(self::class);
|
||||
$this->title = $title;
|
||||
$this->state = TodoStates::Todo;
|
||||
$this->important = $important;
|
||||
}
|
||||
|
||||
public function getID(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
|
|
|
@ -6,7 +6,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class TodoTest extends TestCase
|
||||
{
|
||||
public function testCreateTodo(): void
|
||||
public function testCreateTodo(): void {
|
||||
$todo1 = new Todo("Some title");
|
||||
$todo2 = new Todo("Some title");
|
||||
$this->assertNotEquals(
|
||||
$todo1->getID(),
|
||||
$todo2->getID(),
|
||||
"Expected todos to have different UIDs but they have the same."
|
||||
);
|
||||
}
|
||||
|
||||
public function testTodoHasTitle(): void
|
||||
{
|
||||
$title = "Some task";
|
||||
$todo = new Todo($title);
|
||||
|
|
Reference in a new issue