Search code examples
phpphpunitphar

Including PHPUnit.phar in script


I installed the latest release of PHPUnit using the phar according to the documentation. I have some scripts to compile a code coverage report using the PHP_CodeCoverage object. With the update, when I try to include phpunit.phar phpunit is actually run. The script outputs the list of options for running PHPUnit and then exits.

How can I include the file so that I have the PHPUnit objects available in my script?

The line that I tried was

require '/usr/local/bin/phpunit.phar';

Solution

  • PHPUnit creates and registers an autoload function for including its files in phpunit.phar. I was able to use the PHPUnit classes in my script by extracting this function.

    The code is available on Github

    Basically, all the class paths are mapped and then included via require phar:///user/local/bin/phpunit.phar/<class path>