Download the PHP package m3m0r7/method-injector without Composer

On this page you can find all versions of the php package m3m0r7/method-injector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package method-injector

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.

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

DEMO

Quick start

It can be installed from the following.

How to use?

Easy example

To create a test double with MethodInjector, do the following

Calling a factory method returns an instance of the MethodInjector. inspect takes the first argument as the name of the class to make the test double, the name of the class The second argument can specify the condition to create the verification and test double, and the third argument can specify whether to inherit the original class. You can also call several inspect methods to create a test double of several classes at once.

Because the test double is generated in the namespace dedicated to MethodInjector, it basically does not pollute the global namespace.

Restrict the method for replacing.

You can also specify and restrict the method to be replaced by the MethodInjector of the class Inspector by specifying the method name. Method names are case-insensitive, according to the PHP specification.

Replace fields in the class

You may want to rewrite the default values of the fields in your class. You can also use replaceField to change the default value of a field. Of course, it is possible to change the field even if it is private or protected.

Replace constants in the class

You can use replaceConstant to rewrite a constant value in the same way as you can rewrite a field. Of course, this is also possible with private, even protected.

Output something when start to process the method

You may want to interrupt some processing at the start of the method execution. With MethodInjector, you can specify a before of the Condition class. It is possible to interrupt some processing at the start of execution. For example, it is useful when you want to measure the execution time of a single method.

Output something when finish to process the method

You can also specify the end of the method execution as well as the start. When it is finished, after is called.

Replace classes in the method

The MethodInjector can also replace a class that is instantiated in a method with another class using replaceInstance. This allows for use cases that are still under development, or where you want to replace a class with another one. It is also possible to replace it when reading with static or self.

Of course, even if you are reading a static method of a class, you can use replaceStaticCall to replace it with the following.

Mocking the method

You may want to create a test double when the method itself is in development, or when you want to test a test that returns a certain value, or when it is outside the scope of your testing interests. With MethodInjector it is also possible to create a test double for the method itself using replaceMethod.

Add a replacer

The MethodInjector provides several replacers beforehand, but you may want to add more replacers depending on the situation. In that case, you can also add a replacers. The replacers of MethodInjector is set as the default, but if the original replacers is added, the Note that the replayer provided by MethodInjector is not used by default, so it should be re-specified as an argument.

If you use addReplacer, you can use the replacers provided by MethodInjector as is. The replacers acts like a reduce, applying to the AST parsed nodes in the specified order.

Change the inspector

The inspector of the MethodInjector only provides the bare minimum required functionality and may have obstacles such as not being able to use it on projects with a history. In that case, you may want to replace the inspector itself in order to test it. Of course, it is also possible to implement the original Inspector. In that case, you should extend Inspector, which is provided by MethodInjector by default.

To mock defined constants, fields and methods in the class or trait.

The MethodInjector performs static analysis of the methods and fields defined in the parent class, as well as the traits, and decomposes them into ASTs and mocks them. This feature allows you to focus on writing the test in front of you instead of having to think about how to mock the methods of the parent classes and traits when creating a test double. Also, since MethodInjector refers to a class recursively, it is possible to mock not only the parent class but also the parent class of the parent class, or if it is a trail, a trail defined in a trail.

Builder

If you are using MethodInjector, you may feel that the amount of code to make a mock is long. Therefore, the MethodInjector has a MethodInjector object, a builder class called ConditionBuilder is provided to make it easier to create objects. The ConditionBuilder mocks the methods and properties of the parent class and all traits by default.

It is possible to write the above. Also, the above is equivalent to the following.

The range of methods applied by ConditionBuilder is * by default, that is, all methods. However, you may want to mock only some of the methods. In that case, you can use the group to specify a method to be mutable.

In this case, all the date functions in doSomething are mocked.

In the above case, the date executed with doSomething1 will return 9999-99-99 and the date executed with doSomething2 will return 0000-00-00.

License

MIT


All versions of method-injector with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
nikic/php-parser Version ^4.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package m3m0r7/method-injector contains the following files

Loading the files please wait ....