PHP - 是否有PHPUnit的便携式版本?

8

是否有一款便携版的PHPUnit,可以与我的Web应用程序捆绑在一起?我希望能够在任何服务器上使用phpunit,同时避免使用PEAR时出现的问题(版本冲突,破坏其他托管的应用程序等)。


https://dev59.com/6VvUa4cB1Zd3GeqPpAH5 - Pacerier
3个回答

8

可移植的 PHPUnit(源自 https://github.com/sebastianbergmann/phpunit 中的“从 Git 检出使用 PHPUnit”)

对于 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 ..

然后将这些文件夹中的每一个都放入您的包含路径中。

如果您漏掉其中任何一个包,它将无法正常工作。

如果您不想始终将它们放在包含路径中,这里有一个名为phpunit.sh的可执行文件。

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 $*

3
当edorian写出答案时,它很正确(现在可能仍然有用)。但是现在您可以使用更方便的选项。
除了通过Composer修复特定的PhpUnit之外,您还可以将PHPUnit作为Phar下载并使用。
引用https://github.com/sebastianbergmann/phpunit的话:
“我们分发一个PHP Archive (PHAR),其中包含所有必需(以及一些可选)的PHPUnit依赖项打包在一个单独的文件中:”
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

2
来自edorian的答案漏掉了Symfony / Yaml包。此外,似乎需要Symfony / Finder,尽管在PHPUnit的自述文件中没有提到。
关于PEAR依赖性,只有PHPUnit的自测试需要它。至少我成功地运行了整个Zend Framework 2的测试套件而没有遇到问题。我也没有安装PEAR。
这是我制作的PHPUnit Git checkout安装程序链接:https://github.com/kblomqvist/gitinstall-phpunit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接