Download the PHP package tijmenwierenga/guzzle-mock-handler without Composer

On this page you can find all versions of the php package tijmenwierenga/guzzle-mock-handler. 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 guzzle-mock-handler

Better Guzzle Mock Handler

Build status

Buy us a tree

While the Guzzle HTTP client ships with a basic mock handler it might not be powerful enough in certain situations. For example, when your requests don't arrive in an expected order. That's where this Mock Handler might come in handy.

You'll be able to set expectations for incoming requests. When an expectation is met a predefined response will be returned.

Requirements

Minimum PHP version is 7.4.

Installation

Usually you'll want to install this package as a development dependency:

If you want to install the package for production:

Usage

Instantiating the handler

The Mock Handler works in a similar way as the official Guzzle Mock Handler. Add it as the handler for the HandlerStack and all requests will passed to the handler.

Adding expectations

Use the ExpectationBuilder in order to set request expectations:

Whenever a new request is passed to the Mock Handler it will look if there is an expectation that matches the request. On a match, the handler will return the corresponding response. In the example above the Mock Handler will return an empty 200 OK response on every GET request.

When no expectation matches the request, the Mock Handler will throw a TijmenWierenga\Guzzle\Mocking\UnexpectedRequestException.

Invocation limits

You might want to limit the amount of invocations for an expectation. By default, there is no invocation limit set. The ExpectationBuilder is capable of limiting the amount of times a response can be returned. This can be achieved through the withMaxInvocations() method on the builder:

In the example above, the response will only be returned once, even when it satisfies the defined condition. The handler will throw a TijmenWierenga\Guzzle\Mocking\UnexpectedRequestException on any invocation after the first.

Built-in conditions

The package ships with a few built-in conditions. These conditions can be used to create expectations in an expressive way.

All

While it's perfectly valid to pass a callable and match multiple conditions, it's more expressive to use the All condition. This condition accept any amount of conditions that all need to match based on the current request.

Any

This condition accepts any number of conditions. When any of the supplied conditions is met, the pre-defined response will be returned.

More conditions can be found in the Conditions-folder.

Treeware

You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here offset.earth/treeware

Read more about Treeware at treeware.earth


All versions of guzzle-mock-handler with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/promises Version ^1.3
php Version ^7.4|^8.0
psr/http-message Version ^1.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 tijmenwierenga/guzzle-mock-handler contains the following files

Loading the files please wait ....