Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

PHPUnit: Difference between revisions

From MoodleDocs
Line 13: Line 13:
PHPUnit is distributed as PEAR package, it is not part of Moodle installation. You have to manually install it on your dev computer. The installation procedure depends on your operating system or the way you installed PHP.
PHPUnit is distributed as PEAR package, it is not part of Moodle installation. You have to manually install it on your dev computer. The installation procedure depends on your operating system or the way you installed PHP.


Usual steps on *nix:
Usual steps:
# install or enable PEAR package manager
# install or enable PEAR package manager
# configure PEAR <code>pear config-set auto_discover 1</code>
# install PHPUnit package
# install PHPUnit package <code>pear install pear.phpunit.de/PHPUnit</code>
# verify phpunit can be executed
 
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit


=Configuration of server before first test execution=
=Configuration of server before first test execution=

Revision as of 21:47, 3 April 2012

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

PHPUnit
Project state Work in progress
Tracker issue MDL-32323, MDL-32149, MDL-31857
Discussion see tracker issues
Assignee Petr Škoda (škoďák)

Moodle 2.3


Installation of PHPUnit support

PHPUnit is distributed as PEAR package, it is not part of Moodle installation. You have to manually install it on your dev computer. The installation procedure depends on your operating system or the way you installed PHP.

Usual steps:

  1. install or enable PEAR package manager
  2. install PHPUnit package
  3. verify phpunit can be executed
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

Configuration of server before first test execution

Our PHPUnit integration requires a dedicated database and dataroot. Before the fist test execution the database has to be initialised via command line script:

php admin/tool/phpunit/cli/util.php --drop; php admin/tool/phpunit/cli/util.php --install

Test execution

PHPUnit tests are executed from the command line. PHP IDEs usually have integration options for PHPUnit.

All test suites

Before first execution you should build new configuration file phpunit.xml by executing:

php admin/tool/phpunit/cli/util.php --buildconfig

To execute all system tests specified in default configuration file run:

phpunit

Individual tests

phpunit mod/yourmodule/tests/some_test.php

All tests in one directory

phpunit mod/yourmodule/tests/*_test.php

Writing new tests

Conversion of existing tests

See also