我有以下代碼來測試類構造函數是否會觸發異常但PHPUnit測試失敗。我想弄清楚我做錯了什麼。測試PHPUnit測試「__construct()必須是..的一個實例」不能識別異常
/** @test */
public function should_require_instance_of_uuid()
{
$this->setExpectedException('Exception');
$id = new BusinessPartnerId;
}
PHPUnit的提供了以下錯誤: 有1個錯誤: 1)測試\域\型號\ COMMON \業務夥伴\ BusinessPartnerIdTest :: should_require_instance_of_uuid 參數1傳遞給域\型號\ COMMON \業務夥伴\ BusinessPartnerId :: __ construct()必須是Rhumsaa \ Uuid \ Uuid的一個實例,沒有給出,在第14行的tests/Comain/Model/Common/BusinessPartner/BusinesPartnerIdTest.php中調用,並且定義爲
Domain/Model/Common/BusinessPartner /BusinessPartnerId.php:20 tests/Domain/Model/Common/BusinessPartner/BusinesPartnerIdTest.php:14
我不知道爲什麼這個測試沒有通過?我也曾嘗試: $this->setExpectedException('InvalidArgumentException');
這個工作!謝謝。 –