Unit testing 通过Zend服务提供商通过PHPUnit控制器测试模拟返回值

Unit testing 通过Zend服务提供商通过PHPUnit控制器测试模拟返回值,unit-testing,zend-framework,Unit Testing,Zend Framework,在上面的代码中,我只是获取与“order”服务提供者相关的实际对象的类名。然后创建该对象的模拟 然后,我将服务设置为mock的实例,这样当控制器引用“order”服务时,它将获得mock的实例 接下来,我将基于\Application\Model\Transaction模型创建一个orderServiceEntityMock 然后,每当调用orderServiceMock getEntity时,我都返回mock对象 然后,无论何时调用orderServiceMock getIsPaid,我都希望

在上面的代码中,我只是获取与“order”服务提供者相关的实际对象的类名。然后创建该对象的模拟

然后,我将服务设置为mock的实例,这样当控制器引用“order”服务时,它将获得mock的实例

接下来,我将基于\Application\Model\Transaction模型创建一个orderServiceEntityMock

然后,每当调用orderServiceMock getEntity时,我都返回mock对象

然后,无论何时调用orderServiceMock getIsPaid,我都希望返回true

控制员:

    $serviceManager = $this->getApplicationServiceLocator();
    $serviceManager->setAllowOverride(true);

    //Order Service

    $realOrderService = $serviceManager->get('order');

    $orderServiceMock = $this
        ->getMockBuilder(get_class($realOrderService))
        ->getMock();


    $serviceManager->setService('order', $orderServiceMock);
    //Order Service Entity
    $realOrderServiceEntity = new \Application\Model\Transaction;
    $orderServiceEntityMock = $this
        ->getMockBuilder(get_class($realOrderServiceEntity))
        ->getMock();

    $orderServiceMock
        ->expects($this->any())
        ->method('getEntity')
        ->will($this->returnValue($orderServiceEntityMock));

    $orderServiceMock
        ->expects($this->any())
        ->method('getIsPaid')
        ->will($this->returnValue(TRUE));

$this->dispatch('/test/create','POST', $data);
每当我们进入最后一个条件语句时,它都会使条件失效。 我做错了什么

public function create($data)
{
    //Create the order based on the information sent by the user
    $this->order = $this->getServiceLocator()->get('order');
    $this->order->setCard(new CreditCard($data['order']['billing']));
    $this->order->setAddress(new Address($data['order']['billing']));
    $this->order->setTotal($data['order']['amount']);

    $this->order->processPayment();
    if($this->order->getIsPaid())
    {