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

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

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.

1.5.0(1y ago)392.1M—6.9%5[2 issues](https://github.com/php-mock/php-mock-mockery/issues)20WTFPLPHPPHP &gt;=5.6CI failing

Since Apr 1Pushed 7mo ago2 watchersCompare

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

READMEChangelog (4)Dependencies (3)Versions (12)Used By (20)

[![.github/workflows/tests.yml](https://github.com/php-mock/php-mock-mockery/actions/workflows/tests.yml/badge.svg)](https://github.com/php-mock/php-mock-mockery/actions/workflows/tests.yml)

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

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

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

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

[](#installation)

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

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

Usage
-----

[](#usage)

[`PHPMockery::mock()`](http://php-mock.github.io/php-mock-mockery/api/class-phpmock.mockery.PHPMockery.html#_mock)let's you build a function mock which can be equiped with Mockery's expectations. After your test you'll have to disable all created function mocks by calling `Mockery::close()`.

### Example

[](#example)

```
namespace foo;

use phpmock\mockery\PHPMockery;

$mock = PHPMockery::mock(__NAMESPACE__, "time")->andReturn(3);
assert (3 == time());

\Mockery::close();
```

### 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 mocked. E.g. a call for `time()` in the namespace `foo` is mockable, 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 [`PHPMockery::define()`](http://php-mock.github.io/php-mock-mockery/api/class-phpmock.mockery.PHPMockery.html#_define)before that first call. This would define a side effectless namespaced function.

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

53

—

FairBetter than 97% of packages

Maintenance54

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% 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 ~403 days

Recently: every ~675 days

Total

10

Last Release

436d ago

Major Versions

0.3 → 1.0.02015-10-26

PHP version history (3 changes)0.1PHP &gt;=5.4

0.3PHP &gt;=5.5

1.2.0PHP &gt;=5.6

### 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

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

---

Tags

builtin-functionsmockeryphpphp-mocktestingtestBDDTDDmockerymockstubtest doublefunction

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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-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.

16496.6k15](/packages/php-mock-php-mock-prophecy)[php-mock/php-mock-integration

Integration package for PHP-Mock

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

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

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