2. #MM23NL
Jisse Reitsma
- Founder of Yireo
- Training Magento developers
- Maintaining open source extensions
- Board member of Mage-OS Nederland
- Organizer of MageUnconf NL
- Dad of currently 1 but soon 2
3. #MM23NL
ASSUMPTIONS
- You are familiar with Magento backend development
- You know what integration tests are
- You have tried running (any) tests at least once
20. #MM23NL
FASTER COMPOSER DOWNLOADS
- Use a Mage-OS repository nearby
- Create your own mirror
- mage-os/generate-mirror-repo-js
- Private Packagist
- Satis
21. #MM23NL
TUNING COMPOSER CACHE
- Folder $COMPOSER_HOME/cache
- Try to reuse the cache amongst various installations
- S3 bucket
- Docker volume
- ZIP artifact to unzip before install
26. #MM23NL
FILE phpunit.xml
- TESTS_CLEANUP=enabled at first run, disabled at subsequent runs
- TESTS_MEM_USAGE_LIMIT=4092M (PHP memory limit)
- TESTS_PARALLEL_RUN=1
- Remove Yandex listener if it is there
27. #MM23NL
SETTING UP INTEGRATION TESTS (3)
- Navigate to dev/tests/integration/
- Copy phpunit.xml.dist to phpunit.xml
- Copy etc/install-config-mysql.php.dist to etc/install-
config-mysql.php
30. #MM23NL
SETTING UP INTEGRATION TESTS (4)
- Navigate to dev/tests/integration/
- Copy phpunit.xml.dist to phpunit.xml
- Copy etc/install-config-mysql.php.dist to etc/install-
config-mysql.php
- Run ../../../vendor/bin/phpunit with your tests
31. #MM23NL
SETTING UP INTEGRATION TESTS (4)
- Navigate to dev/tests/integration/
- Copy phpunit.xml.dist to phpunit.xml
- Copy etc/install-config-mysql.php.dist to etc/install-
config-mysql.php
- Run ../../../vendor/bin/phpunit with your tests
Don't use bin/magento dev:tests:run integration because it's slower
32. #MM23NL
MY COMMAND
docker-compose exec -T php-fpm bash <<EOF
cd dev/tests/integration;
php -d memory_limit=-1 ../../../vendor/bin/phpunit
-c ../quick-integration/phpunit.xml
app/code/Yireo/Example/Test/Integration/
EOF
34. #MM23NL
DISCLAIMER
If TESTS_CLEANUP is disabled (so the setup is skipped), the total time
goes down to 4-8s (unoptimized) or even 1-3s (optimized). This talk is
not necessarily about that, even though all of the following tips do
apply.
36. #MM23NL
TEST RUN BENCHMARK
- PHP 8.2
- MySQL 8
- Magento default install (of 1419 modules)
- Yireo GoogleTagManager (27 tests, 127 assertions)
- Reset of entire Docker stack, tmp/, file cache, generated/
This is run on some computer with some CPU and some RAM: Exact
numbers are not important, relative comparison is important
37. #MM23NL
HOW ARE INTEGRATION TESTS RUN
- PHPUnit calls bootstrap file
- Bootstrap kickstarts Magento application
- Magento database setup is run (setup:install)
- Or a restore from existing dump is done
- Various test events are triggered (startTest, endTest, ...)
- Tests are run
42. #MM23NL
YIREO INTEGRATION TESTING HELPER
- Traits for usage in tests
- Command to toggle TESTS_CLEANUP
- Command for test setup validation
- InstallConfig and DisableModules classes
$ composer require --dev yireo/magento2-integration-test-helper
See https://github.com/yireo/Yireo_IntegrationTestHelper
43. #MM23NL
RUNNING THE MAGENTO INSTALLER
$ bin/magento setup:install –help
- Database is validated (unless --skip-db-validation is used)
- Database setup scripts are run (Setup/, db_schema.xml)
- Configuration files are created (app/etc/*.php)
- Search engine is validated
- ...
47. #MM23NL
OPTIMIZE TEMPORARY FOLDERS
- Mount /tmp as tmpfs
- Mount dev/tests/integration/tmp/ as tmpfs
- Possibly mount vendor/ as tmpfs
- Run MySQL in tmpfs
57. #MM23NL
SEARCH ENGINE VALIDATION
Could not validate a connection to Elasticsearch. Verify
that the Elasticsearch host and port are configured
correctly.
58. #MM23NL
OPTION 1: USE MYSQL LEGACY SEARCH
Use https://github.com/swissup/module-search-mysql-legacy
--search-engine=mysql
59. #MM23NL
OPTION 2: FAKE VALIDATION
HEAD request to http://localhost:9200/ should return HTTP/1.1 200 OK
Create a simple HTML page, configure webserver to listen to port 9200
60. #MM23NL
OPTION 3: HACK THE CORE
Create a composer patch for MagentoElasticsearchSetup
Validator::validate() and always return true
Note: A DI plugin does not work. We don't have a working application yet.
63. #MM23NL
TUNE ELASTICSEARCH
- Set discovery.type=single-node
- Set data folder to tmpfs
- When OpenSearch, disable optional plugins
- Tune Xms and Xmx
66. #MM23NL
SKIPPING MODULES
- Adding the flag –disable-modules to the installer
- Or use Yireo Integration Helper DisableModules class
- Or use composer replace
67. #MM23NL
YIREO COMPOSER REPLACE TOOLS
Use yireo/magento2-replace-tools to manage replacements via the CLI (including bulk
replacements and validation)
$ composer require yireo/magento2-replace-tools
$ composer replace:bulk:add yireo/magento2-replace-bundled
$ composer replace:bulk:add yireo/magento2-replace-graphql
$ composer replace:build
$ rm -rf vendor/ composer.lock
$ composer install