PHPackages                             aeris/spy - 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. aeris/spy

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

aeris/spy
=========

Test spies

1.1.0(10y ago)03.9k2BSDPHP

Since Aug 13Pushed 10y ago10 watchersCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (2)

Spy
===

[](#spy)

Test spies for PHP.

Install
-------

[](#install)

```
composer require aeris/spy

```

Overview
--------

[](#overview)

An `Aeris\Spy` allows you to mock `callable`s in PHP. A `Spy` wraps around a [`Mockery\`](http://docs.mockery.io/) object, which means that you can use Mockery expectations with your Aeris Spies.

For example:

```
$spy = new Spy();

$spy(5);
$spy(6);
$spy(7);

$spy->shouldHaveBeenCalled()
  ->twice()
  ->with(\Mockery::on(function($arg) {
    return $arg > 5;
  )))
```

API
---

[](#api)

### `shouldHaveBeenCalled()` / `shouldNotHaveBeenCalled()`

[](#shouldhavebeencalled--shouldnothavebeencalled)

```
$spy = new Spy();

$spy();

$spy->shouldHaveBeenCalled();  // Passes (no exception)
$spy->shouldNotHaveBeenCalled(); // Failed (throws \Mockery\Exception\InvalidCountException)
```

### `andReturn($val)`

[](#andreturnval)

```
$spy = new Spy();
$spy->andReturn('foo');

$spy();  // 'foo'
```

### `andReturnUsing`

[](#andreturnusing)

```
$spy = new Spy()
$spy->andReturnUsing(function($str) {
  strtoupper($str);
});

$spy('foo');  // 'FOO'
```

### `Spy::returns($val);`

[](#spyreturnsval)

Creates a spy which returns a value. Short-hand for creating a spy, then calling `andReturn`.

```
$spy = Spy::returns('foo');

$spy(); 	// 'foo'
```

### `Spy::returnsUsing($callable);`

[](#spyreturnsusingcallable)

Creates a spy which returns a value via a callable. Short-hand for creating a spy, then calling `andReturnUsing`.

```
$spy = Spy::returnsUsing(function($str) {
  strtoupper($str);
});

$spy('foo'); 	// 'FOO'
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

3931d ago

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/aeris-spy/health.svg)

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

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33812.5M350](/packages/brain-monkey)[codeception/mockery-module

Mockery Module for Codeception

344.2M82](/packages/codeception-mockery-module)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.3k13](/packages/lastzero-test-tools)

PHPackages © 2026

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