Download the PHP package karriere/mocky without Composer

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

Mocky - A simple API mock server

Test Lint

Mocky is a simple API mocking solution written in PHP based on the Slim Framework.

Installation

You can either create a new mock api by using the mocky-template as a starting point

or add mocky as a dependency to your project.

Configuration

With mocky you can define your test cases via JSON. The configuration consists of two file types:

A test file contains all your test endpoints (grouped by the request method) and references one or multiple mock files. The mock file defines the mock data to return. This seperation allows you to reuse mock data over multiple tests.

Writing a test file

A test file is stored in the tests folder and has the following basic structure

The test file is a map of request methods (GET, POST, PUT, DELETE, ...). Each request method entry contains a map of endpoints as key and the endpoint definition as value.

Each request definition must define a content-type and a mock field. The mock field is a reference to the mock data file to deliver.

Example:

Structuring your tests

To be able to structure your test json files by feature a test can be stored in a subfolder.

For example to store multiple tests for a user feature you can create a test under tests/user/a-test.json. This test has the following setup route /setup/{scope}/user/a-test.

Writing a mock file

A mock file contains an array of mock responses. Each mock response must have a status and a response field. The status field defines the HTTP status code and the response field the API response in json format.

Use example/mocks/users/list-users.json as a reference.

The mock file uses an array of mock response because you often need different data on subsequent requests.

Lets consider a simple example. You want to test a user feature. Your frontend makes an GET api call to /users and receives 2 user entries. Then the test sends a POST to /users to create a new user and then executes the GET /users again. In the second case 3 user entries should be returned.

Using mocky

To deliver your mock data you need to setup your test case. To do so you call the mocky setup endpoint /setup/{scope}/{test-name}.

The scope variable is needed to allow parallel access to mocky from different applications. The default scope is called default.

Example: http://localhost:8888/setup/default/user-simple

This endpoint call will setup the user-simple test case defined in tests/user-simple.json.

To be able to use another scope you simply call the setup route with your custom scope name and on each real API call you need to include a request header called Mocky-Scope with the custom scope name as value.

Mocky Demo

Webserver Setup

Built-In PHP Webserver (local development)

Nginx

Apache

Your document root points to the public directory and you need to make sure that mod_rewrite is available.

License

Apache License 2.0 Please see LICENSE for more information.


All versions of mocky with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 | ^8.0
slim/slim-skeleton Version ^4.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 karriere/mocky contains the following files

Loading the files please wait ....