Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Last active September 24, 2020 18:57
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 amitaibu/2b8ce08c387e6162c3fd2d2112bb2c91 to your computer and use it in GitHub Desktop.
Save amitaibu/2b8ce08c387e6162c3fd2d2112bb2c91 to your computer and use it in GitHub Desktop.
# https://ddev.readthedocs.io/en/stable/users/cli-usage/#drupal-8-quickstart
mkdir my-drupal8-site
cd my-drupal8-site
ddev config --project-type=drupal8 --docroot=web --create-docroot
ddev start
ddev composer create "drupal/recommended-project:^8"
ddev composer require drush/drush
ddev launch
# Install PHPunit
ddev composer require --dev phpunit/phpunit:^7
ddev composer require --dev symfony/phpunit-bridge:^5.0
ddev composer require --dev mikey179/vfsstream
# Prepare config file.
cp web/core/phpunit.xml.dist web/core/phpunit.xml
sed -i 's/<env name="SIMPLETEST_BASE_URL" value=""\/>/<env name="SIMPLETEST_BASE_URL" value="http:\/\/localhost"\/>/' web/core/phpunit.xml
sed -i 's/<env name="SIMPLETEST_DB" value=""\/>/<env name="SIMPLETEST_DB" value="mysql:\/\/db:db@db\/db"\/>/' web/core/phpunit.xml
# Get module, with the `add-test` branch
git clone git@gitlab.com:drupalforks/pluggable_entity_view_builder.git web/modules/pluggable_entity_view_builder -b add-test
# Execute phpunit from the container.
ddev ssh
../vendor/bin/phpunit -c core/phpunit.xml modules/pluggable_entity_view_builder
@amitaibu
Copy link
Author

Here's how it would look in a more generic way (i.e. without my specific module):

# https://ddev.readthedocs.io/en/stable/users/cli-usage/#drupal-8-quickstart

mkdir my-drupal8-site
cd my-drupal8-site
ddev config --project-type=drupal8 --docroot=web --create-docroot
ddev start
ddev composer create "drupal/recommended-project:^8"
ddev composer require drush/drush
ddev launch

# Install PHPunit

ddev composer require --dev phpunit/phpunit:^7
ddev composer require --dev symfony/phpunit-bridge:^5.0
ddev composer require --dev mikey179/vfsstream

# Prepare config file.
cp web/core/phpunit.xml.dist web/core/phpunit.xml

sed -i 's/<env name="SIMPLETEST_BASE_URL" value=""\/>/<env name="SIMPLETEST_BASE_URL" value="http:\/\/localhost"\/>/' web/core/phpunit.xml

sed -i 's/<env name="SIMPLETEST_DB" value=""\/>/<env name="SIMPLETEST_DB" value="mysql:\/\/db:db@db\/db"\/>/' web/core/phpunit.xml

# Execute phpunit to test custom modules from the container.
ddev ssh
../vendor/bin/phpunit -c core/phpunit.xml modules/custom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment