带有 AbstractController phpunit 参数的方法。任何提示

Method with argument of AbstractController phpunit. Any hints

我需要测试看起来像这样的方法,但我的问题是:我应该如何进入这个方法,尤其是当我不能 "mock" AbstractController 时,如果没有 AbstractController 变量,它就无法工作

public function add(\Queue\Controller\AbstractQueueController $task) 
{
       //Logic of method         
}

你不需要嘲笑它。您已经将其设置为参数,因此本次测试不是测试 AbstractQueueController。

因此,例如,如果您的函数如下所示:

public function add(\Queue\Controller\AbstractQueueController $task) 
{
   $task->doSomething();
}

然后,在测试中,AbstractQueueController 应该接收对 doSomething 方法 () 的调用,然后断言其结果。

好吧,我做了类似的事情,我做了扩展 class

class addtest extends Queue\Controller\AbstractQueueController
{
    public function task() 
    {

    }
}

然后在我的 QueeuServiceTest 中扩展 PHPUnit_framework_TestCase

我做了测试方法

public function testadd()
{
    $this->queueService->add(new addtest);
}

它涵盖了代码,但我不知道这是好的做法