braintree php 开发,php – 如何为使用Braintree和静态方法调用的端点编写集成测试...
我正在使用嚴重依賴靜態(tài)方法的Braintree PHP客戶端.
我在項目中的所有端點都包含集成測試
就像是:
Storage::shouldReceive('put')->once()->andReturn(true);
$this->post('/api/payment');
正如你所看到的,我也在使用Mockery來創(chuàng)建模擬.但是,由于Braintree庫嚴重依賴靜態(tài)方法,我無法創(chuàng)建方法,因此無法測試這些端點.
這是使用Braintree PHP客戶端編寫的代碼示例:
$result = Braintree\Transaction::sale([
'amount' => '1000.00',
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]
]);
我有什么選擇?
解決方法:
this answer只有你有嘲弄才能工作1. *已安裝..早期版本不會做靜態(tài)方法嘲笑.以下代碼有效:
$brainTreeMock = Mockery::mock('alias:Braintree_Transaction');
$transaction = (object)[ 'id' => str_random(5) ];
$brainTreeMock->shouldReceive('sale')->andReturn((object)[
'success' => true,
'transaction' => $transaction
]
);
標簽:braintree,php,integration-testing,mockery
來源: https://codeday.me/bug/20190727/1556038.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結
以上是生活随笔為你收集整理的braintree php 开发,php – 如何为使用Braintree和静态方法调用的端点编写集成测试...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DuangDuangDuang!码云项目
- 下一篇: 碰到日期题就怕的我来写一道水题吧