[英]How to write unit test for a php function that executes stored procedure?
public function get(): array
{
$val = [
'@a' => $this->c,
'@b' => (int)$this->issucess
];
try {
return $this->db->Execute($this->spName, $val);
} catch (\Exception $e) {
}
}
如何為在 PHP 返回時執行存儲過程的此類函數編寫單元測試? PHPUnit
中是否有任何示例?
如果您測試FUNCTION,則不是程序- 創建數據庫模擬
$testParams = [
'@a' => 'value',
'@b' => 'value'
];
//stub procedure results
$testProcedureResult = [];
$dbMock = Mockery::mock(Database::class);
$dbMock->method('Execute')
->once()
->with('procedure', $testParams)
->willReturn($testProcedureResult);
$service = new YourTestedClass($dbMock);
//other service configuration..
$this->assertSame($testProcedureResult, $service->get());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.