4

I'm currently writing unit tests for my PHP code. I've read that unit tests should not interract with external elements such as network and filesystem.

In my code i have a curl wrapper class to simplify curl calls (i just use $response = CurlWrapper::call($url)) For my tests, i added a mock to replace this wrapper. my mock class returns predefined response based on the url. This way i avoid HTTP response times and my tests does not rely on an externaressource which can change at any moment.

Do i need to unit test my curl wrapper (the original one, not the mock) and if i need to, how can i test it ?

4
  • the question you linked is very interesting and i learned some useful things. However, i'm not fully sastisfied with the answer : in my case, the curl wrapper does more than just calling the curl library (not a lot of things but there is a little logic in the class). So does this wrapper needs to be tested in a unit test or is an integration test enough ? Commented Oct 27, 2016 at 13:54
  • that seems to be addressed by an answer in another related question: "Test everything that could possibly break..."
    – gnat
    Commented Oct 27, 2016 at 13:59
  • well i think i have an answer with all these related questions. i'm still not absolutely convinced that what i chose to do is the best answer but it seems that there is no universal answer as the limit between unit and integration test is very tiny Commented Oct 27, 2016 at 14:20
  • An integration test tests the interaction between objects. If you're using mocks, it's not an integration test. Commented Oct 27, 2016 at 15:49

0

Browse other questions tagged or ask your own question.