Download the PHP package idimsh/php-internals-mocker without Composer

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

PHP Internal function mocker

Latest Version on Packagist Build Status Coverage Status Quality Score Total Downloads PHP Version

Util to allow mocking PHP Internal function calls in tests.

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:

Usage

This mocker is intended to be used in Unit Tests, assume a class like this:

Has to be tested with unit tests for method openConnction(). A PhpUnit test case would be like:

We do not really want to open a connection especially in unit tests, so this mocker can avoid the call to the native PHP fsockopen() and replace it with a call to a defined callback like:

Methods Manual

1- PhpFunctionSimpleMocker::reset(): should be called in PhpUnit TestCase setUp() method or at the beginning of a test method.

2- PhpFunctionSimpleMocker::add(): to be called after reset() to register the callbacks expected to native functions, signature:

It can be called multiple times with the same $internalFunctionName and different $callback for each call in the order expected.
The $beingCalledFromClass expects a class FQN which from the namespace will be extracted and the function will be registered at that namespace.

3- PhpFunctionSimpleMocker::phpUnitAssertNotEnoughCalls($testCase): To be called from PhpUnit test method after all the assertions have been registered (last line), this method will make sure that the minimum number of calls has been reached.

4- PhpFunctionSimpleMocker::assertPostConditions(?$testCase): Alternative to PhpFunctionSimpleMocker::phpUnitAssertNotEnoughCalls($testCase) and to be called from PhpUnit TestCase method: assertPostConditions(), instead of calling the previous method at the end of each Test method, a one call passing the TestCase is enough to assert minimum count.

Usage Conditions

The native PHP function call that is to be mocked and replaced with a callback needs to be (All must apply):

Limitations

Quickly:

Credits

Alternatives

There is a solution I havn't tested yet php-mock

License

Released under MIT License - see the License File for details.


All versions of php-internals-mocker with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1
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 idimsh/php-internals-mocker contains the following files

Loading the files please wait ....