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:
- PHPUnit — Automated test suite (355 tests, 787 assertions)
- PHPStan — Static analysis at level 8 (strictest)
- PHPCS — WordPress Coding Standards compliance
Triggers:
- Every push to any branch
- All pull requests
masteranddevelopbranches
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.jsonhash - 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
| Setting | Value |
|---|---|
| Level | 8 |
| Paths | src/ |
| Extensions | szepeviktor/phpstan-wordpress |
| Stubs | php-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
| Setting | Value |
|---|---|
| Standard | WordPress |
| Paths | src/, gsm-middleware.php |
| PHP Version | 8.2+ |
| WordPress Version | 6.0+ |
| Text Domain | gsm-middleware |
| Exclusions | PSR-4 file naming (allows CamelCase class files) |
Composer Scripts Reference
All CI steps use Composer scripts for consistency between local development and CI:
| Script | Command | Description |
|---|---|---|
composer test | phpunit | Run full test suite |
composer test:unit | phpunit --testsuite Unit | Run unit tests only |
composer test:coverage | phpunit --coverage-html coverage/ | Generate coverage report |
composer phpstan | phpstan analyse -c phpstan.neon.dist | Static analysis |
composer phpcs | phpcs | Check coding standards |
composer phpcbf | phpcbf | Auto-fix coding standard violations |
composer format | phpcbf | Alias 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
- Ensure dev dependencies are installed:
composer install - Check PHP version:
php -v(requires 8.2+) - Run with verbose output:
vendor/bin/phpunit --verbose
Related Documentation
- Testing — Writing and running tests locally
- Installation — Development environment setup