Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange output from PHPUnit

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

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>

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

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.

Kind regards

like image 823
KodeFor.Me Avatar asked Jun 20 '13 15:06

KodeFor.Me


1 Answers

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

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;
    }

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

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

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

like image 90
markdrake Avatar answered Oct 21 '22 15:10

markdrake