Integrates PHPUnit with PHP-VCR using annotations.
Use @vcr cassette_name
on your tests to turn VCR automatically on and off.
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).');
}
}
- Install using composer:
composer require --dev covergenius/phpunit-testlistener-vcr
- Add listener to your
phpunit.xml
:
<extensions>
<bootstrap class="VCR\PHPUnit\TestListener\VCRTestListener" />
</extensions>
<listeners>
<listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/covergenius/phpunit-testlistener-vcr/src/VCRTestListener.php" />
</listeners>
PHPUnit-Testlistener-VCR depends on the following;
- PHP 8.1+
- PHPUnit >=10
- PHP 7.1+
- PHPUnit <10
In order to run all tests you need to get development dependencies using composer:
composer install
./vendor/bin/phpunit
The changelog is manage at PHPUnit testlistener for PHP-VCR releases page.
Copyright (c) 2013-2018 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details. Contributors