Created
June 8, 2017 11:50
-
-
Save edmondscommerce/30baa15297241b9e02e101098ce1e451 to your computer and use it in GitHub Desktop.
PHPUnit bash snippet to only use Xdebug if running all tests, otherwsise use a custom php.ini that has xdebug disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
phpCmd="/usr/bin/php" | |
function phpNoXdebug { | |
local temporaryPath="$(mktemp -t php.XXXX).ini" | |
# Using awk to ensure that files ending without newlines do not lead to configuration error | |
/usr/bin/php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "$temporaryPath" | |
/usr/bin/php -n -c "$temporaryPath" "$@" | |
rm -f "$temporaryPath" | |
} | |
if [[ "" != "$noCoverage" ]] | |
then | |
if [[ "" != "$($phpCmd -i | grep xdebug)" ]] | |
then | |
phpCmd=phpNoXdebug | |
fi | |
fi | |
$phpCmd ./vendor/bin/phpunit \ | |
-c phpunit.xml \ | |
--verbose \ | |
--debug \ | |
$noCoverage \ | |
$@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment