Download the PHP package amorpro/soft-mocks without Composer

On this page you can find all versions of the php package amorpro/soft-mocks. 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 soft-mocks

SoftMocks

The idea behind "Soft Mocks" - as opposed to "hardcore" mocks that work on the level of the PHP interpreter (runkit and uopz) - is to rewrite class code on the spot so that it can be inserted in any place. It works by rewriting code on the fly during file inclusion instead of using extensions like runkit or uopz.

Usage

The thing that sets SoftMocks apart (and also limits their usage) is that they need to be initiated (along with all of their dependencies) at the earliest phase of the app launch. It's necessary to do it this way because you can't redefine the classes and functions that are already loaded into the memory in PHP. For an example of PHPUnit bootstrap presets, see src/bootstrap.php and example-phpunit/bootstrap.php.

SoftMocks don't rewrite the following system parts:

In order to add external dependencies (for example, vendor/autoload.php) to a bootstrap file, you need to use a wrapper:

After you've added the file via SoftMocks::rewrite(), all nested include calls will already be "wrapped" by the system itself.

You can see a more detailed example by executing the following command:

API (short description)

Initialize Soft Mocks (set phpunit injections, define internal mocks, get list of internal functions, etc):

Cache files are created in /tmp/mocks by default. If you want to choose a different path, you can redefine it as follows:

Redefine constant

You can assign a new value to $constantName or create one if it wasn't already declared. Since it isn't created using the define() call, the operation can be canceled.

Both "regular constants" and class constants like "className::CONST_NAME" are supported.

Redefine functions

Soft Mocks let you redefine both user-defined and built-in functions except for those that depend on the current context (see \QA\SoftMocksTraverser::$ignore_functions property if you want to see the full list), or for those that have built-in mocks (debug_backtrace, call_user_func* and a few others).

Definition:

Usage example (redefine strlen function and call original for the trimmed string):

Redefine methods

At the moment, only user-defined method redefinition is supported. This functionality is not supported for built-in classes.

Definition:

Arguments are the same as for redefineFunction, but $class is argument is introducted, and it's possible to work in non-strict mode ($strict = false). If non-strict mode is selected, then runkit behavior is emulated when class methods are redefined so that in addition to the $class method itself, its ancestor methods are also redefined.

As an argument, $class accepts a class name or a trait name.

Redefining functions that are generators

This method that lets you replace a generator function call with another \Generator. Generators differ from regular functions in that you can't return a value using "return"; you have to use "yield".

Restore values

The following functions undo mocks that were made using one of the redefine methods described above.

FAQ

Q: How can I prevent a specific function/class/constant from being redefined?

A: Use the \QA\SoftMocks::ignore(Class|Function|Constant) method.

Q: I can't override certain function calls: call_user_func(_array)?, defined, etc.

A: There are a bunch of functions that have their own built-in mocks which by default can't be intercepted. Here is an incomplete list of them:

So you can enable intercepting for them by call \QA\SoftMocks::setRewriteInternal(true) after require bootstrap, but be attentive. For example, if strlen and call_user_func(_array) is redefined, then you can get different result for strlen:

Q: How do I use Soft Mocks with PHPUnit?

A: You need to merge our pull request https://github.com/sebastianbergmann/phpunit/pull/2116 into your phpunit version or just take this branch. Soft Mocks will work even without any phpunit patches but you will see "unreadable" stack traces for failed tests and you will not be able to redefine classes and methods that are defined in tests themselves.

Q: Does Soft Mocks work with PHP7?

A: Yes. The whole idea of Soft Mocks is that it will continue to work for all further PHP versions without requiring a full system rewrite as it is for runkit and uopz.

Q: Does Soft Mocks work with HHVM?

A: It seems that Soft Mocks indeed works when using HHVM at the moment of writing this Q&A (HipHop VM 3.12.1 (rel)). We do not use HHVM internally so there can be some corner cases that are not covered. We appreciate any issues/pull requests regarding HHVM support.

Q: Why do I get parse errors or fatal errors like "PhpParser::pSmth is undefined"?

A: Soft Mocks uses custom pretty-printer for PHP Parser that does not seem to be compatible with all PHP Parser versions. Please use our vendored version until we found a way to get around that.


All versions of soft-mocks with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
nikic/php-parser Version 2.*
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 amorpro/soft-mocks contains the following files

Loading the files please wait ....