我正在呼叫路由到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
}
}
答案 0 :(得分:0)
我不知道我是否正确理解了您的问题,但是您已经在做。 我也不知道为什么在函数()之后使用':',并且在调用要调用的方法后需要用分号
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
}
}