2017 © Pedro Peláez
 

library drunit

Drupal bootstrapper to ease integration/functional testing your Drupal modules

image

korstiaan/drunit

Drupal bootstrapper to ease integration/functional testing your Drupal modules

  • Thursday, March 27, 2014
  • by korstiaan
  • Repository
  • 0 Watchers
  • 3 Stars
  • 106 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Drunit for Drupal 7.x

Drupal bootstrapper to ease integration/functional testing your Drupal modules., (*1)

Build Status, (*2)

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:, (*3)

   {
       "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., (*4)

Now update composer and install the newly added requirement and its dependencies:, (*5)

``` bash $ php composer.phar update korstiaan/drunit --dev, (*6)


## Usage ### Bootstrap Drupal First initialize composer's autoloading by including it in your tests bootstrap file: ```php // 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:, (*7)

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:, (*8)

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)., (*9)

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:, (*10)

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:, (*11)

Drunit::enableModule(__DIR__.'/../modules/my_module1');

License

Drunit is licensed under the MIT license., (*12)

The Versions

27/03 2014

dev-master

9999999-dev http://korstiaan.com/drunit

Drupal bootstrapper to ease integration/functional testing your Drupal modules

  Sources   Download

MIT

The Requires

 

The Development Requires

testing drupal