Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel中同一控制器内的另一个方法对方法的模拟调用_Php_Laravel_Phpunit_Mockery - Fatal编程技术网

Php Laravel中同一控制器内的另一个方法对方法的模拟调用

Php Laravel中同一控制器内的另一个方法对方法的模拟调用,php,laravel,phpunit,mockery,Php,Laravel,Phpunit,Mockery,我正在调用路由到methodIWantToTest的端点,如下所示: $response = $this->json('GET', 'my/endpoint/'); 我在附上下面的代码,你知道如何模拟对第二个方法的调用吗? 谢谢 我不知道我是否正确理解了你的问题,但你已经在做了。 我也不知道为什么在函数中的“()”后面使用“:”,并且在调用要调用的方法之后需要分号 class MyController extends Controller { public function me

我正在调用路由到
methodIWantToTest
的端点,如下所示:

$response = $this->json('GET', 'my/endpoint/');
我在附上下面的代码,你知道如何模拟对第二个方法的调用吗? 谢谢


我不知道我是否正确理解了你的问题,但你已经在做了。 我也不知道为什么在函数中的“()”后面使用“:”,并且在调用要调用的方法之后需要分号

class MyController extends Controller
{
    public function methodIWantToTest()
    {
        //some code to test  
        $this->methodIWantToMock();
        //some more code to test
    }
    public function methodIWantToMock()
    {
        //mock this response
    }
}
如果您想这样做,也可以传递值

class MyController extends Controller
{
    public function methodIWantToTest()
    {
        //some code to test  
        $this->methodIWantToMock($value);
        //some more code to test
    }
    public function methodIWantToMock($value)
    {
        //mock this response
    }
}
class MyController extends Controller
{
    public function methodIWantToTest()
    {
        //some code to test  
        $this->methodIWantToMock($value);
        //some more code to test
    }
    public function methodIWantToMock($value)
    {
        //mock this response
    }
}