Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edmondscommerce/30baa15297241b9e02e101098ce1e451 to your computer and use it in GitHub Desktop.
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
#!/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