PHPackages                             cheprasov/php-extra-mocks - 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. cheprasov/php-extra-mocks

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

cheprasov/php-extra-mocks
=========================

ExtraMocks are a tools that give extra functionality for Mocks.

1.0.0(9y ago)17022MITPHPPHP &gt;=5.5CI failing

Since Jan 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/cheprasov/php-extra-mocks)[ Packagist](https://packagist.org/packages/cheprasov/php-extra-mocks)[ Docs](http://github.com/cheprasov/php-extra-mocks)[ RSS](/packages/cheprasov-php-extra-mocks/feed)WikiDiscussions master Synced 3w ago

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

[![MIT license](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](http://opensource.org/licenses/MIT)

ExtraMocks v1.0.0 for PHP &gt;= 5.5
===================================

[](#extramocks-v100-for-php--55)

About
-----

[](#about)

ExtraMocks are a tools that give extra functionality for Mocks.

Main features
-------------

[](#main-features)

- Allow to redefine global function in namespaces.

Usage
-----

[](#usage)

#### \\ExtraMocks\\Mocks :: mockGlobalFunction ( `string` **$fullName** , `mixed|callable` **$result** \[, `int|null` **$count** = null \] )

[](#extramocksmocks--mockglobalfunction--string-fullname--mixedcallable-result--intnull-count--null--)

---

Redefine global function.

##### Method Pameters

[](#method-pameters)

1. string **$fullName** - name with namespace of function for redefine
2. mixed|callable **$result** - new function or result
3. int|null **$count**, default = null. Count of mocked calls

#### \\ExtraMocks\\Mocks :: getCountCalls ( `string` **$fullName** )

[](#extramocksmocks--getcountcalls--string-fullname-)

---

Get count of mocked calls

##### Method Pameters

[](#method-pameters-1)

1. string **$fullName** - fullname of redefined function

Examples
--------

[](#examples)

```
namespace A;

class A
{
    public static function string_length($str)
    {
        return strlen($str);
    }
}
```

```
namespace B;

class B {

    public static function string_length($str)
    {
        return strlen($str);
    }
}
```

```
namespace Example;

require (__DIR__ . '/../src/autoloader.php');

use ExtraMocks\Mocks;

// 1. Redefine Global Function by Function

\ExtraMocks\Mocks::mockGlobalFunction(
    '\A\strlen',
    function($s) {
        return strlen($s) * 5;
    }
);

echo \A\A::string_length('foo') . PHP_EOL; // 15
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 2. Redefine Global Function by Result

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42);

echo \A\A::string_length('foo') . PHP_EOL; // 42;
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 3. Redefine Global Function by Result once

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42, 1);

echo \A\A::string_length('foo') . PHP_EOL; // 42;
echo \A\A::string_length('foo') . PHP_EOL; // 3;
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 3. Get count of calls mocked function

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42);

echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 0
echo \A\A::string_length('foo') . PHP_EOL;        // 42;
echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 1
echo \A\A::string_length('foo') . PHP_EOL;        // 42;
echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 2
```

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

[](#installation)

### Composer

[](#composer)

Download composer:

```
wget -nc http://getcomposer.org/composer.phar

```

and add dependency to your project:

```
php composer.phar require cheprasov/php-extra-mocks

```

Running tests
-------------

[](#running-tests)

3. To run tests type in console:

    ./vendor/bin/phpunit

Something doesn't work
----------------------

[](#something-doesnt-work)

Feel free to fork project, fix bugs and finally request for pull

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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

3433d ago

### Community

Maintainers

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

---

Top Contributors

[![cheprasov](https://avatars.githubusercontent.com/u/4299922?v=4)](https://github.com/cheprasov "cheprasov (8 commits)")

---

Tags

functionsmockphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cheprasov-php-extra-mocks/health.svg)

```
[![Health](https://phpackages.com/badges/cheprasov-php-extra-mocks/health.svg)](https://phpackages.com/packages/cheprasov-php-extra-mocks)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

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

14228.7M340](/packages/dms-phpunit-arraysubset-asserts)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8219.1M69](/packages/orchestra-workbench)[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)

PHPackages © 2026

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