We continuously try to improve the overall quality of our Magento projects. When we started with Magento 2, we decided that it is finally time to set up automatic test execution. Since we currently use Bitbucket for our private projects, we implemented that via Bitbucket Pipelines. I think the process for GitHub Actions, GitLab CI, you name it, is quite similar.
I will not go into the details of the Bitbucket Pipelines syntax. Check out the official documentation if you want to know more about the basics. I will also not go into the details of everything, just a few interesting notes and recommendations:
- We run three steps:
- Linting & Static Checks & Unit Tests: Checks the syntax of all PHP files, checks the Magento coding standard, executes a PHPStan analysis and runs all (client-specific!) unit tests.
- Integration Tests: Runs all (client-specific!) integration tests.
- MFTF Tests: Runs all (client-specific!) MFTF tests.
- Run multiple steps in parallel. This will not lower the costs / number of build minutes you spend, but it will speed up the execution.
- Make sure to activate the cache for Composer to speed up the setup and to save money / build minutes.
- When you use
docker-php-ext-install, make sure to pass
-j$(nproc)as a parameter. This will parallelise the installation, which again saves money / build minutes.
- We started with
php:7.2-apacheas a base Docker image, which does not come with too many unnecessary dependencies. However, this also means that we need to install many required dependencies ourselves.
- Bitbucket Pipelines currently does not nicely support multiple databases by default. The workaround is to define a root SQL password and then create the necessary databases yourself via CLI.
- For the MFTF tests, we need a (stripped) client database. We currently generate that stripped database dump via a cronjob each night and then get that database dump from a server via
- MFTF currently does not have an option to run all tests from a specific directory. Our workaround is to use a specific group for all client-specific tests. I created a GitHub issue for that.
Here is the complete Bitbucket Pipelines configuration file, which you can probably use with a few customisations in your projects:
Bitbucket Pipelines is nice, but a hell to debug. It took me quite a few evenings to get that to work, so I hope that I can save your time with this post 🙂 If you have any questions or want to say thank you, feel free to leave a comment or contact me!