如何在同一台计算机上运行多个版本的 PHPUnit


How do I run multiple versions of PHPUnit on the same machine?

我正在为一些项目使用 Zend 框架,并希望为它们构建 PHPUnit 测试套件。不幸的是,当前版本(1.11.x)中的Zend Framework仅支持PHPUnit 3.5。同时,我也想开始使用Symfony框架,它反过来支持更新版本的PHPUnit。那么问题是,我怎样才能同时在我的开发机器上运行多个版本的 PHPUnit,而不必安装单独的服务器或类似的东西?

我正在运行OS X Lion(10.7),并使用通过MacPorts安装的apache和php(5.3.10)。理想情况下,我希望最终可以简单地在终端中键入 phpunit5 来执行 3.5 版本,然后键入 phpunit6 来执行 3.6 版本,依此类推。

我建议你查看这篇博文:

  • http://tech.vg.no/2011/11/29/running-multiple-versions-of-phpunit/

有关厨师食谱,请查看我的博客文章:

  • http://till.klampaeckel.de/blog/archives/175-Cooking-PHPUnit-and-a-chef-solo-example-on-top.html

如果链接停止工作:

  • 梨支持--installroot开关
  • 例:

    梨安装 --installroot/some/path/phpunit34 pear.phpunit.de/PHPUnit-3.4.15

安装后,您可能需要向$PATH添加/some/path/phpunit34/usr/bin/或创建指向/usr/bin的符号链接,如博客文章所示。

当你安装 phpunit

3.4 时,公认的答案是有效的,但是如果你想安装 phpunit 3.5(它也可以用于在 Zend 项目中进行单元测试,尽管 Zends 自己的测试可能并不全部通过),你必须遵循稍微不同的路径。在安装 phpunit 之前,您需要单独安装 phpunit 3.5 的依赖项,否则某些依赖项只会强制安装 phpunit 3.6:

首先安装(请注意 -f 选项,它强制安装特定版本):

sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.symfony-project.com/YAML-1.0.2
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit_Selenium-1.0.1
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHP_Timer-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/Text_Template-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit_MockObject-1.0.3
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/File_Iterator-1.2.3
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHP_CodeCoverage-1.0.2
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/DbUnit-1.0.0
sudo pear install -f --installroot /your/path/to/PHPUnit35 pear.phpunit.de/PHPUnit-3.5.15

然后按照接受答案链接中的说明更改包含路径并正确符号链接。

PHPUnit 现在为其所有版本提供捆绑的 PHAR 文件 https://phar.phpunit.de/

只需下载所需的版本并使用以下方法调用它们:

php phpunit-X.Y.Z.phar  

(其中X.Y.Z是 PHPUnit 版本)

PHAR 文件可以很容易地别名,使它们在系统范围内可用。