From 4b173695678f5b0c7df5d1b1cb32657fe3ecc918 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 4 Apr 2012 21:06:01 +0200 Subject: [PATCH] MDL-32323 all-in-one PHPUnit init script --- admin/tool/phpunit/cli/init.sh | 24 ++++++++++++++++++++++++ admin/tool/phpunit/cli/util.php | 6 ++++++ lib/phpunit/lib.php | 4 +--- lib/phpunit/readme.md | 4 +--- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100755 admin/tool/phpunit/cli/init.sh diff --git a/admin/tool/phpunit/cli/init.sh b/admin/tool/phpunit/cli/init.sh new file mode 100755 index 00000000000..66e2f0dca05 --- /dev/null +++ b/admin/tool/phpunit/cli/init.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +CLIDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +UTIL="$CLIDIR/util.php" + +echo "Building phpunit.xml and initialising test database..." + +php $UTIL --buildconfig +RESULT=$? +if [ $RESULT -gt 0 ] ; then + exit $RESULT +fi + +php $UTIL --drop +RESULT=$? +if [ $RESULT -gt 0 ] ; then + exit $RESULT +fi + +php $UTIL --install +RESULT=$? +if [ $RESULT -gt 0 ] ; then + exit $RESULT +fi diff --git a/admin/tool/phpunit/cli/util.php b/admin/tool/phpunit/cli/util.php index 18a08dbcb9b..d08a51979cb 100644 --- a/admin/tool/phpunit/cli/util.php +++ b/admin/tool/phpunit/cli/util.php @@ -31,6 +31,12 @@ define('PHPUNIT_UTIL', true); +// verify PHPUnit installation +if (!@include_once('PHPUnit/Autoload.php')) { + fwrite(STDERR, "Can not load PHPUnit PEAR library, is it installed?\n"); + exit(1); +} + require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php'); require_once($CFG->libdir.'/phpunit/lib.php'); require_once($CFG->libdir.'/adminlib.php'); diff --git a/lib/phpunit/lib.php b/lib/phpunit/lib.php index a1906a9f5a2..65d085aa22a 100644 --- a/lib/phpunit/lib.php +++ b/lib/phpunit/lib.php @@ -23,9 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -// necessary when loaded from cli/util.php script -// If this is missing then PHPUnit is not in your PHP include path. This normally -// happens if installation didn't complete correctly. Check your environment. + require_once 'PHPUnit/Autoload.php'; diff --git a/lib/phpunit/readme.md b/lib/phpunit/readme.md index d9d7f3beb87..772512b99e4 100644 --- a/lib/phpunit/readme.md +++ b/lib/phpunit/readme.md @@ -13,13 +13,12 @@ Installation ------------ 1. install PHPUnit PEAR extension - see [PHPUnit docs](http://www.phpunit.de/manual/current/en/installation.html) for more details 2. edit main config.php - add $CFG->phpunit_prefix and $CFG->phpunit_dataroot - see config-dist.php for more details -3. execute `php admin/tool/phpunit/cli/util.php --install` from dirroot to initialise test database and dataroot +3. execute `admin/tool/phpunit/cli/init.sh` initialise test database and dataroot 4. it is necessary to reinitialise the test database manually after every upgrade or installation of new plugins Test execution -------------- -* optionally generate phpunit.xml by executing `php admin/tool/phpunit/cli/util.php --buildconfig` - it collects test cases from all plugins * execute `phpunit` shell command from dirroot directory * you can also execute a single test `phpunit core_phpunit_basic_testcase lib/tests/phpunit_test.php` * or all tests in one directory `phpunit --configuration phpunit.xml lib/tests/*_test.php` @@ -57,5 +56,4 @@ TODO * convert remaining tests * delete all simpletests * hide old SimpleTests in UI and delete Functional DB tests -* shell script that prepares everything for the first execution * optional support for execution of tests and cli/util.php from web UI (to be implemented via shell execution)