I have got 2 files: MyController.php, APIModel.php
MyController.php
class MyController extends Controller
{
public function post(Request $request)
{
$apiModel = new APIModel;
$apiResponse = $apiModel->GenId();
// Other process such as get data from database, validate data
return view(...);
}
}
APIModel.php
class APIModel extends Model
{
function GenId()
{
$response = $this->callAPI('GET', config('services.api_url.API_URL_GENID'));
}
function callAPI($method, $url, $data = array())
{
$curl = curl_init();
...
try
{
$result = curl_exec($curl);
if (!$result) {
throw new ServiceUnavailableHttpException('Could not connect to interface web service.');
}
}
catch (ServiceUnavailableHttpException $e)
{
throw $e;
}
}
}
Now I want to perform a phpunit test for MyController@post
Because it is running phpunit, when calling to the code line "$apiModel->GenId()", the error occurs
Is it possible to create a dummy method to call a dummy method instead of calling $apiModel->GenId()?
I'm using Laravel 5.2.45
Please help me!