Mock the Symfony HttpClient

💻 Let’s code

First, we create the service that calls the API and check if the user exists.

🍿 The interesting part

🔍 What should we test?

We should test our endpoint /admin/{email} and expect that our code does the job, that means when we call /admin/{email} and the external API return “yes” we expect to have a response:

{“user_exists”: true}
{“user_exists”: false}
{“user_exists”: false}

📚 How to test this stuff?

In a test environment, you don’t care about infrastructure and external services such as API. So we have to mock the API Response and see if our code works as well.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store