Refactored Todo::validateState
This commit is contained in:
parent
df0dd98d7c
commit
f723e0e8c4
2 changed files with 3 additions and 2 deletions
|
@ -5,6 +5,7 @@ namespace MMK2410\MyTodoList;
|
||||||
class Todo
|
class Todo
|
||||||
{
|
{
|
||||||
const ExceptionMsgInvalidTitle = "Empty task title not allowed";
|
const ExceptionMsgInvalidTitle = "Empty task title not allowed";
|
||||||
|
const ExceptionMsgInvalidState = "Invalid state tried to set.";
|
||||||
|
|
||||||
private string $title;
|
private string $title;
|
||||||
private string $state;
|
private string $state;
|
||||||
|
@ -50,7 +51,7 @@ class Todo
|
||||||
$reflect = new \ReflectionClass(TodoStates::class);
|
$reflect = new \ReflectionClass(TodoStates::class);
|
||||||
$constantFound = $reflect->getConstant($state);
|
$constantFound = $reflect->getConstant($state);
|
||||||
if ($constantFound === FALSE) {
|
if ($constantFound === FALSE) {
|
||||||
throw new \InvalidArgumentException("Invalid state tried to set.");
|
throw new \InvalidArgumentException(self::ExceptionMsgInvalidState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -61,7 +61,7 @@ class TodoTest extends TestCase
|
||||||
{
|
{
|
||||||
$todo = new Todo("stub");
|
$todo = new Todo("stub");
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage("Invalid state tried to set.");
|
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidState);
|
||||||
$todo->setState("bogus");
|
$todo->setState("bogus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue