来自命令行的 PHPUnit - 显示的依赖文件列表。如何让它只显示测试脚本?

发布于 2024-12-22 09:15:32 字数 1655 浏览 3 评论 0原文

我已经在 Windows 7 上安装了 PHPUnit,以及 PHP 和 Pear。

我有一个基本的测试脚本,首先:

<?php

class StackTest extends PHPUnit_Framework_TestCase
{
    public function testTest()
    {
        $this->assertTrue(false);
    }
}

我从命令提示符运行它:

phpunit unittest testTest.php

并得到以下返回:

PHPUnit 3.6.5 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 2.75Mb

There was 1 failure:

1) StackTest::testTest
Failed asserting that false is true.

C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:145
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:92
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:2100
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:854
C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:939
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:801
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestResult.php:649
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:748
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:772
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:745
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\TestRunner.php:325
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:187
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:125
C:\Program Files (x86)\PHP\PEAR\phpunit:44

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

我的问题是列出的不同文件的长列表。

我只想在那里看到我的试卷。我错过了什么吗?

I have installed PHPUnit on Windows 7, with PHP and Pear.

I have a basic test script, to start with:

<?php

class StackTest extends PHPUnit_Framework_TestCase
{
    public function testTest()
    {
        $this->assertTrue(false);
    }
}

I'm running it from the command prompt as:

phpunit unittest testTest.php

And getting the following return:

PHPUnit 3.6.5 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 2.75Mb

There was 1 failure:

1) StackTest::testTest
Failed asserting that false is true.

C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:145
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Constraint.php:92
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:2100
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\Assert.php:854
C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:939
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:801
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestResult.php:649
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestCase.php:748
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:772
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\Framework\TestSuite.php:745
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\TestRunner.php:325
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:187
C:\Program Files (x86)\PHP\PEAR\pear\PHPUnit\TextUI\Command.php:125
C:\Program Files (x86)\PHP\PEAR\phpunit:44

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

My problem is the long list of different files listed.

I only want to see my test scrip there. Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-12-29 09:15:32

简短版本:

这是 PHPUnit 中的一个错误。 我已经修复了它。在下一个次要版本中它将起作用。


长版本:

您已经注意到您的文件包含在回溯中,

 C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10

所以问题是为什么您的类周围还有所有其他内容。

PHPUnit 应该 过滤回溯并删除所有 PHPUnit 类,但由于某些原因,这似乎不起作用。

Linux 上的输出:

PHPUnit 3.6.5 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 3.00Mb

There was 1 failure:

1) failingTest::testFail
Failed asserting that false is true.

/home/edo/phpunit-dev/oneFailingTest/failingTest.php:6

我一开始以为 Program Files 中的空格会出现问题,但我已将其安装在一个没有空格的文件夹中,并且它也在那里“中断”。

对我来说这是 PHPUnit 中的一个错误。

我建议您在 github 问题跟踪器上提交问题回溯过滤在Windows上似乎被破坏了,我会看看我是否可以解决这个问题。 编辑:我已经推送了修复。它应该在 PHPUnit 3.6.6 中得到解决(当它发布时)。查看编辑内容。


编辑:是的。该问题似乎来自 PHPUnit_Util_Filter::phpunitFiles();使用 \ 而不是 / 返回路径。

修复

如果您将以下代码放入: PHPUnit/Util/GlobalState.php 第 412 行(在 return 语句之前)

foreach(self::$phpunitFiles as $key => $value) {
    unset(self::$phpunitFiles[$key]);
    self::$phpunitFiles[str_replace("/", "\\", $key)] = $value;
}

,那么您会得到一个漂亮的回溯。我会确保它在 3.6.6 中得到修复,并提供更好的补丁。

Short Version:

It's a bug in PHPUnit. I've fixed it. With the next minor release it will work.


Long Version:

You have already noticed that your file is included in the backtrace

 C:\Users\lbassett\Dropbox\Projects\Test\testTest.php:10

so the question is why is there all that other stuff around your classes.

PHPUnit should filter that backtrace and strip out all the PHPUnit classes but for some reasons that seems to not work.

The output on linux:

PHPUnit 3.6.5 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 3.00Mb

There was 1 failure:

1) failingTest::testFail
Failed asserting that false is true.

/home/edo/phpunit-dev/oneFailingTest/failingTest.php:6

I at first was expecting an issue with the spaces in Program Files but I've installed it in a folder without spaces and it "breaks" there too.

For me this is a bug in PHPUnit.

I suggest you file an issue at the github issue tracker that the backtrace filtering seems broken on windows and I'll see if I can take care of that then. Edit: I've pushed a fix. It should be solved in PHPUnit 3.6.6 (when it is released). See the edits.


Edit: Yeah. The issue seems to come from PHPUnit_Util_Filter::phpunitFiles(); returning the paths with \ instead of /.

Fix

If you put the following code in: PHPUnit/Util/GlobalState.php at line 412. (Before the return statement)

foreach(self::$phpunitFiles as $key => $value) {
    unset(self::$phpunitFiles[$key]);
    self::$phpunitFiles[str_replace("/", "\\", $key)] = $value;
}

then you get a nice looking backtrace. I'll see to it that it gets fixed in 3.6.6 with a nicer patch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文