Public | Automated Build

Last pushed: 17 days ago
Short Description
Western Michigan University's image for testing a Drupal module with Behat.
Full Description

Supported tags and respective Dockerfile links

For more information about this image and its history, please see the westernmichiganuniversity/docker-drupal-module-behat repository on Bitbucket.

What is included?

This image contains the components needed to test a Drupal module project with Behat, including:

  • PHP 5.6
  • Apache
  • MySQL server
  • Selenium

What is not included?

The image does not include Drupal Core because it assumes that you are managing your module project with Composer and have already added Drupal as a dependency. By default, the image expects to find Drupal Core in vendor/drupal/drupal in your project directory. Likewise, if your module depends on any other Drupal modules or third-party libraries, the image expects to find them in vendor/drupal/modules and vendor/drupal/libraries, respectively. If your Composer configuration installs these packages to a different location, set the DRUPAL_CORE, DRUPAL_MODULES and DRUPAL_LIBRARIES environment variables to the corresponding paths within the container.

The image also does not include the executables for Drush (to install the module) or Behat (to run the tests), again assuming that you have already added these as dependencies. By default, Composer will place the executables at vendor/bin/drush and vendor/bin/behat in your project directory. If your Composer configuration installs these executables to a different location, you can tell the container where to find them by setting the DRUSH environment variable and overriding the container's default runtime command. For example, if your Composer configuration installs these executables in /path/to/my/project/bin, you would run the container like so:

docker run -v /path/to/my/project:/opt/project -e DRUSH=/opt/project/bin/drush westernmichiganuniversity/drupal-module-behat /opt/project/bin/behat

If you created your project using the WMU Drupal module template, then all of the above has already been set up for you. If you did not use the template, simply run composer require drupal/drupal:7.*, composer require drush/drush and composer require behat/behat to add Drupal Core, Drush and Behat to your project.

How to use this image

To test a Drupal module project with Behat:

  1. Map your project directory (containing behat.yml, features/ and your module's .info and .module files) into the container as /opt/project.
  2. Set the MODULE environment variable to the machine name of your module (i.e., the name of your .info file, minus the .info).
  3. (optional) If you need to enable additional modules before running the test, set the ENABLE_OTHER_MODULES environment variable to a list of the modules' machine names, separating each module with a space. Note that you do not need to set this for modules that are defined as dependencies in your .info file. For example, if your module defines actions for the Rules module—but does not actually depend on Rules—then you could set ENABLE_OTHER_MODULES="rules" to enable the Rules module before testing those actions. In this case, you would want to add Rules to devDependencies in your composer.json file (by running composer require drupal/rules --dev) so that it is available for testing, but not required when deploying your module in production.

By default, on run, the container executes the command vendor/bin/behat --no-interaction --format=junit --format=pretty in the /opt/project directory. You can override this command by passing a new command as an argument to docker run.


Running with default options

docker run -v /path/to/my/project:/opt/project -e MODULE=my_module westernmichiganuniversity/drupal-module-behat
  • docker run ... westernmichiganuniversity/drupal-module-behat: Starts a Docker container using this image.
  • -v /path/to/my/project:/opt/project: Maps the /path/to/my/project directory on your local machine into the container as the /opt/project directory.
  • -e MODULE=my_module: Copies your module into the container's Drupal site as sites/all/modules/my_module and enables it.
  • Runs all test suites defined in behat.yml.

Running with additional modules enabled

docker run -v /path/to/my/project:/opt/project -e MODULE=my_module -e ENABLE_OTHER_MODULES="rules views" westernmichiganuniversity/drupal-module-behat
  • -e ENABLE_OTHER_MODULES="rules views": Enables the Rules and Views modules.

Running only one test case

docker run -v /path/to/my/project:/opt/project -e MODULE=my_module westernmichiganuniversity/drupal-module-behat vendor/bin/behat --no-interaction --format=junit --format=pretty features/example.feature
  • vendor/bin/behat --no-interaction --format=junit --format=pretty features/example.feature: Runs only the tests defined in example.feature (i.e., /path/to/my/project/features/example.feature on your local machine), rather than all test suites defined in behat.yml.


License information for the software contained in this image is available from:


This image is supported for use by Western Michigan University web developers on Docker version 17.03.0-ce.

Docker Pull Command