Skip to content

Instantly share code, notes, and snippets.

@schemar
Last active August 29, 2015 14:06
Show Gist options
  • Save schemar/15fd87e1fd7718571f71 to your computer and use it in GitHub Desktop.
Save schemar/15fd87e1fd7718571f71 to your computer and use it in GitHub Desktop.
Bash script to reset the database, load fixtures and run tests for Symfony with one call.
#!/bin/bash
function printHelp {
echo "Load fixtures and run tests"
echo "Usage: runTests.sh [options] [directory]"
echo ""
echo "Options:"
echo " -r|--reset resets the sqlite test database before testing"
echo " -h|--help print this help"
echo ""
echo "Directory:"
echo " Optionally you can supply a directory. In that case, all tests inside that"
echo " directory and its subdirectories will be run INSTEAD of the ones specified"
echo " inside app/phpunit.xml"
echo ""
echo "Examples:"
echo " Run the tests as specified inside app/phpunit.xml:"
echo " ./runTests.sh"
echo " Run the tests as specified inside app/phpunit.xml, but reset database first:"
echo " ./runTests.sh -r"
echo " Run the tests from src/AcmeBundle:"
echo " ./runTests.sh src/AcmeBundle"
echo " Run the tests from src/AcmeBundle, but reset database first:"
echo " ./runTests.sh -r src/AcmeBundle"
echo " Run only the service tests from src/AcmeBundle:"
echo " ./runTests.sh -r src/AcmeBundle/Tests/Service"
exit 0
}
DIRECTORY=""
# parse command line arguments
for key in $@
do
case ${key} in
-r|--reset)
php app/console doctrine:cache:clear-metadata --env=test
php app/console cache:clear --env=test
php app/console doctrine:database:drop --env=test --force
php app/console doctrine:database:create --env=test
php app/console doctrine:schema:update --env=test --force
;;
-h|--help)
printHelp
;;
*)
DIRECTORY=${key}
;;
esac
done
# load fixtures and run tests
echo "y" | php app/console doctrine:fixtures:load --fixtures=src/ --env=test
vendor/bin/phpunit -c app ${DIRECTORY}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment