This repository intends to document how to setup a lightweight PHPUnit testing environnement to unit test self developed Joomla components. The unit tests use PHPUnit and DBUnit. The two packages are installed with Composer. The unit tests are run from the command line or run from Eclipse LUNA for PHP developers. Debugging the tests inside Eclipse with XDebug on a local Apache/MySql backed by PHP 5.4 (Xammp 1.8.2 on Windows 8.1 x64) will also be documented. Two main commits are of interest: the commit titled initial Joomla 1.5 PHPUnit testing environment contains the PHPUnit testing environment which works for Joomla 1.5. The commit titled adapt PHPUnit testing environment to Joomla 3.x contains the same environment, but adapted and ported to Joomla 3.x. This commit does display what was changed to the base test classes and to the test data to comply with Joomla 3.x.
At the end of this documentation, a short section explains how to install and configure the MakeGood plugin, which is clearly the best way of running and debugging PHPUnit tests in Eclipse.
French speakers find information rich spoken audio on my site: http://plusconscient.net.
This readme file was written with the free Dillinger Markdown editor
Unless specifed, the explanations below apply to both version of Joomla !
- install composer on your workstation (installable available at https://getcomposer.org/)
- create a composer folder in the root of your Joomla project
- in the composer folder, create a file named composer.json
- edit composer.json and add
{
"require-dev": {
"phpunit/phpunit": "3.7.37",
"phpunit/dbunit": "1.3.1"
}
}
I did not yet figured out how to set up the run and debug Eclipse configuration with PHPUnit 4+ !
- open a dos window on the composer folder and type
composer install
This will download the PHPUNIT and DBUNIT packages in the composer\vendor folder. Composer is easy to use. More info at https://getcomposer.org/.
Notice that no libraries are required to run or debug the tests !
the config displayed above is taken from the Joomla3.x project. On a Joomla 1.5 project, only the Joomla root part of the path does change !
###Warning When running the tests in the Joomla 1.5 environnement, the tests succed but the run ends with the stack trace below. I did not figure out why this happens !
<Joomla root>
TEST
data // contains D£BUnit test data files
lib // contains test base class and test loader
unittest // contains PHPUnit tests
###At command line
###In Eclipse
Running one selected PHPUnit test
Running all PHPUnit tests in the selected folder
###Install MakeGood 3.1.1 or later Previous versions either not compatible with Eclipse PDT Luna or bogged down. Releases are listed here. But normally, install from Eclipse Marketplace like any Eclipse plugin !
###Create preload PHP script somewhere in your workspace with content similar to
<?php
// Setup the path related constants.
define ( 'DS', DIRECTORY_SEPARATOR );
require dirname ( __DIR__ ) . DS . 'composer' . DS . 'vendor' . DS . 'autoload.php';
?>
Here, the preload script is put in the TEST folder
Do not forget to refresh the Eclipse folder !
Finally, edit the MakeGood properties accessed in the project properties
You now are able to run and debug your tests with the MakeGood plugin, as explained in the MakeGood user guide