PHPackages                             pbweb/mimic - 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. pbweb/mimic

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

pbweb/mimic
===========

Mimic classes for functional testing

3.2(1mo ago)28.6kMITPHPPHP &gt;=8.0CI failing

Since May 12Pushed 3w ago2 watchersCompare

[ Source](https://github.com/PBWebMedia/mimic)[ Packagist](https://packagist.org/packages/pbweb/mimic)[ RSS](/packages/pbweb-mimic/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (11)Used By (0)

Mimic
=====

[](#mimic)

This library can be used to create mimics of your classes, which can be used for (functional) testing.

A mimicked class is similar to mock objects with stub methods in phpunit, but on a functional level.

Installation
------------

[](#installation)

### Install with composer

[](#install-with-composer)

Install mimic using composer:

```
composer require pbweb/mimic

```

Example
-------

[](#example)

Lets say you have a client class which talks to an external REST service. The interface might look like this:

```
interface RestClient
{
    public function get($something);
    public function put($something);
}
```

Now, using a class which really connects to the REST server in a (functional) test is a bad idea, since that server may not be in the scope of your test and influence the results.

To create a mimic client you need to extend `MimicActionHandler` like this:

```
class MimicRestClient extends MimicActionHandler implements RestClient
{
    public function get($something)
    {
        return $this->handleAction(__FUNCTION__, func_get_args());
    }

    public function put($something)
    {
        return $this->handleAction(__FUNCTION__, func_get_args());
    }
}
```

Now you can mimic the behaviour of the `RestClient` in your tests:

```
// In your dependency injection container:
$mimicClient = new MimicRestClient();

// In your test setup:
$mimicClient->enqueue('get', ['cheese'], 'cheese result');

// In your test or in a class which you are testing:
$result = $mimicClient->get('cheese'); // returns 'cheese result'
```

#### Argument Matchers

[](#argument-matchers)

In case you want more control over the arguments that are expected for a call, you can use argument matchers.

The `ArgumentMatchers` class instantiates several matchers which can be passed to the expected argument list of enqueue.

```
// Matches any call to update that has 1 as its first argument and any value as its second argument.
$mimicClient->enqueue('update', [1, ArgumentMatchers::any(), 'result');
```

Usage
-----

[](#usage)

Extending `MimicActionHandler` will allow your class to have the mimic enqueue system. Every method you want to mimic should have this as the body:

```
return $this->handleAction(__FUNCTION__, func_get_args());
```

See `tests/Service/SampleMimic` for an example.

### enableQueue

[](#enablequeue)

```
$mimic->enableQueue();
```

`enableQueue` will enable the use of the queue.

### disableQueue

[](#disablequeue)

```
$mimic->disableQueue();
```

`disableQueue` will stop the use of the queue.

### isQueueEnabled

[](#isqueueenabled)

```
$isQueueEnabled = $mimic->isQueueEnabled();
```

`isQueueEnabled` will return a boolean value with the state of the queue.

### enqueue

[](#enqueue)

```
$mimic->enqueue($method, array $argumentList = [], $response = null, $throw = false);
```

`enqueue` will add a method call to the expected queue. You can add as many method prediction as you like. If the next call to the mimic is the expected call then the given response will be returned and it will be removed from the queue. If the next call to the mimic is not the same as the expected call added to the queue then an exception will be thrown.

If you set `throw` to `true` then the response will be thrown instead of returned.

### getQueueContent

[](#getqueuecontent)

```
$actionList = $mimic->getQueueContent();
```

`getQueueContent` will return all the remaining actions added to the queue as Action models. See the `Action` class for more information about the model.

### isFinished

[](#isfinished)

```
$isFinished = $mimic->isFinished();
```

`isFinished` will return true if there are no more action left in the queue. false otherwise.

### clearQueue

[](#clearqueue)

```
$mimic->clearQueue();
```

`clearQueue` will remove all the remaining actions from the queue.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance93

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity74

Established project with proven stability

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

Recently: every ~540 days

Total

10

Last Release

50d ago

Major Versions

0.1 → 1.02016-01-04

1.0.1 → 2.12018-12-10

2.3.1 → 3.02021-09-30

PHP version history (6 changes)0.1PHP &gt;=5.5.0

1.0PHP ^5.5|^7.0

2.1PHP ^7.1

2.3PHP ^7.4

2.3.1PHP &gt;=7.4

3.0PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![DemonTPx](https://avatars.githubusercontent.com/u/2570835?v=4)](https://github.com/DemonTPx "DemonTPx (33 commits)")

---

Tags

testinglibrarymockstubclassmimic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pbweb-mimic/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k516.1M26.2k](/packages/mockery-mockery)[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.

36919.3M120](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4758.2M341](/packages/phake-phake)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.1k1.2M256](/packages/kahlan-kahlan)[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.7M512](/packages/php-mock-php-mock-phpunit)[php-mock/php-mock-mockery

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

392.2M109](/packages/php-mock-php-mock-mockery)

PHPackages © 2026

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