PHPackages                             citruslab/mokkd - 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. citruslab/mokkd

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

citruslab/mokkd
===============

A library for mocking free-standing functions in PHP

v0.0.2(8mo ago)0332Apache-2.0PHPPHP &gt;=8.2CI failing

Since Oct 6Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/darrenedale/Mokkd)[ Packagist](https://packagist.org/packages/citruslab/mokkd)[ RSS](/packages/citruslab-mokkd/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (2)Versions (8)Used By (2)

Mokkd
=====

[](#mokkd)

> Mokkd is pre-release software.

> Mokkd is licensed under the Apache License 2.0. See the LICENSE file.

Aims to do for free functions what Mockery does for classes. Test doubles for functions can be quickly built using a fluent interface. For example, to mock the `time()` built-in function so that it returns 0, use:

```
$time = Mokkd::func("time")
    ->returning(0);
```

---

Basic usage scenarios are covered in this readme. See the documentation for more.

### Return successive array elements

[](#return-successive-array-elements)

```
$time = Mokkd::func("time")
    ->returningFrom([0, 1, 2])
```

### Return a mapped value

[](#return-a-mapped-value)

```
$getEnv = Mokkd::func("getenv"
    ->returningMappedValueFrom(
        [
            "host" => "example.com",
            "secret" => "fake-secret"
        ],
        0,
    )
```

### Completely replace a function

[](#completely-replace-a-function)

```
$time = Mokkd::func("time")
    ->returningUsing(static function(): int {
        static $count = 0;
        return 60 * $count++;
    })
```

Setting expectations
--------------------

[](#setting-expectations)

### Control call count

[](#control-call-count)

```
$time = Mokkd::func("time")
    ->times(3)
    ->returning(0);
```

### Convenience `once()` and `twice()`

[](#convenience-once-and-twice)

```
$time = Mokkd::func("time")
    ->once()
    ->returning(0);
```

```
$time = Mokkd::func("time")
    ->twice()
    ->returning(0);
```

### Expect specified arguments

[](#expect-specified-arguments)

```
$getEnv = Mokkd::func("getenv")
    ->expects("host")
    ->returning("example.com")
```

### Matching arguments

[](#matching-arguments)

```
$getEnv = Mokkd::func("substr")
    ->expects(Mokkd::isString(), 0, Mokkd::isIntGreaterThan(2))
    ->returning("leftmost")
```

### Allowing unmatched calls

[](#allowing-unmatched-calls)

```
$getEnv = Mokkd::func("getenv")
    ->expects("host")
    ->returning("example.com")
    ->withoutBlocking()
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity7

Limited adoption so far

Community12

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

Total

2

Last Release

263d ago

### Community

Maintainers

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

---

Top Contributors

[![darrenedale](https://avatars.githubusercontent.com/u/26558174?v=4)](https://github.com/darrenedale "darrenedale (47 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/citruslab-mokkd/health.svg)

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

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M361](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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