PHPUnit输出异常结果

6
我已经通过PEAR安装了PHPUnit,并且还安装了WordPress插件测试(https://github.com/tierra/wordpress-plugin-tests),以测试我正在开发的WordPress插件。
问题是,尽管测试运行正常,但我得到了以下输出:
Running as single site... To run multisite, use -c multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from E:\LocalWebServer\dch\c\my-wp-installtion.dch\wordpress-test\wordpress\wp-content\plugins\myplugin\phpunit.xml

[41;37mF[0m.[36;1mS[0m

Time : 1 second, Memory: 30.50Mb

There was 1 failure:

1) CDOAjax_Tests::test_tests
Failed asserting that false is true.

E:\LocalWebServer\dch\c\my-wp-installtion.dch\wordpress-test\wordpress\wp-content\plugins\myplugin\Tests\test_CDOAjax_tests.php:7

[37;41m[2KFAILURES!
[0m[37;41m[2KTests: 3, Assertions: 2, Failures: 1, Skipped: 1.
[0m[2K

我不知道这是否有帮助,但phpunit.xml包含以下内容:

<phpunit
bootstrap="bootstrap_tests.php"
backupGlobals="false"
colors="true"
>
    <testsuites>
        <!-- Default test suite to run all tests -->
        <testsuite name="cabdriver">
            <directory prefix="test_" suffix=".php">tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

如您所见,PHPUnit的输出中有一些奇怪的字符,比如包含[0m[2k的最后一行。

我的系统是Windows 7,我使用通过PEAR安装的XAMPP和PHPUnit。

那么,我能否以某种方式解决这个问题,因为输出并不易于阅读。

此致敬礼


1
看起来颜色代码没有被正确转义,这很可能与您的 shell 有关。您使用的是什么 shell 和终端应用程序? - Matt Ryan
正如我上面所描述的,这是在Windows 7上的CMD控制台,谢谢 :) - KodeFor.Me
什么样的 shell?你是什么意思?我通过 Windows 7 的命令行运行 PHPUnit 测试。 - KodeFor.Me
你可以在这里找到相关报告:http://core.trac.wordpress.org/ticket/12277 - 由于你是Windows用户,请参考PHPUnit Windows命令框漂亮的颜色 - hakre
1个回答

13

这些是Unix控制台的颜色代码,它们在PHPUnit框架中被硬编码,如您在此处所见:https://github.com/sebastianbergmann/phpunit/blob/master/PHPUnit/TextUI/ResultPrinter.php

例如:500到509行。

public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
    {
        if ($this->colors) {
            $this->writeProgress("\x1b[31;1mE\x1b[0m");
        } else {
            $this->writeProgress('E');
        }

        $this->lastTestFailed = TRUE;
    }

我相信你可以在phpunit.xml文件中设置属性colors="false"来隐藏颜色:

<phpunit colors="false">
  <!-- ... -->
</phpunit>

你可以在这里阅读更多: http://phpunit.de/manual/3.7/en/appendixes.configuration.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接