Selenium testing PHP sites in Bitbucket Pipelines

It looks like mounting files isn’t possible in the bitbucket services without getting all meta and using custom Docker-in-Docker images, so I ended up ditching the nginx service. However I successfully managed to run the PHP built in webserver!

php -S 127.0.0.1:80 public/index.php &

The -S option starts the built in dev server, and public/index.php is my app’s entrypoint. The & pushes the process into the background. It only seems to work with the 127.0.0.1 IP, if you try a custom host it won’t work.

Here’s my full pipeline config:

image:
  name: php:8.1-fpm
  username: $DH_USER
  password: $DH_PASS

definitions:
  services:
    db:
      image: mariadb:10.2
      variables:
        MARIADB_DATABASE: MY_TEST_DB
        MARIADB_USER: root
        MARIADB_ROOT_PASSWORD: 'root'
    chrome:
      image: selenium/standalone-chrome
      ports:
        - 4444
        - 5900


pipelines:
  pull-requests:
    '**':
      - step:
          services:
            - db
            - chrome
          name: Installing Composer and running Unit Tests...
          script:
            - if [[ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "develop" ]] && [[ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "release/"* ]]; then printf "Skipping Tests for this target (${BITBUCKET_PR_DESTINATION_BRANCH})"; exit; fi
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install --no-scripts
            - vendor/bin/grumphp git:pre-commit
            - cp config/autoload/data.test.php.dist config/autoload/data.test.php
            - php bin/console orm:schema-tool:create
            - php bin/console fixtures:load
            - php -S 127.0.0.1:80 public/index.php &
            - vendor/bin/codecept run --env=bitbucket

  branches:
    develop:
      - step:
          services:
            - db
          name: Installing Composer and running Unit Tests...
          script:
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install --no-scripts
            - vendor/bin/grumphp git:pre-commit
            - cp config/autoload/data.test.php.dist config/autoload/data.test.php
            - php bin/console orm:schema-tool:update --force --complete
            - php bin/console fixtures:load
            - php -S 127.0.0.1:80 public/index.php &
            - vendor/bin/codecept run unit --env=bitbucket