PHPackages                             wp-launchpad/phpunit-wp-hooks - 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. wp-launchpad/phpunit-wp-hooks

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

wp-launchpad/phpunit-wp-hooks
=============================

Custom annotations to mock WP hooks for PHPUnit.

v3.1.0(1y ago)03.2k↓25%[1 issues](https://github.com/wp-launchpad/phpunit-wp-hooks/issues)[1 PRs](https://github.com/wp-launchpad/phpunit-wp-hooks/pulls)5MITPHPPHP ^7.1|^8

Since Dec 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/wp-launchpad/phpunit-wp-hooks)[ Packagist](https://packagist.org/packages/wp-launchpad/phpunit-wp-hooks)[ RSS](/packages/wp-launchpad-phpunit-wp-hooks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (10)Used By (5)

PHPUnit WP Hooks
----------------

[](#phpunit-wp-hooks)

This library is a PHPUnit library aimed to facilitate mocking WordPress hooks during integration testing.

### Install

[](#install)

To install the extension require it:

```
composer require wp-launchpad/phpunit-wp-hooks --dev
```

Once you done that then you can use the trait `MockHooks` and at the following logic to your base `TestCase` where `my_prefix` is your plugin prefix:

```
    protected function setUp(): void
    {
        parent::setUp();
        $this->mockHooks();
    }

    protected function tearDown(): void
    {
        $this->resetHooks();
        parent::tearDown();
    }

     protected function getPrefix(): string {
        return 'my_prefix';
     }

     protected function getCurrentTest(): string {
        return $this->getName();
     }
```

### Mock hooks

[](#mock-hooks)

### Register a callback

[](#register-a-callback)

It is possible to add a callback inside the test class to control the value from a filter. For that first you need to create a callback in the class:

```
public function myCallback() {
    return false;
}
```

Then in the dockblock of that callback you can add the `@hook` annotation:

```
/**
 * @hook my-event 15
 */
```

Where 15 is the priority from the filter. If you forget this part the default priority will be 10.

### Isolate a hook

[](#isolate-a-hook)

To isolate a hook to reduce it to a single callback it is possible by adding `@hook-isolated` annotation on the test method:

```
/**
 * @hook-isolated my-event myCallback 15
 */
```

Where 15 is the priority from the filter. If you forget this part the default priority will be 10.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance40

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~59 days

Total

7

Last Release

519d ago

Major Versions

v1.0.4 → 3.1.x-dev2024-12-15

### Community

Maintainers

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

---

Top Contributors

[![CrochetFeve0251](https://avatars.githubusercontent.com/u/18537428?v=4)](https://github.com/CrochetFeve0251 "CrochetFeve0251 (15 commits)")

---

Tags

hooksphpunittestswordpressphpunitwordpressannotationsextensionshookscustom

### Embed Badge

![Health badge](/badges/wp-launchpad-phpunit-wp-hooks/health.svg)

```
[![Health](https://phpackages.com/badges/wp-launchpad-phpunit-wp-hooks/health.svg)](https://phpackages.com/packages/wp-launchpad-phpunit-wp-hooks)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[rybakit/phpunit-extras

Custom annotations and expectations for PHPUnit.

4778.2k1](/packages/rybakit-phpunit-extras)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[wp-phpunit/wp-phpunit

WordPress core PHPUnit library

803.7M208](/packages/wp-phpunit-wp-phpunit)[yoast/wp-test-utils

PHPUnit cross-version compatibility layer for testing plugins and themes build for WordPress

632.3M52](/packages/yoast-wp-test-utils)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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