tests: disregard PHPUnit 8 for now
authorDenis Ovsienko <denis@ovsienko.info>
Mon, 18 Feb 2019 16:12:20 +0000 (16:12 +0000)
committerDenis Ovsienko <denis@ovsienko.info>
Mon, 18 Feb 2019 20:39:26 +0000 (20:39 +0000)
In Travis CI PHP 7.2 now comes with PHPUnit 8, which seems to require
rewriting the tests in a way that is not compatible with older PHPUnit
versions. Introduce SKIP_PHPUNIT into the Travis CI matrix to avoid
running PHPUnit 8 on PHP 7.2 until RackTables code is ready (and
potentially to prevent running older PHPUnit versions on older PHP
versions if the switch happens).

.travis.yml
tests/express.sh
tests/express_phpunit.sh [new file with mode: 0755]
tests/express_post.sh [new file with mode: 0755]
tests/express_pre.sh [new file with mode: 0755]

index 9587922..c0313ec 100644 (file)
@@ -4,15 +4,15 @@ git:
   quiet: true
   depth: 3
 
-php:
- - 5.5
- - 5.6
- - 7.0
- - 7.1
- - 7.2
-
 matrix:
   fast_finish: true
+  include:
+  - php: 5.5
+  - php: 5.6
+  - php: 7.0
+  - php: 7.1
+  - php: 7.2
+    env: SKIP_PHPUNIT=yes # PHPUnit 8
 
 services:
  - mysql
@@ -21,6 +21,8 @@ before_script:
  - ./tests/travis_setup_mysql.sh racktables_unittest racktables travistest
 
 script:
- - ./tests/express.sh
+ - ./tests/express_pre.sh
+ - if [ "$SKIP_PHPUNIT" = yes ]; then echo '(skipped PHPUnit tests on request)'; else ./tests/express_phpunit.sh; fi
+ - ./tests/express_post.sh
  - mysql -u racktables -ptravistest racktables_unittest < scripts/init-sample-racks.sql
  - DESTDIR=/tmp make install
index 7feb8c2..d66eb24 100755 (executable)
@@ -4,99 +4,9 @@ THISDIR=`dirname $0`
 BASEDIR=`readlink -f "$THISDIR/.."`
 : ${PHPUNIT_BIN:=phpunit}
 
-case `"$PHPUNIT_BIN" --version` in
-       'PHPUnit 4.'*|'PHPUnit 5.'*)
-               BOOTSTRAP_FILE=bootstrap_v4v5.php
-               ;;
-       'PHPUnit 6.'*|'PHPUnit 7.'*)
-               BOOTSTRAP_FILE=bootstrap_v6v7.php
-               ;;
-       *)
-               echo 'ERROR: failed to find a known version of PHPUnit'
-               "$PHPUNIT_BIN" --version
-               exit 5
-esac
+"$THISDIR"/express_pre.sh && \
+"$THISDIR"/express_phpunit.sh && \
+"$THISDIR"/express_post.sh && \
+exit 0
 
-echo "Running express tests using the base directory '$BASEDIR'"
-echo "and PHPUnit bootstrap file '$BOOTSTRAP_FILE'."
-
-testPHPSyntaxOnly()
-{
-       local FORMAT="${1:?}"
-       local INPUT="${2:?}"
-
-       if php --syntax-check "$INPUT" >/dev/null 2>&1; then
-               printf "$FORMAT" "$INPUT" 'OK (syntax only)'
-               return 0
-       else
-               printf "$FORMAT" "$INPUT" "ERROR: PHP syntax check failed"
-               return 1
-       fi
-}
-
-testPHPExitCodeAndOutput()
-{
-       local FORMAT="${1:?}"
-       local INPUT="${2:?}"
-       local TEMPFILE="${3:?}"
-       local fname rc curdir
-
-       fname=`basename "$INPUT"`
-       curdir=`pwd`
-       cd `dirname "$INPUT"`
-       php "$fname" > "$TEMPFILE"
-       rc=$?
-       cd "$curdir"
-       if [ $rc -eq 0 -a ! -s "$TEMPFILE" ]; then
-               printf "$FORMAT" "$INPUT" 'OK'
-               return 0
-       else
-               [ $rc -ne 0 ] && printf "$FORMAT" "$INPUT" "ERROR: PHP interpreter returned code $rc"
-               [ -s "$TEMPFILE" ] && printf "$FORMAT" "$f" 'ERROR: produces output when parsed'
-               return 1
-       fi
-}
-
-# Every file in wwwroot/inc/ must be a valid PHP input file and must not
-# produce any output when parsed by PHP (because, for instance, a plain text
-# file is a valid PHP input file).
-echo
-cd "$BASEDIR"
-files=0
-errors=0
-TEMPFILE=`mktemp /tmp/racktables_unittest.XXXXXX`
-FORMAT='%-50s : %s\n'
-for f in wwwroot/inc/*.php plugins/*/plugin.php; do
-       if [ "$f" = "wwwroot/inc/init.php" ]; then
-               testPHPSyntaxOnly "$FORMAT" "$f" || errors=`expr $errors + 1`
-       else
-               testPHPExitCodeAndOutput "$FORMAT" "$f" "$TEMPFILE" || errors=`expr $errors + 1`
-       fi
-       files=`expr $files + 1`
-done
-for f in tests/*.php; do
-       [ -h "$f" ] && continue
-       testPHPSyntaxOnly "$FORMAT" "$f" || errors=`expr $errors + 1`
-       files=`expr $files + 1`
-done
-echo '---------------------------------------------------'
-echo "Files parsed: $files, failed: $errors"
-rm -f "$TEMPFILE"
-[ $errors -eq 0 ] || exit 1
-
-# The command-line scripts among other things prove that init.php actually works.
-echo
-cd "$BASEDIR/wwwroot"
-# Requires init.php, prints usage and leaves the database intact.
-echo 'Testing syncdomain.php'; ../scripts/syncdomain.php --help || exit 1
-
-# At this point it makes sense to test specific functions.
-echo
-cd "$BASEDIR/tests"
-"$PHPUNIT_BIN" --group small --bootstrap $BOOTSTRAP_FILE || exit 1
-
-cd "$BASEDIR/wwwroot"
-# PHPUnit would fail if this was not a unit testing database, hence
-# at this point is is OK to let the scripts below make changes.
-echo 'Testing cleanup_ldap_cache.php'; ../scripts/cleanup_ldap_cache.php || exit 1
-echo 'Testing reload_dictionary.php'; ../scripts/reload_dictionary.php || exit 1
+exit 1
diff --git a/tests/express_phpunit.sh b/tests/express_phpunit.sh
new file mode 100755 (executable)
index 0000000..73386a1
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+THISDIR=`dirname $0`
+: ${PHPUNIT_BIN:=phpunit}
+
+case `"$PHPUNIT_BIN" --version` in
+       'PHPUnit 4.'*|'PHPUnit 5.'*)
+               BOOTSTRAP_FILE=bootstrap_v4v5.php
+               ;;
+       'PHPUnit 6.'*|'PHPUnit 7.'*)
+               BOOTSTRAP_FILE=bootstrap_v6v7.php
+               ;;
+       *)
+               echo 'ERROR: failed to find a known version of PHPUnit'
+               "$PHPUNIT_BIN" --version
+               exit 5
+esac
+
+# At this point it makes sense to test specific functions.
+echo "Running PHPUnit tests using bootstrap file '$BOOTSTRAP_FILE'."
+
+cd "$THISDIR"
+"$PHPUNIT_BIN" --group small --bootstrap $BOOTSTRAP_FILE || exit 1
diff --git a/tests/express_post.sh b/tests/express_post.sh
new file mode 100755 (executable)
index 0000000..eec874f
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+THISDIR=`dirname $0`
+BASEDIR=`readlink -f "$THISDIR/.."`
+
+echo "Running post-PHPUnit express tests using the base directory '$BASEDIR'."
+cd "$BASEDIR/wwwroot"
+# PHPUnit would fail if this was not a unit testing database, hence
+# at this point is is OK to let the scripts below make changes.
+echo 'Testing cleanup_ldap_cache.php'; ../scripts/cleanup_ldap_cache.php || exit 1
+echo 'Testing reload_dictionary.php'; ../scripts/reload_dictionary.php || exit 1
diff --git a/tests/express_pre.sh b/tests/express_pre.sh
new file mode 100755 (executable)
index 0000000..3e53624
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+THISDIR=`dirname $0`
+BASEDIR=`readlink -f "$THISDIR/.."`
+
+echo "Running pre-PHPUnit express tests using the base directory '$BASEDIR'."
+
+testPHPSyntaxOnly()
+{
+       local FORMAT="${1:?}"
+       local INPUT="${2:?}"
+
+       if php --syntax-check "$INPUT" >/dev/null 2>&1; then
+               printf "$FORMAT" "$INPUT" 'OK (syntax only)'
+               return 0
+       else
+               printf "$FORMAT" "$INPUT" "ERROR: PHP syntax check failed"
+               return 1
+       fi
+}
+
+testPHPExitCodeAndOutput()
+{
+       local FORMAT="${1:?}"
+       local INPUT="${2:?}"
+       local TEMPFILE="${3:?}"
+       local fname rc curdir
+
+       fname=`basename "$INPUT"`
+       curdir=`pwd`
+       cd `dirname "$INPUT"`
+       php "$fname" > "$TEMPFILE"
+       rc=$?
+       cd "$curdir"
+       if [ $rc -eq 0 -a ! -s "$TEMPFILE" ]; then
+               printf "$FORMAT" "$INPUT" 'OK'
+               return 0
+       else
+               [ $rc -ne 0 ] && printf "$FORMAT" "$INPUT" "ERROR: PHP interpreter returned code $rc"
+               [ -s "$TEMPFILE" ] && printf "$FORMAT" "$f" 'ERROR: produces output when parsed'
+               return 1
+       fi
+}
+
+# Every file in wwwroot/inc/ must be a valid PHP input file and must not
+# produce any output when parsed by PHP (because, for instance, a plain text
+# file is a valid PHP input file).
+echo
+cd "$BASEDIR"
+files=0
+errors=0
+TEMPFILE=`mktemp /tmp/racktables_unittest.XXXXXX`
+FORMAT='%-50s : %s\n'
+for f in wwwroot/inc/*.php plugins/*/plugin.php; do
+       if [ "$f" = "wwwroot/inc/init.php" ]; then
+               testPHPSyntaxOnly "$FORMAT" "$f" || errors=`expr $errors + 1`
+       else
+               testPHPExitCodeAndOutput "$FORMAT" "$f" "$TEMPFILE" || errors=`expr $errors + 1`
+       fi
+       files=`expr $files + 1`
+done
+for f in tests/*.php; do
+       [ -h "$f" ] && continue
+       testPHPSyntaxOnly "$FORMAT" "$f" || errors=`expr $errors + 1`
+       files=`expr $files + 1`
+done
+echo '---------------------------------------------------'
+echo "Files parsed: $files, failed: $errors"
+rm -f "$TEMPFILE"
+[ $errors -eq 0 ] || exit 1
+
+# The command-line scripts among other things prove that init.php actually works.
+echo
+cd "$BASEDIR/wwwroot"
+# Requires init.php, prints usage and leaves the database intact.
+echo 'Testing syncdomain.php'; ../scripts/syncdomain.php --help || exit 1