marcin-orlowski / lockpick
Helps accessing protected/private members/consts of foreign objects.
Installs: 1 903
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- marcin-orlowski/type-asserts: ^2.0.0
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/php-code-coverage: ^9.0
- phpunit/phpunit: ^9.0
Replaces
README
▄█ ▄██████▄ ▄████████ ▄█ ▄█▄ ▄███████▄ ▄█ ▄████████ ▄█ ▄█▄
███ ███ ███ ███ ███ ███ ▄███▀ ███ ███ ███ ███ ███ ███ ▄███▀
███ ███ ███ ███ █▀ ███▐██▀ ███ ███ ███▌ ███ █▀ ███▐██▀
███ ███ ███ ███ ▄█████▀ ███ ███ ███▌ ███ ▄█████▀
███ ███ ███ ███ ▀▀█████▄ ▀█████████▀ ███▌ ███ ▀▀█████▄
███ ███ ███ ███ █▄ ███▐██▄ ███ ███ ███ █▄ ███▐██▄
███▌ ▄ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ▀███▄
█████▄▄██ ▀██████▀ ████████▀ ███ ▀█▀ ▄████▀ █▀ ████████▀ ███ ▀█▀
▀ ▀ ▀
Lockpick
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 eitherobject
or class name (string
) - The
Lockpick::call()
argument$args
now accepts single parameters w/oarray
wrapping (socall(..., $arg1)
is now valid and equivalent tocall(..., [ $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
- Written and copyrighted ©2014-2024 by Marcin Orlowski
- Open-sourced software licensed under the MIT license
- ASCII Art created using https://textkool.com