[英]PHPUnit on pre-commit Git Hook seems to use different PHP version
我正在尝试设置一个预提交的git钩子,该钩子将运行并验证我们的单元测试。 我们在Symfony 2平台中使用PHPUnit。
出于某种原因,当我通过git钩子运行单元测试时,它似乎正在使用不同版本的PHP。
当我检查我的php版本时,我得到:
php -v
PHP 5.4.14 (cli) (built: May 8 2013 10:23:18)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
这是我的git钩子:
#!/usr/bin/php
<?php
// Hook configuration
$project = 'My Project';
// Tell the commiter what the hook is doing
echo PHP_EOL;
echo '>> Starting unit tests'.PHP_EOL;
// Execute project unit tests
exec('bin/phpunit -c app/', $output, $returnCode);
// if the build failed, output a summary and fail
if ($returnCode !== 0)
{
// find the line with the summary; this might not be the last
while (($minimalTestSummary = array_pop($output)) !== null)
{
if (strpos($minimalTestSummary, 'Tests:') !== false)
{
break;
}
}
// output the status and abort the commit
echo '>> Test suite for '.$project.' failed:'.PHP_EOL;
echo $minimalTestSummary;
echo chr(27).'[0m'.PHP_EOL; // disable colors and add a line break
echo PHP_EOL;
exit(1);
}
echo '>> All tests for '.$project.' passed.'.PHP_EOL;
echo PHP_EOL;
exit(0);
当我手动运行单元测试时(从我的项目目录中“ bin / phpunit -c app /”),测试执行没有错误。 通过git钩子运行测试时,出现PHP解析错误。 我确定解析错误源于对PHP 5.4中添加的数组括号符号(['key'=>'value'])的使用。
当我在git hook中回显php -v时,得到以下输出
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
由于Zend Engine是不同的(手动运行时为2.4.0,而通过git挂钩运行时为2.3.0),我假设发生了PHP版本不匹配的情况。
有谁知道为什么会这样吗?
谢谢!
git / phpunit可执行文件最有可能看到与您的shell (bash / zsh / ...)可执行文件不同的PATH
环境变量。
如果一个程序查找即php
-从你的第一场比赛PATH
变量将被使用。
可能是您在一个外壳启动文件中的PATH
变量中添加了一个包含不同PHP可执行文件的文件夹。
可能的文件包括:
/etc/profile
/etc/zshenv
/etc/bashrc
~/.profile
~/.bashrc
~/.zshrc
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.