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

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

问题描述

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

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

我的测试用例如下所示:

My test case looks like this:

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

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

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天全站免登陆