Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cushty's avatar

Testing API's

Do you run tests against real APIs? If not, how do you usually check that the API is actually working in the tests, do you mock it, recreate the logic, or rely on something else?

Thanks

1 like
3 replies
vincent15000's avatar

What are you calling a real API ? Do you mean a third party API ?

If yes, I write 2 types of tests :

  • a first test where I only inject the data with the same format as the one coming from the API, you can effectively mock the function from which you call the API

  • a second test in real conditions where I don't mock the function and where I really use the API, but according to me this test is less important than the first one

Please or to participate in this conversation.