问题
I am using MAC OS X El Capitan (Version 10.11.1).
I installed PHPUint using the following command:
brew install homebrew/php/phpunit
When I type which phpunit in the terminal it outputs:
/usr/local/bin/phpunit
but when I run phpunit /pathto/file.php, it gave me this error:
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
So what I did was I installed phpunit again using these commands:
curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
then when I try to use phpunit --version it says:
This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.
So then I did:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
When I run phpinfo() it says my PHP version is 5.6.10. But again I tried to type phpunit --version, the same:
This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.
After some research I found that’s may be because I have 2 installations of PHPUnit so I tried to remove PHPUnit using:
brew uninstall phpunit
it was successful, then again I tried to phpunit --version, but still the PHP version issue.
And also if I try to do a brew uninstall phpunit again, it will show a message:
Error: No such keg: /usr/local/Cellar/phpunit
UPDATE
When I type
php --version in terminal it outputs
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
So I guess php version still picks up as 5.5.29 . I restarted apaches also .
回答1:
You need to make sure that the newly installed php command is executed, not the default one.
Add the folder where the correct php binary resides as the first item to the $PATH environment variable.
回答2:
I had the same issue. Not using brew. Just installing latest PHP (7 as of now) on Mac. Read here: https://coolestguidesontheplanet.com/upgrade-php-on-osx/
I used:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
This takes a long time, but it tells you where it installs. For me, it was:
/usr/local/php5-7.0.12-20161101-102255/bin/php
I just added this to my ~/.bash_profile, refreshed using source. Now the command line sees the right version, and PHPUnit is happy.
来源:https://stackoverflow.com/questions/34127553/phpunit-this-version-of-phpunit-requires-php-5-6-using-the-latest-version-of