Skip to content

Instantly share code, notes, and snippets.

@TimothyBJacobs
Created December 19, 2019 03:18
Show Gist options
  • Save TimothyBJacobs/d42a9c9316751e4fafaf0bda02dc9a00 to your computer and use it in GitHub Desktop.
Save TimothyBJacobs/d42a9c9316751e4fafaf0bda02dc9a00 to your computer and use it in GitHub Desktop.
Testing WordPress Plugins with Codeception on Bitbucket Pipelines using Docker Compose
DB_PORT=9119
WP_PORT=7253
WP_TAG=latest
pipelines:
default:
- step:
name: Build
image: php:7.3
caches:
- composer
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install --ignore-platform-reqs
- cp docker-compose.codeception.env codeception.env
artifacts:
- '**'
- parallel:
- step:
name: WP Unit Tests ( Latest )
services:
- docker
caches:
- docker
script:
- ./bin/setup-pipeline.sh
- npm run-script test-wpunit -- --xml test-reports/wpunit.xml
- step:
name: Acceptance Tests ( Latest )
services:
- docker
caches:
- docker
script:
- ./bin/setup-pipeline.sh
- npm run-script test-build
- npm run-script test-acceptance -- --xml test-reports/acceptance.xml
- step:
name: WP Unit Tests ( 5.2 )
services:
- docker
caches:
- docker
script:
- sed -i -e 's/WP_TAG=latest/WP_TAG=5.2/g' .env
- ./bin/setup-pipeline.sh
- npm run-script test-wpunit -- --xml test-reports/wpunit.xml
- step:
name: Acceptance Tests ( 5.2 )
services:
- docker
caches:
- docker
script:
- sed -i -e 's/WP_TAG=latest/WP_TAG=5.2/g' .env
- ./bin/setup-pipeline.sh
- npm run-script test-build
- npm run-script test-acceptance -- --xml test-reports/acceptance.xml
WP_ROOT_FOLDER="/var/www/html"
TEST_SITE_WP_ADMIN_PATH="/wp-admin"
TEST_SITE_DB_NAME="wp"
TEST_SITE_DB_HOST="db"
TEST_SITE_DB_PORT="3306"
TEST_SITE_DB_USER="wp"
TEST_SITE_DB_PASSWORD="pass"
TEST_SITE_TABLE_PREFIX="wp_"
TEST_SITE_WP_URL="http://localhost"
TEST_SITE_WP_DOMAIN="localhost"
TEST_SITE_ADMIN_EMAIL="admin@localhost"
TEST_SITE_ADMIN_USERNAME="admin"
TEST_SITE_ADMIN_PASSWORD="password"
TEST_DB_NAME="wp"
TEST_DB_HOST="db"
TEST_DB_USER="wp"
TEST_DB_PASSWORD="pass"
TEST_TABLE_PREFIX="wp_"
version: '3.7'
services:
wordpress:
build:
context: ./tests
args:
WP_TAG: wordpress:${WP_TAG}
restart: always
ports:
- ${WP_PORT}:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wp
WORDPRESS_DB_USER: wp
WORDPRESS_DB_PASSWORD: pass
WORDPRESS_SKIP_INSTALL: 'yes'
volumes:
- ./:/var/www/html/wp-content/plugins/your-plugin-dir
depends_on:
- db
db:
image: mysql:5.7
restart: always
ports:
- ${DB_PORT}:3306
environment:
MYSQL_DATABASE: wp
MYSQL_USER: wp
MYSQL_PASSWORD: pass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
ARG WP_TAG
FROM ${WP_TAG}
RUN docker-php-ext-install pdo_mysql
#!/usr/bin/env bash
# Based on https://stackoverflow.com/a/50583452
curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -f docker-compose.yml up -d
./bin/wait-for-it.sh http://localhost:7253
#!/usr/bin/env bash
attempt_counter=0
max_attempts=30
until curl --output /dev/null --silent --fail "$1"; do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi
printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 1
done
echo "Connected to host"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment