The requirement to run unit tests with the Adventure PHP Framework is the PHPUnit framework. It is freely available through several sources. The following section explains two ways to get the phpunit framework.
A convenient way to get the phpunit framework is PEAR. The PEAR CLI provides an easy way to install and update your packages. Most all-in-one solutions like XAMPP provide at least the PEAR installer, if not already have pre-installed some PEAR packages. In the following sections it will be assumed a pear environment is correctly installed, you can get more information under PEAR-Installation.
The installation of the PHPUnit-Framework now proceeds easily and quickly. Therefor call the command line and enter the following commands:
pear config-set auto_discover 1 pear install pear.phpunit.de/File_Iterator pear install pear.phpunit.de/Text_Template pear install pear.phpunit.de/PHP_CodeCoverage pear install pear.phpunit.de/PHP_Timer pear install pear.phpunit.de/PHPUnit_MockObject pear install pear.phpunit.de/PHPUnit
The following packages are optional:
pear install phpunit/DbUnit pear install phpunit/PHPUnit_Selenium pear install phpunit/PHPUnit_Story pear install phpunit/PHPUnit_TestListener_DBUS pear install phpunit/PHPUnit_TestListener_XHProf pear install phpunit/PHPUnit_TicketListener_Fogbugz pear install phpunit/PHPUnit_TicketListener_GitHub pear install phpunit/PHPUnit_TicketListener_GoogleCode pear install phpunit/PHPUnit_TicketListener_Trac pear install phpunit/PHP_Invoker
The second possibility to get the phpunit framework is via GIT. You get more information under the official introduction. If you have a git client installed, you can use the following commands on the command line:
mkdir phpunit && cd phpunit git clone git://github.com/sebastianbergmann/phpunit.git git clone git://github.com/sebastianbergmann/dbunit.git git clone git://github.com/sebastianbergmann/php-file-iterator.git git clone git://github.com/sebastianbergmann/php-text-template.git git clone git://github.com/sebastianbergmann/php-code-coverage.git git clone git://github.com/sebastianbergmann/php-token-stream.git git clone git://github.com/sebastianbergmann/php-timer.git git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git git clone git://github.com/sebastianbergmann/phpunit-selenium.git git clone git://github.com/sebastianbergmann/phpunit-story.git git clone git://github.com/sebastianbergmann/php-invoker.git
If you have the PHPUnit framework installed, there is not much to do to finally bring the unit tests on the Adventure PHP Framework to work.
First you change directory to tests. There are two files, which has to be copied and renamed:
cp phpunit.dist.xml phpunit.xml cp phpunit.dist phpunit
The file "phpunit" is the script to call on commandline to invoke the phpunit test application. Before you can use it correctly, you need to open the file and change the fist constant called PHPUNIT_INCLUDE_PATH, which has the path to the shared pear library. On Windows based systems you may change the second constant PHP_BIN_FILENAME to "php.exe".
Now you may call the script phpunit in the directory ../branches/php5/1.15/tests/ from the commandline with the following command:
The script automatically checks for the default configuration file called
"phpunit.xml" which we have already existing in the current directory.
So if everything works correctly the script should call the described test suites from the configuration file.
If you want to run you own tests or extend the existing, all you have to do is adding it to the configuration file, and of course write the test.