I like the idea of long term learning. Keeping myself learning day by day and sharing knowledge with the community help to grow as a professional and also as a person.
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.
I like the idea of long term learning. Keeping myself learning day by day and sharing knowledge with the community help to grow as a professional and also as a person.
I had one case like you describe. 3rd party library with hardcoded curl.
I extended that 3rd party class (which contained curl) into my own \Test\Dummy\Dummy Library, rewrote some methods to make them more testable and tested that one instead of original one. I know it's not ideal but it is only working thing I think. And it still does the trick.
Stupidest thing I encountered was when part of original library had methods marked as private and the class was final. 🤦
I like the idea of long term learning. Keeping myself learning day by day and sharing knowledge with the community help to grow as a professional and also as a person.
Hey, very sorry i did not see the comment :(. Yes, many third party libraries do not allow to extend certain parts of its code. Another option is to fork the project on github and make the changes on the forked one.
It would be great if that library code was on Github. :) In my case it is proprietary 3rd party PHP library which is not even on Github. It is being shipped few times a month by some company and I just download it and hope for the green tests. :D So far so good. Of course this is nowhere near perfect, but it works.
I like the idea of long term learning. Keeping myself learning day by day and sharing knowledge with the community help to grow as a professional and also as a person.
This is pretty straightforward. But what to do, when someone is so bright, that he used curl inside the tested method
getClimateData?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.
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 :-(
Ah ok, I am sorry. I did missed your sarcasm
I had one case like you describe. 3rd party library with hardcoded curl.
I extended that 3rd party class (which contained curl) into my own \Test\Dummy\Dummy Library, rewrote some methods to make them more testable and tested that one instead of original one. I know it's not ideal but it is only working thing I think. And it still does the trick.
Stupidest thing I encountered was when part of original library had methods marked as private and the class was final. 🤦
Hey, very sorry i did not see the comment :(. Yes, many third party libraries do not allow to extend certain parts of its code. Another option is to fork the project on github and make the changes on the forked one.
It would be great if that library code was on Github. :) In my case it is proprietary 3rd party PHP library which is not even on Github. It is being shipped few times a month by some company and I just download it and hope for the green tests. :D So far so good. Of course this is nowhere near perfect, but it works.
What's the library you are using ? I usually use PhpUnit and Codeception