PHPackages                             lapistano/proxy-object - 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. lapistano/proxy-object

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

lapistano/proxy-object
======================

A library that makes it much easier to generate a proxy of your system under test (SUT)

v2.1.1(11y ago)4225.6k↓50%4[2 issues](https://github.com/lapistano/proxy-object/issues)[1 PRs](https://github.com/lapistano/proxy-object/pulls)8Apache 2.0PHPPHP &gt;=5.3.2

Since May 22Pushed 8y ago2 watchersCompare

[ Source](https://github.com/lapistano/proxy-object)[ Packagist](https://packagist.org/packages/lapistano/proxy-object)[ Docs](http://www.github.com/lapistano/proxy-object)[ RSS](/packages/lapistano-proxy-object/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (8)

=========== ProxyObject
=======================

[](#proxyobject)

Initiated by Thomas Weinert back in 2008 I picked up his work and completed, extended, and tested it. The outcome is this little library making it much easier to generate a proxy of your system under test (SUT). Another thought on this library was, that it should be very easy to use if you know the way to mock classes and methods in PHPUnit. Proxy-object has almost the same API, but does not change the behavior of the proxied class/method. The only purpose is to expose hidden (protected &amp; private) methods and members.

Current travis status: [![Build Status](https://camo.githubusercontent.com/1159baf67f3524c2e81595ba83a3825fe61cda45f668ad8a8ea9ce04a29ce695/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6c6170697374616e6f2f70726f78792d6f626a6563742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/lapistano/proxy-object)

Installation
============

[](#installation)

Thanks to the feedback of [beberlei](https://github.com/beberlei) the source is now PSR-0 compatible. There is no specific installation routine to be followed. Just clone or checkout the source into to your project and use it. In case you don't use a [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compatible autoloader, you only have to add the `bootstrap.php` into your bootstrap or autoloader.

Composer
--------

[](#composer)

Add the following lines to your `composer.json` file and update your project's composer installation.

```
{
    "require-dev": {
        "lapistano/proxy-object": "2.*"
    }
}
```

This composer configuration will checkout the sources tagged as the 2nd release. In case your want the 'cutting eadge' version replace '2.\*' by 'dev-master'. But be alarmed that this might be broken sometimes.

**NOTE:**In case you do not know what this means the [composer project website](http://getcomposer.org) is a good place to start.

Github
------

[](#github)

Thus I recommend the composer way to make proxy-object a dependency to your project. The sources are also available via github. Just clone it as you might be familiar with.

```
$ git clone git://github.com/lapistano/proxy-object.git
```

Usecases
========

[](#usecases)

1. Exposing invisible Methods

---

One of the main purpose of this library is to expose invisible (private or protected) methods to the SUT. To do so use just create a new ProxyBuilder object and pass the method to be exposed.

```
$proxy = new \lapistano\ProxyObject\ProxyBuilder('myClass');

// generate and configure proxied object
$proxiedObject = $proxy
    ->setConstructorArgs(array('Argument1', 'Argument2'))
    ->setMethods(array('myMethod'))
    ->getProxy();

// invoke proxied method
$proxiedObject->myMethod();
```

2. Exposing invisible Members

---

Another purpose of this library is to expose invisible members not reachable via a setter. This is to prevent you from writing setter methods just for the purpose of unit testing. Use the `setProperties()` method to archieve.

```
$proxy = new \lapistano\ProxyObject\ProxyBuilder('myClass');

// generate and configure proxied object
$proxiedObject = $proxy
    ->setProperties(array('myMember'))
    ->getProxy();

// change content proxied member
$proxiedObject->myMember = 'another value';
```

Despite the fact that it is possible to expose private members by naming them in the setProperties array, generating a proxy object without the property declaration will only expose protected members. This is because I am not a big fan of exposing too much from a class. If someone thinks this should be changed, I would be more than happy to discuss this topic.

3. Creating a proxied object without calling the constructor

---

Sometimes it is necessary to supress the invokation of the defined constructor. Therefore I followed the API of PHPunits MockBuilder and added the `disableOriginalConstructor()` method.

```
$proxy = new \lapistano\ProxyObject\ProxyBuilder('myClass');

// generate and configure proxied object
$proxiedObject = $proxy
    ->disableOriginalConstructor()
    ->getProxy();

// change value of proxied member
$proxiedObject->myMember = 'another value';
```

Ease access to the proxy-object in your test suite
==================================================

[](#ease-access-to-the-proxy-object-in-your-test-suite)

Since I am really lazy ;) and I really like convenience I extended the `PHPUnit_Framework_TestCase` class and added the following method.

```
/**
 * Provides a ProxyBuilder object.
 *
 * @param string $classname
 * @return lapistano\ProxyObject\ProxyBuilder
 */
protected function getProxyBuilder($classname) {
    return new \lapistano\ProxyObject\ProxyBuilder($classname);
}
```

Every of your test cases should now extend your own extended test case class so you can create a new proxy builder by just calling `$this->getProxyBuilder('\\my\\namespace\\myclass');`. Used in one of the examples above it will look like this.

```
// generate and configure proxied object
$proxiedObject = $this->getProxyBuilder('myClass')
    ->disableOriginalConstructor()
    ->getProxy();

// change value of proxied member
$proxiedObject->myMember = 'another value';
```

Documentation
=============

[](#documentation)

Since there is a exhausting documentation of the API in the source code, I decided not to write a separate one. Use [phpDocumentor](http://phpdoc.org) to extract and generate your own documentation. I added a phpdoc.example.ini in the doc/config folder. Follow the instructions in the `doc/config/README` to setup the generation of the documentation.

Limitations
===========

[](#limitations)

As you might expect there are also some limitations this library has to deal with. This limitations are not introduced by this implementation, but are limitations which come from PHP. So it is not possible to expose methods marked as final or static.

Future stuff
============

[](#future-stuff)

- Improve error messages (e.g. by telling why a method/member could not be exposed)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 89.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~390 days

Total

3

Last Release

4330d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce9845fe6fb3492df8bd632b865d4ff303051cf68e28282f34bf5cc3372d9150?d=identicon)[lapistano](/maintainers/lapistano)

---

Top Contributors

[![lapistano](https://avatars.githubusercontent.com/u/95115?v=4)](https://github.com/lapistano "lapistano (69 commits)")[![gjerokrsteski](https://avatars.githubusercontent.com/u/503822?v=4)](https://github.com/gjerokrsteski "gjerokrsteski (3 commits)")[![micha149](https://avatars.githubusercontent.com/u/298880?v=4)](https://github.com/micha149 "micha149 (2 commits)")[![bashofmann](https://avatars.githubusercontent.com/u/243056?v=4)](https://github.com/bashofmann "bashofmann (1 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (1 commits)")[![hairmare](https://avatars.githubusercontent.com/u/116588?v=4)](https://github.com/hairmare "hairmare (1 commits)")

---

Tags

testingphpunitproxy-object

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lapistano-proxy-object/health.svg)

```
[![Health](https://phpackages.com/badges/lapistano-proxy-object/health.svg)](https://phpackages.com/packages/lapistano-proxy-object)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[codedungeon/phpunit-result-printer

PHPUnit Pretty Result Printer

1.2k8.8M397](/packages/codedungeon-phpunit-result-printer)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

57026.3M456](/packages/dg-bypass-finals)[phpunit/phpunit-selenium

Selenium Server integration for PHPUnit

59610.9M150](/packages/phpunit-phpunit-selenium)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
