mercredi 29 novembre 2017

How to load testing env variables for Laravel guzzle call in unit test

Even though it may not be good practice for a unit/feature test, I like to have a test for ensuring that my Laravel app gives the expected result for:

calling a web route .. that makes an async (Guzzle) call to the same application and returns the modified result.

Unfortunately, for phpunit I can define that the configuration is loaded from .env.testing and it connects to the testing database. However when a new request is done it will call my application with my normal .env variables. Which makes sense as it is a new http request, however it is not desired in the scenario.

I was thinking of changing the Guzzle call based on the environment used and call my endpoint directly when I am testing. However it doesn't feel good to have env based switches in my code, especially when it results in a different method (what if it does work calling it directly but fails when using guzzle, e.g. guzzle got lost from the dependencies).

What would be your method of preference to test the request till response as a whole, without breaking it up to smaller pieces?

Aucun commentaire:

Enregistrer un commentaire