1
0
Fork 0

Create todos with an ID

This commit is contained in:
Marcel Kapfer 2021-09-20 13:00:01 +02:00
parent 9e75b6f9bb
commit 1f16b4bfe0
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09
2 changed files with 18 additions and 1 deletions

View file

@ -13,15 +13,22 @@ class Todo
private string $title; private string $title;
private string $state; private string $state;
private bool $important; private bool $important;
private int $id;
public function __construct(string $title, bool $important = false) public function __construct(string $title, bool $important = false)
{ {
$this->validateTitle($title); $this->validateTitle($title);
$this->id = IdManager::generateID(self::class);
$this->title = $title; $this->title = $title;
$this->state = TodoStates::Todo; $this->state = TodoStates::Todo;
$this->important = $important; $this->important = $important;
} }
public function getID(): int
{
return $this->id;
}
public function getTitle(): string public function getTitle(): string
{ {
return $this->title; return $this->title;

View file

@ -6,7 +6,17 @@ use PHPUnit\Framework\TestCase;
class TodoTest extends 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"; $title = "Some task";
$todo = new Todo($title); $todo = new Todo($title);