Reputation: 6323
I have a page with a text field and button. After I fill out text field and press a button my controller is connecting to an API and getting some data based on the text.
I prepared a FAKE_API
for testing. Both REAL_API
and FAKE_API
are in the service container. The FAKE_API
is being prioritized when the environment is set to test
(.env.test
file). The controller gets the API object via dependency injection (constructor argument).
When I am testing using PhpBrowser
from Codeception
, the environment of the test itself is set to test
- this can be checked by var_dump($_ENV['APP_ENV'])
from the test.
However, (and this is the issue), if I add var_dump($_ENV['APP_ENV'])
to the controller code and run the same test, I can see that the controller actually uses the regular 'dev' environment (set in .env
file). This means that the REAL API
is being used instead of my FAKE_API
.
How can I force PhpBrowser tests to use my .env.test
? Is it even possible?
Upvotes: 0
Views: 151
Reputation: 14110
You can't do that.
PhpBrowser communicates to system under test via HTTP, so it can't set environment variables of the system.
Your options are:
Upvotes: 1