我正在使用 PHPSpec 测试一个类,它运行良好,直到我想为一个具有静态函数的类创建一个模拟。
我正在测试的课程:
<?php
namespace App\Service;
class PaymentService
{
public function paymentVerification($orderId, array $data)
{
...
// Get the payment details
$payment = \PayPal\Api\Payment::get($data['payKey'], $apiContext);
...
}
}
PHPSpec 类:
<?php
namespace App\Spec\Service;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class PaymentServiceSpec extends ObjectBehavior
{
/**
* @param \PayPal\API\Payment $payment
*/
function it_should_return_false_when_the_payment_verification_failed($payment)
{
...
// This throws a PHP Fatal error: Call to undefined method PhpSpec\Wrapper\Collaborator::get() in
$payment::get(Argument::exact($data['payKey']), Argument::exact($apiContext))->shouldReturn(array('foobar'));
...
$this->paymentVerification($orderId, $data)->shouldReturn(false);
}
}
如何模拟 \PayPal\Api\Payment::get($data['payKey'], $apiContext); ? 目前这会引发 PHP 致命错误:调用未定义的方法 PhpSpec\Wrapper\Collaborator::get()
如何正确地做到这一点?提前致谢!