我正在尝试设置一个预提交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这是我的吉特钩:
#!/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钩子中回显php -v时,我得到以下输出
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies由于Zend引擎是不同的(手动运行时为2.4.0,通过git挂钩运行时为2.3.0 ),所以我假设会出现PHP版本不匹配的情况。
有人知道为什么会发生这种事吗?
谢谢!
发布于 2014-01-21 22:29:40
PATH git/phpunit可执行最有可能看到一个与shell不同的环境变量(bash/zsh/.)可执行文件。
如果程序查找,即php -将使用来自您的PATH变量的第一个匹配。
您可能是在将一个包含不同PHP可执行文件的文件夹添加到一个shell启动文件中的PATH变量中。
可能的档案包括:
/etc/profile
/etc/zshenv
/etc/bashrc
~/.profile
~/.bashrc
~/.zshrc
...https://stackoverflow.com/questions/21268879
复制相似问题