demyan112rv / mountebank-api-php
PHP wrapper for mountebank API
Installs: 83 903
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 4
Forks: 2
Open Issues: 0
Requires
- php: >=7.4 <8.4
- ext-json: *
- guzzlehttp/guzzle: >=4.1.4
Requires (Dev)
- php-coveralls/php-coveralls: >=v2.0.0
- phpstan/phpstan: >=1.0 <3.0
- phpunit/phpunit: >=8.0 <11.0
This package is auto-updated.
Last update: 2024-10-22 20:28:21 UTC
README
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
Tests
Before run tests install dependencies, build Docker images and run containers:
composer install
docker-compose up
Enter the container php container and run tests:
docker exec -it mountebank_php bash
cd /var/www/mountebank-api-php
php vendor/bin/phpunit
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(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('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('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();