Plugin activation in WP tests

Activating plugins before tests in WP Browser.

The problem

While writing functional tests for a plugin that relies on activation to work correctly and using wp-browser I’ve written this in the root codeception.yml file

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Db:
            ...
        WPBrowser:
            ...
        WPDb:
            ...
        WPLoader:
            wpRootFolder: ~/Sites/wp
            dbName: wp-tests
            dbHost: localhost
            dbUser: root
            dbPassword: root
            wpDebug: true
            dbCharset: utf8
            dbCollate: ''
            tablePrefix: wp_
            domain: wp.dev
            adminEmail: admin@wp.dev
            title: 'WP Tests'
            phpBinary: php
            language: ''
            config_file: local-config.php
            plugins:
                - required-plugin-a/required-plugin-a.php
                - plugin-requiring-activation/plugin-requiring-activation.php
                - my-plugin/my-plugin.php
            bootstrapActions:
                - activate_plugin-requiring-activation/plugin-requiring-activation.php
                - another_action
        WPWebDriver:
            ...

The WPLoader setting bootstrapActions will call the specified actions after all of the required plugins have been loaded.
I’m using that to activate a plugin that requires its activation hook to fire to work properly.
This is a good solution but one that might not be that easy to think of.

Activate plugins

I’ve added the activatePlugins setting to WP Loader configuration to allow for a more organized calling of the code in the version 1.7.2 of wp-browser.
The configuration file above could be modified to

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Db:
            ...
        WPBrowser:
            ...
        WPDb:
            ...
        WPLoader:
            wpRootFolder: ~/Sites/wp
            dbName: wp-tests
            dbHost: localhost
            dbUser: root
            dbPassword: root
            wpDebug: true
            dbCharset: utf8
            dbCollate: ''
            tablePrefix: wp_
            domain: wp.dev
            adminEmail: admin@wp.dev
            title: 'WP Tests'
            phpBinary: php
            language: ''
            config_file: local-config.php
            plugins:
                - required-plugin-a/required-plugin-a.php
                - plugin-requiring-activation/plugin-requiring-activation.php
                - my-plugin/my-plugin.php
            activatePlugins:
                - activate_plugin-requiring-activation/plugin-requiring-activation.php
            bootstrapActions:
                - another_action
        WPWebDriver:
            ...

The difference is not that much but it grants a more organized approach to code that I came to appreciate.