【发布时间】:2019-08-18 05:00:38
【问题描述】:
我有课
<?php
class Cards
{
public function __construct($id) {
$this->id = $id;
}
public function add($card) {
// Make API call
return true;
}
}
还有另一个返回 Cards 类的类
<?php
class Payment
{
public function cards() {
return new Cards('1');
}
}
而且我似乎无法弄清楚如何模拟付款,所以它返回一个模拟卡。基本上我想
模拟付款,因此它返回一个模拟的卡片,允许类似的功能
function() {
$vault = new Payment;
$cards = $vault->cards();
if ($cards->add()) {
// do stuff
}
}
无需对支付处理器进行 API 调用即可进行模拟和测试。
【问题讨论】:
标签: php unit-testing mocking phpunit mockery