PHPackages                             m3m0r7/method-injector - 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. m3m0r7/method-injector

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

m3m0r7/method-injector
======================

The library enhance mocking your test.

0.2.0(6y ago)1021MITPHPPHP &gt;=7.3

Since Apr 10Pushed 6y ago3 watchersCompare

[ Source](https://github.com/m3m0r7/method-injector)[ Packagist](https://packagist.org/packages/m3m0r7/method-injector)[ RSS](/packages/m3m0r7-method-injector/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (8)Used By (0)

What is MethodInjector?
=======================

[](#what-is-methodinjector)

`MethodInjector` is an open source software project that provides strong support for generating test doubles for methods, fields, and constants in the target class. For example, the `MethodInjector` can do the following.

- Replace a function in a method with a mock function or an unnamed function and execute it.
- Rewrites the default value of the specified field
- Test by rewriting the value of a constant
- Mock the return value of a specific method itself
- Process can be inserted at the start and end of method execution

`MethodInjector` parses the original class file and reconstructs the class. Therefore, you can easily create test doubles even if the original class is not inheritable (i.e., `final` is defined). However, it is also possible to inherit the original class and create a test double by inheriting the class that the declaration expects.

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

[](#documentation)

- [日本語](./readme-ja.md)
- English

DEMO
====

[](#demo)

[![](docs/demo.gif)](docs/demo.gif)

Quick start
===========

[](#quick-start)

It can be installed from the following.

```
composer require --dev m3m0r7/method-injector

```

How to use?
===========

[](#how-to-use)

Easy example
------------

[](#easy-example)

To create a test double with `MethodInjector`, do the following

```
