Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a unit test harness. #23

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions .travis.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Open XDMoD SUPReMM module Unit Tests
=====================

Run the tests:

$ ./runtests.sh

41 changes: 41 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

$dir = __DIR__;

// Autoloader for test classes.
spl_autoload_register(
function ($className) use ($dir) {
$classPath
= $dir
. '/lib/'
. str_replace('_', '/', $className)
. '.php';

if (is_readable($classPath)) {
return require_once $classPath;
} else {
return false;
}
}
);

// Autoloader for SUPReMM module classes
spl_autoload_register(
function ($className) use ($dir) {
$classPath
= $dir
. '/../classes/'
. str_replace('\\', '/', $className)
. '.php';

error_log("Checking ".$classPath);
if (is_readable($classPath)) {
return require_once $classPath;
} else {
return false;
}
}
);

// Autoloader for XDMoD classes.
require_once __DIR__ . '/../../xdmod/configuration/linker.php';
21 changes: 21 additions & 0 deletions tests/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="bootstrap.php"
cacheTokens="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
verbose="true">
</phpunit>
10 changes: 10 additions & 0 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -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 $?