PHPackages                             markbaker/spymaster - 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. markbaker/spymaster

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

markbaker/spymaster
===================

SpyMaster is a small library, for use in testing, that allows access to verify the values of protected and private properties in a class that is being tested, without needing to modify the class using Reflection.

1.1.0(5y ago)6261MITPHPPHP ^7.0 || ^8.0CI failing

Since Oct 14Pushed 5y ago3 watchersCompare

[ Source](https://github.com/MarkBaker/SpyMaster)[ Packagist](https://packagist.org/packages/markbaker/spymaster)[ Docs](http://github.com/MarkBaker/SpyMaster)[ RSS](/packages/markbaker-spymaster/feed)WikiDiscussions develop Synced 3d ago

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

SpyMaster - Create "Spies" to access the protected and private properties of a class being tested
=================================================================================================

[](#spymaster---create-spies-to-access-the-protected-and-private-properties-of-a-class-being-tested)

SpyMaster is a small library, for use in testing, that allows access to verify the values of protected and private properties in a class that is being tested, or execution of protected or private methods, without needing to modify the class using Reflection.

[![Build Status](https://github.com/MarkBaker/SpyMaster/workflows/main/badge.svg)](https://github.com/MarkBaker/SpyMaster/actions)[![License](https://camo.githubusercontent.com/264867c05bb4d83e2c7afe8cb54894071fea51ee99faf6c336586b03778c965a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f5048504f66666963652f5068705370726561647368656574)](https://packagist.org/packages/markbaker/spymaster)

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

[](#requirements)

- PHP version 7.0.0 or higher

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

[](#installation)

Using composer, either

```
composer require markbaker/spymaster

```

or add the library to your existing composer.json file, and let composer's own autoloader work its magic.

Or you can download the files from github, and include the bootstrap.php file to enable the SpyMaster autoloader

Usage
-----

[](#usage)

There are a few examples of use in the `/examples` folder.

```
// Instantiate your object
$myObject = new myObject();

// Infiltrate a read-only Spy that can view the properties of $myObject
$spy = (new SpyMaster\SpyMaster($myObject))
    ->infiltrate();

// Access the $value property of $myObject
// Any property of $myObject can be accessed, whether it is public, protected or private
echo $spy->value;

```

```
// Instantiate your object
$myObject = new myObject();

// Infiltrate a read-write spy that can both read and modify the properties of $myObject
$spy = (new SpyMaster\SpyMaster($myObject))
    ->infiltrate(SpyMaster\SpyMaster::SPY_READ_WRITE);

// Access the $value property of $myObject
// Any property of $myObject can be accessed, whether it is public, protected or private
echo $spy->value;

// A Read-Write Spy also allows you to set new values for those properties
$spy->value += 1000;
echo $spy->value;

```

Spies cannot unset properties, nor can they access properties that are created dynamically after the Spy is infiltrated.

To execute private or protected methods inside an object, you can use a `Manipulator`.

```
// Instantiate your object
$myObject = new myObject();

// Create a Manipulator
$Manipulator = new Manipulator();

// Call the Manipulator's execute() method, passing in the object and name of the method to execute, together with any arguments
$result = $Manipulator->execute($myObject, 'add', 3, 5);
// This example would execute the add() method of the myObject instance with arguments 3 and 5

```

License
-------

[](#license)

SpyMaster is published under the [MIT](https://github.com/MarkBaker/SpyMaster/blob/master/license.md) license

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity69

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

Total

2

Last Release

1968d ago

PHP version history (2 changes)1.0.1PHP ^7.0.0

1.1.0PHP ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b8457fa3227a7e8e38f0121f1fe254ec965133df93ae5ea8352c757adb98283?d=identicon)[PHPOffice](/maintainers/PHPOffice)

---

Tags

testingtestlibraryspy

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/markbaker-spymaster/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[albertcht/lumen-testing

Testing Suite For Lumen like Laravel does.

4335.5k1](/packages/albertcht-lumen-testing)[sofa/eloquent-testsuite

Helpers for fast and reliable UNIT tests for your Eloquent Models with PHPUnit

10104.7k](/packages/sofa-eloquent-testsuite)[cerbero/octane-testbench

Set of utilities to test Laravel applications powered by Octane.

434.2k1](/packages/cerbero-octane-testbench)

PHPackages © 2026

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