1
0
Fork 0
This repository has been archived on 2021-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
my-todo-list/tests/TodoTest.php

96 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2021-09-18 22:45:49 +02:00
<?php declare(strict_types=1);
use MMK2410\MyTodoList\Todo;
use MMK2410\MyTodoList\TodoStates;
use PHPUnit\Framework\TestCase;
class TodoTest extends TestCase
{
2021-09-20 13:00:01 +02:00
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
2021-09-18 22:45:49 +02:00
{
$title = "Some task";
$todo = new Todo($title);
$this->assertEquals(
$title,
$todo->getTitle(),
"Expected title '$title', but got '{$todo->getTitle()}'"
);
}
public function testDontCreateEmptyTodo(): void
{
2021-09-20 11:27:46 +02:00
$this->expectException(InvalidArgumentException::class);
2021-09-18 22:45:49 +02:00
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidTitle);
new Todo("");
}
public function testUpdateTitle(): void
{
$anotherTitle = "Another title";
$todo = new Todo("Some title");
$todo->setTitle($anotherTitle);
$this->assertEquals(
$anotherTitle,
$todo->getTitle(),
"Expected new title $anotherTitle, but got {$todo->getTitle()}"
);
}
public function testNewTodoState(): void
{
$todo = new Todo("stub");
$this->assertEquals(
TodoStates::Todo,
$todo->getStatus(),
"Expected todo state 'Todo', but got {$todo->getStatus()}"
);
}
public function testChangeTodoState(): void
{
$todo = new Todo("stub");
$todo->setState(TodoStates::Done);
$this->assertEquals(
TodoStates::Done,
$todo->getStatus(),
"Expected todo state 'Done', but got {$todo->getStatus()}"
);
}
public function testSetBogusTodoState(): void
{
$todo = new Todo("stub");
2021-09-20 11:27:46 +02:00
$this->expectException(InvalidArgumentException::class);
2021-09-18 22:49:39 +02:00
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidState);
2021-09-18 22:45:49 +02:00
$todo->setState("bogus");
}
2021-09-20 11:27:46 +02:00
public function testCreateImportantTodo(): void
{
$todo = new Todo("Some title", true);
$this->assertTrue(
$todo->getImportant(),
"Todo created as important, but it is not"
);
}
public function testMakeTodoImportant(): void {
$todo = new Todo("Some title");
$todo->setImportant();
$this->assertTrue(
$todo->getImportant(),
"Todo changed to important, but it is not"
);
}
2021-09-18 22:45:49 +02:00
}