Installing PHPUnit
Unit testing is arguably the most popular means of testing PHP code. Most developers will agree that a solid suite of tests is a requirement for any properly developed project. Few developers actually write these tests. A lucky few have an independent testing group that writes the tests for them! After months of skirmishing with the testing group, however, the remains of the lucky few tend to grumble and complain. In any event, any book on PHP would not be complete without at least a nod and a wink towards testing.
The place to find the latest version of PHPUnit is https://phpunit.de/. PHPUnit5.1 and above support PHP 7. Click on the link for the desired version, and you will download a phpunit.phar
file. You can then execute commands using the archive, as follows:
php phpunit.phar <command>
Tip
The phar
command stands for PHP Archive. The technology is based on tar
, which itself was used in UNIX. A phar
file is a collection of PHP files that are packed together into a single file for convenience.