callmebob
callmebob

Reputation: 6323

Codeception: Force PhpBrowser to use custom environment

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

Answers (1)

Naktibalda
Naktibalda

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:

  • Deploy API in test configuration
  • Pass environment using GET or POST parameters or headers and make your app code accept it. (this is a bad idea)

Upvotes: 1

Related Questions