Testing: Installing PHPUnit

The quickest way to get PHPUnit running is to download a self-contained PHP Archive of the entire PHPUnit package and make it executable. As described at the PHPUnit website, the PHPUnit project makes this archive available at https:// phar.phpunit.de/phpunit.phar. You can download this file and make it executable to run it directly as in Example 13-1, or just run it through the php command-line pro­gram, as in Example 13-2.

Example 13-1. Running PHPUnit as an executable PHAR file

  • Assuming phpunit.phar is in the current directory, this
  • makes it executable chmod a+x phpunit.phar
  • And this runs it ./phpunit.phar –version

Example 13-2. Running PHPUnit with the php command-line program

php ./phpunit.phar –version

However you run PHPUnit, if things are working properly, the output of phpunit.phar –version should look something like this:

PHPUnit 4.7.6 by Sebastian Bergmann and contributors.

If you decide to use PHPUnit for testing in a larger project that relies on Composer to manage packages and dependencies, add a reference to it in the require-dev section of your composer.json file by running the following command:

composer require-dev phpunit/phpunit

Source: Sklar David (2016), Learning PHP: A Gentle Introduction to the Web’s Most Popular Language, O’Reilly Media; 1st edition.

Leave a Reply

Your email address will not be published. Required fields are marked *