PHPackages                             gin0115/wpunit-helpers - 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. gin0115/wpunit-helpers

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

gin0115/wpunit-helpers
======================

A series of helper classes, functions and traits for testing with WPUnit for WordPress

1.1.1(3y ago)153.2k↓42.5%[2 issues](https://github.com/gin0115/WPUnit_Helpers/issues)20MITPHPPHP &gt;=7.1.0

Since Mar 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/gin0115/WPUnit_Helpers)[ Packagist](https://packagist.org/packages/gin0115/wpunit-helpers)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/gin0115-wpunit-helpers/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (13)Versions (18)Used By (20)

WPUnit\_Helpers
===============

[](#wpunit_helpers)

Collection of helper functions, classes and traits for using WPUnit.

[![Latest Stable Version](https://camo.githubusercontent.com/29a747880d1a0db960f741272736c5a5b474a5ad581d44dc18a7053d76bb613a/687474703a2f2f706f7365722e707567782e6f72672f67696e303131352f7770756e69742d68656c706572732f76)](https://packagist.org/packages/gin0115/wpunit-helpers)[![Total Downloads](https://camo.githubusercontent.com/6a78b5cc2fb4ede2d204e1d125e3d4d358fb36eaf033aa06120da7d358d5bc5b/687474703a2f2f706f7365722e707567782e6f72672f67696e303131352f7770756e69742d68656c706572732f646f776e6c6f616473)](https://packagist.org/packages/gin0115/wpunit-helpers)[![License](https://camo.githubusercontent.com/906f59f0d9cc79cbbac5f2780a3c3a4809b7f1b0b307117e6db180a4f9a2876e/687474703a2f2f706f7365722e707567782e6f72672f67696e303131352f7770756e69742d68656c706572732f6c6963656e7365)](https://packagist.org/packages/gin0115/wpunit-helpers)[![PHP Version Require](https://camo.githubusercontent.com/23d719edd00e9f5bcadb16f09e57092466cce292e72dc19bafd0d42694686268/687474703a2f2f706f7365722e707567782e6f72672f67696e303131352f7770756e69742d68656c706572732f726571756972652f706870)](https://packagist.org/packages/gin0115/wpunit-helpers)[![GitHub contributors](https://camo.githubusercontent.com/1f34de757388462a22b80ca85ffaa7748d383221467cd6bd1f25492a15306bf2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f67696e303131352f5750556e69745f48656c706572733f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/1f34de757388462a22b80ca85ffaa7748d383221467cd6bd1f25492a15306bf2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f67696e303131352f5750556e69745f48656c706572733f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/26827450bd35a982ac587ddc239e95e1310137945ab151d1a145c82ad1bb331e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f67696e303131352f5750556e69745f48656c70657273)](https://camo.githubusercontent.com/26827450bd35a982ac587ddc239e95e1310137945ab151d1a145c82ad1bb331e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f67696e303131352f5750556e69745f48656c70657273)[![](https://github.com/gin0115/WPUnit_Helpers/workflows/GitHub_CI/badge.svg " ")](https://github.com/gin0115/WPUnit_Helpers/workflows/GitHub_CI/badge.svg)[![codecov](https://camo.githubusercontent.com/32d1a6c49f70f36c56f087e3d54acb831cb61cf254c256c8b9ba53f73419adf9/68747470733a2f2f636f6465636f762e696f2f67682f67696e303131352f5750556e69745f48656c706572732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d3049464b667545355366)](https://codecov.io/gh/gin0115/WPUnit_Helpers)[![Maintainability](https://camo.githubusercontent.com/8c3173199882c450f64b12b4e188501b84e1f71f1e2ef99a847a58031ee3c004/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35643439643064326163353462353963383464332f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/gin0115/WPUnit_Helpers/maintainability)

Version
-------

[](#version)

**1.0.8**

Setup
-----

[](#setup)

```
$ composer require --dev gin0115/wpunit-helpers
```

Meta Box Inspector
------------------

[](#meta-box-inspector)

Check if meta boxes have been registered correctly, check all values and render the view callback.

```
$box = Meta_Box_Inspector::initialise()->find('my_meta_box_key');
$this->assertInstanceOf(Meta_Box_Entity::class, $box);
$this->assertEquals('My Title', $box->title);
```

**[Read More](docs/Meta_Box_Inspector.md)**

Menu Page Inspector
-------------------

[](#menu-page-inspector)

Allows for the checking of added pages and sub pages. Can be searched to ensure pages are added as expected and can render the pages content, for intergration style tests. Allows for testing parent and child(sub) pages.

```
$page = Menu_Page_Inspector::initialise()->find_parent_page('parent_page_slug');
$this->assertInstanceOf(Menu_Page_Entity::class, $page);
$this->assertEquals('My Settings', $page->menu_title);
```

**[Read More](docs/Menu_Page_Inspector.md)**

Meta Data Inspector
-------------------

[](#meta-data-inspector)

Allows for the checking of registered meta data, for either post, term, user, comment and any other custom meta type added.

```
$post_meta = Meta_Data_Inspector::initialise()->find_post_meta('post', 'my_key');
$this->assertInstanceOf(Meta_Data_Entity::class, $post_meta);
$this->assertEquals('This is my meta field', $post_meta->description);
```

**[Read More](docs/Meta_Data_Inspector.md)**

WP Dependencies
---------------

[](#wp-dependencies)

Allows for the quick and simple installation of themes and plugins from remote sources.

```
WP_Dependencies::install_remote_plugin_from_zip(
    'https://the-url.tc/woocommerce.zip', 'path/to/test_wp/root/'
);
WP_Dependencies::activate_plugin('woocommerce/woocommerce.php');
```

**[Read More](docs/WP_Dependencies.md)**

Object (Reflection wrappers)
----------------------------

[](#object-reflection-wrappers)

Reflection is super useful in testing, especially if you cant access internal properties and methods to create your tests. Or you need to mock parts of the process, which are otherwise not accessible (internal WP States etc). *These also work on static methods/properties*

```
//  Access protected & privates properties.
Objects::get_property($instnace, 'property');
// Set protected or private properties.
Objects::set_property($instnace, 'property', 'new value');
// Invoke private or protected method.
Objects::invoke_method($instance, 'method', ['the', 'args']);
```

**[Read More](docs/Objects.md)**

Utils
-----

[](#utils)

A collection of functions that have no other real place.

```
// iterable_map_with allows array_map to be done with access to the key and as many other
// values you wish to pass.
$result = Utils::iterable_map_with(

    function($key, $value, $spacer){
        return $key . $spacer . $value;
    },
    ['key1'=>'value1', 'key2' => 'value2'],
    ' -|- '

);
var_dump($result); // ['key1 -|- value1', 'key2 -|- value2']
```

**[Read More](docs/Utils.md)**

Output
------

[](#output)

There are a number of methods that can be used to capture output from a function or method. This is useful for testing output from a function or method.

**[Read More](docs/Output.md)**

Logable WPDB
------------

[](#logable-wpdb)

This simple class which extends `wpdb` can be used for Application tests where you need to either mock the return from a WPDB call or log all wpdb calls made.

> Supports all public and common methods.

```
$wpdb = new Logable_WPDB();

// Set a return value.
$wpdb->then_return = 1;

// Mock an insert
$result = $wpdb->insert('table_name', ['col1'=>'value1'], ['%s']);

// Get back the set return value
var_dump($result);

// Access the useage log
$log = $wpdb->usage_log;
var_dump($log);
/**
 * ['insert' =>
 *   [0] => [
 *     'table' => 'table_name',
 *     'data' => ['col1'=>'value1'],
 *     'format' => ['%s'],
 *   ]
 * ]
 */
```

**[Read More](docs/Utils.md)**

WP Unit TestCase Helper Traits
------------------------------

[](#wp-unit-testcase-helper-traits)

These traits are designed to be used with the WP Unit TestCase. They provide a number of helper functions to make testing easier.

**[Read More](docs/WP_Unit_TestCase_Helper_Traits.md)**

Change log
----------

[](#change-log)

- 1.1.1 - Updates dependencies, added in missing docs, missing tests and renamed the `array_map_with` to `iterable_map_with` to better reflect the use case.
- 1.1.0 - Replaced all instance of pipe() from Function\_Constructors with compose() from Function\_Constructors.
- 1.0.7 - Updated dependencies for Function\_Constructors and testing.
- 1.0.6 - Added Logable WPDB, Extended Meta Data Inspector to make use of Comment Meta, Extended to PHP8.1 Support
- 1.0.5 - Update dependencies for php8, also added `plugin_installed` and `plugin_active` to `WP_Dependencies`
- 1.0.4 - Update all dependencies
- 1.0.3 - Clear up issue with the errors found in 1.0.2 but not in dev
- 1.0.2 - Uses menu\_page\_url for menu page urls and Menu\_Page\_Inspector given find\_group function as the current naming is confusing
- 1.0.1 - Added in Meta\_Data\_Inspector for checking all registered meta data.
- 1.0.0 - Most in place now, still needs more docs and some extra tests on output.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity56

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 ~89 days

Recently: every ~97 days

Total

9

Last Release

1177d ago

### Community

Maintainers

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

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (131 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gin0115-wpunit-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/gin0115-wpunit-helpers/health.svg)](https://phpackages.com/packages/gin0115-wpunit-helpers)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

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