PHPackages                             jimthunderbird/phlexmock - 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. jimthunderbird/phlexmock

ActiveLibrary

jimthunderbird/phlexmock
========================

A tool to allow developers to mock any php class by redefining class methods

4141PHP

Since Apr 19Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

phlexmock
=========

[](#phlexmock)

A tool to allow developers to redefine PHP class methods for testing purposes.

Traditionally when we do unit test in PHP using tools like PHPUnit, we would need to create mock classes or mock objects in order to simulate the testing context. Since PHP, unlike other scripting languages for example Ruby, does not support method reopenning, this makes the object and class mocking a bit cumbersome. Phlexmock aims to bring the method reopenning power to PHP.

Phlexmock uses the power of spl\_autoload\_register function in PHP together with static code analysis tool PHP-Parser to achieve the method reopenning feature.

Warning: While method reopening is great, we recommend using phlexmock for unit testing and mocking only, using in production code will have a performance hit.

\##Installation Add phlexmock to your composer.json

```
{
    "require-dev": {
        "jimthunderbird/phlexmock": "*"
    }
}

```

\##Examples

- [Reopenning methods in a class](#example-01)
- [Use this keyword in the reopened methods](#example-02)
- [Use self keyword in the reopened methods](#example-03)

\###Example 01 ####Reopenning methods in a class ####Let's say we have a class named User.php in our current path and it looks like the following:

```
