Skip to content

Kidfund/MonkeyPatcher

Repository files navigation

MonkeyPatcher

Latest Version on Packagist Software License Build Status StyleCI Total Downloads

Access private functions and properties of PHP classes. Primarily used to muck with things under test.

Install

Via Composer

$ composer require kidfund/monkey-patcher

Usage

Note: If you are using this, you may have a broken pattern somewhere. Either in your main code or in test-land. But, sometimes you need it!

Setup

Add the trait to your test

class MonkeyPatcherUnitTest extends PHPUnit_Framework_TestCase
{
    use MonkeyPatcher;

Access a private function

$this->invokeMethod($object, 'do', ['something']);

Set a private property

$this->setProperty($object, 'msg', 'hello');

Get a private property

$this->getProperty($object, 'msg');

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.