Line | |
---|
1 | #!/bin/bash |
---|
2 | |
---|
3 | # This script sets-up the test environment and runs all tests. |
---|
4 | # You'll want to define your local mysql credentials for a test |
---|
5 | # database as environment variables, e.g., in ~/.bash_profile: |
---|
6 | # export DB_NAME="test" |
---|
7 | # export DB_USER="test" |
---|
8 | # export DB_PASS="..." |
---|
9 | |
---|
10 | # Run an individual test like this: |
---|
11 | # ./tests/run_tests.sh /Users/q/src/codebase/trunk/tests/UtilitiesTest.php |
---|
12 | |
---|
13 | function err { |
---|
14 | MSG="$1"; |
---|
15 | IFS=''; |
---|
16 | echo -e $MSG 1>&2 |
---|
17 | exit 1; |
---|
18 | } |
---|
19 | |
---|
20 | # FIXME: Upgrade PHPUnit and upgrade all tests. |
---|
21 | err "Current tests use phpunit ~3.7.0, which does not support versions of PHP above 5.6 ð"; |
---|
22 | |
---|
23 | # Be in the directory with all the tests. |
---|
24 | cd `dirname $0`; |
---|
25 | |
---|
26 | # Get required ENV variables. |
---|
27 | if [[ -z "$DB_USER$DB_PASS$DB_NAME" ]]; then |
---|
28 | echo "MySQL test DB credential environment variables are missing.\nSet these in ~/.bash_profile to avoid seeing these prompts each time."; |
---|
29 | fi |
---|
30 | for E in DB_SERVER DB_NAME DB_USER DB_PASS; do |
---|
31 | while [[ -z ${!E} ]]; do |
---|
32 | read -p "$E: " $E; |
---|
33 | done |
---|
34 | export $E; |
---|
35 | done |
---|
36 | |
---|
37 | # Create database. |
---|
38 | mysql -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`" || err "Failed to create database '${DB_NAME}"; |
---|
39 | |
---|
40 | # Go! |
---|
41 | echo "Running the tests!"; |
---|
42 | echo "You'll want to 'tail -f /tmp/codebase_test_log' and watch for errors."; |
---|
43 | |
---|
44 | # Config options go in phpunit.xml |
---|
45 | # phpunit --tap | grep -v '^ok ' |
---|
46 | ../vendor/phpunit/phpunit/composer/bin/phpunit --stderr "$@" || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log"; |
---|
47 | |
---|
Note: See
TracBrowser
for help on using the repository browser.