Skip to content

How to use different config settings in Magento integration tests?

I want to use Magento’s integration test suite to test some of my customizations. My code calls an external web API, which has different URLs depending of the environment which is used.

My module’s config.xml looks like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <myproject>
            <api_token_manager>
                <base_url>env:CONFIG__DEFAULT__MYPROJECT__API_TOKEN_MANAGER__BASE_URL</base_url>
                <api_key>env:CONFIG__DEFAULT__MYPROJECT__API_TOKEN_MANAGER__API_KEY</api_key>
                <api_key_secret>env:CONFIG__DEFAULT__MYPROJECT__API_TOKEN_MANAGER__API_KEY_SECRET</api_key_secret>
            </api_token_manager>
        </myproject>
    </default>
</config>

When I run the integration tests on my local dev environment, a local mock server should be used.
When I run the integration test on a external test environment, a test version of the API should be used.

So I need those configs to be customizable on different systems. And it is different between the real installation (which uses app/config/env.php) and the integration tests.

During the execution of the integration tests, Magento setup a separate database for the integration tests. I can adjust the installation params in the file dev/tests/integration/etc/install-config-mysql.php.

But I cannot specify the system config in this file.

I tried to use the dev/tests/integration/etc/config-global.php to do that. But the settings I put their are discarded during test execution by an event listener of the testing framework (see this bug report).

So my question is how can I achieve such a setup?