PHPackages                             code-distortion/insight - 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. code-distortion/insight

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

code-distortion/insight
=======================

Test protected and private object methods and properties as if they were public

0.1.6(5mo ago)0452MITPHPPHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*CI passing

Since Feb 4Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/code-distortion/insight)[ Packagist](https://packagist.org/packages/code-distortion/insight)[ Docs](https://github.com/code-distortion/insight)[ RSS](/packages/code-distortion-insight/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (7)Dependencies (5)Versions (8)Used By (0)

Insight
=======

[](#insight)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fe42066d224a3593ffa5559fe81e9f068bdddc99f561a0c7c4c61147774bf83d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d646973746f7274696f6e2f696e73696768742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/code-distortion/insight)[![PHP Version](https://camo.githubusercontent.com/7377a12d33082dcc66e398bcdfe01550146ac043eef13190ae9c5c99018ee3a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e30253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7377a12d33082dcc66e398bcdfe01550146ac043eef13190ae9c5c99018ee3a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e30253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)[![GitHub Workflow Status](https://camo.githubusercontent.com/6827d8aa0365c4f54775eee282b29c22fcbfed7d4261631335b6cbcf3cade65b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64652d646973746f7274696f6e2f696e73696768742f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/code-distortion/insight/actions)[![Buy The World a Tree](https://camo.githubusercontent.com/dc3f77a9b22c3bc83c7b7d863bf138a7ca3418f1826b0b16d073d0aa87c16bc4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/code-distortion/insight)[![Contributor Covenant](https://camo.githubusercontent.com/902d296a65b2997bada7e7717fd929d9177f3bd95414cbb5ea2ed843c680f314/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e7472696275746f72253230636f76656e616e742d76322e3125323061646f707465642d6666363962342e7376673f7374796c653d666c61742d737175617265)](.github/CODE_OF_CONDUCT.md)

***code-distortion/insight*** is a PHP library that allows you to access ***protected*** and ***private*** object methods and properties, as if they were ***public***.

```
$myObject->privateMethod();   // "Error: Call to private method ..."

$testObject = new Insight($myObject);
$testObject->privateMethod(); // success
```

This might be useful when testing. [It might be a good idea, or it might not](https://stackoverflow.com/questions/105007/should-i-test-private-methods-or-only-public-ones). It's up to you.

> ***Note***: Using Insight for purposes other than testing is probably a code smell.

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

[](#installation)

Install the package via composer:

```
composer require code-distortion/insight --dev
```

Usage
-----

[](#usage)

Instantiate an Insight object:

```
// build based on an existing object
$myObject = new MyClass();
$testObject = new Insight($myObject);

// or
$testObject = new Insight(new MyClass());
```

`$testObject` will then act as if it ***is*** the original object, but gives you access to its protected and private methods and properties as well.

Read and write protected and private properties:

```
$testObject->publicProp = 'something';
$testObject->protectedProp = 'something';
$testObject->privateProp = 'something';

print $testObject->publicProp;
print $testObject->protectedProp;
print $testObject->privateProp;
```

Call protected and private methods:

```
print $testObject->publicMethod();
print $testObject->protectedMethod();
print $testObject->privateMethod();
```

These can be useful while testing your code with [phpunit](https://github.com/sebastianbergmann/phpunit):

```
$this->testSame('someValue', $testObject->privateProperty);
$this->testSame('someValue', $testObject->privateMethod());
```

### Abstract classes

[](#abstract-classes)

You can test abstract classes (and classes whose constructor is not public) by passing the *class* when instantiating an Insight object.

```
$testObject = new Insight(MyClass::class);
```

> ***Note***: When instantiating Insight with a class like this (instead of an object) you will only be able to access it's *static* methods and properties.

> ***Note***: To test other functionality of an abstract class you will need to have a concrete class that extends the abstract class, and use that instead.

### Static methods and properties

[](#static-methods-and-properties)

PHP doesn't have `__getStatic()` or `__setStatic()` magic methods either which would help facilitate accessing protected properties.

Instead, Insight lets you access static methods and properties in the same way as regular methods and properties. Just add `StaticProp` or `StaticMethod` after the property or method name respectively:

```
// calling them from an Insight object
$testObject = new Insight(new MyClass());
// or
$testObject = new Insight(MyClass::class);

$testObject->privateStaticProp = 'something';
$testObject->privateStaticMethod();

// this syntax is also available allowing you to access them in one line
Insight::{myClass::class}()->privateStaticProp = 'something';
Insight::{myClass::class}()->privateStaticMethod();
```

### Misc

[](#misc)

You can access the underlying object or class by accessing the `->insight` property:

```
// when instantiated using an object
$myObject = new MyClass();
$testObject = new Insight($myObject);
$testObject->insight; // === $myObject

// when instantiated using a class name
$testObject = new Insight(MyClass::class);
$testObject->insight; // === 'Namespace\To\MyClass'
```

Testing This Package
--------------------

[](#testing-this-package)

- Clone this package: `git clone https://github.com/code-distortion/insight.git .`
- Run `composer install` to install dependencies
- Run the tests: `composer test`

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

### SemVer

[](#semver)

This library uses [SemVer 2.0.0](https://semver.org/) versioning. This means that changes to `X` indicate a breaking change: `0.0.X`, `0.X.y`, `X.y.z`. When this library changes to version 1.0.0, 2.0.0 and so forth, it doesn't indicate that it's necessarily a notable release, it simply indicates that the changes were breaking.

Treeware
--------

[](#treeware)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/code-distortion/insight) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Code of Conduct

[](#code-of-conduct)

Please see [CODE\_OF\_CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tim Chandler](https://github.com/code-distortion)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance70

Regular maintenance activity

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~353 days

Total

7

Last Release

175d ago

PHP version history (6 changes)0.1.0PHP ^7.0

0.1.2PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\*

0.1.3PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\*

0.1.4PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\*

0.1.5PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\*

0.1.6PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56794290?v=4)[Tim](/maintainers/code-distortion)[@code-distortion](https://github.com/code-distortion)

---

Top Contributors

[![code-distortion](https://avatars.githubusercontent.com/u/56794290?v=4)](https://github.com/code-distortion "code-distortion (22 commits)")

---

Tags

testingphpunitunit testingTDDaccesspropertymethodprivatepublicprotectedunit-tests

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/code-distortion-insight/health.svg)

```
[![Health](https://phpackages.com/badges/code-distortion-insight/health.svg)](https://phpackages.com/packages/code-distortion-insight)
```

###  Alternatives

[codedungeon/phpunit-result-printer

PHPUnit Pretty Result Printer

1.2k8.8M397](/packages/codedungeon-phpunit-result-printer)[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)[donatj/mock-webserver

Simple mock web server for unit testing

1382.5M80](/packages/donatj-mock-webserver)[yoast/wp-test-utils

PHPUnit cross-version compatibility layer for testing plugins and themes build for WordPress

632.3M52](/packages/yoast-wp-test-utils)[fiunchinho/phpunit-randomizer

Execute your test cases in random order, so you can check if they have hidden dependencies

50752.0k18](/packages/fiunchinho-phpunit-randomizer)[elliotchance/concise

Concise is test framework for using plain English and minimal code, built on PHPUnit.

45223.8k4](/packages/elliotchance-concise)

PHPackages © 2026

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