Helps accessing protected/private members/consts of foreign objects.

1.4.0 2024-02-07 13:53 UTC

This package is auto-updated.

Last update: 2024-11-07 15:56:25 UTC


README

 ▄█        ▄██████▄   ▄████████    ▄█   ▄█▄    ▄███████▄  ▄█   ▄████████    ▄█   ▄█▄
███       ███    ███ ███    ███   ███ ▄███▀   ███    ███ ███  ███    ███   ███ ▄███▀
███       ███    ███ ███    █▀    ███▐██▀     ███    ███ ███▌ ███    █▀    ███▐██▀  
███       ███    ███ ███         ▄█████▀      ███    ███ ███▌ ███         ▄█████▀  
███       ███    ███ ███        ▀▀█████▄    ▀█████████▀  ███▌ ███        ▀▀█████▄  
███       ███    ███ ███    █▄    ███▐██▄     ███        ███  ███    █▄    ███▐██▄  
███▌    ▄ ███    ███ ███    ███   ███ ▀███▄   ███        ███  ███    ███   ███ ▀███▄
█████▄▄██  ▀██████▀  ████████▀    ███   ▀█▀  ▄████▀      █▀   ████████▀    ███   ▀█▀
▀                                 ▀                                        ▀  

Lockpick

Latest Stable Version License

Collection of PHP helper methods allowing easy access to protected or private properties and constants of objects or classes as well as allowing to call such non-public methods. This library is mostly useful while creating unit tests for your code.

Installation

composer require marcin-orlowski/lockpick

Usage

As all methods come as set of static methods, so you just need to add related use to your code class and all methods should be simply available via static reference Lockpick::...:

use Lockpick\Lockpick;
use PHPUnit\Framework\Assert;

$obj = new Stronghold();
$actual = Lockpick::call($obj, 'openSessame', [ 'abracadabra' ]);
Assert::assertEquals($expected, $actual);
...

Available methods

Notes:

  • The $clsOrObj parameter can be either object or class name (string)
  • The Lockpick::call() argument $args now accepts single parameters w/o array wrapping (so call(..., $arg1) is now valid and equivalent to call(..., [ $arg1 ])) as it will be automatically wrapped under the hood.
  • If you want to actually pass array as single argument to called function you must wrap it into another array, like this: call(..., [[ $arg1, $arg2 ]]). Default is empty array which means no arguments will be passed to the called method.

License