在具有特定php版本的phpunit中运行测试 [英] Run test in phpunit with specific php version

查看:307
本文介绍了在具有特定php版本的phpunit中运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上安装了多个PHP版本,并希望针对特定的PHP版本(或针对​​multipls版本)运行单元测试

I have installed multiple PHP versions on my Mac and want to run unit-tests against a specific PHP version (or against multipls versions)

这是我拥有的php版本:

Here's the php versions I have:

$ php --version
  Output: PHP 5.4.23 ...

$ /Applications/MAMP/bin/php/php5.2.17/bin/php --version
  Output: PHP 5.2.17 ...

我的测试用例如下:

function test_php_version() {
    $actual = phpversion();
    $expected = '5.2.17';
    $this->assertEquals( $expected, $actual, 'Wrong PHP version!' );
}

运行测试时,我得到以下响应:

When I run the test I get this response:

$ phpunit

  Wrong PHP version!
  Failed asserting that two strings are equal.
  --- Expected
  +++ Actual
  @@ @@
  -'5.2.17'
  +'5.4.24'

$ /Applications/MAMP/bin/php/php5.2.17/bin/php phpunit
  Error: Could not open input file: phpunit

如何使用5.2.17版本的php运行测试?

How can I run the tests with the php version 5.2.17?

更新:

我发现PHPUnit不再与php5.2.17一起运行.因此,我更改了对使用php5.3.5进行单元测试的要求.

I discover that PHPUnit does not run with php5.2.17 anymore. So I change my requirements to run unit tests with php5.3.5, which is supported.

推荐答案

$ /Applications/MAMP/bin/php/php5.2.17/bin/php path/to/phpunit.phar

创建脚本,例如phpunit-using-5.2

#!/bin/sh
set -e

/Applications/MAMP/bin/php/php5.2.17/bin/php path/to/phpunit.phar "$@"

现在您可以运行它:

$ phpunit-using-5.2

或者您也可以创建bash别名.

Or you can create a bash alias too.

这篇关于在具有特定php版本的phpunit中运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆