Skip to content

Instantly share code, notes, and snippets.

@xjm
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xjm/fa740a44491bf8bdba62 to your computer and use it in GitHub Desktop.
Save xjm/fa740a44491bf8bdba62 to your computer and use it in GitHub Desktop.
Run a D8 test from a clean install
# Obviously, replace the site location and DB credentials with yours.
# Resets a Drupal installation (destroying all data) without reinstalling.
# Run this command directly to clean up the old installation before
# reinstalling manually.
function drupal-reset() {
# Remove existing database.
drush sql-drop -y;
# Remove existing installation.
sudo rm -rf sites/default;
# Restore the sites/default/default.settings.php file.
sudo git checkout -- sites/default;
# Temporarily make the sites/default writable by anyone.
sudo chmod -R 777 sites/default;
# Ensure the owner is the current user, not the root user.
sudo chown -R `whoami` sites/default;
# Now that it is writeable, restore the directory from the branch.
sudo git checkout -- sites/default;
# Ensure that we still own the folder.
sudo chown -R `whoami` sites/default;
}
# Reinstalls Drupal 8 with a particular install profile, destroying all data.
# Usage: drupal-install 'minimal'
# By default, the 'standard' profile is used.
function drupal-install() {
drupal-reset
# Accept an install profile as an argument.
if [ $1 ] ; then
drush si $1 --db-url=mysql://root:root@localhost/d8 -y
else
drush si --db-url=mysql://root:root@localhost/d8 -y
fi
}
# Reinstalls Drupal 8 with the testing profile and runs a given test.
# Usage: reinstall-test 'Drupal\Tests\Core\UrlTest
function reinstall-test() {
if [ $1 ] ; then
# Install the testing profile.
drupal-install 'testing'
# Enable the simpletest module.
drush en simpletest -y
# Run the given test class, with detailed results.
php ~/d8git/core/scripts/run-tests.sh --color --url http://localhost:8888/d8git/ --verbose --class $1
else
echo "You must specify a test class. Usage: reinstall-test 'Drupal\Tests\Core\UrlTest'"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment