Download the PHP package icecave/isolator without Composer

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

Isolator

Build Status Code Coverage Latest Version

Isolator simplifies testing of classes that make use of global functions by treating all global functions as methods on an "isolator" object.

composer require icecave/isolator

Rationale

A large number of PHP extensions (and the PHP core) implement their functionality as global functions. Testing classes that use these functions quickly becomes difficult due to the inability to replace them with test doubles.

Isolator endeavours to solve this problem by acting as a proxy between your class and global functions. An isolator instance is passed into your object as a dependency and used in place of any global function calls that you may want to replace when testing.

Example

The following class makes use of file_get_contents() to read the contents of a file.

Despite the simplicity of the example, the class immediately becomes difficult to test due to it's reliance on the filesystem. In order to test this class you might be inclined to set up some static fixtures on disk, make a temporary directory when your test suite is set up or perhaps even use a virtual filesystem wrapper.

Isolator provides a fourth alternative. Given below is the same example rewritten using an Isolator instance.

MyDocument now takes an instance of Isolator in it's constructor. It would be a pain - and unnecessary - to create a new Isolator instance every time you construct an object in your production code, so a shared instance is made accessible using the Isolator::get() method. If a non-null value is passed to Isolator::get() it is returned unchanged, allowing you to replace the isolator when necessary.

MyDocument::getContents() is also updated to use the isolator instance rather than calling the global function directly. The behavior of MyDocument remains unchanged but testing the class is easy, as will be shown in the example test suite below.

Note: The test below is written for the PHPUnit testing framework, using Phake for mocking. Phake provides a more flexible alternative to PHPUnit's built-in mock objects.

The test verifies the behavior of the MyDocument class completely, without requiring any disk access.

Using an isolator is most helpful when testing code that uses functions which maintain global state or utilize external resources such as databases, filesystems, etc. It is usually unnecessary to mock out deterministic functions such as strlen(), for example.

Isolator Trait

In PHP 5.4 and later, it is also possible to use IsolatorTrait to bring an isolator into your class. The isolator instance is accessed using $this->isolator() and can be set via $this->setIsolator().

Language Constructs

Isolator can also be used to invoke the following function-like language constructs:

Peculiarities

Several of PHP's core global functions have some peculiarities and inconsitencies in the way they are defined. Isolator attempts to accomodate such inconsistencies when possible, but may have issues with some native C functions for which parameter reflection information is non-standard or incorrect. These issues seem to be largely rectified as of PHP 5.6.


All versions of isolator with dependencies

PHP Build Version
Package Version
Requires php Version >=5.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 icecave/isolator contains the following files

Loading the files please wait ....