PHPackages                             php-mock/php-mock-prophecy - 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. php-mock/php-mock-prophecy

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

php-mock/php-mock-prophecy
==========================

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

0.1.4(5mo ago)16496.6k↓22.9%414WTFPLPHPPHP &gt;=7.2CI passing

Since Feb 16Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/php-mock/php-mock-prophecy)[ Packagist](https://packagist.org/packages/php-mock/php-mock-prophecy)[ Docs](https://github.com/php-mock/php-mock-prophecy)[ GitHub Sponsors](https://github.com/michalbundyra)[ RSS](/packages/php-mock-php-mock-prophecy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (8)Used By (14)

Mock PHP built-in functions with Prophecy
=========================================

[](#mock-php-built-in-functions-with-prophecy)

This package integrates the function mock library [PHP-Mock](https://github.com/php-mock/php-mock) with Prophecy.

Installation
============

[](#installation)

Use [Composer](https://getcomposer.org/):

```
composer require --dev php-mock/php-mock-prophecy
```

Usage
=====

[](#usage)

Build a new [`PHPProphet`](http://php-mock.github.io/php-mock-prophecy/api/class-phpmock.prophecy.PHPProphet.html)and create function prophecies for a given namespace with [`PHPProphet::prophesize()`](http://php-mock.github.io/php-mock-prophecy/api/class-phpmock.prophecy.PHPProphet.html#_prophesize):

```
namespace foo;

use phpmock\prophecy\PHPProphet;

$prophet = new PHPProphet();

$prophecy = $prophet->prophesize(__NAMESPACE__);
$prophecy->time()->willReturn(123);
$prophecy->reveal();

assert(123 == time());
$prophet->checkPredictions();
```

Restrictions
------------

[](#restrictions)

This library comes with the same restrictions as the underlying [`php-mock`](https://github.com/php-mock/php-mock#requirements-and-restrictions):

- Only *unqualified* function calls in a namespace context can be prophesized. E.g. a call for `time()` in the namespace `foo` is prophesizable, a call for `\time()` is not.
- The mock has to be defined before the first call to the unqualified function in the tested class. This is documented in [Bug #68541](https://bugs.php.net/bug.php?id=68541). In most cases you can ignore this restriction. But if you happen to run into this issue you can call [`PHPProphet::define()`](http://php-mock.github.io/php-mock-prophecy/api/class-phpmock.prophecy.PHPProphet.html#_define)before that first call. This would define a side effectless namespaced function.
- Additionally it shares restrictions from Prophecy as well: Prophecy [doesn't support pass-by-reference](https://github.com/phpspec/prophecy/issues/225). If you need pass-by-reference in prophecies, consider using another framework (e.g. [php-mock-phpunit](https://github.com/php-mock/php-mock-phpunit)).

License and authors
===================

[](#license-and-authors)

This project is free and under the WTFPL. Responsable for this project is Markus Malkusch .

Donations
---------

[](#donations)

If you like this project and feel generous donate a few Bitcoins here: 1335STSwu9hST4vcMRppEPgENMHD2r1REK

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance70

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.3% 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 ~594 days

Recently: every ~451 days

Total

7

Last Release

176d ago

PHP version history (2 changes)0.0.1PHP &gt;=5.5

0.1.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/06864e2afad0a0cb0b46016664bf5895c3378c8b413e0bddd03075011fc6d731?d=identicon)[webimpress](/maintainers/webimpress)

![](https://www.gravatar.com/avatar/97ee86e5e22b92173b2787cad0ba7ac144109e126221c6d21adecdae32ef37fc?d=identicon)[malkusch](/maintainers/malkusch)

---

Top Contributors

[![michalbundyra](https://avatars.githubusercontent.com/u/7423207?v=4)](https://github.com/michalbundyra "michalbundyra (25 commits)")[![malkusch](https://avatars.githubusercontent.com/u/1623984?v=4)](https://github.com/malkusch "malkusch (19 commits)")[![TiMESPLiNTER](https://avatars.githubusercontent.com/u/598854?v=4)](https://github.com/TiMESPLiNTER "TiMESPLiNTER (2 commits)")

---

Tags

builtin-functionsmockphpphp-mockprophecytestingtestBDDTDDmockstubtest doubleprophecyfunction

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/php-mock-php-mock-prophecy/health.svg)

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

###  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)[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)[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.1M96](/packages/php-mock-php-mock-mockery)[php-mock/php-mock-integration

Integration package for PHP-Mock

1410.5M3](/packages/php-mock-php-mock-integration)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.2k1.2M247](/packages/kahlan-kahlan)

PHPackages © 2026

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