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

时间:2012-05-08 16:23:31

标签: php unit-testing phpunit

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

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

3 个答案:

答案 0 :(得分:4)

我建议您查看此博文:

对于厨师食谱,请查看我的博客文章:

如果链接停止工作:

  • pear支持--installroot开关
  • 示例:

    pear install --installroot / some / path / phpunit34 pear.phpunit.de/PHPUnit-3.4.15

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

HTH

答案 1 :(得分:1)

当您安装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

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

答案 2 :(得分:0)

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

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

php phpunit-X.Y.Z.phar  

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

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