Skip to content

Instantly share code, notes, and snippets.

@anubisthejackle
Last active January 10, 2021 17:49
Show Gist options
  • Save anubisthejackle/260135f5d820d3dd35b3d8f5ad44e09b to your computer and use it in GitHub Desktop.
Save anubisthejackle/260135f5d820d3dd35b3d8f5ad44e09b to your computer and use it in GitHub Desktop.
PHPUnit Polyfill to auto-detect the correct PHPUnit to use in any development environment
#!/bin/bash
# Check if there is a vendor/bin/ or vendor-bin/ directory that contains PHPUnit
if [ -f $PWD"/vendor/bin/phpunit" ]; then
echo "Using vendor/bin/phpunit..."
$PWD/vendor/bin/phpunit $@
exit 0
fi
if [ -f $PWD"/vendor/bin/simple-phpunit" ]; then
echo "Using vendor/bin/simple-phpunit..."
$PWD/vendor/bin/simple-phpunit $@
exit 0
fi
if [ -f $PWD"/vendor-bin/phpunit" ]; then
echo "Using vendor-bin/phpunit"
$PWD/vendor-bin/phpunit $@
exit 0
fi
# Check if we are currently inside of a WordPress folder, and phpunit-7 is installed as expected
WCCOUNT=$(ls -la | grep "wp-" | wc -l)
if [ $WCCOUNT -gt 0 ] && [ -f /usr/bin/phpunit-7 ]; then
echo "Using /usr/bin/phpunit-7..."
/usr/bin/phpunit-7 $@
exit 0
fi
INSTALLATIONS=($(find /usr/bin -maxdepth 1 -name "phpunit*" -print | sort -r))
if [ -f ${INTALLATIONS[0]} ]; then
echo "Using ${INSTALLATIONS[0]}..."
${INSTALLATIONS[0]} $@
exit 0
fi
echo "No version of PHPUnit was found..."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment