PHP-VCR Lightningtalk

11,763 views

Published on

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.

Published in: Internet, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
11,763
On SlideShare
0
From Embeds
0
Number of Embeds
9,585
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

PHP-VCR Lightningtalk

  1. 1. Lightningtalk by Adrian Philipp @liip 15.04.2014
  2. 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. 3. 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
  4. 4. 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:
  5. 5. PHPUnit ! /** * @vcr unittest_example.yml */ public function testShouldCrawlWebsite() { // do a request $crawler = new Crawler(); $crawler->crawl('http://example.com'); } Example PHPUnit integration
  6. 6. 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:
  7. 7. 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.
  8. 8. 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

×