All Projects → karriereat → mocky

karriereat / mocky

Licence: other
Mocky is a simple API mocking solution written in PHP.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to mocky

Wiremock.net
WireMock.Net is a flexible library for stubbing and mocking web HTTP responses using request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Stars: ✭ 408 (+1306.9%)
Mutual labels:  mock-server, mocking
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (+31.03%)
Mutual labels:  mock-server, mocking
Wiremock
A tool for mocking HTTP services
Stars: ✭ 4,790 (+16417.24%)
Mutual labels:  mock-server, mocking
speakeasy
A tool for creating Go web servers which can be embedded in iOS and Android apps.
Stars: ✭ 27 (-6.9%)
Mutual labels:  mock-server, mocking
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+155.17%)
Mutual labels:  mock-server, mocking
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+16558.62%)
Mutual labels:  mock-server, mocking
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+1744.83%)
Mutual labels:  mock-server, mocking
Mockstar
Demo project on How to be a Mockstar using Mockito and MockWebServer.
Stars: ✭ 53 (+82.76%)
Mutual labels:  mock-server, mocking
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+11789.66%)
Mutual labels:  mock-server, mocking
Prism
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
Stars: ✭ 2,484 (+8465.52%)
Mutual labels:  mock-server, mocking
open-api-mocker
A mock server based in OpenAPI Specification
Stars: ✭ 58 (+100%)
Mutual labels:  mock-server, mocking
wiremock
A tool for mocking HTTP services
Stars: ✭ 5,239 (+17965.52%)
Mutual labels:  mock-server, mocking
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+634.48%)
Mutual labels:  mock-server, mocking
better-mock
Forked from Mockjs, Generate random data & Intercept ajax request. Support miniprogram.
Stars: ✭ 140 (+382.76%)
Mutual labels:  mocking
pactum
REST API Testing Tool for all levels in a Test Pyramid
Stars: ✭ 190 (+555.17%)
Mutual labels:  mock-server
jaymock-cli
Mock an API and generate fake JSON test data, right from the terminal.
Stars: ✭ 13 (-55.17%)
Mutual labels:  mocking
php-test-generator
Generate test cases for existing PHP files
Stars: ✭ 47 (+62.07%)
Mutual labels:  mocking
ynm3k
ynm3k.readthedocs.io
Stars: ✭ 20 (-31.03%)
Mutual labels:  mocking
mock-spy-module-import
JavaScript import/require module testing do's and don'ts with Jest
Stars: ✭ 40 (+37.93%)
Mutual labels:  mocking
umock-c
A pure C mocking library
Stars: ✭ 29 (+0%)
Mutual labels:  mocking

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

composer create-project karriere/mocky-template /destination/path

or add mocky as a dependency to your project.

composer require karriere/mocky

Configuration

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

  • test files
  • mock files

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

{
  "REQUEST_METHOD": {
    "ENDPOINT": {
        "content-type": "application/json",
        "mock": "mock-file.json"
    }
  }
}

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:

{
  "GET": {
    "/users": {
      "content-type": "application/vnd.api+json",
      "mock": "users/list-users.json"
    },
    "/users/1": {
      "content-type": "application/vnd.api+json",
      "mock": "users/single-user.json"
    }
  }
}

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)

php -S localhost:8888 -t public public/index.php

Nginx

server {
    listen 80;
    server_name mocky.example.com;
    index index.php;
    error_log off;
    access_log off;
    root /path/to/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].