将 PHPUnit 测试打包为 PHAR 存档?
是否可以将 PHPUnit 测试打包为 PHAR 存档并运行他们使用 phpunit?
我使用以下脚本创建了 .phar:
<?php
$cPhar = new Phar('mytests-archive.phar', 0);
$cPhar->addFile('mytest.php');
$sStub = <<<ENDSTUB
#! /usr/bin/php
<?php
Phar::mapPhar('mytest-archive.phar');
require 'phar://mytests-archive.phar/mytest.php';
__HALT_COMPILER();
ENDSTUB;
$cPhar->setStub($sStub);
$cPhar->compressFiles(Phar::GZ);
$cPhar->stopBuffering();
?>
但是当我尝试按如下方式运行生成的存档时:
phpunit mytests-archive.phar
我收到错误消息:
#! /usr/bin/php
PHPUnit 3.3.17 by Sebastian Bergmann.
Class MyTestClass could not be found in /path/to/mytests-archive.phar
PHPUnit 是否不支持 PHAR 文件,或者我在构建脚本中缺少某个步骤吗? (这是我第一次尝试使用 PHAR)
Is it possible to package PHPUnit tests as a PHAR archive, and run them using phpunit?
I've created a .phar with the follow script:
<?php
$cPhar = new Phar('mytests-archive.phar', 0);
$cPhar->addFile('mytest.php');
$sStub = <<<ENDSTUB
#! /usr/bin/php
<?php
Phar::mapPhar('mytest-archive.phar');
require 'phar://mytests-archive.phar/mytest.php';
__HALT_COMPILER();
ENDSTUB;
$cPhar->setStub($sStub);
$cPhar->compressFiles(Phar::GZ);
$cPhar->stopBuffering();
?>
But when I then try running the resulting archive as follows:
phpunit mytests-archive.phar
I get the error message:
#! /usr/bin/php
PHPUnit 3.3.17 by Sebastian Bergmann.
Class MyTestClass could not be found in /path/to/mytests-archive.phar
Does PHPUnit not support PHAR files, or am I missing a step in my build script? (This is my first attempt at using PHAR)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 PHPUnit 无法理解 PHAR 存档中的测试。 PHPUnit 不仅仅解释传递的文件并运行测试;它读取要运行的测试的源代码,然后执行它。因此,当它寻找 MyTestClass 的源时,它找不到它,因为它包含在存档中。
I don't think PHPUnit understands tests which are in a PHAR archive. PHPUnit doesn't just interpret the passed file and run tests; it reads the source of the test to be run and then executes it. So when it goes looking for the source of MyTestClass, it can't find it as it's wrapped up inside of the archive.