aboutsummaryrefslogtreecommitdiffstats
path: root/.ddev/commands/web/phpunit
blob: 50265392f8e5e539ea9c2a967565f54904b4972f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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 "$@"