MDL-32323 all-in-one PHPUnit init script

This commit is contained in:
Petr Skoda 2012-04-04 21:06:01 +02:00
parent 6aaae357c9
commit 4b17369567
4 changed files with 32 additions and 6 deletions

24
admin/tool/phpunit/cli/init.sh Executable file
View file

@ -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

View file

@ -31,6 +31,12 @@
define('PHPUNIT_UTIL', true); 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(__DIR__ . '/../../../../lib/phpunit/bootstrap.php');
require_once($CFG->libdir.'/phpunit/lib.php'); require_once($CFG->libdir.'/phpunit/lib.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');

View file

@ -23,9 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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'; require_once 'PHPUnit/Autoload.php';

View file

@ -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 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 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 4. it is necessary to reinitialise the test database manually after every upgrade or installation of new plugins
Test execution 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 * execute `phpunit` shell command from dirroot directory
* you can also execute a single test `phpunit core_phpunit_basic_testcase lib/tests/phpunit_test.php` * 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` * or all tests in one directory `phpunit --configuration phpunit.xml lib/tests/*_test.php`
@ -57,5 +56,4 @@ TODO
* convert remaining tests * convert remaining tests
* delete all simpletests * delete all simpletests
* hide old SimpleTests in UI and delete Functional DB tests * 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) * optional support for execution of tests and cli/util.php from web UI (to be implemented via shell execution)