Martin
Martin

Reputation: 3114

Disable colors in code coverage output from PHPUnit

I want to automate testing for a little PHP project of mine, it works well so far, the only thing I could not get to work is the code coverage report.

In Gitlab-Ci there is the option Test coverage parsing, which accepts a regex. So far so good, I found a regex at http://jarretbyrne.com/2015/04/gitlab-ci-phpunit-test-coverage-parsing/ : ^\s*Lines:\s*\d+.\d+\%

But as the comment says: it doesn't work with colors enabled. PHPUnit has the command line switch --colors-[always|never|auto] but this option only applies to the normal output.

How can I turn off colors for --coverage-text? Can I use another regex?

Edit:

There is an open issue at https://github.com/sebastianbergmann/phpunit/issues/1771

Upvotes: 2

Views: 1900

Answers (2)

elboletaire
elboletaire

Reputation: 5367

You can just set --colors=never and they'll be disabled. It really works with colors previously enabled in the xml file (I've just tested it), try it:

vendor/bin/phpunit --coverage-text --colors=never

So I guess that issue was already fixed :)

Upvotes: 3

Martin
Martin

Reputation: 3114

I'm running phpunit like that now to strip all colors from the output:

php vendor/phpunit/phpunit/phpunit --coverage-text | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"

Upvotes: 2

Related Questions