Last Updated: February 25, 2016
·
2.397K
· adri

PHP-VCR: Integration with PHPUnit

Date: 2013-11-02
Title: PHP-VCR: Integration with PHPUnit

Install PHP-VCR PHPUnit-Testlistener in order to integrate PHP-VCR with PHPUnit.

# Add PHPUnit testlistener
php composer.phar require php-vcr/phpunit-testlistener-vcr

You can use the @vcr [cassette filename] annotation to turn on PHP-VCR for a single test.

/**
 * @vcr [cassette filename]
 */
public function testInterceptsWithAnnotations()
{
    file_get_contents('http://example.com');
}

Replace [cassette filename] with the path to your cassette file relative to the cassette path (default tests/fixtures). Requests are intercepted and stored into the cassette file provided via the @vcr annotation. PHP-VCR is automatically turned on and off.