Extension Key: phpunit
Copyright 2007 Kasper Ligaard <ligaard@daimi.au.dk>
This document is published under the Open Content License
available from http://www.opencontent.org/opl.shtml
The content of this document is related to TYPO3
- a GNU/GPL CMS/Framework available from www.typo3.com
PHPUnit is a TYPO3 extension which provides
a back-end module to run unit tests for extensions of a TYPO3 installation.
The screen shot below shows a test run of the (sample) tests that comes with the phpunit extensions. There are two failing tests, with descriptions of each failure:
These are basic requirements for using this extension:
Make sure you are running PHP 5.2.1 or higher.
Use the Extension Manager to download and install phpunit.
In order to create a unit test, you need to create a directory “tests” in your extension directory and add some PHP files ending with _testcase.php containing a class with functions whose names are prefixed with test_.
If you need to store data for fixtures, create a sub directory tests/fixtures/
Have a look in the phpunit extensions tests/ directory for a template, tx_phpunit_test_testcase.php.
Consult the PHPUnit documentation for information on writing tests, available functions etc.
As of version 3.1.13, phpunit checks if the pear extension is loaded and if it is, then it can use a PHPUnit installed through the pear manager module. You should use version PEAR extension version 3.2.5 or later.
If you can not use this method nor the built-in PHPUnit, then read next section.
As of version 3.1.9 of the phpunit extension it is possible use any PHPUnit version 3.x with phpunit. If you already have PHPUnit installed through PEAR, then you can use that version instead; or you could run ‘bleeding edge’ SVN directly from the phpunit.de Subversion repository.
Using another PHPUnit version is easy if you remember these three points:
Use the absolute path.
Remember the trailing slash in the absolute path.
The path should point to the directory before ‘PHPUnit’ directory. Example: If you have the Framework.php-file installed in c:\xampp\php\PEAR\PHPUnit, then you should point to the directory c:\xampp\php\PEAR\
You can verify the includepath from within the phpunit extension via the ‘About phpunit BE’ entry in the upper right corner of the back-end module.
When you are all set, then you just write the path in the extension conf in the extension manager for phpunit.
The phpunit extension scans all installed extension directories for a ‘tests’ directory. So put your tests in a sub-directory of your extensions root called ‘tests’ and phpunit will automatically detect them.
Now you are ready to write tests. Writing tests is fun but takes some time. I hope using this extension will motivate you to keep on writing good, solid tests :-)
If you are new to unit-testing, the read the PHPUnit pocket guide, http://www.phpunit.de/pocket_guide/3.2/en/ .