From 95b28cbafd37511b70addd2180d1a74a4055d0a1 Mon Sep 17 00:00:00 2001 From: "Joseph P. White" Date: Fri, 27 Jan 2017 11:15:53 -0500 Subject: [PATCH] Added a unit test harness. - Added the necessary boilerplate to run unit tests. The test files should be placed in the tests/lib directory following the same structure as the tests in the XDMoD core. - Also ensure that the tests are run by travis. --- .travis.build.sh | 30 +++++++++--------------------- .travis.yml | 1 + tests/README.md | 7 +++++++ tests/bootstrap.php | 41 +++++++++++++++++++++++++++++++++++++++++ tests/phpunit.xml.dist | 21 +++++++++++++++++++++ tests/runtests.sh | 10 ++++++++++ 6 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 tests/README.md create mode 100644 tests/bootstrap.php create mode 100644 tests/phpunit.xml.dist create mode 100755 tests/runtests.sh diff --git a/.travis.build.sh b/.travis.build.sh index 242be26f..ae53f970 100755 --- a/.travis.build.sh +++ b/.travis.build.sh @@ -61,7 +61,7 @@ if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then fi # Build tests require the corresponding version of Open XDMoD. -if [ "$TEST_SUITE" = "build" ]; then +if [ "$TEST_SUITE" = "build" ] || [ "$TEST_SUITE" = "unit" ]; then # If present, move Travis cache dirs out of the way. xdmod_cache_exists="false"; [ -e ../xdmod ] && xdmod_cache_exists="true" if "$xdmod_cache_exists"; then @@ -77,26 +77,9 @@ if [ "$TEST_SUITE" = "build" ]; then mv ../xdmod-cache/etl/js/node_modules ../xdmod/etl/js/node_modules fi - # If PHP 5.3.3 is installed, SSL/TLS isn't available to PHP. - # Use a newer version of PHP for installing Composer dependencies. - using_php_533="false"; [[ "$(php --version)" == PHP\ 5.3.3\ * ]] && using_php_533="true" - if "$using_php_533"; then - echo "Using newer version of PHP for installing dependencies" - phpenv global 5.3 - php --version - fi - - # Install Composer dependencies. - pushd ../xdmod >/dev/null - composer install - popd >/dev/null - - # If using PHP 5.3.3 for testing purposes, stop using the newer PHP version. - if "$using_php_533"; then - echo "Reverting back to PHP 5.3.3 for testing" - phpenv global 5.3.3 - php --version - fi + pushd ../xdmod + . .travis.install.sh + popd # Create a symlink from Open XDMoD to this module. ln -s "$(pwd)" "../xdmod/open_xdmod/modules/$module_dir" @@ -156,6 +139,11 @@ elif [ "$TEST_SUITE" = "style" ]; then build_exit_value=2 fi done +elif [ "$TEST_SUITE" = "unit" ]; then + tests/runtests.sh + if [ $? != 0 ]; then + build_exit_value=2 + fi elif [ "$TEST_SUITE" = "build" ]; then # If PHP 5.3.3 is installed, SSL/TLS isn't available to PHP. # Use a newer version of PHP for installing Composer dependencies. diff --git a/.travis.yml b/.travis.yml index 70380c06..24d6487c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ env: matrix: - TEST_SUITE=syntax - TEST_SUITE=style + - TEST_SUITE=unit - TEST_SUITE=build CACHE_NAME=build # Add dependency directories to the Travis cache diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..df183c74 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,7 @@ +Open XDMoD SUPReMM module Unit Tests +===================== + +Run the tests: + + $ ./runtests.sh + diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..3231bf90 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,41 @@ + + diff --git a/tests/runtests.sh b/tests/runtests.sh new file mode 100755 index 00000000..4307564d --- /dev/null +++ b/tests/runtests.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if { ! which phpunit >/dev/null 2>&1; } then + echo phpunit not found 1>&2 + exit 127 +fi + +cd $(dirname $0) +phpunit . +exit $?