Download the PHP package jeremeamia/func-mocker without Composer

On this page you can find all versions of the php package jeremeamia/func-mocker. 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 func-mocker

PHP FuncMocker

FuncMocker – Mocking PHP functions like a... punk rocker?

Latest Version on Packagist Build Status Total Downloads

Allows you to overwrite (i.e., mock) global functions used within a given namespace for the purposes of testing.

There are two main use cases I developed this for:

  1. When you are testing objects that call non-deterministic functions like time() and rand(), and you need these functions to return deterministic values for the sake of the test.
  2. When you are working with code where you have objects that must make calls to functions. This is pretty common in legacy codebases that were not previously object-oriented in nature. For example, if you're project has a function called db_add() that you end up using in an object in your model layer, you might want to "mock" that function when you are testing so you don't actually make calls to the database in your unit tests.

The simple technique behind this code is described in this blog post by Fabian Schmengler. Basically, it involves taking advantage of PHP's namespace resolution rules.

Install

Via Composer

Usage

Let's you have a RandomNumberGenerator class in the namespace, My\App, that calls the global function rand(). You could overwrite the usage of rand() for that particular namespace by using FuncMocker.

Longer Example

Assume there is a class that uses the global function (e.g., time()) that you'd like to mock.

Here is an example of a PHPUnit test that uses FuncMocker to mock time() to return a fixed value, making it much easier to write a test.

Disabling and Re-Enabling

FuncMocker also lets you disable mocks you've setup, in case you need the function to behave normally in your some of your tests.

Limitations

  1. The function to be mocked must be used in a namespace other than the global namespace.
  2. The function to be mocked must not be referenced using a fully-qualified name (e.g., \time()).

Testing

Credits

Alternatives

License

The MIT License (MIT). Please see License File for more information.


All versions of func-mocker with dependencies

PHP Build Version
Package Version
Requires php Version ~5.6|~7.0
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 jeremeamia/func-mocker contains the following files

Loading the files please wait ....