I created an helper class that wraps http calls to an external service using the Http facade: all the methods basically wraps the same http call structure: Http::withHeaders()->post() or get() using the right headers, target url and data.
Now I need to mock it during tests to avoid having it making real calls.
Since I do not need to mock the withHeaders method I just want to mock the post/get method so I came up to this:
Http::fake(); Http::partialMock() ->makePartial() ->shouldDeferMissing(); Http::shouldReceive('post') ->with($this->defaultData) ->once() ->andReturn('tests'); but when running the test it breaks beacuse curl is trying to make a real call:
cURL error 6: Could not resolve host: fake-test-host (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for fake-test-host/api/private/v1/target Also, removing the second code block (the one with partialMock) it seems partially working since the error change in
Method Mockery_2_Illuminate_Http_Client_Factory::withHeaders() does not exist on this mock object as if the post method where been mocked but withHeaders did not.