Skip to content

Instantly share code, notes, and snippets.

@aczietlow
Created March 28, 2018 20:33
Show Gist options
  • Save aczietlow/2dbd5a8e3623e7bb2ea4c5a36c902780 to your computer and use it in GitHub Desktop.
Save aczietlow/2dbd5a8e3623e7bb2ea4c5a36c902780 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
## Run project's Behat tests.
##
## Usage: fin behat [--path=path] [arguments]
##
## path defaults to tests/behat
# Environment variables passed from fin:
#
# $PROJECT_ROOT - (string) absolute path to NEAREST .docksal folder
# $VIRTUAL_HOST - (string) ex. projectname.docksal
# $DOCROOT - name of the docroot folder
# $DOCKER_RUNNING - (string) "true" or "false"
copy_settings_file()
{
local source="$1"
local dest="$2"
if [[ ! -f $dest ]]; then
echo "Copying ${dest}..."
cp $source $dest
else
echo-yellow "${dest} already in place."
fi
}
params=''
path='tests/behat'
for i in "$@"; do
case "$i" in
--path=*)
path="${i#*=}"
;;
*)
params="$params$i "
;;
esac;
done
behat_yml_path="$PROJECT_ROOT/behat.yml"
if [[ ! -f "$behat_yml_path" ]]; then
echo "Couldn't find a behat.yml, creating a default file."
copy_settings_file "${PROJECT_ROOT}/config/behat.yml.dist" "${SITEDIR_PATH}/behat.yml"
fi
cd $PROJECT_ROOT
# Make sure Composer dependencies are installed
if [[ ! -d "$PROJECT_ROOT/vendor" ]]; then
fin exec "composer install --prefer-source --no-interaction"
fi
if [ ! -z "$1" ] && [ $1 == "clean" ]; then
echo "Removing screenshots and html dumps from ${PROJECT_ROOT}"
find ${PROJECT_ROOT}/tests/behat/screenshots/ -name '*.png' -exec rm -f {} +
find ${PROJECT_ROOT}/tests/behat/screenshots/ -name '*.html' -exec rm -f {} +
exit 0
fi
# Launch Behat tests
fin exec "bin/behat -p docker $params"
if [ "$DIXON_FUN" == 1 ]; then
if [ $? -eq 0 ]; then
user=$(whoami)
if [ "$user" == "czietlow" ] || [ "$user" == "ccrampton" ] || [ "$user" == "jrokisky" ] || [ "$user" == "mbross" ]; then
art=$(cat "$PROJECT_ROOT/.docksal/media/unicorn.txt")
echo "$art" | base64 -D; echo
afplay "$PROJECT_ROOT/.docksal/media/swage_airhorn.m4a"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment