4
votes

Context

I'm using Composer scripts defined in my composer.json file to run unit tests in my application.

My composer.json:

{
    "name": "my company/my_application",
    "description": "Description of my application",
    "license": "my licence",
    "require": {
        "php": ">=5.6",
        "ext-soap": "*",
        "ext-ssh2": "*",
        "ext-curl": "*",
        "ext-zip": "*",
        "ext-pdo_mysql": "*",
        "ext-gettext": "*",
        "dusank/knapsack": "^9.0"
    },
    "require-dev": {
        "ext-mysqli": "*",
        "phpunit/phpunit": "^5.7",
        "squizlabs/php_codesniffer": "2.*"
    },
    "scripts": {
        "test-php": "vendor/bin/phpunit --colors --verbose --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml",
    }
}

My command is:

vendor/bin/phpunit --colors --verbose --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml tests/

Problem

If I run vendor/bin/phpunit --colors --verbose --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml tests/ inside a terminal, I can see colored output. But if I run it using Composer, I don't see any color.

Question

Using Composer scripts defined in composer.json, how to display phpunit colors?

1

1 Answers

6
votes

To force phpunit to display colors in any situations, add =always to the --color parameters.

With

vendor/bin/phpunit --colors=always --verbose --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml tests/

in my composer.json file, I can see colors.