How can I mock external API during testing in laravel 5?
问题 I want to test an HTTP route in laravel. The action function of the URL calls a helper function, which calls an external API. How can I mock the external API call while testing? public function actionFunction(){ $helper = new HelperClassHelper(); return Response::json($helper->getNames()); } Here, the getNames() function makes an external API call. How do I mock it? 回答1: You can add the HelperClassHelper as a dependency in the action, and then you are able to mock it in the test: public