2017 © Pedro Peláez
 

library reflection

Test any Private/Protected Methods/Properties of any class

image

skagarwal/reflection

Test any Private/Protected Methods/Properties of any class

  • Sunday, May 31, 2015
  • by Sachin Agarwal
  • Repository
  • 1 Watchers
  • 7 Stars
  • 716 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

Php-Reflection-Deflector

Build Status Latest Stable Version Total Downloads Latest Unstable Version License
Test your Private/Protected Methods/Properties with any testing package and with Zero configuration., (*1)

New: Can reflect multiple classes at same time., (*2)

Usage

Step 1: Install Through Composer

composer require skagarwal/reflection --dev

Step 2: Import the trait

Import the SKAgarwal\Reflection\ReflectableTrait in your TestClass of any package. Eg: PhpUnit, PhpSpec, Laracasts\Integrated., (*3)

For PhpUnit, (*4)

use SKAgarwal\Reflection\ReflectableTrait

class ModelTest extends PHPUnit_Framework_TestCase
{
  use ReflectableTrait;
}

And That's it. You are all set to go. :), (*5)

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

Instantiate the Reflector

By using reflect() method like this:, (*7)

$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., (*8)

By using on() method like this:, (*9)

$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., (*10)

Available Methods

reflect($classObj);

Description: Reflect the Class Object

, (*11)

on($classObj);

Description: Reflect the Class Object. This is Chainable Method.
Possible Chaining:, (*12)

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



, (*13)

call($method, $arguments = []);

Description: Call any valid public/Private/Protected Method of reflected Class Object. This is not Chainable Method.

, (*14)

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.

, (*15)

get($property);

Description: Get the value of any valid Public/Private/Protected property of the reflected Class Object. This is not Chainable Method.

, (*16)

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.

, (*17)

set($name, $value);

Description: Set the value of valid Public/Private/Protected property of the reflected Class Object. This is not Chainable Method.

, (*18)

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., (*19)

-, (*20)

Reflect Multiple classes at same time

Example:, (*21)

// 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);
  }

The Versions

31/05 2015

dev-master

9999999-dev

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

dev-develop

dev-develop

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0

1.0.0.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0.1

1.0.1.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0.2

1.0.2.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0.3

1.0.3.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0.4

1.0.4.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties

31/05 2015

1.0.5

1.0.5.0

Test any Private/Protected Methods/Properties of any class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar Sachin Agarwal

testing php reflection unittesting private methods protected methods private properties protected properties