PHPackages                             phuedx/pinkerton - 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. phuedx/pinkerton

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

phuedx/pinkerton
================

Emulating Jasmine's `spyOn` function with UOPZ.

v2.0.1(11y ago)69MITPHPPHP &gt;= 5.4CI failing

Since Aug 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/phuedx/pinkerton)[ Packagist](https://packagist.org/packages/phuedx/pinkerton)[ Docs](https://github.com/phuedx/pinkerton)[ RSS](/packages/phuedx-pinkerton/feed)WikiDiscussions develop Synced today

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

Pinkerton [![Build Status](https://camo.githubusercontent.com/6a131532ef8a9c666e5f8bec5eef39cac7bb3d081d945a49a264111f8640c359/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7068756564782f70696e6b6572746f6e2e706e673f6272616e63683d6d61737465722c646576656c6f70)](http://travis-ci.org/phuedx/pinkerton)
======================================================================================================================================================================================================================================================================================================================

[](#pinkerton-)

So you’re calling some legacy function. Maybe it’s even an *internal* function – it’s `microtime` isn’t it? You’re writing your tests and you want to make an assertion about how it’s called or stub its behaviour.

You should use **Pinkerton**.

**Pinkerton** allows you to spy on or stub the behaviour of functions and methods using [**@krakjoe**'s UOPZ extension](https://github.com/krakjoe/uopz) wrapped up in a port of [Jasmine's](https://jasmine.github.io/) `spyOn` function.

Spyin’
------

[](#spyin)

```
function legacy_function($parameter)
{
    // Do all of the things.
}

$spy = spyOn('legacy_function')->andCallThrough();
$legacyParameter = 1;
legacy_function($legacyParameter);
var_dump($spy->mostRecentCall); // [‘args’ => [1]]
```

Stubbin’
--------

[](#stubbin)

```
$spy = spyOn('legacy_function')->andCallFake(function() {
    return false;
});
var_dump(legacy_function($legacyParameter)); // false
```

Testin’
-------

[](#testin)

So you're writing a test for a method that accepts a `callable` argument. Wellp, you can pass in a **Pinkerton** spy, call the method with the spy as an argument, and then make some assertions about how it was called.

```
class FooTest extends PHPUnit_Framework_TestCase
{
    public function test_bar_should_call_the_callable()
    {
        $spy = createSpy();
        $foo = new Foo();
        $foo->bar($spy);
        $this->assertEquals($spy->callCount, 1);
    }
}
```

API
---

[](#api)

```
/**
 * Spies on the function or method.
 *
 * The function or method is replaced with a handler that will invoke a spy
 * that wraps the original function or method.
 *
 * Note that when spying on a method, the method is replaced with the handler
 * for all instances of the class.
 *
 * @param callable $function
 * @return \Phuedx\Pinkerton\Spy The spy that will be invoked instead of the
 *  function or method
 */
function spyOn($function) {}

/**
 * Stops spying on the function or method.
 *
 * The original function or method is restored but the spy is unaffected.
 *
 * @param callable $function
 * @throws \InvalidArgumentException When the function or method isn't being
 *  spied on
 */
function stopSpyingOn($function) {}

/**
 * Creates a spy that doesn't wrap a function or method.
 *
 * @return \Phuedx\Pinkerton\Spy
 */
function createSpy() {}
```

License
-------

[](#license)

**Pinkerton** is licensed under the MIT license and is copyright (c) 2012-2014 Sam Smith. See the LICENSE file for full copyright and license information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98% 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 ~153 days

Total

4

Last Release

4235d ago

Major Versions

v1.1.0 → v2.0.02014-11-22

PHP version history (2 changes)v1.0.0PHP &gt;= 5.3

v2.0.1PHP &gt;= 5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/36be4b0c8f472f7e9f1fe3ad69d448f952ff7014e515b91e37c092b54a0ef5b8?d=identicon)[phuedx](/maintainers/phuedx)

---

Top Contributors

[![phuedx](https://avatars.githubusercontent.com/u/191857?v=4)](https://github.com/phuedx "phuedx (49 commits)")[![mortonfox](https://avatars.githubusercontent.com/u/495892?v=4)](https://github.com/mortonfox "mortonfox (1 commits)")

---

Tags

testingtestspyspies

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k526.2M26.9k](/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.

37419.9M125](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4848.2M349](/packages/phake-phake)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

34214.3M483](/packages/brain-monkey)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10958.3M21](/packages/ta-tikoma-phpunit-architecture-test)[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.

1719.0M542](/packages/php-mock-php-mock-phpunit)

PHPackages © 2026

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