tools/scripts/npm/postinstall.sh - Comment
[civicrm-core.git] / tools / scripts / phpunit-indiv
CommitLineData
f03dc6b0 1#!/bin/bash
777df9e1
TO
2function absdirname() {
3 pushd $(dirname $0) >> /dev/null
4 pwd
5 popd >> /dev/null
6}
7
8BINDIR=$(absdirname "$0")
f03dc6b0
TO
9PHP=${PHP:-php}
10PHPUNIT=${PHPUNIT:-phpunit}
11MODE=standalone
35e0b420
TO
12XMLDIR=
13JSONDIR=
f03dc6b0 14
35e0b420
TO
15while [ -n "$1" ]; do
16 ARG="$1"
f03dc6b0 17 shift
f03dc6b0 18
35e0b420
TO
19 case "$ARG" in
20 --civi)
21 MODE=civi
22 ;;
5878c670
TO
23 --civibuild-restore)
24 CIVIBUILD_RESTORE="$1"
25 shift
26 ;;
35e0b420
TO
27 --test-dir)
28 TESTSUITE="$1"
29 shift
30 ;;
31 --json-dir)
32 JSONDIR="$1"
33 [ ! -d "$JSONDIR" ] && mkdir -p "$JSONDIR"
34 shift
35 ;;
36 --xml-dir)
37 XMLDIR="$1"
38 [ ! -d "$XMLDIR" ] && mkdir -p "$XMLDIR"
39 shift
40 ;;
41 *)
42 echo "unrecognized option: $ARG"
43 ;;
44 esac
45done
f03dc6b0 46
f03dc6b0 47
35e0b420 48if [ -z "$TESTSUITE" ]; then
f03dc6b0 49 echo "summary: Executes all tests in a suite (individually)"
5878c670 50 echo "usage: $0 --test-dir <dir> [--json-dir <dir>] [--xml-dir <dir>] [--civi] [--civibuild-restore <build-name>]"
f03dc6b0
TO
51 exit 1
52fi
53
f03dc6b0
TO
54
55#phpunit-ls "$TESTSUITE"
777df9e1 56$BINDIR/phpunit-ls "$TESTSUITE" | while read FILE CLASS METHOD ; do
5878c670
TO
57 ## Optionally reset DBs
58 if [ -n "$CIVIBUILD_RESTORE" ]; then
59 civibuild restore "$CIVIBUILD_RESTORE"
60 fi
61
62 ## Prepare test command
35e0b420
TO
63 PHPUNITARGS="--tap"
64 if [ -n "$JSONDIR" ]; then
65 PHPUNITARGS="$PHPUNITARGS --log-json $JSONDIR/$CLASS-$METHOD.json"
66 fi
67 if [ -n "$XMLDIR" ]; then
68 PHPUNITARGS="$PHPUNITARGS --log-junit $XMLDIR/$CLASS-$METHOD.xml"
69 fi
70
5878c670 71 ## Run the test!
f03dc6b0 72 if [ "$MODE" == "civi" ]; then
35e0b420 73 $PHP ./scripts/phpunit $PHPUNITARGS --filter $METHOD'( with.*)?$' "$CLASS"
f03dc6b0
TO
74 fi
75 if [ "$MODE" == "standalone" ]; then
35e0b420 76 $PHP $(which $PHPUNIT) $PHPUNITARGS --filter $METHOD'( with.*)?$' "$FILE"
f03dc6b0
TO
77 fi
78done