PHPUnit的奇怪输出

PHPUnit的奇怪输出

本文介绍了PHPUnit的奇怪输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过PEAR安装了PHPUnit,也已经安装了WordPress插件测试( https://github. com/tierra/wordpress-plugin-tests )来测试我正在开发的WordPress插件.

I have installed the PHPUnit via the PEAR, and also I have installed the WordPress Plugin Test (https://github.com/tierra/wordpress-plugin-tests) to test my WordPress Plugin that is under development.

测试正常运行时,我得到以下输出的问题:

The issue that while the test run normaly, I am getting the following Output:

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包含以下内容:

I don't know if that helps, but the phpunit.xml contains the following:

<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]的最后一行.

As you can see, the PHPUnit output has some strange characters, like the last line that contains the [0m[2k.

我的系统是Windows 7,我通过PEAR运行XAMPP并安装了PHPUnit

My system is a Windows 7 and I run XAMPP with PHPUnit installed via the PEAR

所以,我能以某种方式解决该问题,因为输出内容不太清晰可读.

So, can I fix that issue somehow, because the output is not so clear for reading.

亲切的问候

推荐答案

这些是unix控制台的颜色代码,它们在phpunit框架中进行了硬编码,如您在此处所见:

Those are color codes for unix consoles and they are hard coded in the phpunit framework as you can see here: https://github.com/sebastianbergmann/phpunit/blob/master/PHPUnit/TextUI/ResultPrinter.php

例如:第500到509行.

Example: lines 500 to 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"的颜色:

I believe you can hide the colors setting the attribute colors="false" in your phpunit.xml file:

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

您可以在此处了解更多信息: http://phpunit.de/manual/3.7/en/appendixes .configuration.html

You can read more here: http://phpunit.de/manual/3.7/en/appendixes.configuration.html

这篇关于PHPUnit的奇怪输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:20