kidfund/monkey-patcher

Get tricky with php objects in test

1.0.1 2018-12-14 14:23 UTC

This package is auto-updated.

Last update: 2024-11-11 15:52:51 UTC


README

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.