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(6mo ago)022Apache-2.0PHPPHP &gt;=8.2CI failing

Since Oct 6Pushed 4mo ago1 watchersCompare

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

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

33

—

LowBetter than 75% of packages

Maintenance72

Regular maintenance activity

Popularity2

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

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

209d 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 (42 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

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M679](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[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.9M571](/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.0k](/packages/orchestra-testbench)

PHPackages © 2026

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