Skip to content

Instantly share code, notes, and snippets.

@g-kanoufi
Forked from keesiemeijer/setup-phpunit.sh
Last active August 3, 2019 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-kanoufi/7333099546c471a16cf51a5d1465fa94 to your computer and use it in GitHub Desktop.
Save g-kanoufi/7333099546c471a16cf51a5d1465fa94 to your computer and use it in GitHub Desktop.
Setup Codeception for use in the Local by Flywheel app
image: php:7.2
pipelines:
branches:
# '{develop, staging}':
develop:
- step:
caches:
- composer
script:
# Installing first the libraries necessary to configure and install gd
- apt-get update && apt-get install -y unzip libfreetype6-dev libjpeg62-turbo-dev libpng-dev
# Now we can configure and install the extension
- docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
- docker-php-ext-install -j$(nproc) gd
# Let's add composer
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- mv dev_env .env
- php -S localhost:8001 --docroot web &>/dev/null&
- vendor/bin/codecept run wpunit && vendor/bin/codecept run acceptance
services:
- mysql
definitions:
services:
mysql:
image: mysql:5.6
environment:
MYSQL_DATABASE: 'wpTests'
MYSQL_ROOT_PASSWORD: 'root'
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
params:
- .env
#!/usr/bin/env bash
# ===============================================================================
# Script to install Codeception in the Local by Flywheel Mac app
# These packages are installed
#
# Codeception, git, subversion, composer, curl, wget, chromium and chromedriver
#
#
# WordPress and the WP_UnitTestCase are installed in these directories for use by PHPUnit.
# A database is created for WordPress with these credentials:
# db_name: wpTest
# db_user: root
# db_pass: root
#
# You only have to run this script once. Codeception
# will still be available next time you ssh into your site.
#
#
# Note: This script doesn't install the packages globally in the Local by Flywheel app
# Packages are only installed for the site where you've run this script.
# ===============================================================================
# ===============================================================================
# Instructions
#
# 1 - Download this file (setup-codeception.sh) inside your site's /app folder
# curl -o setup-codeception.sh https://gist.githubusercontent.com/g-kanoufi/7333099546c471a16cf51a5d1465fa94/raw/
#
# 2 - Right click your site in the Local App and click Open Site SSH
# A new terminal window will open
#
# 3 - Go to your site's /app folder:
# cd /app
#
# 4 - Run this script
# bash setup-codeception.sh
#
# ===============================================================================
printf "Installing packages...\n"
# Strings used in error messages
readonly QUIT="Stopping script..."
readonly CONNECTION="Make sure you're connected to the internet"
readonly RED='\033[0;31m' # Red color
readonly RESET='\033[0m' # No color
# Re-synchronize the package index files from their sources
apt-get update -y
# Install packages.
apt-get install wget subversion curl git -y
# Needed for Chromedriver
apt-get install libxss1 libappindicator1 libindicator7 xvfb sudo libgconf-2-4 unzip -y
# Check if packages used for downloading have been installed
if [[ ! -f "/usr/bin/wget" || ! -f "/usr/bin/curl" || ! -f "/usr/bin/svn" ]]; then
printf "${RED}ERROR${RESET} Missing packages. %s\n%s\n" "$CONNECTION" "$QUIT"
exit 1
fi
# Install composer
if ! [[ -f "/usr/local/bin/composer" ]]; then
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer || exit
if [[ -f "$HOME/.bashrc" ]]; then
printf "Adding .composer/vendor/bin to the PATH\n"
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> "$HOME/.bashrc"
fi
else
printf "Updating composer...\n"
composer self-update || printf "${RED}WARNING${RESET} Could not update composer. %s\n" "$CONNECTION"
fi
# Get the current php version
readonly PHP_VERSION=$(php -r "echo PHP_VERSION;")
# Install Codeception
if ! [[ -f "/usr/local/bin/codeception/codeception/codecept" ]]; then
cd /app/public
composer require lucatume/wp-browser --dev
composer require fzaninotto/faker --dev
cd /app
ln -s /app/public/vendor/codeception/codeception/codecept /usr/local/bin/codecept || exit
if [[ -f "$HOME/.bashrc" ]]; then
printf "Adding codecept, phpunit, to the PATH\n"
echo 'export PATH="$PATH:/app/public/vendor/bin"' >> "$HOME/.bashrc"
fi
fi
# Get Chrome driver latest ver
readonly LATEST_VERSION=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
# Install ChromeDriver
if ! [[ -f "/usr/local/bin/chromedriver" ]]; then
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome*.deb
apt-get install -f -y
rm google-chrome-stable_current_amd64.deb
wget -N https://chromedriver.storage.googleapis.com/$LATEST_VERSION/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
mv -f chromedriver /usr/local/share/chromedriver
ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
rm chromedriver_linux64.zip
fi
# Install database if it doesn't exist
printf "Checking if database wpTests exists\n"
database=$(mysqlshow --user=root --password=root wpTests| grep -v Wildcard | grep -o wpTests)
if ! [[ "wpTests" = "$database" ]]; then
printf "Creating database wordpress_test\n"
mysqladmin create wpTests --user=root --password=root --host=localhost
else
printf "Database wpTests already exists\n"
fi
printf "\nFinished setting up codeception packages\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment