Download the PHP package aldidigitalservices/php-mock-collector without Composer
On this page you can find all versions of the php package aldidigitalservices/php-mock-collector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aldidigitalservices/php-mock-collector
More information about aldidigitalservices/php-mock-collector
Files in aldidigitalservices/php-mock-collector
Package php-mock-collector
Short Description A simple Mockserver in PHP that enables you to get the request that was send to the Mockserver (e.g. for Testing)
License MIT
Informations about the package php-mock-collector
How to use:
Install phpMockServer using composer
Create a new instance of phpMockServer and run the run methode:
After that you can define mocks in the mockfolder (By default it is ../mocks based from the phpMockServer.php file but can be configured by the constructor):
If you want to create a mock for /hello/world create the folders /hello/world and place a mock.json in it.
In this json file you can define different methodes (GET, POST, PUT, ...) and define the static response.
If you need it more flexible you can define a customcallback class implementing the customCallbackInterface and place it in a php file named by your classname in the mock folder and add the customCallback setting in the mock.json (see /hellophp/mock.json)
Configure the Mocks
You can configure the mock by the following options:
On top of this you can define wildcard routes. For that you have to place the configuration for the methode into an object with an path element that holds an regex:
rules
You can configure rules like this:
You can implement additional rules by implementing the ruleImplementationInterface.
Integrations
Codeception
You can use the Mock Request inside of codeceptiontests by adding the MockAwaitModule to your Testsuite:
Include Payload validation in external Tests
For every request to the mock server you can await the payload + additional data with the awaitcall function in clientDemo.php (This has to be transfered to a codeception module/helper). You can define a path , a methode (GET, POST, PUT, ...) and the timeout to wait for the response.
All versions of php-mock-collector with dependencies
symfony/http-foundation Version ^5.2
guzzlehttp/guzzle Version ^7.0
symfony/psr-http-message-bridge Version ^2.1
guzzlehttp/psr7 Version ^2.0
nyholm/psr7 Version ^1.4