ddev / ddev-drupal-contrib

DDEV integration for developing Drupal contrib projects
Apache License 2.0
82 stars 17 forks source link
ddev-get

tests project is maintained

DDEV Drupal Contrib

DDEV integration for developing Drupal contrib projects. As a general philosophy, your contributed module 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.

Install

  1. If you haven't already, install Docker and DDEV
  2. git clone your contrib module
  3. cd [contrib module directory]
  4. Configure DDEV for Drupal using ddev config --project-type=drupal --docroot=web --php-version=8.3 --project-name=[module] or select these options when prompted using ddev config
    • Remove underscores in the project name, or replace with hyphens. (DDEV will do this for you in v1.23.5+)
    • See Misc for help on using alternate versions of Drupal core.
  5. Run ddev get ddev/ddev-drupal-contrib
  6. Run ddev start
  7. Run ddev poser
  8. Run ddev symlink-project
  9. ddev config --update to detect expected Drupal and PHP versions.
  10. ddev restart

Update

Update by running the ddev get ddev/ddev-drupal-contrib command.

Commands

This project provides the following DDEV container commands.

Run tests on the web/modules/custom directory:

Codebase layout

Folder tree

Misc

Example of successful test

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)

Automatically correct coding standard violations

You can set up a pre-commit hook that runs phpcbf:

  1. Create a new file touch .git/hooks/pre-commit in your repository if it doesn't already exist.
  2. Add the following lines to the pre-commit file:
#!/bin/bash

ddev phpcbf -q
  1. Mark the file as executable: chmod +x pre-commit.

Troubleshooting

"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

Don't forget to run ddev restart if .ddev/config.yaml has been updated.

Contributed and maintained by @weitzman