18

Composer allow running scripts, as said in defining scripts.

So, I'm trying to run some spec tests with it.

{
    "scripts": {
        "test": "./vendor/davedevelopment/dspec/bin/dspec"
    },
    "require-dev": {
        "esperance/esperance": "dev-master",
        "davedevelopment/dspec": "dev-master"
    }
}

It runs fine, but there is no color output, and for spec tests this difficults the reading.

How can I run the scripts but keep the original colored output?

3 Answers 3

38

Use the --ansi param.

"test": "./vendor/davedevelopment/dspec/bin/dspec --ansi"
2

The davedevelopment/dspec library uses the symfony/console component. Symfony/console uses the POSIX extension to determine whether to allow color output. If you want color to show up by default without passing the --ansi flag, you just need to install the POSIX extension.

1
  • 2
    php -m|grep posix shows POSIX is installed here, but it didn't seem to help. Dec 9, 2017 at 1:40
1

I've just run phpunit via composer and the colors are there. Perhaps the dspec script has no color support or is disabled by default.

"scripts" : {
  "test" : "./vendor/bin/phpunit -c tests/phpunit.xml"
},
6
  • Maybe some singularity of dspec then. I'll take a deeper look. Nov 19, 2014 at 18:48
  • I have problems with PHPUnit outputting colors through Composer. I've tried various ways to call it, but no luck so far. Any pointers? Thanks! Jan 12, 2015 at 19:24
  • 21
    I added --colors=always from PHPUnit master (4.6) branch which did the trick. It seems PHPUnit actually detects it is called through another scripts and suppresses the colors itself. Jan 12, 2015 at 19:53
  • On Windows 10, I have colors enabled in my phpunit.xml, and normally this does enable colors, but when run with composer, the colors are gone. Jun 3, 2020 at 14:16
  • I got it working with --colors=always. This is from my "scripts" section in composer.json "test": "phpunit --colors=always". Composer automatically knows to look in vendor/bin for this phpunit (since it is not in my PATH, and I add it per project). It is also using the default phpunit.xml at my project root. @HaralanDobrev also mentoined --colors=always, but the way they mentioned master confused me into thinking they were doing something other than adding that to their command to run phpunit. Jun 3, 2020 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.