Since around 4.5 colored output stopped working. It does not matter if it is triggered by phpunit --colors switch in console or colors = "true" in phpunit.xml, the line with result (green/yellow OK / red FAILURE) is not colored which makes it harder to quickly assess tests state. What works though is coloring output of --coverage-text, all lines are working as expected.
I couldn't find anything in the project documentation, there are no complaints about the issue on StackOverflow and other such places so I'm wondering what happened? I'm using Ubuntu 14.04 and ZSH shell, PHPUnit is installed through Composer.
This has already been discussed. Look at all the conversations on colour. :)
Thanks for pointers to these issues, but I just noticed another issue: colors are present when PHPUnit is invoked like ./vendor/phpunit/phpunit/phpunit, but not with straight phpunit. In both cases PHPUnit reports latest version 4.6.4. Things get weird when it is invoked using phpunit --colors=always, in this case PHPUnit reports version 3.7.28 (Ubuntu DEB package version) and displays error "option --colors doesn't allow an argument".
case PHPUnit reports version 3.7.28 (Ubuntu DEB package version) and displays error "option --colors doesn't allow an argument".
Yes, you must be using a new 4.x version to use "always".
PHPUnit reports version 3.7.28
That version has the old behaviour, where "true" will do the same thing as "always" now does.
Yes, but isn't it strange that same command triggers different versions of the library? As I said, phpunit without parameters runs Composer version, but DEB version with them. I can't recall such behavior in older versions.
This is unrelated. This is just to do with your system setup. Nothing to do with phpunit. phpunit doesn't determine how to run itself. :)
When I uninstall system package phpunit command is not recognized. How do you then have it installed? Shell alias?
Ok, I managed to work around this issue by creating shell alias to vendor/phpunit/phpunit/phpunit and it's working now. Thanks for conversation.
I' experiencing a similar issue. For one thing, the colors are not displayed any more (despite colors="true" in the phpunit.xml). Also the version seems to change when I use --colors=always. This shouldn't be an issue with the system setup since a command line argument doesn't change the binary that is called.
Example:
$ phpunit --filter NonexistentTest
PHPUnit 4.7.3 by Sebastian Bergmann and contributors.
Time: 175 ms, Memory: 9.75Mb
No tests executed!
$ phpunit --colors --filter NonexistentTest
PHPUnit 4.7.3 by Sebastian Bergmann and contributors.
Time: 176 ms, Memory: 9.75Mb
No tests executed!
$ phpunit --colors=always --filter NonexistentTest
PHPUnit 3.7.28 by Sebastian Bergmann.
option --colors doesn't allow an argument
Only with the suggested workaround of calling vendor/bin/phpunit colors are displayed again.
Sorry, @mzur, but it appears that your PHP / PHPUnit environment is broken (mixed versions of PHPUnit). What you are posting does not make any sense.
@mzur I had the same issue, you probably have installed PHPUnit both as a system package (apt-get or something) and as a composer package in the project directory. Purge the system package and run alias phpunit=./vendor/bin/phpunit and everything should be okay.
@thunderer That'll do but it's kind of a workaround still.
@sebastianbergmann I've digged a little deeper and it seems you're right. My system package is 3.7.28 and the local composer package 4.7.3. The first two calls of phpunit in my previous post seem to have been redirected to the local composer package somehow, whereas the last one wasn't. Don't ask me why but I'll be content with the suggested alias.
Thanks to you both :-)
To anyone who does not have colors with --colors=auto or colors="true": you need to have posix extension installed.
Suggested alias also works for me.
For those on Fedora: posix extension is installed as php-process package.
Most helpful comment
To anyone who does not have colors with
--colors=autoorcolors="true": you need to haveposixextension installed.