我目前正在開發一個存儲敏感數據的項目,因此必須能夠根據請求擦除它們。PHPUnit:將參數傳遞給模擬方法調用
我想測試我的實體(患者)是否保存到數據庫與一個空電話號碼。第一個想法是:將參數傳遞給PatientDao::savePatient(PatientModel $patient)
,並查看其phoneNumber
屬性。
因此,這裏的PatientDao
接口:
interface PatientDao {
function savePatient(PatientModel $patient);
}
而且在我的測試文件中的代碼:
$this->patientDao // This is my mock
->expects($this->once())
->method('savePatient'); // savePatient() must be called once
$this->controller->handleMessage(...);
$patient = ??; // How can I get the patient to make assertions with it ?
我如何能做到這一點,或有任何其他的方式,以確保病人用一個空電話號碼保存?
這應該做的伎倆,許多thx! – aspyct
在這裏工作過。注意:如果參數需要多個參數,則即使您不想全部測試,也需要全部包含它們。例如'$ this-> returnCallback(function($ patient,$ someOtherParameter){})'。 – fazy