开发者

Packaging PHPUnit tests as a PHAR archive?

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);开发者_Python百科
$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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜