elife / isolated-drupal-behat-extension
Extension for Behat that tests Drupal sites in isolation
Installs: 3 796
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 13
Forks: 1
Open Issues: 2
Requires
- php: >=5.4
- behat/behat: ^3.0.6
- behat/mink-extension: ~2.0
- drupal/drupal-driver: ^1.0.1
- drupal/drupal-extension: ~3.0
- symfony/dependency-injection: ~2.5|~3.0
- symfony/event-dispatcher: ~2.3|~3.0
- symfony/filesystem: ~2.3|~3.0
- symfony/process: ~2.3|~3.0
Requires (Dev)
- behat/mink-goutte-driver: ~1.0
- drush/drush: ~7.0|~8.0
- mikey179/vfsstream: ~1.2
- phpunit/phpunit: ~4.8|~5.0
This package is not auto-updated.
Last update: 2019-02-20 21:15:56 UTC
README
What does the extension do?
The Drupal extension for Behat allows you to use Behat to writes scenarios that describe and test the functionality of your Drupal 7 site.
It's flexible, in that you are able to do things such as test remote sites. Because of this, however, it doesn't run each scenario in isolation, which means that they can be influenced by each other, as well as the existing site. When using Behat to purely test your codebase this is dangerous, as scenarios might pass or fail when in fact the opposite should happen.
This extension solves this problem by running each scenario on a freshly-installed site, which allows you to test your site with confidence.
Isn't that slow?
Yes. To help counter this, the extension actually copies the first install, then copies that back instead of actually installing the site again. This means that the first scenario might take a little while to run, but you won't notice much of a difference with the others.
Won't this destroy the site that I'm working on?
No. It (mis)uses Drupal's multi-site feature, so that your site isn't touched. If your site is available at http://localhost/, for example, it installs a site into sites/localhost
and tests on that (Drupal will serve it instead of your normal site), then removes it when the suite is finished.
How does it know what modules to enable?
It assumes that your install profile will set up your site. That said, you could add steps in your feature to enable modules etc as needed.
Requirements
- Behat 3.x
- Drupal extension for Behat 3.x
- A web server locally running your site.
Enabling the extension
-
Add the extension to your dependencies (
composer require elife/isolated-drupal-behat-extension
). -
Add the extension to your Behat configuration:
default: extensions: eLife\IsolatedDrupalBehatExtension: db_url: 'mysql://user:password@localhost/db_name'
See below for configuration options.
-
Run Behat as normal.
Configuration
The extension will use configuration options for the Drupal extension for Behat to know where your site is located, what URL it's served on etc.
Its own options are:
db_url
This is required. It is a connection string to a database that the isolated sites can be installed into.
This doesn't have to be the same type as your production setup, so you could use SQLite rather than MySQL. (Though bear in mind that if you're not using Drupal's database abstraction layer at any point you will need to use the same database type.)
Examples
mysql://user:password@localhost/db_name
sqlite:/db_name.sqlite
profile
This is the name of the install profile to use. The default value is standard
.
settings_file
This is a path to a settings.php
file to use. This is empty by default.
Note that the following values will be overwritten to ensure isolation:
$base_url
$databases
$drupal_hash_salt
$conf["file_public_path"]
$conf["file_private_path"]
$conf["file_temporary_path"]
clean_up
By default, the extension will remove the sites it created after the suite has finished. If you're running the suite a few times in quick succession, this means it will be installing a site each time, which can be quite slow. Setting this value to false
(the default is true
) which cause it not clean up the filesystem, so the second (and subsequent) runs will use the copy of the installed site from the first run. This will be quicker, but it's up to the developer to make sure that no changes have been made to the install process (if required, the master site will need to be manually removed).
Running the extension's tests
$ composer install $ ./vendor/bin/phpunit $ ./vendor/bin/behat
Extending the extension
You can write your own Behat extension and listen for the following events:
elife_drupal.installing_site
elife_drupal.mirroring_path
elife_drupal.site_installed
elife_drupal.site_settings
This will allow you to interact with/extend the extension.