MOVED to https://hub.docker.com/repository/docker/phpacto/mock-server
3.2K
Contract testing solution for your applications
If you want to know more about Contract Testing please read more here and here.
DISCLAIMER: This is a work in progress. The code can be subject to any changes without BC until the release version
1.0.0. Please use the issue tracker to report any enhancements or issues you encounter.
You can find some contract examples in examples directory.
First of all clone this repository git clone [email protected]:bigfoot90/phpacto.git
and install vendors with composer composer install.
Can use phpdotenv to load environment variables from file.
Validate your contracts with
bin/phpacto validate path-to/directory-or-single-file
Generate cURL commands from contracts with
bin/phpacto curl path-to/directory-or-single-file
You can use this server mock to provide mocked responses to your clients.
export ALLOW_ORIGIN=all # This adds CORS headers to the response
export CONTRACTS_DIR='where-are/your-contracts/stored'
php -S 0.0.0.0:8000 bin/server_mock.php
If there are not a Contract matching your request, the server cannot generate a response.
So a special Response with status code 418 will be returned.
You can create new contract file from an already working client-server application.
export CONTRACTS_DIR='where/new-contracts/will-be-stored/'
php -S 0.0.0.0:8000 bin/mock_proxy_recorder.php
Validate your contracts with
docker run -it --rm \
-v $PWD/contracts:/srv/data \
-e CONTRACTS_DIR=data \
-p 8000:8000 \
90bigfoot/phpacto \
validate
Generate cURL commands from contracts with
docker run -it --rm \
-v $PWD/contracts:/srv/data \
-e CONTRACTS_DIR=data \
-p 8000:8000 \
90bigfoot/phpacto \
curl
You can use this server mock to provide mocked responses to your clients.
docker run -it --rm \
-v $PWD/contracts:/srv/data \
-e CONTRACTS_DIR=data \
-p 8000:8000 \
90bigfoot/phpacto \
server_mock
If there are not a Contract matching your request, the server cannot generate a response.
So a special Response with status code 418 will be returned.
You can create new contract file from an already working client-server application.
docker run -it --rm \
-v $PWD/contracts:/srv/data \
-e CONTRACTS_DIR=data \
-e RECORDER_PROXY_TO=http://localhost/ \
-p 8000:8000 \
90bigfoot/phpacto \
mock_proxy_recorder
PHPacto is compatible with PHP ^7.1, PHPUnit ^7.0, Guzzle ^5.3.1|^6.0|^7.0.
If your project satisfies this requirements, you can run composer req --dev bigfoot90/phpacto and test
your contracts with phpunit, else you need to run contracts testing with PHPacto's CLI wich is slower but works with any kind of application.
If your test ends with so much verbose tracelog maybe your TestCase is not extending from Bigfoot\PHPacto\Test\PHPUnit\PHPactoTestCase, so add this line in your setUp method:
PHPUnit\Util\Blacklist\Blacklist::$blacklistedClassNames[__CLASS__] = 1;
See this Gist https://gist.github.com/bigfoot90/d4f146bacad359329d219a804f6cd12a
There are two different test files ConsumerTest.php and ProviderTest.php
Read the dedicated page here
Feel free to contribute by opening a pull request. Bug fixes or feature suggestions are always welcome.
Content type
Image
Digest
Size
33.7 MB
Last updated
almost 8 years ago
docker pull 90bigfoot/phpacto