How to mock an HTTP API using Laravel and Pest

I've made a YouTube video to demonstrate how to mock an HTTP API. The key to doing it is you can't use the vendor's API. You have to "redo" their API calls using the Laravel facade.

Every wondered why people Rave about Laravel's testing? To me the magic is HTTP mocking. I made this video to show a really simple example.

Before making the video I tried Googling it again with Pest and with luck I found this video by Spatie:
https://spatie.be/courses/testing-laravel-with-pest/using-http-fakes

My sincere gratitude to them for the incredible work they do!

The only thing I forgot in the video is to show that should you have some doubt if the API has changed, you can simply comment to mock and it will call the real API.

Also I found it interesting that the YouTube quality sucks, even though I chose what seems to be good defaults, namely H264 (MP4) and 60 frames per second.

Check out the video and let us know what you think!

Updated: 1 year ago

© 2022 Eugene's Blog