Is it possible to test an abort that was called inside a model?
Hi everyone,
I want to unit test my User Model if the assignRole method would throw an error if an invalid role name was entered. The method inside looks like this:
public function assignRole($role)
{
$role = Role::where('name', $role)->first();
if (! $role) {
abort(422, "Invalid role assigned");
}
$this->roles()->attach($role->id);
}
It's working. I just don't know how to test it. Is this possible? If not, what's the best way to do this? Or am I doing something wrong here?
Thanks for the reply. I already have a test which checks if a valid role can be assigned to a user. What I want to do is to check if the assignRole method would throw an exception using the abort helper if an invalid role is entered.