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
}
}