korstiaan / drunit
Drupal bootstrapper to ease integration/functional testing your Drupal modules
Requires
- drupal/core: *
- drush/drush: 6.0.*
- symfony/process: *
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-10-26 14:07:10 UTC
README
Drupal bootstrapper to ease integration/functional testing your Drupal modules.
Requirements
- PHP 5.3.3+ (unfortunately the SQLite implementation in Drupal is not compatible with PHP 5.4)
- PDO SQLite driver
- Any other extension Drupal 7.* requires
Installation
The recommended way to install Drunit
is with composer.
Just add the following to your composer.json
:
{ "repositories": [ ... { "type": "package", "package": { "version": "7.23", "name": "drupal/core", "dist": { "url": "http://ftp.drupal.org/files/projects/drupal-7.23.zip", "type": "zip" } } } ], "require-dev": { ... "korstiaan/drunit": "*" }, "scripts": { "post-install-cmd": [ ... "Drunit\\Composer\\ScriptHandler::installDrupal" ], "post-update-cmd": [ ... "Drunit\\Composer\\ScriptHandler::installDrupal" ] } }
And change the versions in the drupal/core
definition to match the Drupal version you want to test with.
Now update composer and install the newly added requirement and its dependencies:
$ php composer.phar update korstiaan/drunit --dev
Usage
Bootstrap Drupal
First initialize composer's autoloading by including it in your tests bootstrap file:
// tests/bootstrap.php use Drunit\Drunit; require __DIR__ . '/../vendor/autoload.php';
Bootstrap Drupal on each test
Drunit
provides a TestCase class which bootstraps Drupal to its final phase DRUPAL_BOOTSTRAP_FULL
and makes sure each test is run in its own isolated process. Just extend it to make use of it:
use Drunit\TestCase; class FooTest extends TestCase { ... }
Enable your module(s)
To enabled your modules in a test just add the following to your test:
use Drunit\TestCase; class FooTest extends TestCase { public function setUp() { parent::setUp(); Drunit::enableModule(__DIR__.'/../module', array('my_module')); } ... }
This will enable module my_module
located at __ROOT__.'/module'
(Drupal recursively looks for file my_module.module
).
If you have multiple modules located in a single directory (for example __ROOT__.'/modules/my_module1'
and __ROOT__.'/modules/my_module2
),
you can enable them all as follows:
Drunit::enableModule(__DIR__.'/../modules', array('my_module1', 'my_module2'));
If your module name is the same as the base name of the directory you can leave out the 2nd parameter:
Drunit::enableModule(__DIR__.'/../modules/my_module1');
License
Drunit is licensed under the MIT license.