From 1f16b4bfe0cdfaf9db5b505864cbc3391f9bdfb7 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Mon, 20 Sep 2021 13:00:01 +0200 Subject: [PATCH] Create todos with an ID --- src/Todo.php | 7 +++++++ tests/TodoTest.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Todo.php b/src/Todo.php index b4d2f05..2b994fb 100644 --- a/src/Todo.php +++ b/src/Todo.php @@ -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; diff --git a/tests/TodoTest.php b/tests/TodoTest.php index 2bf96b1..ccaf6df 100644 --- a/tests/TodoTest.php +++ b/tests/TodoTest.php @@ -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);