Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle PHPUnit with my code?

I would like to:

  • Run tests with PHPUnit regardless of my environment (and if PHPUnit or PEAR is installed or not)
  • Show test results on screen if possible

How can I do this? I tried downloading the code here and including Autoload.php but it still have some dependencies. Maybe there's some better approach for this than trying to bundle it with my code...?

like image 778
Hugo Mota Avatar asked Oct 06 '22 11:10

Hugo Mota


1 Answers

To include PHPUnit in your projects source files I'd suggest following the guide:

Using PHPUnit From a Git Checkout from the PHPUnit Contributung section.

It tells you about all the packages you need to install and shows you show to build a runner/wrapper script for the phpunit executable.

#!/bin/bash
php -d include_path='.:../phpunit/:../dbunit/:../php-code-coverage/:../php-file-iterator/:../php-invoker/:../php-text-template/:../php-timer:../php-token-stream:../phpunit-mock-objects/:../phpunit-selenium/:../phpunit-story/:/usr/local/lib/php' ../phpunit/phpunit.php $*

You can adapt the path to your need or if you want to wrap it in another script you can also use phpunit somewhat programmatically by

require '/path/to/phpunit/PHPUnit/Autoload.php';
PHPUnit_TextUI_Command::main();

This assumes that you ether have a phpunit.xml.dist file or that you use the proper cli parameters when calling your wrapper script.


You can also use the pear packages and unpack all the stable versions instead of working from the git checkout to save some disk and repo space. The wrapper script and all the include path work is the same :)


Related SO questions:

PHP - Is there a portable version of PHPUnit?

PHPUNIT without installation

like image 186
edorian Avatar answered Oct 13 '22 10:10

edorian