如何正确要求Phar文件 [英] How to properly require a phar file

查看:117
本文介绍了如何正确要求Phar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

phpunit已停止支持PEAR安装.这导致我们需要继续使用phpunit的phar安装.我们有一个包装脚本,该脚本循环访问许多目录并在这些目录上调用phpunit可执行文件.然后,包装脚本将所有生成的报告合并为一个报告.

phpunit has stopped supporting PEAR installation. This has caused us to need to use the phar installation of phpunit moving forward. We have a wrapping script that iterates through many directories and calls the phpunit executable on those directories. The wrapping script then consolidates all of the generated reports into a single report.

在PEAR中安装phpunit时,包装脚本顶部唯一需要的条件是

When phpunit was installed with PEAR, the only require we needed at the top of the wrapping script was

require 'PHP/CodeCoverage/Autoload.php';

然后,当包装脚本执行

$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process($codeCoverage, "${reportsDir}/clover-coverage.xml");

自动加载器将(大概)加载执行该代码所需的任何内容,我们将继续前进.

The autoloader would (presumably) load whatever was needed to execute this code and we'd go on our happy way.

但是,自从转移到phar装置以来,事情变得一团糟.最初我以为我只需要phar文件本身,一切都会很好.

Since the move to a phar installation, however, things have gotten messy. Initially I thought I could just require the phar file itself and everything would be good.

require 'phpunit-3.7.31.phar';

但是,这会导致phar文件在击中require行后立即执行,从而中止了带phpunit用法输出的包装脚本.由于您不能在php require语句中使用通配符,因此我慢慢构建了一个文件列表,这些文件是完成包装脚本所需的,并要求如下:

However this caused the phar file to be executed as soon as the require line was hit, aborting the wrapping script with phpunit usage output. Since you can't use wildcards in a php require statement, I then slowly built a list of files needed to complete our wrapping script and required them like this:

require 'phar://phpunit-3.7.31.phar/php-code-coverage/CodeCoverage/Report/Clover.php';

当我从其目录中执行包装脚本并且phpunit.phar文件位于同一目录中时,此方法有效.但是,尝试从其他目录执行该命令将失败,原因是无法在包含路径中找到phar文件.我试图更改包含路径,将.phar文件放在包含路径上已经存在的位置,并在包含中给phar文件提供绝对路径,例如:

This worked when I executed the wrapping script from it's directory and the phpunit.phar file was in the same directory. However, trying to execute it from a different directory would fail saying the phar file was not found on the include path. I attempted to change the include path, put the .phar file in locations already on the include path, and give an absolute path to the phar file in the include like:

require 'phar://actual/path/to/file/phpunit-3.7.31.phar/php-code-coverage/CodeCoverage/Report/Clover.php';

解决我的问题的这些尝试均无济于事.

None of these attempts at solving my issue worked.

如何以一种允许我从系统上任何位置运行脚本的方式包含.phar文件中的文件?

另一个可接受的答案是让我使用phar文件中的类,而不必单独包含我需要的所有内容.

Another acceptable answer would be one that lets me use the classes in the phar file without including everything I need individually.

Ubuntu 12.04

Ubuntu 12.04

PHPUnit 3.7.31(我们必须保留此版本,但这并不会真正影响问题)

PHPUnit 3.7.31 (we have to stay on this version, but that doesn't really affect the question)

推荐答案

还可以查看 PHPCOV ,以合并多次运行中的代码覆盖率数据.

Also have a look at PHPCOV for merging code coverage data from multiple runs.

这篇关于如何正确要求Phar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆