PHPackages                             previousnext/drupal-test-utils - 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. previousnext/drupal-test-utils

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

previousnext/drupal-test-utils
==============================

Utility traits for Drupal testing.

0.0.5(4mo ago)219.2k↓44.6%[3 PRs](https://github.com/previousnext/drupal-test-utils/pulls)GPL-2.0+PHPPHP ^8

Since Dec 13Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/previousnext/drupal-test-utils)[ Packagist](https://packagist.org/packages/previousnext/drupal-test-utils)[ RSS](/packages/previousnext-drupal-test-utils/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependenciesVersions (9)Used By (0)

Drupal Test Utils
=================

[](#drupal-test-utils)

Utilities for testing Drupal!

ConfigTrait
-----------

[](#configtrait)

A trait to facilitate overriding config for the duration of a test.

### Usage

[](#usage)

Add the trait to your base class and override the tearDown method.

```
use PNX\DrupalTestUtils\Traits\ConfigTrait;
use weitzman\DrupalTestTraits\ExistingSiteBase;

abstract class MyBaseClass extends ExistingSiteBase {

  /**
   * {@inheritdoc}
   */
  protected function tearDown(): void {
    $this->setConfigValues($this->originalConfiguration, FALSE);
    parent::tearDown();
  }

}
```

In a test case, call `$this->setConfigValues`:

```
$this->setConfigValues([
  'system.logging' => [
    'error_level' => \ERROR_REPORTING_DISPLAY_VERBOSE,
  ],
]);
```

EntityLoadTrait
---------------

[](#entityloadtrait)

A trait to assist with loading entities in tests.

### Usage

[](#usage-1)

Load one node with the title "Hello, World":

```
$node = $this->loadEntityByProperty('node', ['title' => 'Hello, World']);
```

Load all article nodes:

```
$nodes = $this->loadEntityByProperty('node', ['type' => 'article'], FALSE);
```

Get the last created node. Useful for asserting on entities created via the UI:

```
$node = $this->getLastCreatedEntity('node');
```

ExpectsCacheableResponseTrait
-----------------------------

[](#expectscacheableresponsetrait)

A trait to add Dynamic Page Cache cacheability testing to every request in your Functional tests.

### Usage

[](#usage-2)

Once your trait is added to your test base class, you can check cachability by overriding the `drupalGet` function.

```
/**
 * {@inheritdoc}
 */
protected function drupalGet($path, array $options = [], array $headers = []): string {
  $response = parent::drupalGet($path, $options, $headers);
  $this->detectUncacheableResponse($path, $options);
  return $response;
}
```

### Marking paths as uncacheable

[](#marking-paths-as-uncacheable)

There are some paths that are always uncacheable (i.e pages with forms like node/add). These paths can marked as uncacheable by adding the `$uncacheableDynamicPagePatterns` property to your tests. You can add a common set of these to your test base and add more specific paths in indivdual tests as these patterns will be gathered up the class hierarchy at run time.

Patterns are regular expressions matched with `preg_match`

E.g

```
 protected static array $uncacheableDynamicPagePatterns = [
   '/user/login',
   '/big_pipe/no-js',
   '/batch',
   '/node/add/.*',
 ];
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance77

Regular maintenance activity

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~304 days

Total

5

Last Release

127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9fb4020bd7f47e4b88e336a1049bdd6e376a64125fd7070889de60e00c34ddce?d=identicon)[pnx-bot](/maintainers/pnx-bot)

![](https://avatars.githubusercontent.com/u/44692040?v=4)[Skpr](/maintainers/skpr)[@skpr](https://github.com/skpr)

---

Top Contributors

[![acbramley](https://avatars.githubusercontent.com/u/569927?v=4)](https://github.com/acbramley "acbramley (6 commits)")[![mstrelan](https://avatars.githubusercontent.com/u/665110?v=4)](https://github.com/mstrelan "mstrelan (3 commits)")

---

Tags

drupal

### Embed Badge

![Health badge](/badges/previousnext-drupal-test-utils/health.svg)

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

PHPackages © 2026

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