PHPackages                             chadicus/test-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. chadicus/test-helpers

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

chadicus/test-helpers
=====================

Classes designed to assist with PHPUnit testing

v3.0.0(2y ago)125.7k↓34.6%1[2 issues](https://github.com/chadicus/test-helpers/issues)1MITPHPPHP ^7.3 || ^8.0

Since Apr 30Pushed 2y agoCompare

[ Source](https://github.com/chadicus/test-helpers)[ Packagist](https://packagist.org/packages/chadicus/test-helpers)[ RSS](/packages/chadicus-test-helpers/feed)WikiDiscussions master Synced 1mo ago

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

Chadicus Test Helpers
=====================

[](#chadicus-test-helpers)

[![Latest Stable Version](https://camo.githubusercontent.com/6254fc24a10c41f45eea8b0301aacdc636966de7e11090cae0598c05787ff21a/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f762f737461626c65)](https://packagist.org/packages/chadicus/test-helpers)[![Latest Unstable Version](https://camo.githubusercontent.com/a1a2f6fea32c9d154e6aa4eeb2486af2f7246a3e45ab09934032942e828da910/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f762f756e737461626c65)](https://packagist.org/packages/chadicus/test-helpers)[![License](https://camo.githubusercontent.com/238e61b3a947e83329f37f39611f32635593366d92eab780f3556d9eda2406c7/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f6c6963656e7365)](https://packagist.org/packages/chadicus/test-helpers)

[![Total Downloads](https://camo.githubusercontent.com/4c1839c631282b3cd2e92d8a420d9504e95ad20c268d59ab97ae626546a8da68/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f646f776e6c6f616473)](https://packagist.org/packages/chadicus/test-helpers)[![Daily Downloads](https://camo.githubusercontent.com/01d6376bc05e8e789413fcce5ad5811f5cc73e33c4f20475ec6214bcc3651953/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f642f6461696c79)](https://packagist.org/packages/chadicus/test-helpers)[![Monthly Downloads](https://camo.githubusercontent.com/87cc1fb0a43ee349acec47b4101c512c14d3e86895199724c8699dd7141c5318/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f746573742d68656c706572732f642f6d6f6e74686c79)](https://packagist.org/packages/chadicus/test-helpers)

Requirements
------------

[](#requirements)

Test Helpers requires PHP 7.3 (or later).

Composer
--------

[](#composer)

To add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on `chadicus/test-helpers` to your project's `composer.json` file such as:

```
composer require --dev chadicus/test-helpers
```

NOTE: test-helpers should never be used in production. They are meant for testing enviornments only.

Documentation
-------------

[](#documentation)

PHP docs for the project can be found [here](http://chadicus.github.io/test-helpers).

Contact
-------

[](#contact)

Developers may be contacted at:

- [Pull Requests](https://github.com/chadicus/test-helpers/pulls)
- [Issues](https://github.com/chadicus/test-helpers/issues)

Project Build
-------------

[](#project-build)

With a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:

```
composer install
composer run test
composer run lint
```

\\Chadicus\\FunctionRegistry
============================

[](#chadicusfunctionregistry)

Some internal PHP functions are documented to return certain values on failure. If you're a meticulous programmer you want to account for these return values in your code and respond to them accordingly.

```
class MyClass
{
    public function doSomething()
    {
        $curl = curl_init();
        if ($curl === false) {
            throw new \Exception('curl_init() failed');
        }

        //do something with $curl ...
    }
}
```

A meticulous programmer may also want to ensure their unit test code coverage is 100%.

One way to accomplish this is to use @codeCoverageIgnore annotations

```
class MyClass
{
    public function doSomething()
    {
        $curl = curl_init();
        if ($curl === false) {
            //@codeCoverageIgnoreStart
            throw new \Exception('curl_init() failed');
            //@codeCoverageIgnoreEnd
        }

        //do something with $curl ...
    }
}
```

This gets us the code coverage but the code isn't really tested.

The `FunctionRegistry` class alows you to *mock* an internal PHP function

```
class MyClassTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        // prepare the curl functions for mocking
        \Chadicus\FunctionRegistry::reset(__NAMESPACE__, array('curl'));
    }

    /**
     * @expectedExceptionMessage curl_init() failed
     */
    public function testCurlInitFails()
    {
        \Chadicus\FunctionRegistry::set(
            __NAMESPACE__,
            'curl_init',
            function () {
                return false;
            }
        );

        $myClass = new MyClass();

        // this will call our custom curl_init function
        $myClass->doSomething();
    }
}
```

For functions and constants, PHP will fall back to global functions or constants if a namespaced function or constant does not exist. It is because of this behavior that we can *mock* internal functions.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 97.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 ~747 days

Total

5

Last Release

1048d ago

Major Versions

v1.0.1 → v2.0.02016-12-05

v2.0.1 → v3.0.02023-07-05

PHP version history (4 changes)v1.0.0PHP ~5.4

v1.0.1PHP &gt;=5.4

v2.0.0PHP ^5.6 || ^7.0

v3.0.0PHP ^7.3 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![chadicus](https://avatars.githubusercontent.com/u/1182337?v=4)](https://github.com/chadicus "chadicus (42 commits)")[![chrisryan](https://avatars.githubusercontent.com/u/704326?v=4)](https://github.com/chrisryan "chrisryan (1 commits)")

---

Tags

phpunittestmockfunctions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chadicus-test-helpers/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33812.5M350](/packages/brain-monkey)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[colinodell/psr-testlogger

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

1712.1M47](/packages/colinodell-psr-testlogger)

PHPackages © 2026

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