Skip to content

piotrrepetowski/service-double

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Service Double

Tool that simplifies creation of fake http based services.

Example - fake implementation of JSONRpc service:

  1. Define which method should be mocked:
<?xml version="1.0" encoding="utf-8"?>
<!-- config/config.xml -->
<handlers>
    <handler response="foo_response.xml">
        <matcher type="equals" name="request.method" value="foo" />
    </handler>
    ...
</handlers>

Response attributes tell where is stored information about response. Matcher tells when this response should be returned.

Currently supported matchers:

  • any - always true,
  • none - always false,
  • equals - matches whether specified attribute (see below for more details) has specified value,
  • logical and - true when submatchers returns true, false otherwise.

Currently supported attributes:

  • request.method - represents http method used in request,
  • request.jsonrpc - represents jsonrpc attributes,
  • request.get - represents query string attributes.

Request attributes may be nested e.g.:

{
 "result": {
  "name": "foo"
 },
 "errors": null,
 "id": 12
}

To use value of name in matcher definition reference to it with result.data.name.

<matcher type="equals" name="request.jsonrpc.result.name" value="foo" />
  1. Define proxy to use original service for other calls:
<?xml version="1.0" encoding="utf-8"?>
<!-- config/config.xml -->
<handlers>
    ...
    <handler url="http://localhost:3500">
        <matcher type="any" />
    </handler>
</handlers>
  1. Define response
<?xml version="1.0" encoding="utf-8"?>
<!-- config/foo_response.xml -->
<response>
    <body><![CDATA[FOO]]></body>
</response>

This response will return "FOO".

  1. Run Service Double server:
bin/service_double.sh start

and use your new service.

About

PHP based tool for stubing jsonrpc server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published