kidfund / monkey-patcher
Get tricky with php objects in test
1.0.1
2018-12-14 14:23 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2026-02-11 18:26:30 UTC
README
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.