DDEV integration for developing Drupal contrib projects. As a general philosophy, your contributed module/theme is the center of the universe. The codebase layout (see image below) and commands in this project match the Gitlab CI approach from the Drupal Association.
git clone
your contrib moduleddev config --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable
or select these options when prompted using ddev config
ddev add-on get ddev/ddev-drupal-contrib
ddev start
ddev poser
ddev symlink-project
ddev config --update
to detect expected Drupal and PHP versions.ddev restart
ddev add-on get ddev/ddev-drupal-contrib
ddev restart
This project provides the following DDEV container commands.
drupal/core-recommended
becomes a dev dependency. This way the composer.json from the module is untouched.composer install
so that dependencies are available. Additional arguments to ddev poser
like --prefer-source
are passed along to composer install
web/modules/custom
) so Drupal can find your module. This command runs automatically on every ddev start
as long as Composer has generated vendor/autoload.php
which occurs during composer install/update
. See codebase image below.ddev phpunit
Run PHPUnit tests.ddev nightwatch
Run Nightwatch tests, requires DDEV Selenium Standalone Chrome.ddev phpcs
Run PHP_CodeSniffer.ddev phpcbf
Fix phpcs findings.ddev phpstan
. Run phpstan on project files.ddev eslint
Run ESLint on JavaScript files.ddev stylelint
Run Stylelint on CSS files.ddev core-version
. Update your codebase to a newer or older version of Drupal core. More info..ddev
folder after this plugin installs. This saves other users from having to install this integration.ddev exec "cd web/core && yarn install"
ddev restart
ddev symlink-project
cweagans/composer-patches:^1
is added by ddev poser
so feel free to configure any patches that your project needs.composer require
command to do that.Override any environment variable value from .ddev/config.contrib.yaml by creating a .ddev/config.local.yaml
(or any filename lexicographically following config.contrib.yaml) file which has the same structure as .ddev/config.contrib.yaml. Add your overrides under web_environment
.
Use the ddev core-version
command to set the core version environment variable and update the dependencies, for example:
ddev core-version ^11
You can also do this manually by setting a version in .ddev/.env.web
:
DRUPAL_CORE=^11
Then run ddev restart
and then ddev poser
to update the Drupal core version.
If Drupal core cannot be changed because the project is using an unsupported version of PHP, ddev poser
will show a composer
error. In that case, open .ddev/config.yaml
and change the PHP_VERSION
to a supported version; then run ddev restart
and ddev poser
again. Note that the project PHP version is set in .ddev/config.yaml
, while the core version to use is set in .ddev/.env.web
.
In .ddev/config.local.yaml
set the location relative to webroot (which usually is web/
). Defaults to modules/custom
web_environment:
- ...
- DRUPAL_PROJECTS_PATH=modules/custom
Then run ddev restart
to update the symlink location.
To use with Drupal themes, set DRUPAL_PROJECTS_PATH=themes/custom
in your config.local.yaml.
This is what a successful test looks like, based on Config Enforce Devel.
user:~/config_enforce_devel$ ddev phpunit
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
Default Target Module (Drupal\Tests\config_enforce_devel\Functional\DefaultTargetModule)
✔ Default target module created
Form Alter Implementation Order (Drupal\Tests\config_enforce_devel\Functional\FormAlterImplementationOrder)
✔ Form alter implementation order
Theme Settings Form (Drupal\Tests\config_enforce_devel\Functional\ThemeSettingsForm)
✔ Theme settings form submit
Time: 00:13.453, Memory: 4.00 MB
OK (3 tests, 20 assertions)
To run a single test class, make sure to use the path relative to the web
directory. Or use –filter to refer to a test class or method. For example:
ddev phpunit --filter MyTest.php
ddev phpunit --filter testMyFunction
You can set up a pre-commit hook that runs phpcbf:
touch .git/hooks/pre-commit
in your repository if it doesn’t already exist.pre-commit
file:#!/usr/bin/env bash
ddev phpcbf -q
chmod +x pre-commit
.“Error: unknown command”:
The commands from this addon are available when the project type is drupal
. Make sure the type
configuration is correctly set in .ddev/config.yaml
:
type: drupal
Tip
Remember to run ddev restart
if .ddev/config.yaml
has been updated.
Tests are done with Bats. It is a testing framework that uses Bash. To run tests locally you need to first install bats’ git submodules with:
git submodule update --init
Then you can run within the root of this project:
./tests/bats/bin/bats ./tests
Tests will be run using the default drupal core of the contrib. To test against a different Drupal core version, update the TEST_DRUPAL_CORE
environment
variable.
i.e. TEST_DRUPAL_CORE=11 ./tests/bats/bin/bats ./tests
.
Tests are triggered automatically on every push to the repository, and periodically each night. The automated tests are against all the supported Drupal core versions.
Also, consider adding tests in your PR.
To learn more about Bats, see the documentation.
Contributed and maintained by Moshe Weitzman (@weitzman) and Dezső BICZÓ (@mxr576)