Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AndyDunn's avatar

Testing with BitBucket Pipelines

Has anyone managed to get a pipeline setup in BitBucket that will automatically install and configure their Laravel application and then run a series of PHPUnit tests against it?

I've had a quick look but from what I can see their support for databases is quite limited and I'm not sure if it's even possible. Would love to see if someone has managed to do this already and what their .yaml file is like.

0 likes
9 replies
dkruger's avatar

@AndyDunn for what I saw before.. BitBucket still doesn't support DB :( maybe pushing a sqlite DB on the repository for just test and using that would work?

vijay.rangan's avatar

Hey @AndyDunn, I just setup my bitbucket pipeline to setup my project and run phpunit. Here's the docker image I used https://hub.docker.com/r/smartapps/bitbucket-pipelines-php-mysql/ and here's my yaml config :

image: smartapps/bitbucket-pipelines-php-mysql

pipelines:
    default:
        - step:
            script:
                - composer install
    branches:
        staging:
            - step:
                script:
                    - composer install
                    - service mysql start
                    - mysql -h localhost -u root -proot -e "CREATE DATABASE test_db"
                    - php artisan migrate --env=testing
                    - phpunit -c phpunit.xml

Since bitbucket allows us to use custom docker images, this seems to the best solution so far for supporting custom environments rather than depending upon bitbucket's pre-set docker images.

1 like
willvincent's avatar

Literally the exact same container I suggested.. :)

1 like
AndyDunn's avatar

We actually went with something very similar except using our own Docker image. It's been working out very well and is great to get a status of our tests on every commit.

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: ivanthecrazy/laravel

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - service mysql start
          - mysql -uroot -e "DROP DATABASE IF EXISTS idpal; CREATE DATABASE IF NOT EXISTS idpal;"
          - cp .env.test .env
          - composer install
          - php artisan migrate:refresh --seed
          - ./vendor/bin/phpunit
4 likes
reasondigital's avatar

Has anyone gotten Dusk tests running with bitbucket pipelines?

2 likes
zaherg's avatar

@AndyDunn you can use bitbucket mysql service instead like in this example:

clone:           # the 'clone' section
  depth: 1       # the depth, in this case the clone will contain last commit

options:
  max-time: 10

image: zaherg/php-7.2-xdebug-alpine:latest

pipelines:
  branches:

    '{master,develop}':
      - step:
          name: Build and push the image
          caches:
            - composer
          script:
            - composer config -g github-oauth.github.com $GITHUB_TOKEN
            - composer global require hirak/prestissimo
            - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
            - cp .env.example .env
            - php artisan key:generate
            - composer run test
          services:
            - redis
            - mysql

  default:
    - step:
        name: Build and push the image
        caches:
          - composer
        script:
          - composer config -g github-oauth.github.com $GITHUB_TOKEN
          - composer global require hirak/prestissimo
          - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
          - cp .env.example .env
          - php artisan key:generate
          - composer run test
        services:
          - redis
          - mysql

 definitions:
   services:
     redis:
       image: redis
     mysql:
       image: mysql:5.7
       environment:
         MYSQL_DATABASE: 'homestead'
         MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
         MYSQL_USER: 'homestead'
         MYSQL_PASSWORD: 'secret'

you can read more about it here https://confluence.atlassian.com/bitbucket/use-services-and-databases-in-bitbucket-pipelines-874786688.html

PS: am using hirak/prestissimo package here to speed up composer install process a bit (more can be explained here https://mhdzaherghaibeh.name/2018/03/04/two-tips-to-speed-up-bitbucket-pipelines/ )

Please or to participate in this conversation.