DEV Community

Discussion on: Testing an external api using PHPUnit

Collapse
 
icolomina profile image
Nacho Colomina Torregrosa • Edited

Hey Milan, I think I would create another service which will use Curl to get climate data (let's name it ClimateCurlHandler). Then I would inject ClimateCurlHandler into ClimateHandler (instead of HttpClient). Then, into the test, I would create an stub for ClimateCurlHandler mocking the method which executes the curl so that it would return the response to test. Finally, I would create the stub for ClimateHandler but setting as constructor argument the ClimateCurlHandler stub.

I am sure there are other and better ways to drive your case but I think this would be valid.

Collapse
 
milanobrtlik profile image
Milan Obrtlik

You maybe missed my sarcasm there. When i used sentence "is so bright", i meant there is hard dependency, which i am unable to refactor :-(

Thread Thread
 
icolomina profile image
Nacho Colomina Torregrosa

Ah ok, I am sorry. I did missed your sarcasm