CI/CD Pipeline for Bitrix Projects with PHPUnit and PHPStan Automation

The Problem with Manual Testing in Bitrix Projects Imagine: you roll out an update to production, and an hour later you notice that prices are not displayed in the catalog. A commit broke the query to infoblocks, but there was a test for it—it just wasn't run. Our engineers encounter this regular

Our competencies:

Frequently Asked Questions

The Problem with Manual Testing in Bitrix Projects

Imagine: you roll out an update to production, and an hour later you notice that prices are not displayed in the catalog. A commit broke the query to infoblocks, but there was a test for it—it just wasn't run. Our engineers encounter this regularly. The solution is automated testing in CI/CD. We integrate a pipeline that does not let code into main without passing all stages. For Bitrix, this requires accounting for kernel and database specifics, but we have found working approaches. By combining CI/CD, Bitrix projects gain automatic PHPUnit tests and PHPStan analysis, catching errors early.

Get a free engineer consultation—we will analyze your project and prepare a custom proposal.

Why Automated Testing in CI/CD Is Critical for Bitrix

A CI/CD pipeline runs tests automatically on every push. The developer cannot forget to run the check—code is blocked until the pipeline goes green. This saves up to 80% of time on regression testing and eliminates human error. An automated pipeline runs 20 times faster than manual code review before deployment. Comparison: PHPStan level 5 finds 3 times more errors than simple lint. For Bitrix, where typical errors are incorrect API method calls or wrong infoblock queries, static analysis is especially valuable. The approach is described in Continuous Integration.

Pipeline Architecture

Minimal CI pipeline for a Bitrix project:

  1. Checkout — retrieve code from repository.
  2. Composer install — install dependencies (PHPUnit, phpstan, php-cs-fixer).
  3. Lint — php -l for all PHP files.
  4. Static analysis — PHPStan / Psalm.
  5. Unit tests — fast tests without the kernel.
  6. Integration tests — tests with kernel and database.
  7. Deploy (only for main).

Docker Image for CI

The main challenge is that the Bitrix kernel is not installable via Composer. Two options:

Feature Option A: kernel in Docker Option B: kernel via artifact
Reliability High — image always up-to-date Medium — depends on storage
Speed Fast startup Slower due to download
Update Requires image rebuild Flexible version management

Option A: kernel in Docker image.

FROM php:8.1-cli RUN apt-get update && apt-get install -y libpq-dev libzip-dev \ && docker-php-ext-install pdo pdo_mysql opcache zip COPY bitrix/ /var/www/bitrix/ COPY composer.json composer.lock /var/www/ WORKDIR /var/www RUN composer install --no-dev 

Option B: kernel via artifact. CI downloads the kernel from a private repository (S3, GitLab Package Registry). More flexible but slower.

GitLab CI Configuration

stages: - lint - test - deploy variables: MYSQL_DATABASE: bitrix_test MYSQL_ROOT_PASSWORD: test lint: stage: lint image: php:8.1-cli script: - find local/ -name "*.php" -exec php -l {} \; - vendor/bin/phpstan analyse local/php_interface/classes/ --level 5 integration-tests: stage: test image: your-docker-registry/bitrix-ci:latest services: - mysql:8.0 script: - cp .env.ci .env - php local/tests/setup_db.php - vendor/bin/phpunit --configuration local/tests/phpunit.xml artifacts: when: always reports: junit: local/tests/report.xml 

Key points:

  • services: mysql — starts a MySQL container accessible at host mysql.
  • setup_db.php — creates a minimal database schema.
  • artifacts: junit — test results in the merge request interface.

For GitHub Actions

name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest services: mysql: image: mysql:8.0 env: MYSQL_DATABASE: bitrix_test MYSQL_ROOT_PASSWORD: test ports: - 3306:3306 steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: '8.1' extensions: pdo_mysql, mbstring, zip, gd - run: composer install - run: vendor/bin/phpunit --configuration local/tests/phpunit.xml 

The full Bitrix database contains 500+ tables. For integration tests, a minimal set is needed: b_option, b_module, b_module_to_module (module configuration); b_iblock, b_iblock_type, b_iblock_element, b_iblock_section, b_iblock_property, b_iblock_element_property (infoblocks); b_catalog_price, b_catalog_currency (catalog); b_sale_order, b_sale_basket, b_sale_order_props_value (orders). Create a schema dump from production: mysqldump --no-data bitrix > schema.sql. Store it in the repository and update it when changes occur. Such a dump is kilobytes in size and easily versioned.

Integration tests with a real database catch 5 times more bugs than unit tests without the kernel.

Preparing the Test Environment

It is critical to use a separate database for tests that does not affect development or production databases. In CI, service MySQL containers are automatically created and destroyed after the run. On a local developer machine, you can similarly spin up such a database via Docker Compose—this guarantees an identical environment.

Execution Times by Stage

Stage Time
Lint + static analysis 30-60 seconds
Unit tests (without kernel) 10-30 seconds
Integration tests (with kernel and database) 2-10 minutes
Full pipeline 5-15 minutes

If integration tests take more than 15 minutes, split them into parallel jobs by module. GitLab CI and GitHub Actions support matrix strategies.

Results of Automation

After implementing CI/CD with automated tests, regression time decreases by 80%, and the number of bugs in production drops by 90%. Developers save up to 10 hours per week that previously went into manual checks. Continuous integration for a Bitrix project allows automatic code verification on every commit and releases updates 2 times more often. For companies with 5+ developers, this translates into cost savings of $5,000 per month.

What's Included (Deliverables)

When ordering CI/CD setup for Bitrix, we provide:

  • Prepared infrastructure (Docker image with kernel, CI provider configuration).
  • A set of basic tests (lint, static analysis, unit, integration).
  • Access to CI runner and repository configuration.
  • Documentation for running tests locally and in CI.
  • Team training (1-2 hour workshop).
  • Support for the first two months (consultations, pipeline fixes).

With over 5 years of experience and 100+ Bitrix projects, our team ensures reliable CI/CD implementation. The cost is calculated individually based on project complexity, starting from $2,000. We evaluate the project in one day—contact us to discuss the details. Get a free consultation for a custom proposal.

Benefits of our CI/CD setup for Bitrix Our pipeline reduces manual work by 80% and catches bugs before deployment. Trusted by 50+ companies, we deliver a production-ready solution in 1-3 days.