PHPackages                             ray/test-double - 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. ray/test-double

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

ray/test-double
===============

An AOP powered test double library

0.1.0(3y ago)2955MITPHPPHP ^8.0

Since Oct 4Pushed 1y ago2 watchersCompare

[ Source](https://github.com/ray-di/Ray.TestDouble)[ Packagist](https://packagist.org/packages/ray/test-double)[ GitHub Sponsors](https://github.com/koriym)[ Fund](https://tidelift.com/funding/github/packagist/ray/aop)[ RSS](/packages/ray-test-double/feed)WikiDiscussions 1.x Synced 2w ago

READMEChangelog (1)Dependencies (9)Versions (3)Used By (0)

Ray.TestDouble
==============

[](#raytestdouble)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/be35a06edc32dfe228618253d0603f52baa59af724a58ab6dcff041ebf7c28fe/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261792d64692f5261792e54657374446f75626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d312e78)](https://scrutinizer-ci.com/g/ray-di/Ray.TestDouble/?branch=1.x)[![Continuous Integration](https://github.com/ray-di/Ray.TestDouble/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ray-di/Ray.TestDouble/actions/workflows/continuous-integration.yml)

An AOP powered test double library for PHP

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

[](#installation)

### Composer install

[](#composer-install)

```
$ composer require ray/test-double --dev

```

What is Spy?
============

[](#what-is-spy)

A Spy is a test double that records every invocation made against it and can verify certain interactions took place after the fact.

Create Spy
----------

[](#create-spy)

You can do it directly with `newInstance` or specify it with a binding.

### By newInstance()

[](#by-newinstance)

```
$spyLog = new SpyLog();
$spy = (new Spy())->newInstance(Foo::class, 'add', $spyLog);
// $spy records the 'add' method call
```

### By SpyModule

[](#by-spymodule)

Specify the target to spy on by interface or class name.

```
$injector = new Injector(new class extends AbstractModule{
        protected function configure(): void
        {
            $spyTargets = [
                FooInterface::class,
            ];
            $this->install(new SpyModule($spyTargets));
        }
    }
);
$spy = $injector->getInstance(Foo::class);
```

### By Matcher

[](#by-matcher)

Specify the spying target using the [Ray.Aop matcher](https://github.com/ray-di/Ray.Aop/blob/2.x/src/MatcherInterface.php).

```
$injector = new Injector(new class extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new SpyBaseModule());
        $this->bindInterceptor(
            $this->matcher->any(),             // any class
            $this->matcher->startsWith('add'), // methods startWith 'add'
            [SpyInterceptor::class]
        );
    }
});
$fake = $injector->getInstance(FakeAdd::class);
$spy = $injector->getInstance(Foo::class);
```

Assertion
---------

[](#assertion)

`SpyLog::get($className, $methodName)` to get the log and make assertions.

```
public function testSpy()
{
    $result = $foo->add(1, 2); // 3
    $spy = $injector->getInstance(Spy::class);
    // @var array $addLog
    $addLog = $spyLog->getLogs(FakeAdd::class, 'add');
    $subLog = $spyLog->getLogs(FakeAdd::class, 'sub');

    $this->assertSame(1, count($addLog), 'Should have received once');
    $this->assertSame(0, count($subLog), 'Should have not received');
    $this->assertSame([1, 2], $addLog[0]->arguments);
    $this->assertSame(1, $addLog[0]->namedArguments['a']);

}
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.4% 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 ~760 days

Total

2

Last Release

606d ago

Major Versions

0.1.0 → 1.x-dev2024-11-02

### Community

Maintainers

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

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (78 commits)")[![kuma-guy](https://avatars.githubusercontent.com/u/7978290?v=4)](https://github.com/kuma-guy "kuma-guy (47 commits)")

---

Tags

aopfakemocking-frameworkspystubtest doublespy

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ray-test-double/health.svg)

```
[![Health](https://phpackages.com/badges/ray-test-double/health.svg)](https://phpackages.com/packages/ray-test-double)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k526.2M26.6k](/packages/mockery-mockery)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k560.2M773](/packages/phpspec-prophecy)[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.9M122](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4848.2M343](/packages/phake-phake)[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.0M527](/packages/php-mock-php-mock-phpunit)[bear/resource

Hypermedia framework for object as a service

48687.7k43](/packages/bear-resource)

PHPackages © 2026

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