Download the PHP package fansipan/mock-client without Composer

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

Fansipan Mock HTTP Client

Latest Version on Packagist Github Actions Codecov Total Downloads

Fansipan mock HTTP client is PSR-18 Client implementation that provides ability send test requests with fake responses.

The MockClient accepts Psr\Http\Message\ResponseInterface which when used on a request, will respond with a fake response without actually sending a real request to the web. This helps speed up tests massively and can help you test your application for different API response scenarios, like a 404 error or 500 error.

Installation

You can install the package via composer:

Usage

Creating Mock Client

By default MockClient will always return 200 - OK status code with empty body. If you want to return a different response, create a Psr\Http\Message\ResponseInterface instance and pass it as constructor argument. You can use MockResponse to quickly create a fake response.

Faking Response

The MockResponse class is used to create fake responses. It can accept a body, status, and headers. These properties will be populated in the fake response. The response body accepts an array for a JSON body or plain strings to simulate other responses, like XML.

You don't have to add ['Content-Type' => 'application/json'] header if your body is array.

If you have fixture data and don't want to create response manually, you can also use fixture method to create a response.

If your fixture is a JSON or XML file, there's no need to add the Content-Type header manually.

Faking Response Sequences

Sequence faking allows you to define a number of fake responses in a specific order. It will pull out the next response in the sequence, removing it from the sequence. Each response can only be consumed once. When all the responses in a response sequence have been consumed, any further requests will cause the response sequence to throw an exception.

Faking Specific URLs

Alternatively, you may use ScopingMockClient and pass an array to the constructor argument. The array's keys should represent URL patterns that you wish to fake and their associated responses. The * character may be used as a wildcard character. Any requests made to URLs that have not been faked will actually be executed.

Sequence Faking also works with ScopingMockClient

Adding Expectations

When using faking responses, it's important to be able to check that a specific make request was sent and with the correct data, and headers. MockClient & ScopingMockClient provide you with various ways to add expectations to your tests.

Available Expectations

The assertSent / assertNotSent are the two most powerful expectation methods. They can accept a URL pattern or even a closure where you define if a request/response is what you expect.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of mock-client with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2.5|^8.0
php-http/discovery Version ^1.14
psr/http-client Version ^1.0
psr/http-factory 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 fansipan/mock-client contains the following files

Loading the files please wait ....