How do you import config sync files in a Drupal 8 functional test?

Viewed 1635

I would like to know how to import config sync files in my functional tests for modules I am testing. For instance, I have some custom content types I would like to test against, and there are a number of files in config/sync that pertain to the node modules that defines the custom content type.

class ArticleControllerTest extends BrowserTestBase {
    protected static $modules = ['node', 'dist_source'];
}

At the top of my test I define the modules which do succesfully import, but it doesn't include the config sync settings so none of my custom content types are present. How can I import these into my test environment?

2 Answers

I do it in my testing base class (extends BrowserTestBase) in setUp() like this:

    // import config from sync
    $config_path =  '/home/rainer/src/asdent/config/sync';
    $config_source = new FileStorage($config_path);
    \Drupal::service('config.installer')->installOptionalConfig($config_source);

works great.

It's just like a drush cim sync

And provides the production config to my end-2-end automated phpunit tests in gitlab CI.

Related