#!/bin/bash # This script sets-up the test environment and runs all tests. # You'll want to define your local mysql credentials for a test # database as environment variables, e.g., in ~/.bash_profile: # export DB_NAME="test" # export DB_USER="test" # export DB_PASS="..." # Run an individual test like this: # ./tests/run_tests.sh /Users/q/src/codebase/trunk/tests/UtilitiesTest.php function err { MSG="$1"; IFS=''; echo -e $MSG 1>&2 exit 1; } # Be in the directory with all the tests. cd `dirname $0`; # Get required ENV variables. if [[ -z "$DB_USER$DB_PASS$DB_NAME" ]]; then echo "MySQL test DB credential environment variables are missing.\nSet these in ~/.bash_profile to avoid seeing these prompts each time."; fi for E in DB_SERVER DB_NAME DB_USER DB_PASS; do while [[ -z ${!E} ]]; do read -p "$E: " $E; done export $E; done # Create database. mysql -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`" || err "Failed to create database '${DB_NAME}"; # Go! echo "Running the tests!"; echo "You'll want to 'tail -f /tmp/codebase_test_log' and watch for errors."; # Config options go in phpunit.xml # phpunit --tap | grep -v '^ok ' ../vendor/phpunit/phpunit/composer/bin/phpunit --stderr "$@" || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log";