Record HTTP interactions in your tests and replay them during future test runs for fast, deterministic and accurate tests. This is a PHP fork of the fabulous VCR for ruby library.
2. Record HTTP interactions in your tests
...and replay them during future test runs for fast,
deterministic and accurate tests.
Port of the VCR library for ruby
3.
4. Why?
Much faster tests
Independent of API
Inspect HTTP requests
Deterministic tests (no rate limits, external errors)
See if external APIs change (version control of recordings)
See when unexpected HTTP requests happen
No manual mocking
5. Usage
!
// start interception
VCR::turnOn();
!
// start recording
VCR::insertCassette('unittest_example.yml');
!
// do a request
file_get_contents('http://example.com');
!
// stop recording
VCR::eject();
!
// stop interception
VCR::turnOff();
Example usage with plain PHP:
7. Record
request:
method: GET
url: 'http://example.com'
headers:
Host: example.com
User-Agent: 'Guzzle/3.8.1 curl/7.30.0 PHP/5.4.16'
response:
status: 302
headers:
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: 'Wed, 26 Feb 2014 21:50:54 GMT'
Etag: '"359670651"'
Expires: 'Wed, 05 Mar 2014 21:50:54 GMT'
Last-Modified: 'Fri, 09 Aug 2013 23:54:35 GMT'
Server: 'EOS (lax004/45BF)'
Content-Length: '1270'
body: "<!doctype html><html><head>…"
Example recording in YAML format:
8. Disclaimer
Not so easy in PHP (no monkey patching)
How it works: Replacing function calls on
the fly using a stream wrapper filter when
including PHP files.
9. Info
Info and documentation: http://php-
vcr.github.io
Source: https://github.com/php-vcr/php-vcr
VCR (ruby): https://github.com/vcr/vcr
Follow: @adrian_philipp @lapistano