Download the PHP package edmondscommerce/mock-server without Composer

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

Mock Web Server and Router

By Edmonds Commerce

Codacy Badge Build Status Scrutinizer Code Quality Code Coverage

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

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 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

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 routerBottom.php which handle some basic boilerplate for you.

Template

Here is a template router for you to start with:

Starting the server manually

To start the server manually, you can simply use start-mock-server which will start a backgrounded mock server. If you want it in the foreground, simply pass "foreground" as an argument

If you want the server to listen on a specific IP address, you can do this by exporting a config variable:

Router Types

Static Files (css/js/html/etc...)

Static files that are located in the htdocs folder will be served without any further configuration

For the full list of support file types, see: StaticRouter::STATIC_EXTENSIONS_SUPPORTED

Callback

The callback router sets a closure which will be passed the request object and must return a response object.

See this test for an exmaple of a callback.

File Download

The download router will return a file as a download. Internally it sets a callback that then returns a BinaryFileResponse object

Static Text

Second param of addRoute($uri, $response) is the text that will be returned after visiting specified uri.

See this test for an example of text route.

Static

Second param of addStaticRuote($uri, $response) is the the file content that will be returned after visiting specified uri.

Do not use this to return files that are in the htdocs folder, it's pointless. This is largely being kept for legacy reasons.


All versions of mock-server with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1
ext-fileinfo Version *
symfony/http-foundation Version ~4
symfony/routing Version ~4
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 edmondscommerce/mock-server contains the following files

Loading the files please wait ....