PHPackages                             jimigrunge/invoke-private-methods - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jimigrunge/invoke-private-methods

ActiveLibrary[Testing &amp; Quality](/categories/testing)

jimigrunge/invoke-private-methods
=================================

This is a class to aid in unit testing of private methods.

3.0.1(3y ago)327.3k↓42.3%MITPHPPHP ^8.1

Since Mar 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jimigrunge/invoke-private-methods)[ Packagist](https://packagist.org/packages/jimigrunge/invoke-private-methods)[ RSS](/packages/jimigrunge-invoke-private-methods/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (11)Used By (0)

Invoke Private Methods
======================

[](#invoke-private-methods)

[![Latest Stable Version](https://camo.githubusercontent.com/c24bead95bcb2c583e34c23a41808db9f5544206baf58e5364d32f9869eaf7e3/68747470733a2f2f706f7365722e707567782e6f72672f6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f64732f762f737461626c65)](https://packagist.org/packages/jimigrunge/invoke-private-methods)[![Build Status](https://camo.githubusercontent.com/c1296a6c57c0580dbbbe4e5fd6d2e248810c95f24da2297c342de800afd50860/68747470733a2f2f7472617669732d63692e6f72672f6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f64732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jimigrunge/invoke-private-methods)[![Coverage Status](https://camo.githubusercontent.com/8d381da1d5e2188cc58080247355a570f2a6993a4fc2f5d2a687b30c90a0c29a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f64732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/jimigrunge/invoke-private-methods?branch=master)[![License](https://camo.githubusercontent.com/b5ed2bde77cbd3b439875609c062956247fdc5f0c4e21e7f9a5081b8125cfbfe/68747470733a2f2f706f7365722e707567782e6f72672f6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f64732f6c6963656e7365)](https://packagist.org/packages/jimigrunge/invoke-private-methods)[![Total Downloads](https://camo.githubusercontent.com/daafe82f1e1d613ed5524d18bb99e03a505fb68dac03624b725b48ff7ccb02fe/68747470733a2f2f706f7365722e707567782e6f72672f6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f64732f646f776e6c6f616473)](https://packagist.org/packages/jimigrunge/invoke-private-methods)[![](https://camo.githubusercontent.com/bdf33548b3bf011b21f302d643afd87e5efea316cf892e83d52170a006a1e080/68747470733a2f2f7265706f73732e6865726f6b756170702e636f6d2f3f706174683d6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f6473)](https://camo.githubusercontent.com/bdf33548b3bf011b21f302d643afd87e5efea316cf892e83d52170a006a1e080/68747470733a2f2f7265706f73732e6865726f6b756170702e636f6d2f3f706174683d6a696d696772756e67652f696e766f6b652d707269766174652d6d6574686f6473)[![This is a forkable respository](https://camo.githubusercontent.com/e22d060f09fbd60a85b246078e4f17188adf378fbf3170d4795333c14855295f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666f726b61626c652d7965732d627269676874677265656e2e737667)](https://basicallydan.github.io/forkability/?u=jimigrunge&r=invoke-private-methods)

This is a class to aid in unit testing of private methods. It can be used either as a stand alone class or as a trait and called either programmatically or statically.

Although testing of private methods is not recommended in most cases, sometimes it is necessary. Such as to insure correct calculations in a protected method aside form the methods that currently utilize it. Hence this repository.

***Note:**I mainly use PhpUnit for all testing so I make no guaranties when it comes to other testing utilities as I have not utilized them yet.*

Installation
------------

[](#installation)

```
$ composer require jimigrunge/invoke-private-methods

```

### Note on version requirements

[](#note-on-version-requirements)

If you are using a version of PHP less than 8.1 please use the 2.0 branch If you are using a version of PHP less than 7.1 please use the 1.0 branch

```
$ composer require jimigrunge/invoke-private-methods:~1.0

```

Usage
-----

[](#usage)

### class InvokePrivateMethod

[](#class-invokeprivatemethod)

This class can be used to test private and protected methods.

Once you include the class with the 'use' statement, you can utilize it on one of two ways. You can either create an instance of `InvokePrivateMethod` and call `invokeMethod`, as in `testMyMethod()`, or call `invoke()` statically as in `testMyMethodStatically()`

```
