PHPackages                             komex/influence - 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. komex/influence

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

komex/influence
===============

Mocking any objects and classes

v1.1.0(11y ago)0321CC BY-SA 4.0PHPPHP &gt;=5.4

Since Oct 21Pushed 11y ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5264c9d77c71ac39c4e4090f4fd758b3616dd448e5e2d6fd8963a4bd7a06394e/68747470733a2f2f7472617669732d63692e6f72672f6b6f6d65782f696e666c75656e63652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/komex/influence)[![Code Coverage](https://camo.githubusercontent.com/882b3c6875b75e0046cf605522adde42f99f41110eb71adf620244c0b7f72b1f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6d65782f696e666c75656e63652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/komex/influence/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2269dd9300e6e69944a20a7731e8ac198acded627d1f5faad8614f2d917a3d40/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6d65782f696e666c75656e63652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/komex/influence/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f434cff08189b7f6038b51948c01fd77957fa556bcffcf0bd1ae71a2a106e4d9/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6d65782f696e666c75656e63652f762f737461626c652e737667)](https://packagist.org/packages/komex/influence)[![License](https://camo.githubusercontent.com/04e6ed84e562cfe240e3f477191ece4c41cde255314884bde42d1fe4dc576a89/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6d65782f696e666c75656e63652f6c6963656e73652e737667)](https://packagist.org/packages/komex/influence)[!\[Gitter\](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/komex/influence)

Influence
=========

[](#influence)

**Influence** is the PHP library gives you ability to mock any objects and static classes. Works only if you use Composer autoloader. This library very useful for testing your code.

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

[](#requirements)

- PHP 5.4 or higher
- SPL extension
- Tokenizer extension
- Composer loader

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

[](#installation)

To add Influence as a local, per-project dependency to your project, simply add a dependency on `komex/influence` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a develop dependency on Influence:

```
{
    "require-dev": {
        "komex/influence": "1.1.*"
    }
}
```

Usage
-----

[](#usage)

**Influence** must be injected as early as possible. If you are using unit test framework like [unteist](https://github.com/komex/unteist) or [PHPUnit](https://phpunit.de/) the best way to do this is include autoload and influence in bootstrap file.

```
require 'vendor/autoload.php';
Influence\Influence::affect();
```

Since this moment you are able to mock any objects and static classes. By default, all objects behave as usual. You need to configure behavior of each object or class you need to control.

### Manage objects

[](#manage-objects)

Let imagine we have a simple class A:

```
class A
{
    public function sum($a)
    {
        return $a + $this->rand(0, $a);
    }
    private fuction rand($min, $max)
    {
        return rand($min, $max);
    }
}
```

#### Custom method behavior.

[](#custom-method-behavior)

So, if we create an object of class `A` we can invoke only `sum()` method and control only `$a` and never know result of our operation.

```
$a = new A();
echo $a->sum(1); // ??
echo $a->sum(7); // ??
```

But with **Influence** you can simply test this code. Just specify the behavior of `sum()` like this:

```
$a = new A();
$method = Influence\RemoteControl::controlObject($a)->get('rand');
$method->setValue(new Value(1));
echo $a->sum(1); // 2
echo $a->sum(7); // 8
$method->setValue();
echo $a->sum(1); // ??
echo $a->sum(7); // ??
```

#### Log method calls

[](#log-method-calls)

If you don't need to set custom method behavior, but want to know how many times method was called and with what arguments.

```
$a = new A();
$method = Influence\RemoteControl::controlObject($a)->get('rand');
$method->setLog(true);
echo $a->sum(1); // ??
echo $a->sum(7); // ??
var_dump($method->getLogs()); // [ [0, 1], [0, 7] ]
```

License
-------

[](#license)

Influence by [Andrey Kolchenko](https://github.com/komex) is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).

[![Creative Commons License](https://camo.githubusercontent.com/08d150eb65b779b961c5516cf643c42b02ca6b6b2b51b26b1d3365d4cb96f756/68747470733a2f2f692e6372656174697665636f6d6d6f6e732e6f72672f6c2f62792d73612f342e302f38387833312e706e67)](http://creativecommons.org/licenses/by-sa/4.0/)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity60

Established project with proven stability

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 ~21 days

Total

2

Last Release

4206d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8eec3e08123ce80baedf4965600a9980be3e84c23b6dc775468a647378a723b4?d=identicon)[komex](/maintainers/komex)

---

Tags

phptestingunittestmockstubunittest

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[icecave/isolator

Dependency injection for global functions.

371.3M29](/packages/icecave-isolator)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)

PHPackages © 2026

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