I have the following code that creates a new user. I am using PHPUnit to prepare test cases but however my code coverage is unable to cover the exception case i.e. throw new Exception(__CLASS__ . ': Invalid data');.
Can someone please show me how to cover the exception case in phpunit using assertInstanceOf() or something else?
/**
* Creates a new user
*
* @param string $email
* @param UserType $UserType
*
* @return UserID
* @throws Exception If Invalid Data is Provided
*/
static public function Create($email, UserType $UserType)
{
if (!$UserType instanceof UserType) {
throw new Exception(__CLASS__ . ': Invalid data');
}
$UserID = parent::Create($email, $UserType);
return $UserID;
}
Many thanks