News Archive
PhpRiot Newsletter
Your Email Address:

More information

Quality Assurance on PHP projects - PHPUnit part 1

Note: This article was originally published at Planet PHP on 19 April 9320.
Planet PHP
Of all tools available for improving quality assurance, there's one tool that is the core tool you have to master: PHPUnit. PHPUnit is a complete testing framework crafted by Sebastian Bergmann (@s_bergmann), who ported existing xUnit frameworks to PHP. And with this testing framework you're able to test your functionality in an automated way before you push code into production.

[editorial]AAs I cannot summarize the whole usage of phpunit in one blogpost, this will be a sequence of several articles that will pick up a specific task you want to cover with phpunit.

InstallationWell, first of all you need to have PHPUnit installed on your system. The easiest way to accomplish this is to use the PEAR installer.
user@server: $ pear channel-discover pear.phpunit.deuser@server: $ pear channel-discover components.ez.nouser@server: $ pear
Once you've got the right channels, you can install the framework:
user@server: $ pear install phpunit/PHPUnit
ConfigurationYou can use three methods to configure the way PHPUnit executes tests on your project:
  • a configuration file
  • command line parameters
  • a combination of both
Using a configuration file called "phpunit.xml" is by far the easiest way to run your unit tests in a consistent and organized way. It's a simple XML configuration file and the following works for me most of the times.

NOTE:AI use phpunit with a configuration file that matches my project settings, so you might need to modify these settings if you're using a framework or have a different source code layout.

A A A A A A ./A A

Truncated by Planet PHP, read more at the original (another 31884 bytes)