lzakrzewski / r2d2

R2D2 - DeathStar API consumer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

r2d2 Build Status

R2D2 - DeathStar API consumer

Demo

example-output

Live API

https://death-star-api.herokuapp.com/

Requirements

  • docker
    or
  • composer && "php": ">=7.2", "ext-json": "*"

Installation & usage

  1. Clone repo
  2. Run composer install or make build
  3. Run bin/console r2d2 or make r2d2

Implementation

ApiConsumer

DeathStarApiConsumer

Contract testing

Contract - The set of pre-defined requests and expected responses. In order to ensure that our integration has been implemented correctly we might need to perform an end to end test between an API provider and an API consumer. This test can assert that the API provider returns expected responses for a set of pre-defined requests by the API consumer. Unfortunately, "end to end" tests with API provider and API consumer involved are expensive in terms of time and resources. In case of any change in our API provider we might need to perform e2e testing again. I think it is much better to test against shared contract rather than perform e2e test every time, so I decided to introduce contract test-suite instead of end to end test-suite.

Ports & Adapters Pattern

In order to satisfy goal of Contract testing and follow the single responsibility principle, I decided to extract DeathStarApiAdapter interface and use multiple implementations of this interface:

interface DeathStarApiAdapter
{
    /**
     * @param string $method
     * @param string $uri
     * @param array  $options
     *
     * @throws DeathStarApiException
     *
     * @return array
     */
    public function request(string $method, string $uri, array $options): array;
}

Implementations:

About

R2D2 - DeathStar API consumer


Languages

Language:PHP 98.8%Language:Makefile 1.2%