PHP code example of demyan112rv / mountebank-api-php

1. Go to this page and download the library: Download demyan112rv/mountebank-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

demyan112rv / mountebank-api-php example snippets


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(Behavior::TYPE_WAIT))
        ->setConfig((new Behavior\Config\Wait())->setValue(500))
);
 
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('selector')));

use Demyan112rv\MountebankPHP\Stub;

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


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

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

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

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

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