PHPUnit - 此版本的 PHPUnit 需要 PHP 5.6;强烈建议使用最新版本的 PHP - OSX 10.11

PHPUnit - This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended - OSX 10.11

我正在使用 MAC OS X El Capitan(版本 10.11.1)。

我使用以下命令安装了 PHPUint:

brew install homebrew/php/phpunit

当我在终端中输入 which phpunit 时,它输出:

/usr/local/bin/phpunit

但是当我 运行 phpunit /pathto/file.php 时,它给了我这个错误:

Parse error: parse error, expecting '&'' or"variable (T_VARIABLE)"' in phar:///usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar/phar/phpunit-mock-objects/Framework/MockObject/Builder/InvocationMocker.php on line 82

所以我所做的是使用这些命令再次安装 phpunit:

curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

然后当我尝试使用 phpunit --version 时,它说:

This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.

然后我做了:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

当我 运行 phpinfo() 它说我的 PHP 版本是 5.6.10。但我再次尝试输入 phpunit --version,相同的是:

This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.

经过一些研究,我发现这可能是因为我安装了 2 个 PHPUnit,所以我尝试使用以下方法删除 PHPUnit:

brew uninstall phpunit 

成功了,然后又试了phpunit --version,还是PHP版本问题。

而且,如果我再次尝试执行 brew uninstall phpunit,它会显示一条消息:

Error: No such keg: /usr/local/Cellar/phpunit

更新

当我输入

php --version 在终端输出

PHP 5.5.29 (cli) (built: Sep  9 2015 00:26:40) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

所以我猜 php 版本仍然是 5.5.29 。我也重新启动了 apaches。

您需要确保执行的是新安装的php命令,而不是默认命令。

将正确的 php 二进制文件所在的文件夹作为第一项添加到 $PATH 环境变量中。

我遇到了同样的问题。不使用酿造。只需在 Mac 上安装最新的 PHP(截至目前为 7)。 在这里阅读: https://coolestguidesontheplanet.com/upgrade-php-on-osx/

我用过:

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

这需要很长时间,但它会告诉您安装位置。对我来说,是:

/usr/local/php5-7.0.12-20161101-102255/bin/php

我刚刚将此添加到我的 ~/.bash_profile,使用 source 刷新。现在命令行看到正确的版本,PHPUnit 很高兴。