无法运行Phar档案

时间:2014-11-03 16:44:58

标签: php unit-testing phpunit phar

在RHEL服务器上,我似乎无法运行PhpUnit。以下是作为root的示例,以说明我尝试安装PhpUnit的步骤以及它如何不运行:

# wget https://phar.phpunit.de/phpunit.phar
# chmod +x phpunit.phar
# ./phpunit --version

PHP Fatal error:  require(): Failed opening required 'phar://phpunit-4.3.4.phar/phpunit/TextUI/Command.php' (include_path='.:') in /usr/local/bin/phpunit on line 592
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. {closure}() /usr/local/bin/phpunit:0

# mv phpunit.phar /usr/local/bin/phpunit
# which phpunit
/usr/local/bin/phpunit

# phpunit --version

PHP Fatal error:  require(): Failed opening required 'phar://phpunit-4.3.4.phar/phpunit/TextUI/Command.php' (include_path='.:') in /usr/local/bin/phpunit on line 592
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. {closure}() /usr/local/bin/phpunit:0

似乎PHP在第13行定义的phar://地址格式上窒息:

# cat /usr/local/bin/phpunit | awk 'NR==592'
          require __PHPUNIT_PHAR_ROOT__ . $classes[$class];

# cat /usr/local/bin/phpunit | grep -n __PHPUNIT_PHAR_ROOT__
13:define('__PHPUNIT_PHAR_ROOT__', 'phar://phpunit-4.3.4.phar');
592:          require __PHPUNIT_PHAR_ROOT__ . $classes[$class];
601:        print file_get_contents(__PHPUNIT_PHAR_ROOT__ . '/manifest.txt');
20811:        if (defined('__PHPUNIT_PHAR_ROOT__')) {
20812:            $prefix = __PHPUNIT_PHAR_ROOT__;
26020:        copy(__PHPUNIT_PHAR_ROOT__ . '/ca.pem', $caFile);

服务器是RHEL 6.5:

# uname -a
Linux foobar 2.6.32-220.38.1.el6.x86_64 #1 SMP Wed May 15 08:34:56 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

1 个答案:

答案 0 :(得分:0)

解决方案是使用PEAR中的PHPUnit,它也不会运行此错误:

[root@panthercrm ~]# /usr/bin/phpunit
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/pear/PHPUnit/
Autoload.php on line 64
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. require() /usr/bin/phpunit:43
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:') in /usr/share/pear/PHPUni
t/Autoload.php on line 64
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. require() /usr/bin/phpunit:43        

将以下行添加到/etc/php.ini解决了PHPUnit的PEAR版本的问题:

include_path = ".:/usr/share/pear"