【发布时间】:2014-01-21 20:53:21
【问题描述】:
我正在尝试设置一个预提交 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 hook 运行测试时,我得到一个 PHP Parse Error。我确定解析错误源于 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 版本不匹配。
有人知道为什么会这样吗?
谢谢!
【问题讨论】:
-
运行
which php会得到什么? -
/usr/local/opt/php54/bin/php ,我还尝试更新 !# 语句以使用该路径并尝试使用 /usr/bin/env php。到目前为止没有运气
标签: php git unit-testing symfony