yireo / magento2-integration-test-helper

yireo/magento2-integration-test-helper

Magento 2 module to support integration tests in other modules

  • Jisse Reitsma (Yireo)
magento2-module Compatibility: 2.4.7-2.4.8 Code Quality: Fail Tests: Pass Security: Pass OSL-3.0

Magento 2 integration testing helper

This module adds various utilities to aid in creating integration tests for Magento 2.

Installation

Use the following commands to install:

composer require yireo/magento2-integration-test-helper --dev

Enable this module:

./bin/magento module:enable Yireo_IntegrationTestHelper
./bin/magento setup:upgrade

Using this helper to enhance your tests

Parent classes:

  • \Yireo\IntegrationTestHelper\Test\Integration\AbstractTestCase
  • \Yireo\IntegrationTestHelper\Test\Integration\GraphQlTestCase

These classes offer some utility functions plus import numerous traits (see Test/Integration/Traits/) with PHPUnit assertions. For instance, the following test checks for the proper registration of your module:

<?php declare(strict_types=1);

namespace Yireo\Example\Test\Integration;

use PHPUnit\Framework\TestCase;
use Yireo\IntegrationTestHelper\Test\Integration\Traits\AssertModuleIsEnabled;
use Yireo\IntegrationTestHelper\Test\Integration\Traits\AssertModuleIsRegistered;
use Yireo\IntegrationTestHelper\Test\Integration\Traits\AssertModuleIsRegisteredForReal;

class ModuleTest extends TestCase
{
    use AssertModuleIsEnabled;
    use AssertModuleIsRegistered;
    use AssertModuleIsRegisteredForReal;

    public function testIfModuleIsWorking()
    {
        $this->assertModuleIsEnabled('Yireo_Example');
        $this->assertModuleIsRegistered('Yireo_Example');
        $this->assertModuleIsRegisteredForReal('Yireo_Example');
    }
}

Toggle TESTS_CLEANUP in integration tests configuration

When running integration tests, you probably want to frequently toggle the constant TESTS_CLEANUP from disabled to enabled to disabled. The following command-line easily allows for this (assuming the file is actually dev/tests/integration/phpunit.xml cause you shouldn't modify the *.dist version):

bin/magento integration_tests:toggle_tests_cleanup

It is toggled. You can also set the value directly:

bin/magento integration_tests:toggle_tests_cleanup enabled

Generating the install-config-mysql.php return array

When installing Magento - as part of the procedure of running Integration Tests - the file dev/tests/integration/etc/install-config-mysql.php should return an array with all of your relevant settings, most importantly the database settings. By using the utility class Yireo\IntegrationTestHelper\Utilities\InstallConfig you can quickly generate the relevant output, plus details like Redis and ElasticSearch:

<?php declare(strict_types=1);

use Yireo\IntegrationTestHelper\Utilities\InstallConfig;

return (new InstallConfig())
    ->addDb('mysql80_tmpfs')
    ->addRedis()
    ->addElasticSearch('elasticsearch6')
    ->get();

Disable modules when installing Magento

When installing Magento - as part of the procedure of running Integration Tests - the file dev/tests/integration/etc/install-config-mysql.php is modified to point to your test database. There is also a flag disable-modules that allows you to disable specific Magento modules. Disabling modules is a benefit for performance. The utility class Yireo\IntegrationTestHelper\Utilities\DisableModules allows you to generate a listing of modules to disable quicker.

In the following example, first all (!) modules that are listed in the global app/etc/config.php are disabled by default. But then all Magento core modules and the module Yireo_GoogleTagManager2 are enabled (but only if they are marked as active in the global configuration):

<?php declare(strict_types=1);

use Yireo\IntegrationTestHelper\Utilities\DisableModules;
use Yireo\IntegrationTestHelper\Utilities\InstallConfig;

$disableModules = (new DisableModules())
    ->disableAll()
    ->enableMagento()
    ->enableByName('Yireo_GoogleTagManager2')
    ->toString();

return (new InstallConfig())
    ->setDisableModules($disableModules)
    ->addDb('mysql80_tmpfs')
    ->addRedis()
    ->addElasticSearch('elasticsearch6')
    ->get();

Instead of using a hard-coded value, you might also want to set an environment variable MAGENTO_MODULE - for instance, in the Run configuration in PHPStorm. This way, you can keep the same install-config-mysql.php file while reusing it for various Run configurations:

MAGENTO_MODULE=Yireo_Example

Note that if your module has dependencies, they need to be added to the same environment as well:

MAGENTO_MODULE=Yireo_Example,Yireo_Foobar

If you have a lot of requirements, you can also use the MAGENTO_MODULE_FOLDER variable instead, which parses your own etc/module.xml and adds all declared modules to the whitelist:

MAGENTO_MODULE_FOLDER=app/code/Yireo/Example

Another example, all the Magento modules are enabled by default. But then MSI and GraphQL are disabled again, while all Yireo modules are enabled:

$disableModules = (new DisableModules())
    ->disableAll()
    ->enableMagento()
    ->disableMagentoInventory()
    ->disableGraphQl()
    ->enableByPattern('Yireo_')
    ->toString();

Note that if there would be a module Yireo_ExampleGraphQl then this would be first disabled with disableGraphQl() and then re-enabled again with enableByPattern('Yireo_'). The ordering of your methods matters!

Validating your configuration

The module also ships with a CLI command to easily check whether the currently returned setup:install flags make sense:

$ bin/magento integration_tests:check
+--------------------+--------------------+
| Setting            | Value              |
+--------------------+--------------------+
| TESTS_CLEANUP      | enabled            |
| TESTS_MAGENTO_MODE | developer          |
| DB host            | mysql57_production |
| DB username        | root               |
| DB password        | root               |
| DB name            | m2_test            |
| DB reachable       | Yes                |
| ES host            | localhost          |
| ES port            | 9207               |
| ES reachable       | Yes                |
| Redis host         | 127.0.0.1          |
| Redis port         | 6379               |
| Redis reachable    | Yes                |
+--------------------+--------------------+

FAQ

Do I need ElasticSearch / OpenSearch for integration tests?

Yes, by default. No, with a little bit of work. You could just disable all Elasticsearch and Opensearch modules at installation time (see code sample below), but then Magento will still try to detect a valid search engine during the setup. This could be hacked with a modified setup/src/Magento/Setup/Model/SearchConfig.php file, but it's not perfect.

$disableModules = (new DisableModules(__DIR__.'/../../../../'))
    ->disableByPattern('Elasticsearch')
    ->disableByPattern('Opensearch')
    ...

Another option might be to configure a Docker-based dummy service that responds with a HTTP status 200 while listening to port 9200. The following is an example docker-compose entry for this:

  elasticsearch-dummy:
      command: php -S 0.0.0.0:9200
      ports:
        - 9200

When using the DisableModules approach, all tests fail

The DisableModules class tries to determine which modules are known to Magento by reading from the regular app/etc/config.php file. If this file is outdated, because modules have been installed but not yet registered to this file, then these modules will be enabled by default through the DisableModules class approach. If you don't want this to happen, first run setup:upgrade in the regular environment and then run the tests again. Or explicitly disable the new modules as well.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.

[Unreleased]

[0.0.23] - 13 June 2026

Fixed

  • Bump constraints
  • Remove AssertModuleIsRegisteredForReal usage

[0.0.22] - 13 June 2026

Fixed

  • Add Symfony 7 compat
  • Add debugging flag to assertModuleIs* calls

[0.0.21] - 22 October 2025

Fixed

  • Add PHP 8.4 compat

[0.0.20] - 03 September 2025

Fixed

  • Add support for custom MODULE.json file
  • Add GitHub actions

[0.0.19] - 24 July 2025

Fixed

  • Upgrade PHP 8.4
  • Add "dev" composer keyword

[0.0.18] - 24 July 2025

Fixed

  • Add type hint for PHP 8.4
  • Allow server port to be either string or int
  • Better detection of deps of deps
  • New method addSearchEngine (instead of addElasticSearch)
  • Add PHP 8.4

[0.0.17] - 2022-2025

  • Previous releases
Versions
Version Stability QA Status Compatibility Released
0.0.23 stable Fail Magento 2.4.7-2.4.8 Details 2026-06-13 18:15:21
0.0.22 stable Not tested Not yet tested Details 2026-06-13 13:12:14
0.0.21 stable Fail Magento 2.4.7-2.4.8 Details 2025-10-22 11:23:18
0.0.20 stable Not tested Not yet tested Details 2025-09-03 17:47:02
0.0.19 stable Not tested Not yet tested Details 2025-07-24 11:57:38
0.0.18 stable Not tested Not yet tested Details 2025-07-24 10:19:28
0.0.17 stable Not tested Not yet tested Details 2025-04-17 09:00:01
0.0.16 stable Not tested Not yet tested Details 2025-03-14 16:06:20
0.0.15 stable Not tested Not yet tested Details 2024-10-11 07:30:57
0.0.14 stable Not tested Not yet tested Details 2024-10-08 12:40:09
0.0.13 stable Not tested Not yet tested Details 2024-06-28 13:03:59
0.0.12 stable Not tested Not yet tested Details 2024-06-05 13:21:28
0.0.11 stable Not tested Not yet tested Details 2023-10-16 10:37:11
0.0.10 stable Not tested Not yet tested Details 2023-08-28 13:46:18
0.0.9 stable Not tested Not yet tested Details 2023-08-28 07:14:51
0.0.8 stable Not tested Not yet tested Details 2023-06-07 12:02:19
0.0.7 stable Not tested Not yet tested Details 2023-01-20 16:00:31
0.0.6 stable Not tested Not yet tested Details 2022-09-18 07:33:04
0.0.5 stable Not tested Not yet tested Details 2022-09-13 13:01:55
0.0.4 stable Not tested Not yet tested Details 2022-08-04 08:07:45
0.0.3 stable Not tested Not yet tested Details 2022-08-04 08:01:21
0.0.2 stable Not tested Not yet tested Details 2022-08-04 07:50:35
0.0.1 stable Not tested Not yet tested Details 2022-02-09 16:29:37

Requires 2

Package Constraint
magento/framework ^101.0.1|^101.1|^102.0|^103.0
php 8.0.*||8.1.*||8.2.*||8.3.*||8.4.*

Requires-dev 6

Package Constraint
colinmollenhour/cache-backend-redis ^1.17
ext-json *
ext-pcre *
guzzlehttp/guzzle ^6.0|^7.0
magento/zend-cache ^1.16
symfony/console ^5.0|^6.0|^7.0

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass not tested

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Fail 37 1 error, 36 warnings (ruleset: Magento2) — 11 auto-fixable with phpcbf
PHPMD Error 0 phpmd produced unparseable XML output (exit=1)
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 7 7
2.4.8 7 7
2.4.9 7 N/A

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass not tested

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
OSL-3.0
Homepage
https://www.yireo.com/software/magento-extensions/
Authors

More from yireo

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.