PHPUnit from command line - list of dependancy files displayed. How can I make it display only the test script?

Deadly 提交于 2019-12-21 20:16:34

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8576472/phpunit-from-command-line-list-of-dependancy-files-displayed-how-can-i-make-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!