PHP code example of covergenius / phpunit-testlistener-vcr

1. Go to this page and download the library: Download covergenius/phpunit-testlistener-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/ */

    

covergenius / phpunit-testlistener-vcr example snippets

 php

use PHPUnit\Framework\TestCase;
use VCR\PHPUnit\TestListener\Attributes\Vcr;

class VCRTest extends TestCase
{
    /**
     * @vcr unittest_annotation_test
     */
    public function testInterceptsWithAnnotations()
    {
        // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy".
        $result = file_get_contents('http://google.com');
        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');
    }

    #[Vcr('unittest_annotation_test')]
    public function testInterceptsWithAttributes(): void
    {
        // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy".
        $result = file_get_contents('http://google.com');
        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using attributes).');
    }
}
 xml
<listeners>
    <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/covergenius/phpunit-testlistener-vcr/src/VCRTestListener.php" />
</listeners>
 php
composer install
./vendor/bin/phpunit