Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/edmondscommerce/mock-server

Mock Web Server and Router - great for testing PHP projects that interact with remote web services and web sites
https://github.com/edmondscommerce/mock-server

composer html mock-server php testing

Last synced: about 2 months ago
JSON representation

Mock Web Server and Router - great for testing PHP projects that interact with remote web services and web sites

Awesome Lists containing this project

README

        

# Mock Web Server and Router
## By [Edmonds Commerce](https://www.edmondscommerce.co.uk)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a791bb0914a243749b3c9918c70af2da)](https://www.codacy.com/app/edmondscommerce/mock-server?utm_source=github.com&utm_medium=referral&utm_content=edmondscommerce/mock-server&utm_campaign=Badge_Grade)
[![Build Status](https://travis-ci.org/edmondscommerce/mock-server.svg?branch=master)](https://travis-ci.org/edmondscommerce/mock-server)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/edmondscommerce/mock-server/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/edmondscommerce/mock-server/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/edmondscommerce/mock-server/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/edmondscommerce/mock-server/?branch=master)

## Installation

### PHP 7.0

Install via composer

`composer require edmondscommerce/mock-server:~1 --dev`

### PHP 7.1+

Install via composer

`composer require edmondscommerce/mock-server:~2 --dev`

## Usage

To start the web server, you need to instantiate the `\EdmondsCommerce\MockServer\MockServer` and call `startServer`

```php
startServer();
```

### Configuration

When using the Factory, the configuration for the MockServer is pulled from `MockServerConfig` which in turn checks for values in the `$_SERVER` superglobal - generally populated with any thing that has been exported from your environment.

The default values are fairly sensible though. Based upon the project root, the default configuration expects you to have a [`tests`](./tests) folder which in turn contains a [`MockServer`](./tests/MockServer) folder. Inside the MockServer folder we expect a `router.php` file and a `htdocs` folder which contains static assets to be served directly.

**Note -** this is exactly as it has been configured in this library.

### Router

An example of a basic router set up can be found in [router.php](./tests/MockServer/router.php)

The router file should contain an instance of the `\EdmondsCommerce\MockServer\StaticRouter` which is a wrapper around
Symfony's router class. The file should load the Composer autoloader and create the static router before registering routes for different URIs.

The router supports static file routes, callback routes and text routes.

**Note -** there are helpful includes [routerTop.php](./src/include/routerTop.php) and [routerBottom.php](./src/include/routerBottom.php) which handle some basic boilerplate for you.

#### Template

Here is a template router for you to start with:

```php