PHPackages                             protomock/protomock - 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. protomock/protomock

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

protomock/protomock
===================

Mocking native PHP requests (file\_get\_contents(), ...)

v1.0.3(2y ago)2024.6k↓28.6%3MITPHPPHP ^7.1 || ^8.0

Since Mar 18Pushed 2y agoCompare

[ Source](https://github.com/Halleck45/ProtoMock)[ Packagist](https://packagist.org/packages/protomock/protomock)[ RSS](/packages/protomock-protomock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

ProtoMock
=========

[](#protomock)

[![License](https://camo.githubusercontent.com/737ab089baa354e51ac0a5f92862da8272be9b782d6189a9fd423cb1050112f8/68747470733a2f2f706f7365722e707567782e6f72672f70726f746f6d6f636b2f70726f746f6d6f636b2f6c6963656e73652e737667)](https://camo.githubusercontent.com/737ab089baa354e51ac0a5f92862da8272be9b782d6189a9fd423cb1050112f8/68747470733a2f2f706f7365722e707567782e6f72672f70726f746f6d6f636b2f70726f746f6d6f636b2f6c6963656e73652e737667)[![Build Status](https://github.com/Halleck45/ProtoMock/actions/workflows/ci.yml/badge.svg)](https://github.com/Halleck45/ProtoMock/actions/workflows/ci.yml/badge.svg)

Allow to mock your requests.

```
$protomock = new ProtoMock();
$protomock->enable('file');
$protomock->enable('http');

$protomock
    ->with('http://my-website.fr/hello')
    ->will('I am a mocked response');

// ...

echo file_get_contents('http://my-website.fr/hello');
// I am a mocked response
```

Why ?
-----

[](#why-)

Because legacy code exists, and generally needs unit tests...

(and because my train is late (yes, I'm french), and I have one hour to kill...)

Usage
-----

[](#usage)

**Installation**

```
composer require protomock/protomock
```

**Enabling / disabling mocking for given protocol**

```
$protomock->enable('http'); // will capture all http://... requests

// disabling
$protomock->disable('http');
```

**Mocking a resource**

```
$protomock
    ->with()
    ->will('wanted response');

// disabling
$mocked = $protomock->with()->will('wanted response');
$protomock->without($mocked)
```

**Mocking a resource by regex**

```
$protomock
    ->matching()
    ->will('wanted response');

// example
$protomock
    ->matching('!.*\.txt!')
    ->will('wanted response');
```

**Mocking a resource by path (case insensitive)**

```
$protomock
    ->with($path, Mock::MATCHING_EXACT_CASE_INSENSITIVE)
    ->will('wanted response');
```

**Using a function for response**

```
// you can use any callable

$protomock
    ->with('/my/file1.txt')
    ->will(function($path) {
        return 'I a a mock. Current path is ' . $path;
    });
```

**Expecting a failure as response**

```
// will trigger a WARNING
$protomock
    ->with('/my/file1.txt')
    ->willFail();
```

**Expecting a failure as response (due to DNS resolution)**

```
// will trigger a WARNING and wait for default_socket_timeout delay
$protomock
    ->with('/my/file1.txt')
    ->willFail();
```

**Cancelling all**

```
$protomock->reset();
```

FAQ
---

[](#faq)

\_ *"That's look magic ! This project must be so complex !"*

**nope**. It needs only 200 lines of code, including comments... I just use the `stream_wrapper_register` PHP function.

\_ *"Can I use it for my unit tests?"*

**Yes**. ProtoMock is used by several companies for the Continuous Integration (CI) of their projects.

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

[](#requirements)

- `PHP >= 7`

License
-------

[](#license)

MIT. See the LICENSE file

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~438 days

Total

4

Last Release

938d ago

PHP version history (2 changes)v1.0.0PHP ~7

v1.0.3PHP ^7.1 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![Halleck45](https://avatars.githubusercontent.com/u/1076296?v=4)](https://github.com/Halleck45 "Halleck45 (24 commits)")[![jausions](https://avatars.githubusercontent.com/u/271436?v=4)](https://github.com/jausions "jausions (2 commits)")[![mrDlef](https://avatars.githubusercontent.com/u/1705964?v=4)](https://github.com/mrDlef "mrDlef (1 commits)")[![Wall-E-psr](https://avatars.githubusercontent.com/u/39435122?v=4)](https://github.com/Wall-E-psr "Wall-E-psr (1 commits)")

---

Tags

httpunittestmock

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/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.

36918.1M98](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33812.5M350](/packages/brain-monkey)[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.2M399](/packages/php-mock-php-mock-phpunit)[colinodell/psr-testlogger

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

1712.1M47](/packages/colinodell-psr-testlogger)[polishsymfonycommunity/symfony-mocker-container

Provides base Symfony dependency injection container enabling service mocking.

1468.0M237](/packages/polishsymfonycommunity-symfony-mocker-container)

PHPackages © 2026

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