PHP code example of mtk3d / laravel-http-vcr

1. Go to this page and download the library: Download mtk3d/laravel-http-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/ */

    

mtk3d / laravel-http-vcr example snippets


#[UseCassette('shopify/get-product')]
public function testGetProduct(): void
{
    $product = Http::get('https://shop.myshopify.com/admin/api/products/123.json')->json();

    $this->assertSame('T-Shirt', $product['title']);
}



use HttpVcr\Config;
use HttpVcr\Provider;

return Config::create(
    providers: [
        'shopify' => new Provider(hosts: ['*.myshopify.com'], 

#[UseCassette('shopify/get-product')]
public function testItAsksForTheRightProduct(): void
{
    Http::record();

    (new Shopify)->product('123');

    Http::assertSent(fn (Request $request) => str_contains($request->url(), '/products/123'));
}

#[UseCassette('shopify/get-product', mode: RecordMode::PlaybackOnly)]
public function testGetProduct(): void
{
    Http::preventStrayRequests();   // in your base TestCase, most likely

    $product = (new Shopify)->product('123');   // replayed, not stray
}

Http::allowStrayRequests(['https://shop.myshopify.com/*']);