Skip to content

Instantly share code, notes, and snippets.

@leewillis77
Last active October 25, 2018 15:25
Show Gist options
  • Save leewillis77/8348193 to your computer and use it in GitHub Desktop.
Save leewillis77/8348193 to your computer and use it in GitHub Desktop.
How to use config values in Codeception tests?

I'm currently looking at using Codeception to test WordPress plugins. I've got most things set up how I'd like, but there's one final step that doesn't feel right. Because the tests will be distributed, and I want anyone to be able to run them on an install of their choosing some of the "config" for the tests needs to be easily changeable.

So - I need the real config to not be stored in version control. For site URL that's straightforward, I can not distribute the acceptance.suite.yml and instead distribute a sample file that the user can copy to acceptance.suite.yml and customise as appropriate.

However - my tests also need some other config that I'd want to be outside of version control. Ideally I'd add this config to the same YML file, but I need to be able to access it from the tests, e.g.

acceptance.suite.yml:

class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://wctwoone'
    testconfig:
        loginusername: <WordPresss login username here>
        loginpassword: <WordPresss login password here>

Then in the tests I want to be able to grab those values and use them, e.g.

$I->fillField('signin[username]', $this->testconfig['loginusername']);
$I->fillField('signin[password]', $this->testconfig['loginpassword']);

The syntax isn't important, but the concept of accessing values from the config in the test is what I'm trying to achieve.

From reading the docs I expect I can achieve this by writing a helper [Next on my list to try], but it seems like there should be an out-of-the-box way that I'm missing?

@tupikoff
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment