我正在用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\支付::get($data‘’payKey,$apiContext);?当前,这会引发一个PHP致命错误:调用未定义的方法PhpSpec\Wrapper\Collaborator::get()
如何才能正确地做到这一点?提前感谢!
发布于 2013-11-01 12:05:21
你应该避免这么做。创建一个薄层,它将封装paypal库。嘲笑你自己的东西。
请参阅https://github.com/phpspec/prophecy/pull/20#issuecomment-18133965
https://stackoverflow.com/questions/19682754
复制相似问题