News Archive
PhpRiot Newsletter
Your Email Address:

More information

Using PHPUnit from a PHP Archive (PHAR)

Note: This article was originally published at Planet PHP on 17 April 7000.
Planet PHP

Downloading a single file to use PHPUnit? Not an idea that is too phar out anymore!

Starting with version 3.7.5, PHPUnit seems to finally work correctly when packaged as a PHP Archive (PHAR).

The example below shows one usage scenario for the PHPUnit PHAR:

azo git checkout -b use-phpunit-from-bundled-phar Switched to a new branch 'use-phpunit-from-bundled-phar' azo mkdir vendor azo curl -o vendor/phpunit.phar % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2544k 100 2544k 0 0 488k 0 0:00:05 0:00:05 --:--:-- 527k azo chmod +x vendor/phpunit.pharazo git add vendorazo vi build.xml azo git diff diff --git a/build.xml b/build.xml index be917a6..efff7de 100644 --- a/build.xml +++ b/build.xml @@ -157,7 +157,7 @@ - + azo ant phpunit Buildfile: /usr/local/src/bankaccount/build.xml phpunit: [exec] PHPUnit 3.7.5 by Sebastian Bergmann. [exec] [exec] Configuration read from /usr/local/src/bankaccount/phpunit.xml.dist [exec] [exec] ........................I................................ [exec] [exec] Time: 0 seconds, Memory: 10.75Mb [exec] [exec] There was 1 incomplete test: [exec] [exec] 1) ViewTest::testCanBeConstructed [exec] This test did not perform any assertions [exec] [exec] OK, but incomplete or skipped tests! [exec] Tests: 57, Assertions: 73, Incomplete: 1. [exec] [exec] Generating code coverage report in Clover XML format ... done [exec] [exec] Generating code coverage report in html format ... done BUILD SUCCESSFUL Total time: 2 seconds

The PHAR archive gives users a third option to install PHPUnit besides PEAR and Composer. This flexibility hopefully makes PHPUnit more accessible to new / more users.