Skip to content
forked from php-vcr/php-vcr

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

License

Notifications You must be signed in to change notification settings

benzittlau/php-vcr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-VCR

This is a port of VCR for ruby.

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

Features

  • Automatically records and replays your HTTP(s) interactions with minimal setup/configuration code.
  • Supports common http functions and extensions
    • everyting using streamWrapper: fopen(), fread(), file_get_contents(), ... without any modification
    • SoapClient using your own wrapper class
    • curl(), using runkit extension and runkit.internal_override=1 in your php.ini
    • Todo: curl_multi()
  • The same request can receive different responses in different tests--just use different cassettes.
  • Disables all HTTP requests that you don't explicitly allow (except SoapClient if not configured).
  • Request matching is configurable based on HTTP method, URI, host, path, body and headers, or you can easily implement a custom request matcher to handle any need.
  • The recorded requests and responses are stored on disk in a serialization format of your choice (currently YAML and JSON are built in, and you can easily implement your own custom serializer)
  • Todo: Recorded requests and responses can easily be inspected and edited.
  • Todo: Supports PHPUnit annotations.
  • Todo: Automatically filters confidential or private information like passwords, auth tokens and emails.
  • Todo: Automatically re-records cassettes on a configurable regular interval to keep them fresh and current.

Usage example

Using annotations:

class VCRTest extends \PHPUnit_Framework_TestCase { public function setUp() { // Initialize VCR VCR::init(); } public function testNoCassetteUsed() { // Now all HTTP requests will be intercepted, an exception is thrown // if you don't provide a @VCR:useCassette($name) annotation, example: $this->setExpectedException('\BadMethodCallException'); file_get_contents('http://example.com'); } /**  * You can use a test method annotation...  * @VCR:useCassette('example')  */ public function testUsingAnnotation() { // Following request will be recorded once and replayed in furture test runs $result = file_get_contents('http://example.com'); $this->assertNotEmpty($result); } }

Using inline method calls:

class VCRTest extends \PHPUnit_Framework_TestCase { public function setUp() { // Initialize VCR VCR::init(); } public function testUsingInlineMethodCall() { // .... or use an inline method call VCR::useCassette('example'); // Following request will be recorded once and replayed in furture test runs $result = file_get_contents('http://example.com'); $this->assertNotEmpty($result); } public function tearDown() { // When using inline method calls, make sure to clean up after every test // This is not needed when using annotations VCR::eject(); } }

Installation

There is no release yet, sorry.

git clone git@github.com:adri/php-vcr cd php-vcr composer install --dev phpunit tests

Dependencies

PHP-VCR depends on:

  • PHP 5.3+
  • Curl extension
  • HTTP library Guzzle
  • symfony/yaml
  • beberlei/assert
  • (optional) runkit extension with runkit.internal_override=1 in php.ini if you want to intercept curl

Composer installs all depenencies except extensions like curl or runkit.

Run tests

In order to run all tests you need to get development dependencies using composer:

composer install -dev phpunit ./tests

Changelog

  • 2013-02-22 Added YAML support
  • 2013-02-21 Added custom request matcher
  • 2013-02-21 Added JSON storage which uses less memory
  • 2013-02-21 Added support for binary data
  • 2013-02-20 Added Soap support
  • 2013-02-19 Curl hook fixes, more tests
  • 2013-02-18 First prototype

Copyright

Copyright (c) 2013 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details.

About

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%