PHPackages                             mnapoli/mockup - 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. mnapoli/mockup

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

mnapoli/mockup
==============

Concise mock library for PHP tests

0.1.0(10y ago)315MITPHPPHP ^5.5|^7.0

Since Mar 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mnapoli/mockup)[ Packagist](https://packagist.org/packages/mnapoli/mockup)[ Docs](http://example.com)[ RSS](/packages/mnapoli-mockup/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Mockup
======

[](#mockup)

Concise mock library for PHP tests.

[![Build Status](https://camo.githubusercontent.com/a1b3ce55d9b9c9a85bfd1ef277f7956ed30895dabd5e725ffcb51be7dc1b3737/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6e61706f6c692f6d6f636b75702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mnapoli/mockup)

Why?
----

[](#why)

This mock library is meant to be a simple yet powerful alternative to existing solutions.

- Mockup

```
$mock = mock(Foo::class, [
    'foo' => 'Hello',
]);
```

- PHPUnit

```
$mock = $this->getMock(Foo::class, [], [], '', false);
$mock->expect($this->any())
    ->method('foo')
    ->willReturn('Hello');
```

- Prophecy

```
$prophet = new \Prophecy\Prophet();
$mock = $prophet->prophesize(Foo::class);
$mock->foo()->willReturn('Hello');
$mock = $mock->reveal();
```

- Mockery

```
$mock = Mockery::mock(Foo::class);
$mock->shouldReceive('foo')
    ->andReturn('Hello');
```

Additionally, Mockup **doesn't include assertions**. Instead of forcing you to learn a specific assertion syntax, complex enough to cover all cases, it lets you use the assertions you already know (PHPUnit, phpspec, …). Here is an example in a PHPUnit test:

```
// The mock method was called once
$this->assertEquals(1, inspect($mock)->foo()->invokationCount());
```

Read more about spying method calls below.

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

[](#installation)

```
composer require --dev mnapoli/mockup

```

Usage
-----

[](#usage)

### Mocks

[](#mocks)

You can mock a class or an interface:

```
use function Mockup\mock;

interface Foo
{
    public function foo($bar);
}

$mock = mock(Foo::class);
$mock->foo();
```

All its methods will do nothing and return `null` ([null object pattern](https://en.wikipedia.org/wiki/Null_Object_pattern)). The mock will implement the interface or extend the class given, as such it will work fine with any type-hint.

You can make some methods return values other than null:

```
$mock = mock(Foo::class, [
    'foo' => 'hello',
]);

$mock->foo('john'); // hello
```

You can also use a closure to define the new method's body:

```
$mock = mock(Foo::class, [
    'foo' => function ($bar) {
        return strtoupper('hello ' . $bar);
    }
]);

$mock->foo('john'); // HELLO JOHN
```

### Spies

[](#spies)

You can spy calls to an object:

```
use function Mockup\{spy, inspect};

$spy = spy($cache);
$foo->doSomething($spy);

inspect($spy)->set()->invokationCount(); // number of calls to $spy->set()
inspect($spy)->set()->parameters(0); // parameters provided to the first call to $spy->set()
inspect($spy)->set()->returnValue(0); // value returned by the first call to $spy->set()
```

The difference with a mock is that you are spying real calls to a real object. A mock is a [null object](https://en.wikipedia.org/wiki/Null_Object_pattern).

Mockup does not provide assertions or expectations so that you can use the assertion library you prefer.

Every mock object is also a spy, so you can create a mock and spy its method calls:

```
use function Mockup\{mock, inspect};

$mock = mock(CacheInterface::class);
$foo->doSomething($mock);

inspect($spy)->set()->invokationCount();
inspect($spy)->set()->parameters(0);
inspect($spy)->set()->returnValue(0);
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

3748d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mnapoli-mockup/health.svg)

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

###  Alternatives

[dms/phpunit-arraysubset-asserts

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

14228.7M341](/packages/dms-phpunit-arraysubset-asserts)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)[concrete5/core

Concrete – an open source content management system.

20163.8k49](/packages/concrete5-core)

PHPackages © 2026

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