Skip to main content

CI/CD Pipeline

GSM Middleware uses Bitbucket Pipelines for continuous integration, running automated tests and code quality checks on every push.

Overview

The CI/CD pipeline runs three parallel checks:

  1. PHPUnit — Automated test suite (355 tests, 787 assertions)
  2. PHPStan — Static analysis at level 8 (strictest)
  3. PHPCS — WordPress Coding Standards compliance

Triggers:

  • Every push to any branch
  • All pull requests
  • master and develop branches

Pipeline Architecture

graph LR
A[Git Push] --> B[Install Dependencies]
B --> C[PHPUnit Tests]
B --> D[PHPStan Analysis]
B --> E[PHPCS Standards]
C --> F[Results]
D --> F
E --> F

Execution Environment

  • Runner: Self-hosted (self.hosted, linux.shell)
  • Caching: Composer dependencies cached by composer.json hash
  • Parallelism: PHPUnit, PHPStan, and PHPCS run in parallel after dependency installation

Pipeline Steps

Step 1: Install Dependencies

- step:
name: Install Dependencies
script:
- composer install --no-interaction --prefer-dist
caches:
- composer-cache

Installs all Composer dependencies (including dev dependencies) with caching for faster subsequent runs.

Step 2a: PHPUnit Tests

- step:
name: PHPUnit
script:
- composer test

Runs the full test suite. See Testing for details on the test infrastructure.

Step 2b: PHPStan Static Analysis

- step:
name: PHPStan
script:
- composer phpstan

Runs PHPStan at level 8 (maximum strictness) with WordPress stubs via szepeviktor/phpstan-wordpress.

Configuration: phpstan.neon.dist

SettingValue
Level8
Pathssrc/
Extensionsszepeviktor/phpstan-wordpress
Stubsphp-stubs/wordpress-stubs

Step 2c: PHPCS Coding Standards

- step:
name: PHPCS
script:
- composer phpcs

Checks code against WordPress Coding Standards with project-specific exceptions.

Configuration: .phpcs.xml.dist

SettingValue
StandardWordPress
Pathssrc/, gsm-middleware.php
PHP Version8.2+
WordPress Version6.0+
Text Domaingsm-middleware
ExclusionsPSR-4 file naming (allows CamelCase class files)

Composer Scripts Reference

All CI steps use Composer scripts for consistency between local development and CI:

ScriptCommandDescription
composer testphpunitRun full test suite
composer test:unitphpunit --testsuite UnitRun unit tests only
composer test:coveragephpunit --coverage-html coverage/Generate coverage report
composer phpstanphpstan analyse -c phpstan.neon.distStatic analysis
composer phpcsphpcsCheck coding standards
composer phpcbfphpcbfAuto-fix coding standard violations
composer formatphpcbfAlias for phpcbf

Running Locally

Run the same checks locally before pushing:

cd wp-content/plugins/gsm-middleware

# Install dev dependencies
composer install

# Run all checks (same as CI)
composer test
composer phpstan
composer phpcs

# Auto-fix coding standard issues
composer phpcbf

Troubleshooting

PHPStan Errors

If PHPStan reports unknown WordPress functions:

# Ensure WordPress stubs are installed
composer require --dev szepeviktor/phpstan-wordpress php-stubs/wordpress-stubs

PHPCS Errors

To auto-fix most coding standard violations:

composer phpcbf

For PSR-4 file naming conflicts (WordPress expects hyphenated filenames, PSR-4 uses CamelCase), these are excluded in .phpcs.xml.dist.

Test Failures

  1. Ensure dev dependencies are installed: composer install
  2. Check PHP version: php -v (requires 8.2+)
  3. Run with verbose output: vendor/bin/phpunit --verbose