A contract testing solution
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci travis-ci Nov 6, 2017
bin
docs
examples
src
tests
.codacy.yml
.dockerignore updates Nov 19, 2017
.gitignore
.php_cs
.scrutinizer.yml
.travis.yml
BANNER
Dockerfile
LICENSE.md
README.md
code of conduct.md
composer.json
composer.lock
entrypoint.sh
phpunit.xml.dist

README.md

PHPacto

Contract testing solution for your applications

If you want to know more about Contract Testing please read more here and here.

License Build Status CodeCov Scrutinizer Quality Score Codacy Quality Grade Latest Stable Version Total Downloads

Docker Build Status Docker Image Size Docker Pulls Docker Stars

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.

Usage standalone CLI

First of all clone this repository git clone git@github.com:bigfoot90/phpacto.git and install vendors with composer composer install

Validate

Validate your contracts with

bin/phpacto validate path-to/directory-or-single-file

cURL command generator

Generate cURL commands from contracts with

bin/phpacto validate path-to/directory-or-single-file

Server Mock

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

Mock Proxy Recorder

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

Usage standalone CLI with Docker

Validate

Validate your contracts with

docker run -it --rm \
    -v $PWD/contracts:/srv/data \
    -e CONTRACTS_DIR=data \
    -p 8000:8000 \
    90bigfoot/phpacto \
    validate

cURL command generator

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

Server Mock

You can use this server mock to provide mocked responses to your clients.

docker run -it --rm \
    -v $PWD/contracts:/srv/data \
    -e ALLOW_ORIGIN=all \
    -e CONTRACTS_DIR=data \
    -p 8000:8000 \
    90bigfoot/phpacto \
    server_mock

Mock Proxy Recorder

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

Testing your application with PHPUnit and PHPacto

PHPacto is compatible with PHP ^7.1, PHPUnit ^6|^7, Guzzle ^5.3.1|^6.

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.

Integration with PHPUnit

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;

Integration with Guzzle

Need to write ...

Mastering with PHPacto contract Rules

Documentaion is coming ...