PHPackages                             drupal/drupal-driver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. drupal/drupal-driver

ActiveLibrary[Testing &amp; Quality](/categories/testing)

drupal/drupal-driver
====================

A collection of reusable Drupal drivers

v3.2.0(1w ago)6816.4M↓36.3%10220GPL-2.0-or-laterPHPPHP ^8.2CI passing

Since Oct 16Pushed 1w ago7 watchersCompare

[ Source](https://github.com/jhedstrom/DrupalDriver)[ Packagist](https://packagist.org/packages/drupal/drupal-driver)[ Docs](http://github.com/jhedstrom/DrupalDriver)[ GitHub Sponsors](https://github.com/jhedstrom)[ RSS](/packages/drupal-drupal-driver/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (104)Versions (102)Used By (20)

Drupal Driver
=============

[](#drupal-driver)

[![Latest Stable Version](https://camo.githubusercontent.com/5af217b8d070005a310e7ae939902f8573cd9b734102b1f9097663ba5a3c5c62/68747470733a2f2f706f7365722e707567782e6f72672f64727570616c2f64727570616c2d6472697665722f762f737461626c652e737667)](https://packagist.org/packages/drupal/drupal-driver)[![Total Downloads](https://camo.githubusercontent.com/7edbbb333719ab01d051d7e20737c19ec9b1374a2f8fa4af4c3d8e0f8d3c607b/68747470733a2f2f706f7365722e707567782e6f72672f64727570616c2f64727570616c2d6472697665722f646f776e6c6f6164732e737667)](https://packagist.org/packages/drupal/drupal-driver)[![License](https://camo.githubusercontent.com/75837645ac5724fb68aa8e212e1df9df9fdfd3ce8cb44d9d45d85b171025f197/68747470733a2f2f706f7365722e707567782e6f72672f64727570616c2f64727570616c2d6472697665722f6c6963656e73652e737667)](https://packagist.org/packages/drupal/drupal-driver)

[![ci](https://github.com/jhedstrom/DrupalDriver/actions/workflows/ci.yml/badge.svg)](https://github.com/jhedstrom/DrupalDriver/actions/workflows/ci.yml)[![GitHub Issues](https://camo.githubusercontent.com/9c0fb2aa99df518762ea0ea0f37527cd5c698d562e915dfd67ee326925510e68/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a6865647374726f6d2f44727570616c4472697665722e737667)](https://github.com/jhedstrom/DrupalDriver/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/6880f5a9c2c2a0d5458cd3d03e9cb1ae49ba921aec6688d261f0adf59711ba0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6a6865647374726f6d2f44727570616c4472697665722e737667)](https://github.com/jhedstrom/DrupalDriver/pulls)

[![Join our community](https://camo.githubusercontent.com/d0bc3521ba40d2b454138bc886ecbd5236834d0ffbcc3b1bad5a66aac5b31c0b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e2532306f7572253230636f6d6d756e6974792d536c61636b2d3441313534423f7374796c653d666f722d7468652d6261646765266c6f676f3d736c61636b266c6f676f436f6c6f723d7768697465)](https://drupal.slack.com/archives/C4T2JHG9K)

A collection of lightweight drivers with a common interface for interacting with [Drupal](https://www.drupal.org). These are generally intended for testing and are not meant to be API-complete.

> **Note:** v3 supports Drupal 10 and 11 on PHP 8.2+. Sites that need Drupal 7 or PHP 8.1 should pin to the [`2.x` branch](https://github.com/jhedstrom/DrupalDriver/tree/2.x). See [UPGRADING.md](UPGRADING.md) for the v2 to v3 migration guide.

Drivers
-------

[](#drivers)

DriverDescription**Blackbox**No Drupal bootstrap. Interacts only through HTTP.**Drupal API**Bootstraps Drupal directly in PHP for programmatic access to entities, fields, users, and configuration.**Drush**Interacts with Drupal through the [Drush](https://www.drush.org) command line tool.Installation
------------

[](#installation)

```
composer require drupal/drupal-driver
```

Usage
-----

[](#usage)

```
use Drupal\Driver\DrupalDriver;
use Drupal\Driver\Entity\EntityStub;

require 'vendor/autoload.php';

$path = './web';           // Path to Drupal root.
$uri  = 'http://my-site';  // Site URI.

$driver = new DrupalDriver($path, $uri);
$driver->setCoreFromVersion();

// Bootstrap Drupal.
$driver->bootstrap();

// Create a node.
$node = new EntityStub('node', 'article', [
  'uid' => 1,
  'title' => $driver->getRandom()->name(),
]);
$saved = $driver->nodeCreate($node);
$nid = $saved->getId();
```

Extending
---------

[](#extending)

The driver lets consumer projects override two things without forking: individual field handlers and the top-level Core implementation.

### Custom field handler

[](#custom-field-handler)

Implement `Drupal\Driver\Core\Field\FieldHandlerInterface` (extending `AbstractHandler` is the usual path):

```
namespace MyProject\Driver\Field;

use Drupal\Driver\Core\Field\AbstractHandler;

class PhoneHandler extends AbstractHandler {
  public function expand(mixed $values): array {
    // Convert each scenario-facing phone string into the storage shape
    // Drupal's field system expects (a list of deltas keyed by column).
    return array_map(static fn (string $number): array => ['value' => $number], (array) $values);
  }
}
```

Register it on the active Core instance, typically in a test bootstrap:

```
$driver = new DrupalDriver($root, $uri);
$driver->setCoreFromVersion();
$driver->getCore()->registerFieldHandler('phone', \MyProject\Driver\Field\PhoneHandler::class);
```

Consumer registrations win over the handlers this project ships for the same field type. Registration order at runtime is: driver default handlers (populated by `Core::registerDefaultFieldHandlers()` at construction) → consumer registrations → registry lookup at `expand()`time, with a fall-through to `DefaultHandler` for field types no handler claims.

### Custom Core

[](#custom-core)

Implement `Drupal\Driver\Core\CoreInterface`. The class name and namespace do not matter. The easiest path is to extend `Drupal\Driver\Core\Core` and add version-specific field handlers by re-scanning your own `Field/` directory:

```
namespace MyProject\Driver;

use Drupal\Driver\Core\Core as BaseCore;

class Core extends BaseCore {
  protected function registerDefaultFieldHandlers(): void {
    parent::registerDefaultFieldHandlers();
    $this->registerHandlersFromDirectory(__DIR__ . '/Field', __NAMESPACE__ . '\\Field');
  }
}
```

Inject it with `$driver->setCore($core)`:

```
$driver = new DrupalDriver($root, $uri);
$driver->setCore(new \MyProject\Driver\Core($root, $uri));
```

Credits
-------

[](#credits)

- Originally developed by [Jonathan Hedstrom](https://github.com/jhedstrom)
- Maintainers
    - [Alex Skrypnyk](https://github.com/AlexSkrypnyk)
- [All contributors](https://github.com/jhedstrom/DrupalDriver/graphs/contributors)

Release notes
-------------

[](#release-notes)

See [GitHub Releases](https://github.com/jhedstrom/DrupalDriver/releases).

Contributing
------------

[](#contributing)

Features and bug fixes are welcome!

See [CONTRIBUTING.md](https://github.com/jhedstrom/DrupalDriver/blob/master/CONTRIBUTING.md) for more information.

###  Health Score

77

—

ExcellentBetter than 100% of packages

Maintenance98

Actively maintained with recent releases

Popularity64

Solid adoption and visibility

Community41

Growing community involvement

Maturity92

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 65.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~8 days

Total

71

Last Release

12d ago

Major Versions

v1.4.0 → v2.0.0-alpha12018-03-19

v2.5.1 → v3.0.0-alpha12026-05-03

PHP version history (4 changes)v1.4.0PHP &gt;=5.5.9

v2.0.0-rc1PHP &gt;=5.6

v2.2.0PHP &gt;=7.4

v3.0.0-alpha1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/a753aefee83a2962b5962cd13c64b377eaeb1e5950e4e2ecc11f773bdebac440?d=identicon)[jhedstrom](/maintainers/jhedstrom)

---

Top Contributors

[![jhedstrom](https://avatars.githubusercontent.com/u/76833?v=4)](https://github.com/jhedstrom "jhedstrom (700 commits)")[![AlexSkrypnyk](https://avatars.githubusercontent.com/u/378794?v=4)](https://github.com/AlexSkrypnyk "AlexSkrypnyk (85 commits)")[![pfrenssen](https://avatars.githubusercontent.com/u/442924?v=4)](https://github.com/pfrenssen "pfrenssen (65 commits)")[![ademarco](https://avatars.githubusercontent.com/u/153362?v=4)](https://github.com/ademarco "ademarco (38 commits)")[![eliza411](https://avatars.githubusercontent.com/u/216054?v=4)](https://github.com/eliza411 "eliza411 (27 commits)")[![Berdir](https://avatars.githubusercontent.com/u/40826?v=4)](https://github.com/Berdir "Berdir (23 commits)")[![jonathanjfshaw](https://avatars.githubusercontent.com/u/3512385?v=4)](https://github.com/jonathanjfshaw "jonathanjfshaw (20 commits)")[![greg-1-anderson](https://avatars.githubusercontent.com/u/612191?v=4)](https://github.com/greg-1-anderson "greg-1-anderson (18 commits)")[![grasmash](https://avatars.githubusercontent.com/u/539205?v=4)](https://github.com/grasmash "grasmash (10 commits)")[![dawehner](https://avatars.githubusercontent.com/u/29678?v=4)](https://github.com/dawehner "dawehner (9 commits)")[![kerasai](https://avatars.githubusercontent.com/u/1098973?v=4)](https://github.com/kerasai "kerasai (8 commits)")[![claudiu-cristea](https://avatars.githubusercontent.com/u/473868?v=4)](https://github.com/claudiu-cristea "claudiu-cristea (6 commits)")[![acbramley](https://avatars.githubusercontent.com/u/569927?v=4)](https://github.com/acbramley "acbramley (6 commits)")[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (6 commits)")[![clemens-tolboom](https://avatars.githubusercontent.com/u/371014?v=4)](https://github.com/clemens-tolboom "clemens-tolboom (6 commits)")[![dsnopek](https://avatars.githubusercontent.com/u/191561?v=4)](https://github.com/dsnopek "dsnopek (5 commits)")[![webflo](https://avatars.githubusercontent.com/u/123946?v=4)](https://github.com/webflo "webflo (4 commits)")[![kugta](https://avatars.githubusercontent.com/u/380659?v=4)](https://github.com/kugta "kugta (4 commits)")[![xaqrox](https://avatars.githubusercontent.com/u/394919?v=4)](https://github.com/xaqrox "xaqrox (3 commits)")[![aritomelo](https://avatars.githubusercontent.com/u/9381722?v=4)](https://github.com/aritomelo "aritomelo (3 commits)")

---

Tags

drupaldrupal-8phptestwebdrupal

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/drupal-drupal-driver/health.svg)

```
[![Health](https://phpackages.com/badges/drupal-drupal-driver/health.svg)](https://phpackages.com/packages/drupal-drupal-driver)
```

###  Alternatives

[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k16.7M1.0k](/packages/phpro-grumphp)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
