Unit test for https://github.com/civicrm/civicrm-core/pull/18568
[civicrm-core.git] / tools / scripts / phpunit-indiv
index 459ec6608d21e796d74fa5189f47767a7e60f171..8dc447c5336c91ee708d385a535fd5edd5a0ba76 100755 (executable)
@@ -1,4 +1,11 @@
 #!/bin/bash
+function absdirname() {
+  pushd $(dirname $0) >> /dev/null
+    pwd
+  popd >> /dev/null
+}
+
+BINDIR=$(absdirname "$0")
 PHP=${PHP:-php}
 PHPUNIT=${PHPUNIT:-phpunit}
 MODE=standalone
@@ -13,6 +20,10 @@ while [ -n "$1" ]; do
     --civi)
       MODE=civi
       ;;
+    --civibuild-restore)
+      CIVIBUILD_RESTORE="$1"
+      shift
+      ;;
     --test-dir)
       TESTSUITE="$1"
       shift
@@ -36,13 +47,21 @@ done
 
 if [ -z "$TESTSUITE" ]; then
   echo "summary: Executes all tests in a suite (individually)"
-  echo "usage: $0 --test-dir <dir> [--json-dir <dir>] [--xml-dir <dir>] [--civi]"
+  echo "usage: $0 --test-dir <dir> [--json-dir <dir>] [--xml-dir <dir>] [--civi] [--civibuild-restore <build-name>]"
   exit 1
 fi
 
 
 #phpunit-ls "$TESTSUITE"
-phpunit-ls "$TESTSUITE" | while read FILE CLASS METHOD ; do
+$BINDIR/phpunit-ls "$TESTSUITE" | while read FILE CLASS METHOD ; do
+  if [ -z "$FILE" -o ! -f "$FILE" ]; then continue; fi
+  echo "[[Processing $FILE $CLASS::$METHOD]]"
+  ## Optionally reset DBs
+  if [ -n "$CIVIBUILD_RESTORE" ]; then
+    civibuild restore "$CIVIBUILD_RESTORE"
+  fi
+
+  ## Prepare test command
   PHPUNITARGS="--tap"
   if [ -n "$JSONDIR" ]; then
     PHPUNITARGS="$PHPUNITARGS --log-json $JSONDIR/$CLASS-$METHOD.json"
@@ -51,7 +70,7 @@ phpunit-ls "$TESTSUITE" | while read FILE CLASS METHOD ; do
     PHPUNITARGS="$PHPUNITARGS --log-junit $XMLDIR/$CLASS-$METHOD.xml"
   fi
 
-
+  ## Run the test!
   if [ "$MODE" == "civi" ]; then
     $PHP ./scripts/phpunit $PHPUNITARGS --filter $METHOD'( with.*)?$' "$CLASS"
   fi