1
0
Fork 0

Refactored Todo::validateState

This commit is contained in:
Marcel Kapfer 2021-09-18 22:49:39 +02:00
parent df0dd98d7c
commit f723e0e8c4
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09
2 changed files with 3 additions and 2 deletions

View file

@ -5,6 +5,7 @@ namespace MMK2410\MyTodoList;
class Todo
{
const ExceptionMsgInvalidTitle = "Empty task title not allowed";
const ExceptionMsgInvalidState = "Invalid state tried to set.";
private string $title;
private string $state;
@ -50,7 +51,7 @@ class Todo
$reflect = new \ReflectionClass(TodoStates::class);
$constantFound = $reflect->getConstant($state);
if ($constantFound === FALSE) {
throw new \InvalidArgumentException("Invalid state tried to set.");
throw new \InvalidArgumentException(self::ExceptionMsgInvalidState);
}
}
}

View file

@ -61,7 +61,7 @@ class TodoTest extends TestCase
{
$todo = new Todo("stub");
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Invalid state tried to set.");
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidState);
$todo->setState("bogus");
}
}