Run test in phpunit with specific php version(使用特定 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 中运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用特定 php 版本在 phpunit 中运行测试


基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01