PHPackages                             flarone/reflection - 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. flarone/reflection

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

flarone/reflection
==================

Test any Private/Protected Methods/Properties of any class

1.0(3y ago)031MITPHPPHP &gt;=5.4.0

Since Nov 16Pushed 3y agoCompare

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

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

php-reflection-deflector
========================

[](#php-reflection-deflector)

[![Latest Stable Version](https://camo.githubusercontent.com/acf5b848c0515597546b95d9da1c3dd028978747ea0295ad32b59e796c6b3cc7/68747470733a2f2f706f7365722e707567782e6f72672f666c61726f6e652f7265666c656374696f6e2f762f737461626c65)](https://packagist.org/packages/flarone/reflection) [![Total Downloads](https://camo.githubusercontent.com/805c5d621fac9228654fa2d2ff0e6a1811a5ab77131fdc982228a09fb36ff63a/68747470733a2f2f706f7365722e707567782e6f72672f666c61726f6e652f7265666c656374696f6e2f646f776e6c6f616473)](https://packagist.org/packages/flarone/reflection) [![Latest Unstable Version](https://camo.githubusercontent.com/a96cb2d7ffea9c4d88c8e1bc7f0e256717562241f045e56ea1e5ac6f76f396b9/68747470733a2f2f706f7365722e707567782e6f72672f666c61726f6e652f7265666c656374696f6e2f762f756e737461626c65)](https://packagist.org/packages/flarone/reflection) [![License](https://camo.githubusercontent.com/9fc1c280ba3f849ccfce8b4bba67a4f32e2c0fa26c2193a436b140443ff60a30/68747470733a2f2f706f7365722e707567782e6f72672f666c61726f6e652f7265666c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/flarone/reflection)
Test your **Private/Protected** Methods/Properties with any testing package and with **Zero** configuration.

**New:** Can reflect multiple classes at same time.

Usage
=====

[](#usage)

### Step 1: Install Through Composer

[](#step-1-install-through-composer)

```
composer require flarone/reflection --dev
```

### Step 2: Import the trait

[](#step-2-import-the-trait)

Import the `Flarone\Reflection\ReflectableTrait` in your `TestClass` of any package. Eg: `PhpUnit`, `PhpSpec`, `Laracasts\Integrated`.

For `PhpUnit`

```
use Flarone\Reflection\ReflectableTrait

class ModelTest extends PHPUnit_Framework_TestCase
{
  use ReflectableTrait;
}
```

And That's it. You are all set to go. :)

**Now you can do the following to test private/protected methods or properties:**

### Instantiate the Reflector

[](#instantiate-the-reflector)

By using `reflect()` method like this:

```
$randomClass = new RandomClass();
$this->reflect($randomClass);
```

**This Method is not chainable**
**Note:** Its preferable to use this in `constructor` or for PhpUnit in `setUp()` method etc.

By using `on()` method like this:

```
$randomClass = new RandomClass();
$this->on($randomClass)->call($method, $args = []);
```

**This method is chainable**\*\*Note: \*\*This method relfects the class object only once. That is only for one call to method or property. It can be used for relfecting multiple classes at same time.

Available Methods
=================

[](#available-methods)

#### reflect($classObj);

[](#reflectclassobj)

**Description:** Reflect the Class Object

#### on($classObj);

[](#onclassobj)

**Description:** Reflect the Class Object. This is Chainable Method.
Possible Chaining:

```
$this->on($classObject)->callMethod($arguments = []);
$this->on($classObject)->call($method, $arguments = []);
$this->on($classObject)->get($property);
$this->on($classObject)->get{Proerty};
```

\#### call($method, $arguments = \[\]); \*\*Description:\*\* Call any valid public/Private/Protected Method of reflected Class Object. This is not Chainable Method.

\#### call{Method}($arguments = \[\]); \*\*Description:\*\* Same as `call()` but dynamically calls the method. This is not Chainable Method.
{method} Can be any valid public/private/protected method of reflected Class Object.

\#### get($property); \*\*Description:\*\* Get the value of any valid Public/Private/Protected property of the reflected Class Object. This is not Chainable Method.

\#### get{Property}; \*\*Description:\*\* Same as `get()` but dynamically gets the value of the property. This is not Chainable Method.
{property} Can be any valid Public/Private/Protected property of the reflected Class Object.

\#### set($name, $value); \*\*Description:\*\* Set the value of valid Public/Private/Protected property of the reflected Class Object. This is not Chainable Method.

\#### set{Property} = $value; \*\*Description:\*\* Same as `set()` but dynamically sets the value of the property. This is not Chainable Method.
{property} Can be any valid Public/Private/Protected property of the reflected Class Object. -

### Reflect Multiple classes at same time

[](#reflect-multiple-classes-at-same-time)

**Example:**

```
// Considering phpunit

 protected function setUp()
  {
    $this->foo = new Foo();
    $this->reflect($this->foo);
  }

  public function test_something()
  {
    $hello = $this->callSayHello(); // this will call SayHello() of class `Foo`
    $this->assertEquals('Hello', $hello);

    $hello = $this->on(new FooBar())->callSayHello(); // this will call SayHello() of class `FooBar`
    $this->assertEquals('Hello FooBar', $hello);

    $hello = $this->callSayHello(); // this will call SayHello() of class `Foo`
    $this->assertEquals('Hello', $hello);
  }
```

Contribution
============

[](#contribution)

Feel free to report issues or make Pull Requests. If you find this document can be improved in any way, please feel free to open an issue for it.

License
=======

[](#license)

The php-reflection-deflector was forked from `skagarwal/reflection`. The php-reflection-deflector is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1279d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/51fd7905d0acba590e8e161f4c10f91eef023650ec78751bb7885ce4e9664df0?d=identicon)[Flarone](/maintainers/Flarone)

---

Top Contributors

[![MarcelWiebenga](https://avatars.githubusercontent.com/u/10196899?v=4)](https://github.com/MarcelWiebenga "MarcelWiebenga (1 commits)")

---

Tags

phptestingreflectionunittestingPrivate MethodsProtected MethodsPrivate PropertiesProtected Properties

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flarone-reflection/health.svg)

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

###  Alternatives

[php-vfs/php-vfs

Virtual file system implementation for use with PHP unit testing.

572.7M24](/packages/php-vfs-php-vfs)[marvinrabe/laravel-graphql-test

Provides you with a simple GraphQL testing trait.

58329.7k](/packages/marvinrabe-laravel-graphql-test)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

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