Hi,
Not sure if there’s anyone who could help us regarding this issue but we’re trying to upgrade our CI to be compliant with CircleCI 2.0.
We’re trying to implement PHPUnit to run tests on deploy but are having some problems with it. It seems to be having errors when running PHPUnit on CircleCI 2.
We’ve been trying to work with php:7.1.21-fpm-node-browsers
. It appears that we don’t have any error logs setup within the CircleCi environment, so we’ve been relying on output for feedback. CircleCi quits without much info, just an “Exited with code 255” message.
Attempting to SSH in and running phpunit
manually, there’s no error message at all.
Any help would be appreciated.
Here’s a copy of the config:
version: 2
defaults: &defaults
working_directory: ~/site
docker:
- image: circleci/php:7.1.21-fpm-node-browsers
environment:
WP_TESTS_DIR: /tmp/wpdev/tests/phpunit
WP_DEVELOP_DIR: /tmp/wpdev
MU_PLUGINS_DIR: /tmp/mu-plugins
jobs:
build:
<<: *defaults
steps:
- checkout
# Set the host
- run:
name: Setup hosts
command: echo 127.0.0.1 local.site.com | sudo tee -a /etc/hosts
# Set environment variables
- run:
name: Setup environment variables
command: |
echo 'export WP_TESTS_DIR="$WP_TESTS_DIR"' >> $BASH_ENV
echo 'export WP_DEVELOP_DIR="$WP_DEVELOP_DIR"' >> $BASH_ENV
echo 'export MU_PLUGINS_DIR="$MU_PLUGINS_DIR"' >> $BASH_ENV
source $BASH_ENV
# Get latest master
- run:
name: Get latest version of the code
command: |
git checkout master
git fetch
git reset --hard origin/master
git checkout $CIRCLE_BRANCH
# Make sure submodules are present and up to date
- run:
name: Update submodules
command: |
git submodule sync
git submodule foreach git prune
git submodule foreach git fetch --all
git submodule foreach git fetch --tags
git submodule update --init --recursive || (rm -fr .git/config .git/modules && git submodule deinit -f . && git submodule update --init --recursive)
# Pre Dependencies
- run:
name: Install GEM
command: sudo apt-get install ruby-dev
# Required for Node-SASS to work
- run:
name: Install GEM dependencies
command: sudo gem install sass
# Install NPM dependencies
- restore_cache:
keys:
- v1-npm-cache-{{ .Branch }}-{{ checksum "~/site/themes/site/package.json" }}
- v1-npm-cache-{{ .Branch }}
- run:
name: Install NPM dependencies
command: |
cd ~/site/themes/site
npm install
- save_cache:
key: v1-npm-cache-{{ .Branch }}-{{ checksum "~/site/themes/site/package.json" }}
paths:
- ~/site/themes/site
# Production build
- run:
name: Start production build
command: |
cd ~/site/themes/site
npm run build
# Install Composer dependencies
- restore_cache:
keys:
- v1-composer-cache-{{ .Branch }}-{{ checksum "~/site/themes/site/composer.lock" }}
- v1-composer-cache-{{ .Branch }}
- run:
name: Install Composer dependencies
command: |
cd ~/site/themes/site
composer install
- save_cache:
key: v1-composer-cache-{{ .Branch }}-{{ checksum "~/site/themes/site/composer.lock" }}
paths:
- ~/site/themes/site
# WP CLI install
- restore_cache:
keys:
- wp-cli-cache-{{ .Branch }}-{{ .Revision }}
- run:
name: Install WP CLI
command: |
if [ ! -d ~/wp-cli ]; then
git clone git@github.com:wp-cli/wp-cli.git ~/wp-cli
cd ~/wp-cli && composer install
sudo ln -s ~/wp-cli/bin/wp /bin/wp ;
fi
- save_cache:
key: wp-cli-cache-{{ .Branch }}-{{ .Revision }}
paths:
- ~/wp-cli
# WP Unit Tests
- restore_cache:
keys:
- v1-wp-develop-site-cache-{{ .Branch }}-{{ .Revision }}
- run:
name: Install WordPress unit testing suite
command: |
if [ ! -d "$WP_DEVELOP_DIR" ]; then
git clone git://develop.git.wordpress.org/ $WP_DEVELOP_DIR
rm -rf /tmp/wpdev/src/wp-content ;
fi
- save_cache:
key: v1-wp-develop-site-cache-{{ .Branch }}-{{ .Revision }}
paths:
- $WP_DEVELOP_DIR
# Install WordPress Must-Use Plugins
- restore_cache:
keys:
- v1-wp-develop-site-cache-{{ .Branch }}-{{ .Revision }}
- run:
name: Install WordPress Must-Use plugins
command: |
if [ ! -d "$MU_PLUGINS_DIR" ]; then
git clone --recursive https://github.com/Automattic/vip-go-mu-plugins.git $MU_PLUGINS_DIR ;
fi
- save_cache:
key: v1-wp-develop-site-cache-{{ .Branch }}-{{ .Revision }}
paths:
- $MU_PLUGINS_DIR
# Create SymLinks
- run:
name: Create symlinks used for testing and plugins
command: |
ln -Pf ~/site/themes/site/tests/php/wp-tests-config.php /tmp/wpdev/wp-tests-config.php
ln -sf ~/site/themes/site/tests/php/config ~/site
ln -sf ~/site /tmp/wpdev/src/wp-content
ln -sf $MU_PLUGINS_DIR /tmp/wpdev/src/wp-content/mu-plugins
# Install PHPUnit
# Use older ver of PHPUnit - 6.1.0 does not run the tests
- run:
name: Install PHPUnit
command: |
sudo wget -O /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-6.5.phar
sudo chmod +x /usr/local/bin/phpunit
- run:
name: Run PHPUnit tests
command: |
mkdir -p ~/phpunit
cd ~/site/themes/site
sudo chmod +x vendor/phpunit/phpunit/phpunit
vendor/phpunit/phpunit/phpunit --log-junit ~/phpunit/junit.xml
when: always
- store_test_results:
path: ~/phpunit
- store_artifacts:
path: ~/phpunit
# cd ~/site/themes/site
# mkdir -p ~/phpunit
# phpunit --log-junit ~/phpunit/junit.xml
# vendor/phpunit/phpunit/phpunit
# # Mocha & Enzyme tests
# - run:
# name: Run Mocha and Enzyme tests
# command: |
# cd ~/site/themes/site
# npm test
# # Code Sniffer - only if there are modified files
# - run:
# name: Run PHP Code Sniffer on modified files
# command: |
# cd ~/site/themes/site
# echo "$(git diff --name-status master...$CIRCLE_BRANCH --relative . | grep '^[MA].*\.php' | awk '{ print $2 }')" > modified.php.txt
# if [[ -n $(cat modified.php.txt | grep -v '^$') ]]; then
# ./vendor/bin/phpcs -q --standard=phpcs.ruleset.xml --file-list=modified.php.txt ;
# fi
# # ESlint
# - run:
# name: Run ESLint
# command: |
# cd ~/site/themes/site
# node_modules/eslint/bin/eslint.js --color --max-warnings=0 .
Thanks.
Robin