#!/usr/bin/env bash ## Description: Run phpunit in the ddev environment ## Usage: phpunit ## Example: ddev phpunit coverage # The meaning of the first arg is: # # - setup: Create the test DB for the current database engine # - coverage: Produce coverage info in tests/results/coverage # - debug: Runs the tests with the debugger enabled # - profile: Collects profiling information from the test run. # # The first arg can also be empty, in which case the tests are run # without enabling any of the debugger modes. # # Using coverage, debug or profile required that xdebug is enabled. set -e export XDEBUG_CONFIG="output_dir=tests/results" export HZ_TEST_DB_HOST=db export HZ_TEST_DB_USER=test_user export HZ_TEST_DB_PASS=hubzilla export HZ_TEST_DB_TYPE=$DDEV_DATABASE_FAMILY export HZ_TEST_DB_ROOT_USER=db export HZ_TEST_DB_ROOT_PASS=db case $1 in coverage | debug | profile) mode=$1; shift ;; setup) tests/create_test_db.sh; exit ;; *) mode=off esac # Clean out old logs [ -a tests/results/unit_test.log ] && rm tests/results/unit_test.log # Run the tests if [ "$mode" == "coverage" ]; then extra_args='--coverage-html=tests/results/coverage'; fi XDEBUG_MODE=$mode vendor/bin/phpunit -c tests/phpunit.xml $extra_args "$@"