我有以下代碼創建一個新用戶。我正在使用PHPUnit編寫測試用例,但是我的代碼覆蓋範圍無法覆蓋例外情況,即throw new Exception(__CLASS__ . ': Invalid data');.
PHPUnit異常
有人可以告訴我如何使用assertInstanceOf()或其他方法介紹phpunit中的異常情況嗎?
/**
* 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;
}
非常感謝
夥計們,請不要在不知道我在找什麼的情況下將其作爲重複帖子。您發佈的鏈接對我沒有任何幫助,因爲它沒有說明處理類型提示異常的任何內容。謝謝 – user2909892
那是不是重複? – hakre
作爲問題的提出者,您可以告訴我們您「正在尋找什麼」。你還希望如何得到答案? – vascowhite