You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
These classes offer some utility functions plus import numerous traits (seeTest/Integration/Traits/) with PHPUnit assertions. For instance, the following test checks for the proper registration of your module:
Toggle TESTS_CLEANUP in integration tests configuration
When running integration tests, you probably want to frequently toggle the constantTESTS_CLEANUP fromdisabled toenabled todisabled. The following command-line easily allows for this (assuming the file is actuallydev/tests/integration/phpunit.xml cause you shouldn't modify the*.dist version):
When installing Magento - as part of the procedure of running Integration Tests - the filedev/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 classYireo\IntegrationTestHelper\Utilities\InstallConfig you can quickly generate the relevant output, plus details like Redis and ElasticSearch:
When installing Magento - as part of the procedure of running Integration Tests - the filedev/tests/integration/etc/install-config-mysql.php is modified to point to your test database. There is also a flagdisable-modules that allows you to disable specific Magento modules. Disabling modules is a benefit for performance. The utility classYireo\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 globalapp/etc/config.php are disabled by default. But then all Magento core modules and the moduleYireo_GoogleTagManager2 are enabled (but only if they are marked as active in the global configuration):
Instead of using a hard-coded value, you might also want to set an environment variableMAGENTO_MODULE - for instance, in theRun configuration in PHPStorm. This way, you can keep the sameinstall-config-mysql.php file while reusing it for variousRun 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 theMAGENTO_MODULE_FOLDER variable instead, which parses your ownetc/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:
Note that if there would be a moduleYireo_ExampleGraphQl then this would be first disabled withdisableGraphQl() and then re-enabled again withenableByPattern('Yireo_'). The ordering of your methods matters!
Validating your configuration
The module also ships with a CLI command to easily check whether the currently returnedsetup: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 modifiedsetup/src/Magento/Setup/Model/SearchConfig.php file, but it's not perfect.
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 exampledocker-compose entry for this:
When using theDisableModules approach, all tests fail
TheDisableModules class tries to determine which modules are known to Magento by reading from the regularapp/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 theDisableModules class approach. If you don't want this to happen, first runsetup:upgrade in the regular environment and then run the tests again. Or explicitly disable the new modules as well.