开发者

PHP - Is there a portable version of PHPUnit?

Is there a portable version of PHPUnit that I can开发者_开发百科 bundle with my web app? I want to be able to use phpunit on any server while avoiding the issues of using PEAR (version conflicts, breaking other hosted apps, etc.).


Portable phpunit (taken from https://github.com/sebastianbergmann/phpunit "Using PHPUnit From a Git Checkout" )

For phpunit 3.5:

git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git

cd phpunit && git checkout 3.5 && cd ..
cd dbunit && git checkout 1.0 && cd ..
cd php-file-iterator && git checkout 1.2 && cd ..
cd php-code-coverage && git checkout 1.0 && cd ..
cd php-token-stream && git checkout 1.0 && cd ..
cd phpunit-mock-objects && git checkout 1.0 && cd ..
cd phpunit-selenium && git checkout 1.0 && cd ..

and then put every single of those folders into your include path.

It will not work if you leave out any one of those packages.

If you don't want to always have them in the include path here is a phpunit.sh executable

phpunit.sh

x='./checkoutDir/';

php -d include_path=".:$x/phpunit/:$x/dbunit/:$x/php-code-coverage/:$x/php-file-iterator/:$x/php-text-template/:$x/php-timer/:$x/php-token-stream/:$x/phpunit-mock-objects/:$x/phpunit-selenium/:$x/phpunit-story/:/usr/share/php/"  $x/phpunit/phpunit.php $*


The answer by edorian was spot on at the time it was written (and probably still is useful today). However, nowadays there is some more convenient options at your disposal.

In addition to fixing to a specific PhpUnit via Composer, you can also download PHPUnit as a Phar and use that.

Quoting https://github.com/sebastianbergmann/phpunit

We distribute a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file:

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit


The answer from edorian missed the Symfony/Yaml package. Moreover, Symfony/Finder seemed to be needed, although not mentioned in PHPUnit's readme file.

Regarding to PEAR dependency, it's only the PHPUnit's selftest that tends to need it. At least I have managed to run the whole test suite of Zend Framework 2 without problems. And I hadn't PEAR installed.

Here's the installer for PHPUnit Git checkout that I have made https://github.com/kblomqvist/gitinstall-phpunit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜