Bij Pronamic maken we binnen WordPress projecten veel gebruik van Composer, PHPUnit en andere tools. Om het aanroepen van scripts te vereenvoudigen maken we ook wel gebruik van Composer scripts. In plaats van bijvoorbeeld vendor/bin/phpunit
te typen kunnen we dan composer phpunit
gebruiken.
{
"name": "…",
"description": "…",
"config": {
"sort-packages": true
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"scripts": {
"phpunit": "vendor/bin/phpunit"
}
}
Nadeel daarvan was echter dat composer phpunit
geen kleuren output gaf. Terwijl het aanroepen van vendor/bin/phpunit
wel een kleuren output gaf. Dit terwijl in het PHPUnit configuratie bestand phpunit.xml.dist
wel colors="true"
stond. Na een kleine zoektocht kwam ik de oorzaak en oplossing tegen op Stack Overflow:
I added
Haralan Dobrev – https://stackoverflow.com/questions/27024298/keep-color-output-when-running-scripts-on-composer#comment44218731_27024464--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.
{
"name": "…",
"description": "…",
"config": {
"sort-packages": true
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"scripts": {
"phpunit": "vendor/bin/phpunit --colors=always"
}
}
Hoe we dit bij Pronamic in gebruik hebben is bijvoorbeeld te zien in de WordPress pay core bibliotheek:
https://github.com/wp-pay/core
