Skip to main content

Bitbucket Pipelines

Set php-ci as the top-level image (or per-step image) in bitbucket-pipelines.yml and your steps run with PHP, Composer and PHPUnit ready to go.

Minimal pipeline

image: himanshuramavat/php-ci:8.3

pipelines:
default:
- step:
name: Test
script:
- composer install --no-interaction --prefer-dist
- ./vendor/bin/phpunit

Cache Composer dependencies

Bitbucket has a built-in composer cache; you can also define your own:

image: himanshuramavat/php-ci:8.3

definitions:
caches:
composer-cache: ~/.composer/cache

pipelines:
default:
- step:
name: Test
caches:
- composer-cache
script:
- composer install --no-interaction --prefer-dist
- ./vendor/bin/phpunit

Run across PHP versions

Bitbucket has no native matrix, so use one step per version with an explicit per-step image:

pipelines:
default:
- parallel:
- step:
name: PHP 8.2
image: himanshuramavat/php-ci:8.2
script:
- composer update --no-interaction --prefer-dist
- ./vendor/bin/phpunit
- step:
name: PHP 8.3
image: himanshuramavat/php-ci:8.3
script:
- composer update --no-interaction --prefer-dist
- ./vendor/bin/phpunit
- step:
name: PHP 8.4
image: himanshuramavat/php-ci:8.4
script:
- composer update --no-interaction --prefer-dist
- ./vendor/bin/phpunit

With a database service

image: himanshuramavat/php-ci:8.3

definitions:
services:
mysql:
image: mysql:8.0
variables:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app_test

pipelines:
default:
- step:
name: Test
services:
- mysql
script:
- export DB_HOST=127.0.0.1
- export DB_DATABASE=app_test
- export DB_USERNAME=root
- export DB_PASSWORD=root
- composer install --no-interaction --prefer-dist
- ./vendor/bin/phpunit
Service networking

In Bitbucket Pipelines, service containers share the network namespace with your build container, so reach them on 127.0.0.1 (not the service name).

Full quality pipeline

image: himanshuramavat/php-ci:8.3

definitions:
caches:
composer-cache: ~/.composer/cache

pipelines:
default:
- step:
name: Quality & Tests
caches:
- composer-cache
script:
- composer install --no-interaction --prefer-dist
- ./vendor/bin/phpcs --standard=PSR12 src
- ./vendor/bin/phpstan analyse src --level=6
- ./vendor/bin/phpunit --coverage-text