Download the PHP package nivseb/php-mock-server-connector without Composer

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

PHP Mock Server Connector

Tests Supported PHP Version Latest Stable Version Total Downloads

PHP Mock Server Connector is a tool that make it easy to use the MockServer in php based tests. The method of utilisation is based on the Mockery project. The creation of Expectations is therefore very similar.

Installation

  1. To install PHP Mock Server Connector you can easily use composer.

  2. You need a running instance of the MockServer.
  3. Existing test setup for php based test. For example a setup with PHPUnit.

Usage

Setup in your tests

After the installation, you can start to use the connector in your tests. The first step is now to connect to the MockServer instance, for that add the following code to your test. This can be done in a single test case or in another setup part for your tests (like the setUp Method in PHPUnit tests). But this need the first step that is executed.

The next part you must add is this code. It must be placed after your tests, for example in the tearDown method in PHPUnit tests. This code will verify the expectations in your MockServer instance.

For PHPUnit tests the package comes with the trait UseMockServer. This adds two methods to the test class initMockServer and closeMockServer. The method closeMockServer is called in the tearDown from the phpunit test. Now your integration can look like this:

Create expectation

After you finished the setup for your test cases, you can now add expectations to you tests. First you must create an instance for an endpoint. This endpoint is the route entry point for a mock. This design allow you that you can build mocks for different other external apis with only one MockServer instance.

For every request that you want to mock you call now the allows method. That give you a PendingExpectation, this will create the expectation at your MockServer instance on destruct or with the call of the run method.

The expectation will be verified on the close call for the mock server, see for that Setup in your tests.

Supported request expectations

methods and uri

You can create expectations for methods and paths in all combinations that are possible with the MockServer.

Parameters

To add a check for parameters to your expectations, you can call the method withPathParameters or withQueryParameters.

Request Headers

You can add expected headers in the request by calling the withHeaders method on the pending expectation.

Body

A request body can be expected with a call of the withBody method. The Body can be sent as array or string.

Multiple calls

With the times method you can define that a request should be executed multiple times.

Response

The response for an expectation can be defined in with the andReturn method. For the response you can define the status code, body and headers.

Defaults

Every expectation comes with some default values. This example will define, that the request is executed one time and return an empty response with the status code 200.

Example

Here you have an example for a full functional PHPUnit test case.


All versions of php-mock-server-connector with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/guzzle Version ^7.8
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 nivseb/php-mock-server-connector contains the following files

Loading the files please wait ....