ArtisanTinkerer.github.io

Blog

View on GitHub

https://laracasts.com/lessons/testing-http-requests

Testing HTTP Requests

Don’t want to hit API everytime.

PHP-VCR

Turn on, record

Want to get the data without calling the API.

public function test_intercepts_successfully()
{
  VCR::turnOn();
  VCR::insertCassete('google');
  
  file_get_contents("www.google.com");
  
  VCR::eject();
  VCR::turnOff();
}

Next time it is called, it will use the file instead of making thre request.

Next level is adding listener to phpunit.xml. Then you can just add @vcr comment.

Is VCR outdated?