Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

Mountebank API PHP

Latest Stable Version Total Downloads License PHPStan Build Status Coverage Status

What is the Mountebank? See original documentation for understanding.

This package is a php wrapper for mountebank API.

Install

composer require demyan112rv/mountebank-api-php

Usage basics

Response for stub

use Demyan112rv\MountebankPHP\Response;
use Demyan112rv\MountebankPHP\Response\Behavior;
        
$response = new Response(Response::TYPE_IS);
$response->setConfig([
    'statusCode' => 200,
    'headers' => ['Content-Type' => 'application/json'],
    'body' => ['foo' => 'bar']
])->addBehavior(
    (new Behavior())
        ->setType(Behavior::TYPE_WAIT)
        ->setConfig((new Behavior\Config\Wait())->setValue(500))
);

Predicate for stub

use Demyan112rv\MountebankPHP\Predicate;
use Demyan112rv\MountebankPHP\Predicate\XPath;
use Demyan112rv\MountebankPHP\Predicate\JsonPath;

$predicate = new Predicate(Predicate::OPERATOR_EQUALS);
$predicate->setConfig(['path' => '/test'])
    ->setXPath((new XPath())->setSelector('selector')->setNs(['foo' => 'bar']))
    ->setJsonPath((new JsonPath())->setSelector('selector'));

Stub for imposter

use Demyan112rv\MountebankPHP\Stub;

$stub = new Stub();
$stub->addResponse($response)->addPredicate($predicate);

Imposter for Mountebank

use Demyan112rv\MountebankPHP\Imposter;
use Demyan112rv\MountebankPHP\Mountebank;

$imposter = new Imposter();
$imposter->setName('Test imposter')
    ->setPort(1234)
    ->setProtocol(Imposter::PROTOCOL_HTTP)
    ->addStub($stub);

// Mountbank config client
$mb = new Mountebank(new \GuzzleHttp\Client());
$mb->setHost('http://localhost')->setPort(2525);

// Add new imposter
$response = $mb->addImposter($imposter);

// remove all imposters
$response = $mb->removeImposters();