PHP code example of jlaswell / vcr
1. Go to this page and download the library: Download jlaswell/vcr library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jlaswell / vcr example snippets
namespace Jlaswell\Weather\Tests;
use Jlaswell\VCR\VCR;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Jlaswell\Weather\Client as WeatherClient;
class ClientTest extends TestCase
{
// This will make a real request the first time and replay the request
// on future calls.
public function testCurrentWeather(): void
{
$cassette = VCR::insertCassette('weather-client');
$stack = HandlerStack::create();
$stack->push($cassette);
$client = new Client(['handler' => $stack]);
$weather = new WeatherClient($client)
$conditions = $weather->forZipcode('20252');
$this->assertEquals('Sunny', $conditions->simpleDescription);
$this->assertEquals('Sunny with a 30% chance of rain', $conditions->longDescription);
}
public function testAndRecordEveryTime(): void
{
$cassette = VCR::insertCassette('weather-client', Cassette::MODE_RECORD);
$stack = HandlerStack::create();
$stack->push($cassette);
// test logic
}
public function testAndOnlyReplayIfPresent(): void
{
$cassette = VCR::insertCassette('weather-client', Cassette::MODE_REPLAY);
$stack = HandlerStack::create();
$stack->push($cassette);
// test logic
}
}