PHPackages                             donatj/mock-duck - 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. donatj/mock-duck

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

donatj/mock-duck
================

Sane mocking library

00PHP

Since May 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/donatj/mock-duck)[ Packagist](https://packagist.org/packages/donatj/mock-duck)[ RSS](/packages/donatj-mock-duck/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Mock Duck
=========

[](#mock-duck)

[![Latest Stable Version](https://camo.githubusercontent.com/165651459a471cf194a0417437d2168b083b685562a4b96e206e5aa1ba6dbbea/68747470733a2f2f706f7365722e707567782e6f72672f646f6e61746a2f6d6f636b2d6475636b2f76657273696f6e)](https://packagist.org/packages/donatj/mock-duck)[![License](https://camo.githubusercontent.com/c2eee414a5d1f4b0269e745f8726a7e9abb836c868cb10037cc5919f9fa49844/68747470733a2f2f706f7365722e707567782e6f72672f646f6e61746a2f6d6f636b2d6475636b2f6c6963656e7365)](https://packagist.org/packages/donatj/mock-duck)

A Simple, Sane, Mock Builder for PHPUnit

Currently in a very early stage of development.

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

[](#requirements)

Installing
----------

[](#installing)

Install the latest version with:

```
composer require 'donatj/mock-duck'
```

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

[](#documentation)

### Class: \\donatj\\MockDuck\\Exceptions\\MockBuilderRuntimeException

[](#class-donatjmockduckexceptionsmockbuilderruntimeexception)

Exception thrown as a general runtime exception for the MockBuilder

### Class: \\donatj\\MockDuck\\Exceptions\\MockMethodNotFoundException

[](#class-donatjmockduckexceptionsmockmethodnotfoundexception)

Exception thrown by a method mock on invoke when it does not match the spec and wishes to indicate the parent should continue

### Class: \\donatj\\MockDuck\\InvokableMethodInterface

[](#class-donatjmockduckinvokablemethodinterface)

### Class: \\donatj\\MockDuck\\MethodCallFallthrough

[](#class-donatjmockduckmethodcallfallthrough)

Executes given invokables until one is successful

#### Undocumented Method: `MethodCallFallthrough->__construct(callable ...$invokables)`

[](#undocumented-method-methodcallfallthrough-__constructcallable-invokables)

---

#### Undocumented Method: `MethodCallFallthrough->__invoke($args)`

[](#undocumented-method-methodcallfallthrough-__invokeargs)

### Class: \\donatj\\MockDuck\\MethodCallOrdered

[](#class-donatjmockduckmethodcallordered)

Allows setting method invocations on subsequent calls

This is one of the only parts of MockDuck that is not functionally pure and thus should be handled with special care

#### Undocumented Method: `MethodCallOrdered->__construct(callable ...$invokables)`

[](#undocumented-method-methodcallordered-__constructcallable-invokables)

---

#### Undocumented Method: `MethodCallOrdered->__invoke($args)`

[](#undocumented-method-methodcallordered-__invokeargs)

### Class: \\donatj\\MockDuck\\MethodCallParameterMatcher

[](#class-donatjmockduckmethodcallparametermatcher)

Matches a given set of method parameters to a method invoker

#### Undocumented Method: `MethodCallParameterMatcher->withEquality([ $equality = true])`

[](#undocumented-method-methodcallparametermatcher-withequality-equality--true)

---

#### Method: MethodCallParameterMatcher-&gt;withMethodParameterMatch

[](#method-methodcallparametermatcher-withmethodparametermatch)

```
function withMethodParameterMatch(callable $invokable, $args) : self
```

##### Parameters:

[](#parameters)

- ***callable*** `$invokable` - The method invokable
- ***mixed*** `$args` - The arguments to match against. Accepts and matches against PHPUnit constraints

##### Returns:

[](#returns)

- ***$this***

---

#### Undocumented Method: `MethodCallParameterMatcher->__invoke($args)`

[](#undocumented-method-methodcallparametermatcher-__invokeargs)

### Class: \\donatj\\MockDuck\\MethodCallReturns

[](#class-donatjmockduckmethodcallreturns)

#### Method: MethodCallReturns-&gt;\_\_construct

[](#method-methodcallreturns-__construct)

```
function __construct($value)
```

##### Parameters:

[](#parameters-1)

- ***mixed*** `$value` - The value to return

---

#### Undocumented Method: `MethodCallReturns->__invoke($args)`

[](#undocumented-method-methodcallreturns-__invokeargs)

### Class: \\donatj\\MockDuck\\MockBuilder

[](#class-donatjmockduckmockbuilder)

#### Method: MockBuilder-&gt;\_\_construct

[](#method-mockbuilder-__construct)

```
function __construct(string $className [, ?\PHPUnit\Framework\Assert $asserter = null])
```

MockBuilder constructor.

---

#### Undocumented Method: `MockBuilder->withMethodsExcluded(string ...$methods)`

[](#undocumented-method-mockbuilder-withmethodsexcludedstring-methods)

---

#### Method: MockBuilder-&gt;withDisabledConstructor

[](#method-mockbuilder-withdisabledconstructor)

```
function withDisabledConstructor(bool $disable) : self
```

Enable or disable the original constructor

##### Returns:

[](#returns-1)

- ***$this***

---

#### Method: MockBuilder-&gt;withMockMethod

[](#method-mockbuilder-withmockmethod)

```
function withMockMethod(string $method, callable $invokable) : self
```

##### Returns:

[](#returns-2)

- ***$this***

---

#### Method: MockBuilder-&gt;buildMockClass

[](#method-mockbuilder-buildmockclass)

```
function buildMockClass() : string
```

Build the requested mock to the given spec

##### Returns:

[](#returns-3)

- ***string*** - The fully qualified class name of the new mock object

---

#### Method: MockBuilder-&gt;buildMock

[](#method-mockbuilder-buildmock)

```
function buildMock($constructorArgs) : object
```

Build the requested mock to the given spec and instantiate it

##### Parameters:

[](#parameters-2)

- ***mixed*** `$constructorArgs` - The arguments to pass to the constructor

##### Returns:

[](#returns-4)

- ***object*** - The instance of the Mock

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![donatj](https://avatars.githubusercontent.com/u/133747?v=4)](https://github.com/donatj "donatj (19 commits)")

### Embed Badge

![Health badge](/badges/donatj-mock-duck/health.svg)

```
[![Health](https://phpackages.com/badges/donatj-mock-duck/health.svg)](https://phpackages.com/packages/donatj-mock-duck)
```

###  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.8M753](/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)
