Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using different codeception environments

I am working on some Unit Tests for an API using Codeception. The idea is to make sure that each API call returns the expected response codes and a JSON object in a desired format.

The problem that I have is that I need to use different URLs depending on whether the server is localhost, the test server or the production one.

I can't use the values of $_SERVER['SERVER_NAME'] because the tests are not ran through the web browser.

Here http://codeception.com/docs/07-AdvancedUsage#Environments they explain that some environments can be set by modifying the configuration file. The documentation doesn't explain how to modify the configuration file to use it within your own unit tests.

Id like to set some environments like local, test, production and then, inside my unit test classes, to know what URLs to use. Each environment would have different URLs.

I've read the documentation but I can't find the way to do it.

Do you know any way to achieve what I need?

like image 632
woodgate Avatar asked Feb 25 '14 13:02

woodgate


1 Answers

Make sure that your codeception version is at least 1.8, as environment is only supported from 1.8.

Below is our setup for codeception, specified in api.suite.yml, with PhpBrowser and REST modules enabled for BDD and API testings:

...
env:
    local:
        modules:
            config:
                PhpBrowser:
                    url: http://local.example.com/
                REST:
                    url: http://local.example.com/v1/
    integration:
        modules:
            config:
                PhpBrowser:
                    url: http://integration.example.com/
                REST:
                    url: http://integration.example.com/v1/
    staging:
        modules:
            config:
                PhpBrowser:
                    url: http://staging.example.com/
                REST:
                    url: http://staging.example.com/v1/

When running codecept command, you need to provide an --env option to specify which environment the tests should use.

like image 125
hidro Avatar answered Nov 05 '22 09:11

hidro