Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 days ago
JSON representation
Mock Web Server and Router - great for testing PHP projects that interact with remote web services and web sites
- Host: GitHub
- URL: https://github.com/edmondscommerce/mock-server
- Owner: edmondscommerce
- Created: 2018-03-06T15:44:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-22T11:21:58.000Z (over 5 years ago)
- Last Synced: 2024-04-05T01:45:58.302Z (7 months ago)
- Topics: composer, html, mock-server, php, testing
- Language: PHP
- Homepage:
- Size: 143 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
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