[英]PHPUnit on pre-commit Git Hook seems to use different PHP version
I'm trying to set up a pre-commit git hook that will run and validate our unit tests. 我正在尝试设置一个预提交的git钩子,该钩子将运行并验证我们的单元测试。 We are using PHPUnit in the Symfony 2 platform.
我们在Symfony 2平台中使用PHPUnit。
For some reason it seems that when I run the unit tests via the git hook that it is using a different version of PHP. 出于某种原因,当我通过git钩子运行单元测试时,它似乎正在使用不同版本的PHP。
When I check my php version I get: 当我检查我的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
Here is my git hook: 这是我的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);
When I run the unit tests manually ("bin/phpunit -c app/" from my project directory) the tests execute with out error. 当我手动运行单元测试时(从我的项目目录中“ bin / phpunit -c app /”),测试执行没有错误。 When I run the tests via the git hook I get a PHP Parse Error.
通过git钩子运行测试时,出现PHP解析错误。 I've determined that the parse error stems from the use of array bracket notation (['key'=>'value']) that was added in PHP 5.4
我确定解析错误源于对PHP 5.4中添加的数组括号符号(['key'=>'value'])的使用。
When I echo php -v in the git hook I get the following output 当我在git hook中回显php -v时,得到以下输出
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
Since the Zend Engine is different (2.4.0 when run manually and 2.3.0 when run via the git hook) I'm assuming that there is a PHP version mismatch happening. 由于Zend Engine是不同的(手动运行时为2.4.0,而通过git挂钩运行时为2.3.0),我假设发生了PHP版本不匹配的情况。
Does anyone have any clues as to why this is happening? 有谁知道为什么会这样吗?
Thanks! 谢谢!
the git/phpunit executable most likely sees a different PATH
environment variable than your shell (bash/zsh/...) executable. git / phpunit可执行文件最有可能看到与您的shell (bash / zsh / ...)可执行文件不同的
PATH
环境变量。
If a program looks for ie php
- the first match from your PATH
variable will be used. 如果一个程序查找即
php
-从你的第一场比赛PATH
变量将被使用。
Probably you're adding a folder containing a different PHP executable to the PATH
variable in one of your shell startup files. 可能是您在一个外壳启动文件中的
PATH
变量中添加了一个包含不同PHP可执行文件的文件夹。
Possible files include: 可能的文件包括:
/etc/profile
/etc/zshenv
/etc/bashrc
~/.profile
~/.bashrc
~/.zshrc
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.